Changeset 28


Ignore:
Timestamp:
Dec 8, 2008, 11:06:23 AM (16 years ago)
Author:
george
Message:
  • Upraveno: Systém ukládání dat do databáze přepracován na jednodušší. Původní záměr počítal s verzováním položek seznamů čímž se komplikovaly SQL dotazy. Systém sledování změn bude později řešen přes tabulku Audit.
  • Odebráno: Sloupce tabulek Author, ItemId, CreationTime, DeletionTime, ValidtTimeFrom a ValidTimeTo.
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r27 r28  
    55  global $Database, $Config;
    66
    7   if(!CheckPermission('Read', $List['ItemId']))
     7  if(!CheckPermission('Read', $List['Id']))
    88  {
    99    if($Column != '') return('');
     
    2121  $Output .= '<th>Akce</th></tr>';
    2222
    23   $Where = ' AND (t1.DeletionTime IS NULL)';
     23  $Where = '1';
    2424
    2525  if(($Column != '') and ($ColumnValue != 0))
    2626  {
    27     $Where .= ' AND (t1.'.$Column.'='.$ColumnValue.')';
     27    $Where .= ' AND ('.$Column.'='.$ColumnValue.')';
    2828    $ColumnSelection = '&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue;
    29     $FullListLink = '<a href="?Action=ViewList&amp;Table='.$List['ItemId'].'">Celkový seznam</a>';
     29    $FullListLink = '<a href="?Action=ViewList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
    3030  } else
    3131  {
     
    3939    if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse order
    4040      $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2;
    41     if($_SESSION['OrderTable'] != $List['ItemId']) // Different table => set ascending order
     41    if($_SESSION['OrderTable'] != $List['Id']) // Different table => set ascending order
    4242      $_SESSION['OrderDirection'] = 0;
    4343    $_SESSION['OrderColumn'] = $_GET['OrderColumn'];
    44     $_SESSION['OrderTable'] = $List['ItemId'];
    45   }
    46   if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['ItemId']))
     44    $_SESSION['OrderTable'] = $List['Id'];
     45  }
     46  if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['Id']))
    4747  {
    4848    $OrderDirection = array('ASC', 'DESC');
    49     $Order = 'ORDER BY t1.`'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
     49    $Order = 'ORDER BY `'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
    5050  } else $Order = '';
    5151
     
    5353  //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))';
    5454  $Where .= ' '.$Order;
    55   $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');
     55  $DbResult = $Database->query('SELECT COUNT(*) AS Count FROM `'.$List['TableName'].'` WHERE 1'.$Where);
    5656  $DbRow = $DbResult->fetch_row();
    5757  $TotalItemCount = $DbRow[0];
    5858
    59   $DbResult = $Database->query('SELECT t1.* FROM `'.$List['TableName'].'` AS t1 LEFT JOIN `'.$List['TableName'].'` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL)'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
     59  $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` WHERE '.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
    6060  //echo($Database->LastQuery);
    6161  while($DbRow = $DbResult->fetch_assoc())
     
    6666      if($Item['VisibleInList'] == 1)
    6767      {
    68         $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['ItemId'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     68        $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
    6969        $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
    7070      }
    7171    }
    7272    $Output .= '<td>';
    73     if(CheckPermission('Read', $List['ItemId'])) $Output .= '<a href="?Action=ViewItem&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['ItemId'].'"><img border="0" src="images/view.png" alt="Zobrazit" title="Zobrazit"></a>';
    74     if(CheckPermission('Write', $List['ItemId'])) $Output .= ' <a href="?Action=EditItem&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['ItemId'].'"><img border="0" src="images/edit.png" alt="Editovat" title="Editovat"></a>';
    75     if(CheckPermission('Write', $List['ItemId'])) $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['ItemId'].'"><img border="0" src="images/delete.png" alt="Smazat" title="Smazat" onclick="return confirmAction(\'Opravdu smazat položku?\');"></a>';
     73    if(CheckPermission('Read', $List['Id'])) $Output .= '<a href="?Action=ViewItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'"><img border="0" src="images/view.png" alt="Zobrazit" title="Zobrazit"></a>';
     74    if(CheckPermission('Write', $List['Id'])) $Output .= ' <a href="?Action=EditItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'"><img border="0" src="images/edit.png" alt="Editovat" title="Editovat"></a>';
     75    if(CheckPermission('Write', $List['Id'])) $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'"><img border="0" src="images/delete.png" alt="Smazat" title="Smazat" onclick="return confirmAction(\'Opravdu smazat položku?\');"></a>';
    7676    $Output .= '</td></tr>';
    7777  }
     
    7979  $PageList = PagesList($Page, $TotalItemCount);
    8080  if(strlen($PageList) != 0) $Output .= $PageList.'<br />';
    81   if(CheckPermission('Write', $List['ItemId'])) $Output .= ' <a href="?Action=AddItem&amp;Table='.$List['ItemId'].$ColumnSelection.'">Přidat</a> '.$FullListLink;
    82   if(CheckPermission('Read', $List['ItemId'])) $Output .= ' <a href="?Action=ShowSearch&amp;Table='.$List['ItemId'].$ColumnSelection.'">Hledat</a> '.$FullListLink;
    83   return($Output);
    84 }
    85 
     81  if(CheckPermission('Write', $List['Id'])) $Output .= ' <a href="?Action=AddItem&amp;Table='.$List['Id'].$ColumnSelection.'">Přidat</a> '.$FullListLink;
     82  if(CheckPermission('Read', $List['Id'])) $Output .= ' <a href="?Action=ShowSearch&amp;Table='.$List['Id'].$ColumnSelection.'">Hledat</a> '.$FullListLink;
     83  return($Output);
     84}
     85
     86/*
    8687function ShowHistory($List, $Id, $Title = '')
    8788{
     
    149150  return($Output);
    150151}
     152*/
    151153
    152154function ShowEditItem($List, $Id)
     
    154156  global $Database;
    155157
    156   if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    157   $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
     158  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     159  $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
    158160  while($DbRow = $DbResult->fetch_assoc())
    159161  {
     
    166168        if($Item['Editable'] == 1)
    167169        {
    168           $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['ItemId'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     170          $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
    169171        } else $DefinitionItems[] = array('Name' => $Index, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $DbRow[$Index]);
    170172      }
     
    182184  if(($Column != '') and ($ColumnValue != 0))
    183185  {
    184     $Output .= '<a href="?Action=ShowList&amp;Table='.$List['ItemId'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
     186    $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
    185187  } else
    186188  {
    187     $Output .= '<a href="?Action=ShowList&amp;Table='.$List['ItemId'].'">Celkový seznam</a>';
     189    $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
    188190  }
    189191  return($Output);
     
    194196  global $Database, $System, $LogActionType;
    195197
    196   if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    197   $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
     198  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     199  $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
    198200  while($DbRow = $DbResult->fetch_assoc())
    199201  {
     
    204206      if($Type['BaseType'] != 'PointerOneToMany')
    205207      {
    206         $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['ItemId'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     208        $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
    207209      }
    208210    }
     
    216218  );
    217219  $Form->LoadValuesFromForm();
    218   $System->Modules['DatabaseList']->EditItem($List['ItemId'], $Form->Values, $Id);
     220  $System->Modules['DatabaseList']->EditItem($List['Id'], $Form->Values, $Id);
    219221  $NewId = $Database->insert_id;
    220   $System->Modules['Log']->Add($List['ItemId'], $NewId, $LogActionType['Edit']);
     222  $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Edit']);
    221223  $Output = 'Změny uloženy.';
    222224  $Output .= ShowViewItem($List, $Id);
    223225  $Form->Values['Column'] = $_POST['Column'];
    224   $Form->Values['ItemId'] = $Id;
     226  $Form->Values['Id'] = $Id;
    225227  $Form->Values['ListTableName'] = $List['TableName'];
    226   ExecuteListEvent($List['ItemId'], 'OnEdit', $Form->Values);
     228  ExecuteListEvent($List['Id'], 'OnEdit', $Form->Values);
    227229  return($Output);
    228230}
     
    232234  global $Database;
    233235
    234   if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     236  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    235237  $DefinitionItems = array();
    236238  $AfterTableOutput = '';
     
    243245      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
    244246      if($Item['Editable'] == 1)
    245         $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['ItemId'], 'SourceItemId' => 0);
     247        $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
    246248    } else
    247249    if($Item['Name'] == $Column)
     
    263265  if(($Column != '') and ($ColumnValue != 0))
    264266  {
    265     $Output .= '<a href="?Action=ShowList&amp;Table='.$List['ItemId'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
     267    $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
    266268  } else
    267269  {
    268     $Output .= '<a href="?Action=ShowList&amp;Table='.$List['ItemId'].'">Celkový seznam</a>';
     270    $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
    269271  }
    270272  return($Output);
     
    275277  global $Database, $System, $LogActionType;
    276278
    277   if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     279  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    278280  $DefinitionItems = array();
    279281  $AfterTableOutput = '';
     
    285287    {
    286288      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
    287       $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['ItemId'], 'SourceItemId' => 0);
     289      $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
    288290    } else
    289291    if($Item['Name'] == $Column)
     
    301303  );
    302304  $Form->LoadValuesFromForm();
    303   $NewItemId = $System->Modules['DatabaseList']->AddItem($List['ItemId'], $Form->Values);
     305  $NewItemId = $System->Modules['DatabaseList']->AddItem($List['Id'], $Form->Values);
    304306  $NewId = $Database->insert_id;
    305   $System->Modules['Log']->Add($List['ItemId'], $NewId, $LogActionType['Add']);
     307  $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Add']);
    306308  $Output = 'Položka přidána';
    307309  $Output .= ShowViewItem($List, $NewItemId);
    308310  $Form->Values['Column'] = $_POST['Column'];
    309   ExecuteListEvent($List['ItemId'], 'OnAdd', $Form->Values);
     311  ExecuteListEvent($List['Id'], 'OnAdd', $Form->Values);
    310312  return($Output);
    311313}
     
    315317  global $Database;
    316318
    317   if(!CheckPermission('Read', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     319  if(!CheckPermission('Read', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    318320  $Output = '';
    319   $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
     321  $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
    320322  while($DbRow = $DbResult->fetch_assoc())
    321323  {
     
    327329      if($Type['BaseType'] != 'PointerOneToMany')
    328330      {
    329         $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['ItemId'], 'SourceItemId' => 0);
     331        $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
    330332      }
    331333    }
     
    337339    );
    338340    $Output .= $Form->ShowReadOnlyForm();
    339     if(CheckPermission('Write', $List['ItemId'])) $Output .= '<a href="?Action=EditItem&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['ItemId'].'">Editovat</a> ';
     341    if(CheckPermission('Write', $List['Id'])) $Output .= '<a href="?Action=EditItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'">Editovat</a> ';
    340342
    341343    if(($Column != '') and ($ColumnValue != 0))
    342344    {
    343       $Output .= '<a href="?Action=ShowList&amp;Table='.$List['ItemId'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
     345      $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
    344346    } else
    345347    {
    346       $Output .= '<a href="?Action=ShowList&amp;Table='.$List['ItemId'].'">Celkový seznam</a>';
    347     }
    348     $Output .= ' <a href="?Action=ShowHistory&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['ItemId'].'">Historie</a>';
    349     $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['ItemId'].'"  onclick="return confirmAction(\'Opravdu smazat položku?\');">Smazat</a>';
     348      $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
     349    }
     350    $Output .= ' <a href="?Action=ShowHistory&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'">Historie</a>';
     351    $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'"  onclick="return confirmAction(\'Opravdu smazat položku?\');">Smazat</a>';
    350352    $Output .= '<div class="line"></div>';
    351353    foreach($List['Items'] as $Index => $Item)
     
    355357      {
    356358        $SubList = GetListDefinition($Type['Parameters'][0]);
    357         $Output .= ShowList($SubList, $Type['Parameters'][1], $DbRow['ItemId'], $Item['TextBefore']).'<br /><br />';
     359        $Output .= ShowList($SubList, $Type['Parameters'][1], $DbRow['Id'], $Item['TextBefore']).'<br /><br />';
    358360      }
    359361    }
     
    366368  global $Database, $System, $LogActionType;
    367369
    368   if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    369   $System->Modules['Log']->Add($List['ItemId'], $Id, $LogActionType['Delete']);
    370   $System->Modules['DatabaseList']->DeleteItem($List['ItemId'], $Id);
     370  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     371  $System->Modules['Log']->Add($List['Id'], $Id, $LogActionType['Delete']);
     372  $System->Modules['DatabaseList']->DeleteItem($List['Id'], $Id);
    371373  $Output = 'Položka smazána.';
    372374  $Output .= ShowList($List, $_SESSION['Column'], $_SESSION['ColumnValue']).'<br /><br />';
    373   ExecuteListEvent($List['ItemId'], 'OnDelete', $Id);
     375  ExecuteListEvent($List['Id'], 'OnDelete', $Id);
    374376  return($Output);
    375377}
     
    379381  global $Database;
    380382
    381   if(!CheckPermission('Read', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     383  if(!CheckPermission('Read', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    382384  $DefinitionItems = array();
    383385  $AfterTableOutput = '';
     
    389391    {
    390392      if($Item['Editable'] == 1)
    391         $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => '', 'SourceTable' => $List['ItemId'], 'SourceItemId' => 0);
     393        $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
    392394    } else
    393395    if($Item['Name'] == $Column)
     
    414416  global $Database, $System, $LogActionType;
    415417
    416   if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    417   $System->Modules['Log']->Add($List['ItemId'], $Id, $LogActionType['Delete']);
    418   $System->Modules['DatabaseList']->DeleteItem($List['ItemId'], $Id);
     418  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     419  $System->Modules['Log']->Add($List['Id'], $Id, $LogActionType['Delete']);
     420  $System->Modules['DatabaseList']->DeleteItem($List['Id'], $Id);
    419421  $Output = 'Položka smazána.';
    420422  $Output .= ShowList($List, $_SESSION['Column'], $_SESSION['ColumnValue']).'<br /><br />';
    421   ExecuteListEvent($List['ItemId'], 'OnDelete', $Id);
     423  ExecuteListEvent($List['Id'], 'OnDelete', $Id);
    422424  return($Output);
    423425
     
    431433
    432434  $Output = '';
    433   $DbResult = $Database->query('SELECT t1.* FROM `SystemMenu` AS t1 LEFT JOIN `SystemMenu` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL)');
     435  $DbResult = $Database->query('SELECT * FROM `SystemMenu`');
    434436  while($DbRow = $DbResult->fetch_assoc())
    435437  {
    436438    $Group = '';
    437     $DbResult2 = $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.`Menu` = '.$DbRow['ItemId'].')');
     439    $DbResult2 = $Database->query('SELECT * FROM `SystemList` WHERE `Menu` = '.$DbRow['Id']);
    438440    while($DbRow2 = $DbResult2->fetch_assoc())
    439441    {
    440       if(CheckPermission('Read', $DbRow2['ItemId']))
    441         $Group .= '<a href="?Action=ShowList&amp;Table='.$DbRow2['ItemId'].'">'.$DbRow2['Title'].'</a><br />';
     442      if(CheckPermission('Read', $DbRow2['Id']))
     443        $Group .= '<a href="?Action=ShowList&amp;Table='.$DbRow2['Id'].'">'.$DbRow2['Title'].'</a><br />';
    442444    }
    443445    if($Group != '')
     
    511513  if(!array_key_exists($Id, $Lists))
    512514  {
    513     $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.ItemId="'.$Id.'"');
     515    $DbResult = $Database->query('SELECT * FROM `SystemList` WHERE Id='.$Id);
    514516    if($DbResult->num_rows > 0)
    515517    {
    516518      $DbRow = $DbResult->fetch_assoc();
    517519      $Items = array();
    518       $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'].')');
     520      $DbResult2 = $Database->query('SELECT * FROM `SystemListItem` WHERE List='.$DbRow['Id']);
    519521      while($DbRow2 = $DbResult2->fetch_assoc())
    520522      {
     
    523525      $List = array(
    524526       'Id' => $DbRow['Id'],
    525        'ItemId' => $DbRow['ItemId'],
    526527       'TableName' => $DbRow['TableName'],
    527528       'Title' => $DbRow['Title'],
     
    533534        if(class_exists($ClassName)) $List['Class'] = new $ClassName;
    534535      }
    535       $Lists[$List['ItemId']] = $List;
    536     } else $Lists[$List['ItemId']] = NULL;
     536      $Lists[$List['Id']] = $List;
     537    } else $Lists[$List['Id']] = NULL;
    537538  }
    538539  return($Lists[$Id]);
     
    546547  if(!array_key_exists($Id, $Types))
    547548  {
    548     $DbResult = $Database->query('SELECT t1.* FROM `SystemType` AS t1 LEFT JOIN `SystemType` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL) AND t1.ItemId='.$Id);
     549    $DbResult = $Database->query('SELECT * FROM `SystemType` WHERE Id='.$Id);
    549550    if($DbResult->num_rows > 0)
    550551    {
     
    553554      if(($DbRow['ParentType'] == TypePointerOneToOneId) or ($DbRow['ParentType'] == TypePointerOneToManyId))
    554555      {
    555         $DbResult2 = $Database->query('SELECT t1.* FROM `SystemList` AS t1 LEFT JOIN `SystemType` 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="'.$DbRow['Parameters'][0].'"');
     556        $DbResult2 = $Database->query('SELECT * FROM `SystemList` WHERE TableName="'.$DbRow['Parameters'][0].'"');
    556557        $DbRow2 = $DbResult2->fetch_assoc();
    557558        //echo($DbRow['ParentType'].'-'.$DbRow['Parameters'][0].'='.$DbRow2['ItemId'].'<br>');
    558         $DbRow['Parameters'][0] = $DbRow2['ItemId'];
     559        $DbRow['Parameters'][0] = $DbRow2['Id'];
    559560      }
    560561      $DbRow['BaseType'] = $DbRow['Name'];
     
    577578      }
    578579      $DbRow['Class'] = &$TypeDefinitionList[$DbRow['BaseType']];
    579       $Types[$DbRow['ItemId']] = $DbRow;
    580     } else $Types[$DbRow['ItemId']] = NULL;
     580      $Types[$DbRow['Id']] = $DbRow;
     581    } else $Types[$DbRow['Id']] = NULL;
    581582  }
    582583  //print_r($Types);
     
    620621  $Result = FALSE;
    621622  //return(TRUE);
    622   $DbResult = $Database->query('SELECT t1.* FROM `Permission` AS t1 LEFT JOIN `Permission` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND t1.PermissionGroup = (SELECT PermissionGroup.Id FROM PermissionGroup WHERE PermissionGroup.Id=(SELECT User.PermissionGroup FROM User WHERE User.ItemId='.$System->Modules['User']->User['ItemId'].' ORDER BY User.Id DESC LIMIT 1) ORDER BY PermissionGroup.Id DESC LIMIT 1) AND t1.DeletionTime IS NULL AND t1.List='.$ListId);
     623  $DbResult = $Database->query('SELECT t1.* FROM `Permission` AS t1 WHERE t1.PermissionGroup = (SELECT PermissionGroup.Id FROM PermissionGroup WHERE PermissionGroup.Id=(SELECT User.PermissionGroup FROM User WHERE User.Id='.$System->Modules['User']->User['Id'].')) AND t1.List='.$ListId);
    623624  if($DbResult->num_rows > 0)
    624625  {
  • database_list.php

    r24 r28  
    77  function AddItem($TableId, $Values)
    88  {
    9     $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$TableId.' ORDER BY Id DESC LIMIT 1');
     9    $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE Id='.$TableId);
    1010    $DbRow = $DbResult->fetch_assoc();
    1111    $TableName = $DbRow['TableName'];
    1212
    13     $Values['Author'] = $this->System->Modules['User']->User['ItemId'];
    14     $Values['CreationTime'] = 'NOW()';
    15     $Values['ValidTimeFrom'] = 'NOW()';
    16     $DbResult = $this->Database->select($TableName, 'MAX(ItemId)');
    17     $DbRow = $DbResult->fetch_row();
    18     $AutoincrementId = $DbRow[0];
    19     $Values['ItemId'] = $AutoincrementId + 1;
    2013    $this->Database->insert($TableName, $Values);
    21     return($Values['ItemId']);
     14    return($this->Database->insert_id);
    2215  }
    2316
    2417  function DeleteItem($TableId, $ItemId)
    2518  {
    26     $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$TableId.' ORDER BY Id DESC LIMIT 1');
     19    $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE Id='.$TableId);
    2720    $DbRow = $DbResult->fetch_assoc();
    2821    $TableName = $DbRow['TableName'];
    29 
    30     $DbResult = $this->Database->select($TableName, 'Id', 'ItemId='.$ItemId.' ORDER BY Id DESC LIMIT 1');
    31     $DbRow = $DbResult->fetch_assoc();
    32     $this->Database->update($TableName, 'Id='.$DbRow['Id'], array('DeletionTime' => 'NOW()'));
     22    $this->Database->delete($TableName, 'Id='.$ItemId, array('DeletionTime' => 'NOW()'));
    3323  }
    3424
    3525  function EditItem($TableId, $Values, $ItemId)
    3626  {
    37     $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$TableId.' ORDER BY Id DESC LIMIT 1');
     27    $DbResult = $this->Database->query('SELECT TableName FROM SystemList WHERE Id='.$TableId);
    3828    $DbRow = $DbResult->fetch_assoc();
    3929    $TableName = $DbRow['TableName'];
    4030    $this->DeleteItem($TableId, $ItemId);
    41     $Values['ItemId'] = $ItemId;
    42     $Values['Author'] = $this->System->Modules['User']->User['ItemId'];
    43     $Values['CreationTime'] = 'NOW()';
    44     $Values['ValidTimeFrom'] = 'NOW()';
    45     $this->Database->insert($TableName, $Values);
     31    $Values['Id'] = $ItemId;
     32    $this->Database->replace($TableName, $Values);
    4633  }
    4734}
  • lists/SystemList.php

    r26 r28  
    99    $Database->query('CREATE TABLE IF NOT EXISTS `'.$Parameters['TableName'].'` (
    1010    `Id` int(11) NOT NULL auto_increment,
    11     `ItemId` int(11) NOT NULL,
    12     `Author` int(11) NOT NULL,
    13     `ValidTimeFrom` datetime default NULL,
    14     `ValidTimeTo` datetime default NULL,
    15     `CreationTime` datetime default NULL,
    16     `DeletionTime` datetime default NULL,
    1711    PRIMARY KEY  (`Id`)
    1812    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;');
    19     $Database->query('ALTER TABLE `'.$Parameters['TableName'].'` ADD INDEX ( `ItemId` );');
    2013    //echo($Database->LastQuery);
    2114  }
     
    2518    global $Database;
    2619
    27     $DbResult = $Database->query('SELECT `TableName` FROM `'.$Parameters['ListTableName'].'` WHERE ItemId='.$Parameters['ItemId'].' ORDER BY `Id` DESC LIMIT 1,1');
     20    $DbResult = $Database->query('SELECT `TableName` FROM `'.$Parameters['ListTableName'].'` WHERE Id='.$Parameters['Id']);
    2821    $DbRow = $DbResult->fetch_assoc();
    2922    if($DbRow['TableName'] != $Parameters['TableName'])
    3023      $Database->query('RENAME TABLE `'.$DbRow['TableName'].'` TO `'.$Parameters['TableName'].'`');
    3124  }
     25
     26  function ApplySQLToItems($SQL)
     27  {
     28    global $Database;
     29
     30    $DbResult = $Database->query('SELECT `TableName` FROM `SystemList`');
     31    while($DbRow = $DbResult->fetch_assoc())
     32    {
     33      $Database->query(str_replace('`TableName`', '`'.$DbRow['TableName'].'`', $SQL));
     34    }
     35  }
    3236}
    3337
  • lists/SystemListItem.php

    r27 r28  
    77    global $Database;
    88
    9     $Database->query('UPDATE SystemListItem AS Table1 SET Sequence = (SELECT COUNT(*) FROM (SELECT * FROM SystemListItem) AS Table2 WHERE (Table1.ItemId = Table2.ItemId) AND ((Table2.Sequence < Table1.Sequence) OR ((Table1.Sequence = Table2.Sequence) AND (Table2.Id < Table1.Id))))');
     9    $Database->query('UPDATE SystemListItem AS Table1 SET Sequence = (SELECT COUNT(*) FROM (SELECT * FROM SystemListItem) AS Table2 WHERE ((Table2.Sequence < Table1.Sequence) OR ((Table1.Sequence = Table2.Sequence) AND (Table2.Id < Table1.Id))))');
    1010  }
    1111
     
    1515
    1616    //print_r($Parameters);
    17     $DbResult = $Database->query('SELECT DbDataType FROM SystemType WHERE ItemId='.$Parameters['Type'].' ORDER BY Id DESC LIMIT 1');
     17    $DbResult = $Database->query('SELECT DbDataType FROM SystemType WHERE Id='.$Parameters['Type']);
    1818    //echo($Database->LastQuery);
    1919    $DbRow = $DbResult->fetch_assoc();
    20     $DbResult = $Database->query('SELECT TableName FROM SystemList WHERE ItemId='.$Parameters[$Parameters['Column']].' ORDER BY Id DESC LIMIT 1');
     20    $DbResult = $Database->query('SELECT TableName FROM SystemList WHERE Id='.$Parameters[$Parameters['Column']]);
    2121    //echo($Database->LastQuery);
    2222    $DbRow2 = $DbResult->fetch_assoc();
  • lists/include.php

    r24 r28  
    55include('lists/SystemListItem.php');
    66
    7 define('ListSystemLogId', 20);
     7define('ListSystemLogId', 59);
    88
    99?>
  • types/PointerOneToOne.php

    r26 r28  
    1111    $List = GetListDefinition($Type['Parameters'][0]);
    1212    $TargetTable = $List['TableName'];
     13    //echo($TargetTable.'<');
     14    //print_r($List);
    1315    foreach($List['Items'] as $Index => $ListItem)
    1416    {
     
    2123        {
    2224          //print_r($Type);
    23           $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Item['Value'].' ORDER BY Id DESC LIMIT 1');
     25          $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Item['Value']);
    2426          $DbRow = $DbResult->fetch_assoc();
    25           $DefinitionItem = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => $DbRow[$Index], 'SourceTable' => $List['ItemId'], 'SourceItemId' => 0);
     27          $DefinitionItem = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
    2628          $SubTarget = $this->GetTablePointerName($Type, $DefinitionItem);
    2729          $Columns .= '"'.$SubTarget['Name'].' ",';
     
    2931      }
    3032    }
    31     $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, ItemId, Id';
    32     $DbResult = $Database->select($TargetTable, $Columns, 'ItemId='.$Item['Value'].' AND (DeletionTime IS NULL) ORDER BY Id DESC LIMIT 1');
    33     echo($Database->LastQuery);
     33    $Columns = substr($Columns, 0, -1);
     34    if($Columns == '') $Columns = 'Id AS Name, Id';
     35      else $Columns = 'CONCAT('.$Columns.') AS Name, Id';
     36    $DbResult = $Database->select($TargetTable, $Columns, 'Id='.$Item['Value']);
     37    //echo($Database->LastQuery);
    3438    if($DbResult->num_rows > 0)
    3539    {
     
    4650    $TargetTable = $List['TableName'];
    4751    foreach($List['Items'] as $ListItem)
    48       if($ListItem['VisibleInPointer'] == 1) $Columns .= 't1.`'.$ListItem['Name'].'`," ",';
    49     $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, t1.Id, t1.ItemId, t1.DeletionTime';
    50     $DbResult = $Database->query('SELECT t3.* FROM (SELECT '.$Columns.' FROM `'.$TargetTable.'` AS t1 LEFT JOIN `'.$TargetTable.'` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL)) AS t3 WHERE t3.DeletionTime IS NULL');
     52      if($ListItem['VisibleInPointer'] == 1) $Columns .= '`'.$ListItem['Name'].'`," ",';
     53    $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, Id';
     54    $DbResult = $Database->query('SELECT '.$Columns.' FROM `'.$TargetTable.'`');
    5155    //echo($Database->LastQuery);
    5256    if($DbResult->num_rows > 0)
    5357    {
    5458
    55       $Result = array(array('Name' => 'Žádný', 'Id' => 0, 'ItemId' => 0));
     59      $Result = array(array('Name' => 'Žádný', 'Id' => 0));
    5660      while($DbRow = $DbResult->fetch_assoc())
    5761        $Result[] = $DbRow;
     
    6771    $TargetTable = $Type['Parameters'][0];
    6872    $TargetName = $this->GetTablePointerName($Type, $Item);
    69     $Output = '<a href="?Action=ViewItem&amp;Table='.$TargetTable.'&amp;Item='.$TargetName['ItemId'].'">'.$TargetName['Name'].'</a>';
     73    $Output = '<a href="?Action=ViewItem&amp;Table='.$TargetTable.'&amp;Item='.$TargetName['Id'].'">'.$TargetName['Name'].'</a>';
    7074    return($Output);
    7175  }
     
    8185    foreach($TargetNameList as $TargetName)
    8286    {
    83       if($Item['Value'] == $TargetName['ItemId']) $Selected = ' selected="1"'; else $Selected = '';
    84       $Output .= '<option value="'.$TargetName['ItemId'].'"'.$Selected.'>'.$TargetName['Name'].'</option>';
     87      if($Item['Value'] == $TargetName['Id']) $Selected = ' selected="1"'; else $Selected = '';
     88      $Output .= '<option value="'.$TargetName['Id'].'"'.$Selected.'>'.$TargetName['Name'].'</option>';
    8589    }
    8690    $Output .= '</select>';
  • user.php

    r20 r28  
    5454    if($Row['User'] != 0)
    5555    {
    56       $Query = $this->Database->query('SELECT * FROM `'.$this->TableUser.'` WHERE `ItemId`='.$Row['User'].' ORDER BY `Id` DESC LIMIT 1');
     56      $Query = $this->Database->query('SELECT * FROM `'.$this->TableUser.'` WHERE `Id`='.$Row['User']);
    5757      $this->User = $Query->fetch_assoc();
    5858      //print_r($this->User);
     
    6060    } else
    6161    {
    62       $Query = $this->Database->select($this->TableUser, '*', "`ItemId`=0");
     62      $Query = $this->Database->select($this->TableUser, '*', "`Id`=0");
    6363      $this->User = $Query->fetch_assoc();
    6464      $Result = USER_NOT_LOGGED;
     
    139139      {
    140140        $this->Database->update($this->TableUser, 'Id='.$Row['Id'], array('LastLoginTime' => 'NOW()'));
    141         $this->Database->update($this->TableUserOnline, 'SessionId="'.$SID.'"', array('User' => $Row['ItemId'], 'ItemId' => $Row['ItemId']));
     141        $this->Database->update($this->TableUserOnline, 'SessionId="'.$SID.'"', array('User' => $Row['Id'], 'Id' => $Row['mId']));
    142142        // načtení stavu stromu
    143143        $Result = USER_LOGGED_IN;
Note: See TracChangeset for help on using the changeset viewer.