RFE #925817, better page selector with flexible jumping/pagination controls
This commit is contained in:
@@ -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.
|
||||
|
@@ -112,25 +112,16 @@ $pageNow = @floor($pos / $session_max_rows) + 1;
|
||||
$nbTotalPage = @ceil($the_total / $session_max_rows);
|
||||
|
||||
if ($the_total > $per_page) {
|
||||
$gotopage = '<br />' . $GLOBALS['strPageNumber']
|
||||
. '<select name="goToPage" onchange="goToUrl(this, \'browse_foreigners.php?field=' . urlencode($field) . '&' . PMA_generate_common_url($db, $table) . $pk_uri . '&fieldkey=' . (isset($fieldkey) ? $fieldkey : '') . '&\');">';
|
||||
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 .= ' <option ' . $selected . ' value="' . (($i - 1) * $session_max_rows) . '">' . $i . '</option>' . "\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 = '';
|
||||
}
|
||||
|
@@ -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 = '<br />' . $GLOBALS['strPageNumber']
|
||||
. '<select name="goToPage" onchange="goToUrl(this, \'' . $url . '\');">' . "\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 .= ' <option ' . $selected . ' value="' . (($i - 1) * $rows) . '">' . $i . '</option>' . "\n";
|
||||
}
|
||||
|
||||
$gotopage .= ' </select>';
|
||||
|
||||
return $gotopage;
|
||||
}
|
||||
|
||||
} // end if: minimal common.lib needed?
|
||||
|
||||
?>
|
||||
|
@@ -349,29 +349,20 @@ function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
|
||||
<td>
|
||||
<?php //<form> for keep the form alignment of button < and << ?>
|
||||
<form>
|
||||
<?php echo $GLOBALS['strPageNumber']; ?>
|
||||
<select name="goToPage" onchange="goToUrl(this, '<?php echo "sql.php?sql_query=".$encoded_query."&session_max_rows=".$session_max_rows."&disp_direction=".$disp_direction."&repeat_cells=".$repeat_cells."&goto=".$goto."&dontlimitchars=".$dontlimitchars."&".PMA_generate_common_url($db, $table)."&"; ?>')">
|
||||
|
||||
<?php
|
||||
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 = "";
|
||||
}
|
||||
echo " <option ".$selected." value=\"".(($i - 1) * $session_max_rows)."\">".$i."</option>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
<?php echo PMA_pageselector(
|
||||
'sql.php?sql_query=' . $encoded_query .
|
||||
'&session_max_rows=' . $session_max_rows .
|
||||
'&disp_direction=' . $disp_direction .
|
||||
'&repeat_cells=' . $repeat_cells .
|
||||
'&goto=' . $goto .
|
||||
'&dontlimitchars=' . $dontlimitchars .
|
||||
'&' . PMA_generate_common_url($db, $table) .
|
||||
'&',
|
||||
$session_max_rows,
|
||||
$pageNow,
|
||||
$nbTotalPage
|
||||
);
|
||||
?>
|
||||
</form>
|
||||
</td>
|
||||
<?php
|
||||
|
Reference in New Issue
Block a user