Ignore:
Timestamp:
Apr 16, 2016, 9:53:17 PM (9 years ago)
Author:
chronos
Message:
  • Added: Allow to independently select table page and column order. This solves a problem where going between pages with tables incorrectly set default ordering column.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Global.php

    r824 r825  
    131131}
    132132
    133 function GetPageList($TotalCount)
     133function GetPageList($ObjectName, $TotalCount)
    134134{
    135135  global $System;
     
    149149  }
    150150
    151   if(!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
    152   if(array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
    153   if($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
    154   if($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
    155   $CurrentPage = $_SESSION['Page'];
    156 
     151  if(!array_key_exists($ObjectName.'Page', $_SESSION)) $_SESSION[$ObjectName.'Page'] = 0;
     152  if(array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName)) {
     153    if(array_key_exists('page', $_GET)) $_SESSION[$ObjectName.'Page'] = $_GET['page'] * 1;
     154  }
     155  if($_SESSION[$ObjectName.'Page'] < 0) $_SESSION[$ObjectName.'Page'] = 0;
     156  if($_SESSION[$ObjectName.'Page'] >= $PageCount) $_SESSION[$ObjectName.'Page'] = $PageCount - 1;
     157  $CurrentPage = $_SESSION[$ObjectName.'Page'];
    157158
    158159  $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> &nbsp; Stránky: ';
     160  $QueryItems['ObjectName'] = $ObjectName;
    159161
    160162  $Result = '';
     
    206208$OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
    207209
    208 function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
     210function GetOrderTableHeader($ObjectName, $Columns, $DefaultColumn, $DefaultOrder = 0)
    209211{
    210212  global $OrderDirSQL, $OrderArrowImage, $Config, $System;
    211213
    212   if(array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
    213   if(array_key_exists('OrderDir', $_GET)) $_SESSION['OrderDir'] = $_GET['OrderDir'];
    214   if(!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
    215   if(!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
    216 
     214  if(array_key_exists('ObjectName', $_GET) and ($_GET['ObjectName'] == $ObjectName))
     215  {
     216    if(array_key_exists('OrderCol', $_GET)) $_SESSION[$ObjectName.'OrderCol'] = $_GET['OrderCol'];
     217    if(array_key_exists('OrderDir', $_GET)) $_SESSION[$ObjectName.'OrderDir'] = $_GET['OrderDir'];
     218  }
     219  if(!array_key_exists($ObjectName.'OrderCol', $_SESSION)) $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn;
     220  if(!array_key_exists($ObjectName.'OrderDir', $_SESSION) ) $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder;
     221   
    217222  // Check OrderCol
    218223  $Found = false;
    219224  foreach($Columns as $Column)
    220225  {
    221     if($Column['Name'] == $_SESSION['OrderCol'])
     226    if($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])
    222227    {
    223228      $Found = true;
     
    225230    }
    226231  }
    227   if(($_SESSION['OrderCol'] == '') or ($Found == false))
    228   {
    229     $_SESSION['OrderCol'] = $DefaultColumn;
    230     $_SESSION['OrderDir'] = $DefaultOrder;
     232  if(($_SESSION[$ObjectName.'OrderCol'] == '') or ($Found == false))
     233  {
     234    $_SESSION[$ObjectName.'OrderCol'] = $DefaultColumn;
     235    $_SESSION[$ObjectName.'OrderDir'] = $DefaultOrder;
    231236  }
    232237  // Check OrderDir
    233   if(($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
     238  if(($_SESSION[$ObjectName.'OrderDir'] != 0) and ($_SESSION[$ObjectName.'OrderDir'] != 1))
     239    $_SESSION[$ObjectName.'OrderDir'] = 0;
    234240
    235241  $Result = '';
     
    237243  foreach($Columns as $Index => $Column)
    238244  {
     245    $QueryItems['ObjectName'] = $ObjectName;
    239246    $QueryItems['OrderCol'] = $Column['Name'];
    240     $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
    241     if($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.$System->Link('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow">';
     247    $QueryItems['OrderDir'] = 1 - $_SESSION[$ObjectName.'OrderDir'];
     248    if($Column['Name'] == $_SESSION[$ObjectName.'OrderCol'])
     249      $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.
     250      $System->Link('/images/'.$OrderArrowImage[$_SESSION[$ObjectName.'OrderDir']]).'" alt="order arrow">';
    242251      else $ArrowImage = '';
    243252    if($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
     
    245254  }
    246255  return(array(
    247     'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']],
     256    'SQL' => ' ORDER BY `'.$_SESSION[$ObjectName.'OrderCol'].'` '.$OrderDirSQL[$_SESSION[$ObjectName.'OrderDir']],
    248257    'Output' => '<tr>'.$Result.'</tr>',
    249     'Column' => $_SESSION['OrderCol'],
    250     'Direction' => $_SESSION['OrderDir'],
     258    'Column' => $_SESSION[$ObjectName.'OrderCol'],
     259    'Direction' => $_SESSION[$ObjectName.'OrderDir'],
    251260  ));
    252261}
     
    365374    if($Delay < 0) $Delay = 0;
    366375
    367     echo('Waiting remaining '.$Delay.' of '.$Period.' seconds...'."\n");
     376    echo('Waiting remaining '.$Delay.' of '.$Period.' seconds period...'."\n");
    368377    sleep($Delay);
    369378  }
Note: See TracChangeset for help on using the changeset viewer.