Changeset 30 for base.php


Ignore:
Timestamp:
Dec 16, 2008, 8:15:34 AM (16 years ago)
Author:
george
Message:
  • Přidáno: Podpora pro určování v definicích krom tabulky také jméno databáze a jméno primárního identifikačního sloupce.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r29 r30  
    11<?php
     2
     3function GetListTableName($List)
     4{
     5  if($List['Database'] != '') return('`'.$List['Database'].'`.`'.$List['TableName'].'`');
     6  else return('`'.$List['TableName'].'`');
     7}
    28
    39function ShowList($List, $Column = '', $ColumnValue = 0, $Title = '', $Filter = '')
     
    5460  //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))';
    5561  $Where .= ' '.$Order;
    56   $DbResult = $Database->query('SELECT COUNT(*) AS Count FROM `'.$List['TableName'].'` WHERE '.$Where);
     62  $DbResult = $Database->query('SELECT COUNT(*) AS Count FROM '.GetListTableName($List).' WHERE '.$Where);
    5763  $DbRow = $DbResult->fetch_row();
    5864  $TotalItemCount = $DbRow[0];
    5965
    60   $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` WHERE '.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
     66  $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
    6167  //echo($Database->LastQuery);
    6268  while($DbRow = $DbResult->fetch_assoc())
     
    6773      if($Item['VisibleInList'] == 1)
    6874      {
    69         $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     75        $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow[$List['IdName']], 'Type' => $Item['Type']);
    7076        $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
    7177      }
    7278    }
    7379    $Output .= '<td>';
    74     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>';
    75     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>';
    76     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>';
     80    if(CheckPermission('Read', $List['Id'])) $Output .= '<a href="?Action=ViewItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'"><img border="0" src="images/view.png" alt="Zobrazit" title="Zobrazit"></a>';
     81    if(CheckPermission('Write', $List['Id'])) $Output .= ' <a href="?Action=EditItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'"><img border="0" src="images/edit.png" alt="Editovat" title="Editovat"></a>';
     82    if(CheckPermission('Write', $List['Id'])) $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'"><img border="0" src="images/delete.png" alt="Smazat" title="Smazat" onclick="return confirmAction(\'Opravdu smazat položku?\');"></a>';
    7783    $Output .= '</td></tr>';
    7884  }
     
    158164
    159165  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    160   $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     166  $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$List['IdName'].'='.$Id);
    161167  while($DbRow = $DbResult->fetch_assoc())
    162168  {
     
    169175        if($Item['Editable'] == 1)
    170176        {
    171           $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     177          $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow[$List['IdName']], 'Type' => $Item['Type']);
    172178        } else $DefinitionItems[] = array('Name' => $Index, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $DbRow[$Index]);
    173179      }
     
    198204
    199205  if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    200   $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     206  $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$List['IdName'].'='.$Id);
    201207  while($DbRow = $DbResult->fetch_assoc())
    202208  {
     
    207213      if($Type['BaseType'] != 'PointerOneToMany')
    208214      {
    209         $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     215        $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow[$List['IdName']], 'Type' => $Item['Type']);
    210216      }
    211217    }
     
    227233  $Form->Values['Id'] = $Id;
    228234  $Form->Values['ListTableName'] = $List['TableName'];
     235  $Form->Values['ListDatabaseName'] = $List['Database'];
    229236  ExecuteListEvent($List['Id'], 'OnEdit', $Form->Values);
    230237  return($Output);
     
    320327  if(!CheckPermission('Read', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    321328  $Output = '';
    322   $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     329  $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$List['IdName'].'='.$Id);
    323330  while($DbRow = $DbResult->fetch_assoc())
    324331  {
     
    340347    );
    341348    $Output .= $Form->ShowReadOnlyForm();
    342     if(CheckPermission('Write', $List['Id'])) $Output .= '<a href="?Action=EditItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'">Editovat</a> ';
     349    if(CheckPermission('Write', $List['Id'])) $Output .= '<a href="?Action=EditItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'">Editovat</a> ';
    343350
    344351    if(($Column != '') and ($ColumnValue != 0))
     
    349356      $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
    350357    }
    351     $Output .= ' <a href="?Action=ShowHistory&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'">Historie</a>';
    352     $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow['Id'].'"  onclick="return confirmAction(\'Opravdu smazat položku?\');">Smazat</a>';
     358    $Output .= ' <a href="?Action=ShowHistory&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'">Historie</a>';
     359    $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'"  onclick="return confirmAction(\'Opravdu smazat položku?\');">Smazat</a>';
    353360    $Output .= '<div class="line"></div>';
    354361    foreach($List['Items'] as $Index => $Item)
     
    358365      {
    359366        $SubList = GetListDefinition($Type['Parameters'][0]);
    360         $Output .= ShowList($SubList, $Type['Parameters'][1], $DbRow['Id'], $Item['TextBefore']).'<br /><br />';
     367        $Output .= ShowList($SubList, $Type['Parameters'][1], $DbRow[$List['IdName']], $Item['TextBefore']).'<br /><br />';
    361368      }
    362369    }
     
    472479    while($DbRow2 = $DbResult2->fetch_assoc())
    473480    {
    474       if(CheckPermission('Read', $DbRow2['Id']))
     481      if(CheckPermission('Read', $DbRow2[$List['IdName']]))
    475482        $Group .= '<a href="?Action=ShowList&amp;Table='.$DbRow2['Id'].'">'.$DbRow2['Title'].'</a><br />';
    476483    }
     
    485492function Output()
    486493{
     494  //print_r($_SESSION);
    487495  $PermanentVar = array('Table', 'Item', 'Column', 'ColumnValue', 'Action');
    488496  if($_GET['Table'] != $_SESSION['Table'])
     
    496504  }
    497505  $Output = '';
    498   if(array_key_exists('Table', $_SESSION))
     506  if(array_key_exists('Table', $_SESSION) and ($_SESSION['Table'] != ''))
    499507  {
    500508    $List = GetListDefinition($_SESSION['Table']);
     
    561569       'Id' => $DbRow['Id'],
    562570       'TableName' => $DbRow['TableName'],
     571       'Database' => $DbRow['Database'],
    563572       'Title' => $DbRow['Title'],
     573       'IdName' => $DbRow['IdName'],
    564574       'Items' => $Items,
    565575      );
     
    643653  global $Database;
    644654
    645   $DbResult = $Database->select('SystemList', '*');
     655  $DbResult = $Database->select(array('Table' => 'SystemList'));
    646656  while($DbRow = $DbResult->fetch_assoc())
    647657  {
Note: See TracChangeset for help on using the changeset viewer.