From 2a3da9f8f6c45cf02db74cffb37a4ae938ee08ab Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Tue, 2 Nov 2004 15:47:19 +0000 Subject: [PATCH] RFE #925817, better page selector with flexible jumping/pagination controls --- ChangeLog | 4 ++ browse_foreigners.php | 29 ++++-------- libraries/common.lib.php | 88 +++++++++++++++++++++++++++++++++++ libraries/display_tbl.lib.php | 37 ++++++--------- 4 files changed, 116 insertions(+), 42 deletions(-) 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'] - . '' . "\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 .= ' ' . "\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 << ?>
- - +