Changeset 20 for base.php


Ignore:
Timestamp:
Oct 22, 2008, 9:31:11 AM (16 years ago)
Author:
george
Message:
  • Upraveno: Redukce použité paměti změnou načítání seznamů "na přání" místo všech najednou.
  • Upraveno: Použití fetch_assoc a fetch_row místo společného fetch_array,
File:
1 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r19 r20  
    120120  $DbResult = $Database->query('SELECT COUNT(t2.Id) AS Count FROM (SELECT DISTINCT(ItemId) as Id FROM `'.$List['TableName'].'` as t1 WHERE 1'.$Where.') as t2');
    121121  //echo($Database->LastQuery.'<br>');
    122   $DbRow = $DbResult->fetch_array();
     122  $DbRow = $DbResult->fetch_row();
    123123  $TotalItemCount = $DbRow[0];
    124124
    125125  $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` AS t1 WHERE 1'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
    126126  //echo($Database->LastQuery.'<br>');
    127   while($DbRow = $DbResult->fetch_array())
     127  while($DbRow = $DbResult->fetch_assoc())
    128128  {
    129129    $Output .= '<tr>';
     
    155155  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    156156  $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
    157   while($DbRow = $DbResult->fetch_array())
     157  while($DbRow = $DbResult->fetch_assoc())
    158158  {
    159159    $DefinitionItems = array();
     
    194194  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    195195  $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
    196   while($DbRow = $DbResult->fetch_array())
     196  while($DbRow = $DbResult->fetch_assoc())
    197197  {
    198198    $DefinitionItems = array();
     
    308308function ShowViewItem($List, $Id,  $Column = '', $ColumnValue = 0)
    309309{
    310   global $Database, $Types, $Lists;
     310  global $Database, $Types;
    311311
    312312  if(!CheckPermission('Read', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    313313  $Output = '';
    314314  $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
    315   while($DbRow = $DbResult->fetch_array())
     315  while($DbRow = $DbResult->fetch_assoc())
    316316  {
    317317    $DefinitionItems = array();
     
    346346      if($Types[$Item['Type']]['BaseType'] == 'PointerOneToMany')
    347347      {
    348         $SubList = $Lists[$Types[$Item['Type']]['Parameters'][0]];
     348        $SubList = GetListDefinition($Types[$Item['Type']]['Parameters'][0]);
    349349        $Output .= ShowList($SubList, $Types[$Item['Type']]['Parameters'][1], $DbRow['ItemId'], $Item['TextBefore']).'<br /><br />';
    350350      }
     
    356356function ShowDeleteItem($List, $Id)
    357357{
    358   global $Database, $Lists, $System, $LogActionType;
     358  global $Database, $System, $LogActionType;
    359359
    360360  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     
    362362  $System->Modules['DatabaseList']->DeleteItem($List['TableName'], $Id);
    363363  $Output = 'Položka smazána.';
    364   $Output .= ShowList($Lists[$_SESSION['Table']], $Lists[$_SESSION['Column']], $Lists[$_SESSION['ColumnValue']]).'<br /><br />';
     364  $Output .= ShowList($_SESSION['Table'], $_SESSION['Column'], $_SESSION['ColumnValue']).'<br /><br />';
    365365  ExecuteListEvent($List['TableName'], 'OnDelete', $Id);
    366366  return($Output);
     
    369369function ShowMenu()
    370370{
    371   global $Lists, $Database;
     371  global $Database;
    372372
    373373  $Output = '';
     
    391391function Output()
    392392{
    393   global $Lists;
    394 
    395393  $PermanentVar = array('Table', 'Item', 'Column', 'ColumnValue', 'Action');
    396394  if($_GET['Table'] != $_SESSION['Table'])
     
    404402  }
    405403  $Output = '';
    406   if(array_key_exists('Table', $_SESSION) and array_key_exists($_SESSION['Table'], $Lists))
    407   {
    408     $List = $Lists[$_SESSION['Table']];
     404  if(array_key_exists('Table', $_SESSION))
     405  {
     406    $List = GetListDefinition($_SESSION['Table']);
    409407    if(array_key_exists('Action', $_SESSION))
    410408    {
     
    441439}
    442440
    443 function LoadListDefinition()
     441function GetListDefinition($Id)
    444442{
    445443  global $Database, $Lists;
    446444
    447   $DbResult = $Database->query('SELECT t1.* FROM `SystemList` AS t1 LEFT JOIN `SystemList` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL)');
    448   while($DbRow = $DbResult->fetch_assoc())
    449   {
    450     $Items = array();
    451     $DbResult2 = $Database->query('SELECT t1.* FROM `SystemListItem` AS t1 LEFT JOIN `SystemListItem` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL) AND (t1.List='.$DbRow['ItemId'].')');
    452     while($DbRow2 = $DbResult2->fetch_assoc())
    453     {
    454       $Items[$DbRow2['Name']] = $DbRow2;
    455     }
    456     $List = array(
    457      'Id' => $DbRow['Id'],
    458      'ItemId' => $DbRow['ItemId'],
    459      'TableName' => $DbRow['TableName'],
    460      'Title' => $DbRow['Title'],
    461      'Items' => $Items,
    462     );
    463     $Lists[$List['TableName']] = $List;
    464   }
     445  if(!array_key_exists($Id, $Lists))
     446  {
     447    $DbResult = $Database->query('SELECT t1.* FROM `SystemList` AS t1 LEFT JOIN `SystemList` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL) AND t1.TableName="'.$Id.'"');
     448    if($DbResult->num_rows > 0)
     449    {
     450      $DbRow = $DbResult->fetch_assoc();
     451      $Items = array();
     452      $DbResult2 = $Database->query('SELECT t1.* FROM `SystemListItem` AS t1 LEFT JOIN `SystemListItem` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL) AND (t1.List='.$DbRow['ItemId'].')');
     453      while($DbRow2 = $DbResult2->fetch_assoc())
     454      {
     455        $Items[$DbRow2['Name']] = $DbRow2;
     456      }
     457      $List = array(
     458       'Id' => $DbRow['Id'],
     459       'ItemId' => $DbRow['ItemId'],
     460       'TableName' => $DbRow['TableName'],
     461       'Title' => $DbRow['Title'],
     462       'Items' => $Items,
     463      );
     464      $Lists[$List['TableName']] = $List;
     465    } else $Lists[$List['TableName']] = NULL;
     466  }
     467  return($Lists[$Id]);
    465468  //print_r($Lists);
    466469}
Note: See TracChangeset for help on using the changeset viewer.