From e1a5b9c54f3ea112a0ce5b2f0f3a0ace9583a354 Mon Sep 17 00:00:00 2001 From: "Jehan-Guillaume (ioguix) de Rorthais" Date: Fri, 17 Aug 2012 21:12:00 +0200 Subject: [PATCH] Makes display more plugin friendly Plugins might need (at least Report) to set parameters in the URL and use them in their code while working with display.php. This patch makes sure their URL parameters are not lost while clicking on sort or pager links when navigating in the result set. Nice side effect: cleaner code (hopefuly with no bug...). --- classes/Misc.php | 30 +++++++++---------- display.php | 76 +++++++++++++++++------------------------------- 2 files changed, 42 insertions(+), 64 deletions(-) diff --git a/classes/Misc.php b/classes/Misc.php index d26a45eb..7264b542 100644 --- a/classes/Misc.php +++ b/classes/Misc.php @@ -1627,12 +1627,12 @@ /** * Do multi-page navigation. Displays the prev, next and page options. - * @param $page the page currently viewed - * @param $pages the maximum number of pages - * @param $url the url to refer to with the page number inserted - * @param $max_width the number of pages to make available at any one time (default = 20) + * @param $page - the page currently viewed + * @param $pages - the maximum number of pages + * @param $gets - the parameters to include in the link to the wanted page + * @param $max_width - the number of pages to make available at any one time (default = 20) */ - function printPages($page, $pages, $url, $max_width = 20) { + function printPages($page, $pages, $gets, $max_width = 20) { global $lang; $window = 10; @@ -1641,13 +1641,15 @@ if ($pages < 0) return; if ($max_width <= 0) return; + unset ($get['page']); + $url = http_build_query($gets); + if ($pages > 1) { echo "

\n"; if ($page != 1) { - $temp = str_replace('%s', 1, $url); - echo "{$lang['strfirst']}\n"; - $temp = str_replace('%s', $page - 1, $url); - echo "{$lang['strprev']}\n"; + echo "{$lang['strfirst']}\n"; + $temp = $page - 1; + echo "{$lang['strprev']}\n"; } if ($page <= $window) { @@ -1669,15 +1671,13 @@ $max_page = min($max_page, $pages); for ($i = $min_page; $i <= $max_page; $i++) { - $temp = str_replace('%s', $i, $url); - if ($i != $page) echo "$i\n"; + if ($i != $page) echo "$i\n"; else echo "$i\n"; } if ($page != $pages) { - $temp = str_replace('%s', $page + 1, $url); - echo "{$lang['strnext']}\n"; - $temp = str_replace('%s', $pages, $url); - echo "{$lang['strlast']}\n"; + $temp = $page + 1; + echo "{$lang['strnext']}\n"; + echo "{$lang['strlast']}\n"; } echo "

\n"; } diff --git a/display.php b/display.php index 1a9cf8f3..4d0f87ae 100644 --- a/display.php +++ b/display.php @@ -294,7 +294,7 @@ /* Print table header cells * @param $sortLink must be urlencoded already * */ - function printTableHeaderCells(&$rs, $sortLink, $withOid) { + function printTableHeaderCells(&$rs, $args, $withOid) { global $misc, $data, $conf; $j = 0; @@ -310,12 +310,19 @@ echo "", $misc->printVal($finfo->name), "\n"; } else { - echo "", - $misc->printVal($finfo->name), "\n"; + $args['sortdir'] = ( + $_REQUEST['sortdir'] == 'asc' + and $_REQUEST['sortkey'] == ($j + 1) + ) ? 'desc' : 'asc'; + + $sortLink = http_build_query($args); + + echo "" + , $misc->printVal($finfo->name) + , "\n"; } $j++; } @@ -454,6 +461,7 @@ } } else { $misc->printTitle($lang['strqueryresults']); + /*we comes from sql.php, $_SESSION['sqlquery'] has been set there */ $type = 'QUERY'; } @@ -490,47 +498,17 @@ $fkey_information =& getFKInfo(); - // Build strings for GETs - $gets = $misc->href; - if (isset($object)) $gets .= "&" . urlencode($subject) . '=' . urlencode($object); - if (isset($subject)) $gets .= "&subject=" . urlencode($subject); - if (isset($_REQUEST['query'])) $gets .= "&query=" . urlencode($_REQUEST['query']); - if (isset($_REQUEST['count'])) $gets .= "&count=" . urlencode($_REQUEST['count']); - if (isset($_REQUEST['return'])) $gets .= "&return=" . urlencode($_REQUEST['return']); - if (isset($_REQUEST['search_path'])) $gets .= "&search_path=" . urlencode($_REQUEST['search_path']); - if (isset($_REQUEST['table'])) $gets .= "&table=" . urlencode($_REQUEST['table']); - - // Build strings for GETs in array - $_gets = array( - 'server' => $_REQUEST['server'], - 'database' => $_REQUEST['database'] - ); - - if (isset($_REQUEST['schema'])) $_gets['schema'] = $_REQUEST['schema']; - if (isset($object)) $_gets[$subject] = $object; - if (isset($subject)) $_gets['subject'] = $subject; - if (isset($_REQUEST['query'])) $_gets['query'] = $_REQUEST['query']; - if (isset($_REQUEST['count'])) $_gets['count'] = $_REQUEST['count']; - if (isset($_REQUEST['return'])) $_gets['return'] = $_REQUEST['return']; - if (isset($_REQUEST['search_path'])) $_gets['search_path'] = $_REQUEST['search_path']; - if (isset($_REQUEST['table'])) $_gets['table'] = $_REQUEST['table']; - - // This string just contains sort info - $getsort = "sortkey=" . urlencode($_REQUEST['sortkey']) . - "&sortdir=" . urlencode($_REQUEST['sortdir']); - - // This array only contains sort info - $_getsort = array( - 'sortkey' => $_REQUEST['sortkey'], - 'sortdir' => $_REQUEST['sortdir'] - ); + // Build array OF parameters for sorts/pages links + $_gets = $_REQUEST; + unset($_gets['query']); + unset($_gets['MAX_FILE_SIZE']); if ($save_history && is_object($rs) && ($type == 'QUERY')) //{ $misc->saveScriptHistory($_REQUEST['query']); if (is_object($rs) && $rs->recordCount() > 0) { // Show page navigation - $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&{$gets}&{$getsort}&nohistory=t&strings=" . urlencode($_REQUEST['strings'])); + $misc->printPages($_REQUEST['page'], $max_pages, $_gets); echo "\n"; @@ -556,7 +534,7 @@ 'action' => 'confeditrow', 'strings' => $_REQUEST['strings'], 'page' => $_REQUEST['page'], - ), $_gets, $_getsort) + ), $_gets) ) ) ), @@ -569,7 +547,7 @@ 'action' => 'confdelrow', 'strings' => $_REQUEST['strings'], 'page' => $_REQUEST['page'], - ), $_gets, $_getsort) + ), $_gets) ) ) ), @@ -583,7 +561,7 @@ foreach (array_keys($actions['actionbuttons']) as $action) { $actions['actionbuttons'][$action]['attr']['href']['urlvars'] = array_merge( $actions['actionbuttons'][$action]['attr']['href']['urlvars'], - $_gets, $_getsort + $_gets ); } @@ -596,7 +574,7 @@ echo "\n"; /* we show OIDs only if we are in TABLE or SELECT type browsing */ - printTableHeaderCells($rs, $gets, isset($object)); + printTableHeaderCells($rs, $_gets, isset($object)); echo "\n"; @@ -655,7 +633,7 @@ echo "

", $rs->recordCount(), " {$lang['strrows']}

\n"; // Show page navigation - $misc->printPages($_REQUEST['page'], $max_pages, "display.php?page=%s&{$gets}&{$getsort}&strings=" . urlencode($_REQUEST['strings'])); + $misc->printPages($_REQUEST['page'], $max_pages, $_gets); } else echo "

{$lang['strnodata']}

\n"; @@ -707,7 +685,7 @@ 'href' => array ( 'url' => 'display.php', 'urlvars' => array_merge( - $_gets, $_getsort, + $_gets, array ( 'strings' => 'collapsed', 'page' => $_REQUEST['page'] @@ -722,7 +700,7 @@ 'href' => array ( 'url' => 'display.php', 'urlvars' => array_merge( - $_gets, $_getsort, + $_gets, array ( 'strings' => 'expanded', 'page' => $_REQUEST['page'] @@ -789,7 +767,7 @@ 'href' => array ( 'url' => 'display.php', 'urlvars' => array_merge( - $_gets, $_getsort, + $_gets, array( 'strings' => $_REQUEST['strings'], 'page' => $_REQUEST['page'] -- 2.39.5
{$lang['stractions']}