diff --git a/ChangeLog b/ChangeLog index d53c3b31d..3136ea68b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,10 @@ $Source$ 2004-11-09 Garvin Hicking + * libraries/display_tbl.lib.php, libraries/common.lib.php, + browse_foreigners.php: RFE #925817 - Abstracted page selector to + its own function, now create sloped pagination to easily jump + to any wanted page. * read_dump.php: RFE #1053039, show filename of uploaded SQL file * sql.php, tbl_indexes.php, libraries/tbl_indexes.lib.php, lang/*: Added checks for common problems with table indices. diff --git a/browse_foreigners.php b/browse_foreigners.php index 4aa582602..5925f05ce 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -112,25 +112,16 @@ $pageNow = @floor($pos / $session_max_rows) + 1; $nbTotalPage = @ceil($the_total / $session_max_rows); if ($the_total > $per_page) { - $gotopage = '' . $GLOBALS['strPageNumber'] - . ''; - if ($nbTotalPage < 200) { - $firstPage = 1; - $lastPage = $nbTotalPage; - } else { - $range = 20; - $firstPage = ($pageNow - $range < 1 ? 1 : $pageNow - $range); - $lastPage = ($pageNow + $range > $nbTotalPage ? $nbTotalPage : $pageNow + $range); - } - - for ($i=$firstPage; $i<=$lastPage; $i++){ - if ($i == $pageNow) { - $selected = 'selected="selected"'; - } else { - $selected = ''; - } - $gotopage .= ' ' . $i . '' . "\n"; - } + $gotopage = PMA_pageselector( + 'browse_foreigners.php?field=' . urlencode($field) . + '&' . PMA_generate_common_url($db, $table) + . $pk_uri . + '&fieldkey=' . (isset($fieldkey) ? $fieldkey : '') . + '&', + $session_max_rows, + $pageNow, + $nbTotalPage + ); } else { $gotopage = ''; } diff --git a/libraries/common.lib.php b/libraries/common.lib.php index b6f08bff8..6ef9954f5 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -2335,6 +2335,94 @@ if (typeof(document.getElementById) != 'undefined' } } // end function + /** + * Generate a pagination selector for browsing resultsets + * + * @param string URL for the JavaScript + * @param string Number of rows in the pagination set + * @param string current page number + * @param string number of total pages + * @param string If the number of pages is lower than this + * variable, no pages will be ommitted in + * pagination + * @param string How many rows at the beginning should always + * be shown? + * @param string How many rows at the end should always + * be shown? + * @param string Percentage of calculation page offsets to + * hop to a next page + * @param string Near the current page, how many pages should + * be considered "nearby" and displayed as + * well? + * + * @access public + * @author Garvin Hicking (pma@supergarv.de) + */ + function PMA_pageselector($url, $rows, $pageNow = 1, $nbTotalPage = 1, $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20, $range = 10) { + $gotopage = '' . $GLOBALS['strPageNumber'] + . '' . "\n"; + if ($nbTotalPage < $showAll) { + $pages = range(1, $nbTotalPage); + } else { + $pages = array(); + + // Always show first X pages + for ($i = 1; $i <= $sliceStart; $i++) { + $pages[] = $i; + } + + // Always show last X pages + for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++) { + $pages[] = $i; + } + + // garvin: Based on the number of results we add the specified $percent percentate to each page number, + // so that we have a representing page number every now and then to immideately jump to specific pages. + // As soon as we get near our currently chosen page ($pageNow - $range), every page number will be + // shown. + $i = $sliceStart; + $x = $nbTotalPage - $sliceEnd; + $met_boundary = false; + while($i <= $x) { + if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range)) { + // If our pageselector comes near the current page, we use 1 counter increments + $i++; + $met_boundary = true; + } else { + // We add the percentate increment to our current page to hop to the next one in range + $i = $i + floor($nbTotalPage / $percent); + + // Make sure that we do not cross our boundaries. + if ($i > ($pageNow - $range) && !$met_boundary) { + $i = $pageNow - $range; + } + } + + if ($i > 0 && $i <= $x) { + $pages[] = $i; + } + } + + // Since because of ellipsing of the current page some numbers may be double, + // we unify our array: + sort($pages); + $pages = array_unique($pages); + } + + foreach($pages AS $i) { + if ($i == $pageNow) { + $selected = 'selected="selected" style="font-weight: bold"'; + } else { + $selected = ''; + } + $gotopage .= ' ' . $i . '' . "\n"; + } + + $gotopage .= ' '; + + return $gotopage; + } + } // end if: minimal common.lib needed? ?> diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index f220cce93..8b9081d74 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -349,29 +349,20 @@ function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query) for keep the form alignment of button < and << ?> - - ')"> - - $nbTotalPage ? $nbTotalPage : $pageNow + $range); - } - for ($i=$firstPage; $i<=$lastPage; $i++){ - if ($i == $pageNow) { - $selected = 'selected="selected"'; - } else { - $selected = ""; - } - echo " ".$i."\n"; - } - ?> - - +