Changeset 15


Ignore:
Timestamp:
Oct 19, 2008, 8:16:37 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Mezitabulkovéí odkazy na položky jsou nyní realizovány jako odkazy na id položky(ItemId) namísto id řádku v tabulce(Id).
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r14 r15  
    44{
    55  global $Database, $Types, $Config;
     6
     7  //if(!CheckPermission('Read', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
    68
    79  if($Title == '') $Output = '<div>'.$List['Title'].'</div>';
     
    3234  {
    3335    if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse orded
    34       $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2; 
     36      $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2;
    3537    if($_SESSION['OrderTable'] != $List['TableName']) // Different table => set ascending order
    3638      $_SESSION['OrderDirection'] = 0;
     
    6365      }
    6466    }
    65     $Output .= '<td><a href="?Action=ViewItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['Id'].'">Zobrazit</a> <a href="?Action=EditItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['Id'].'">Editovat</a> <a href="?Action=DeleteItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['Id'].'">Smazat</a></td></tr>';
     67    $Output .= '<td><a href="?Action=ViewItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['ItemId'].'">Zobrazit</a> <a href="?Action=EditItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['ItemId'].'">Editovat</a> <a href="?Action=DeleteItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['ItemId'].'">Smazat</a></td></tr>';
    6668  }
    6769  $Output .= '</table>';
     
    7476function ShowHistory($List, $Id, $Title = '')
    7577{
    76   global $Database, $Types, $Config;
     78  global $Database, $Types, $Config, $TypeNames;
    7779
    7880  if($Title == '') $Output = '<div>'.$List['Title'].'</div>';
     
    125127      }
    126128    }
    127     $Item = array('Name' => 'Author', 'Type' => 'PointerOneToOne:User');
    128     $ItemType = explode(':', $Item['Type']);
     129    echo($TypeNames['PointerOneToUser']);
     130    $Item = array('Name' => 'Author', 'Type' => $TypeNames['PointerOneToUser']);
     131    $ItemType = explode('|', $Types[$Item['Type']]['Parameters']);
    129132    $Type = $Types[$ItemType[0]];
    130133    $ItemDefinition = array('Name' => $Item['Name'], 'Value' => $DbRow[$Item['Name']], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     
    146149  global $Database, $Types;
    147150
    148   $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     151  $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
    149152  while($DbRow = $DbResult->fetch_array())
    150153  {
     
    181184  global $Database, $Types, $System, $LogActionType;
    182185
    183   $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     186  $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
    184187  while($DbRow = $DbResult->fetch_array())
    185188  {
     
    205208  $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Edit']);
    206209  $Output = 'Změny uloženy.';
    207   $Output .= ShowViewItem($List, $NewId);
     210  $Output .= ShowViewItem($List, $Id);
    208211  $Form->Values['Column'] = $_POST['Column'];
    209212  ExecuteListEvent($List['TableName'], 'OnEdit', $Form->Values);
     
    279282  );
    280283  $Form->LoadValuesFromForm();
    281   $System->Modules['DatabaseList']->AddItem($List['TableName'], $Form->Values);
     284  $NewItemId = $System->Modules['DatabaseList']->AddItem($List['TableName'], $Form->Values);
    282285  $NewId = $Database->insert_id;
    283   $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Add']);
     286   $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Add']);
    284287  $Output = 'Položka přidána';
    285   $Output .= ShowViewItem($List, $NewId);
     288  $Output .= ShowViewItem($List, $NewItemId);
    286289  $Form->Values['Column'] = $_POST['Column'];
    287290  ExecuteListEvent($List['TableName'], 'OnAdd', $Form->Values);
     
    294297
    295298  $Output = '';
    296   $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
     299  $DbResult = $Database->select($List['TableName'], '*', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
    297300  while($DbRow = $DbResult->fetch_array())
    298301  {
     
    312315    );
    313316    $Output .= $Form->ShowReadOnlyForm();
    314     $Output .= '<a href="?Action=EditItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['Id'].'">Editovat</a> ';
     317    $Output .= '<a href="?Action=EditItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['ItemId'].'">Editovat</a> ';
    315318
    316319    if(($Column != '') and ($ColumnValue != 0))
     
    328331      {
    329332        $SubList = $Lists[$Types[$Item['Type']]['Parameters'][0]];
    330         $Output .= ShowList($SubList, $Types[$Item['Type']]['Parameters'][1], $DbRow['Id'], $Item['TextBefore']).'<br /><br />';
     333        $Output .= ShowList($SubList, $Types[$Item['Type']]['Parameters'][1], $DbRow['ItemId'], $Item['TextBefore']).'<br /><br />';
    331334      }
    332335    }
     
    418421  global $Database, $Lists;
    419422
    420   $DbResult = $Database->select('SystemList', '*');
     423  $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)');
    421424  while($DbRow = $DbResult->fetch_assoc())
    422425  {
    423426    $Items = array();
    424     $DbResult2 = $Database->select('SystemListItem', '`Id`, `Name`, `TextBefore`, `TextAfter`, `Type`, `Default`, `Help`, `Required`, `Editable`, `VisibleInList`, `VisibleInPointer`', 'List='.$DbRow['Id']);
     427    $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.List='.$DbRow['ItemId']);
    425428    while($DbRow2 = $DbResult2->fetch_assoc())
    426429    {
     
    437440    $Lists[$List['TableName']] = $List;
    438441  }
     442  //print_r($Lists);
    439443}
    440444
     
    445449  $Types = array();
    446450  $TypeNames = array();
    447   $DbResult = $Database->select('SystemType', '*');
     451  $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)');
    448452  while($DbRow = $DbResult->fetch_assoc())
    449453  {
    450454    $DbRow['Parameters'] = explode('|', $DbRow['Parameters']);
    451455    $DbRow['BaseType'] = $DbRow['Name'];
    452     $Types[$DbRow['Id']] = $DbRow;
    453     $TypeNames[$DbRow['Name']] = $DbRow['Id'];
     456    $Types[$DbRow['ItemId']] = $DbRow;
     457    $TypeNames[$DbRow['Name']] = $DbRow['ItemId'];
    454458  }
    455459
     
    483487  //echo($Callback.',');
    484488  if(is_callable($Callback)) return($Callback($Parameters));
    485     else return($Callback);
     489    else return($Callback.'('.$Type.')');
    486490}
    487491
     
    497501}
    498502
     503function CheckPermission($Right, $ListId, $ItemId = 0)
     504{
     505  global $Database;
     506
     507  $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['Id'].' ORDER BY User.Id DESC LIMIT 1) ORDER BY PermissionGroup.Id DESC LIMIT 1) AND t1.DeletionTime IS NULL AND t1.List='.$ListId);
     508  if($DbResult->num_rows > 0)
     509  {
     510    $DbRow = $DbResult->fetch_assoc();
     511    switch($DbRow['Right'])
     512    {
     513      case 0: return(array('Read' => FALSE, 'Write' => FALSE));
     514      case 1: return(array('Read' => TRUE, 'Write' => FALSE));
     515      case 2: return(array('Read' => TRUE, 'Write' => TRUE));
     516    }
     517  }
     518}
     519
    499520?>
  • database_list.php

    r13 r15  
    1515    $Values['ItemId'] = $AutoincrementId + 1;
    1616    $this->Database->insert($TableName, $Values);
     17    return($Values['ItemId']);
    1718  }
    1819
    1920  function DeleteItem($TableName, $Id)
    2021  {
    21     $this->Database->update($TableName, 'Id='.$Id, array('DeletionTime' => 'NOW()'));
     22    $DbResult = $this->Database->select($TableName, 'Id', 'ItemId='.$Id.' ORDER BY Id DESC LIMIT 1');
     23    $DbRow = $DbResult->fetch_assoc();
     24    $this->Database->update($TableName, 'Id='.$DbRow['Id'], array('DeletionTime' => 'NOW()'));
    2225  }
    2326
    2427  function EditItem($TableName, $Values, $Id)
    2528  {
    26     $DbResult = $this->Database->select($TableName, 'ItemId', 'Id='.$Id);
    27     $DbRow = $DbResult->fetch_assoc();
    28     $Values['ItemId'] = $DbRow['ItemId'];
     29    $this->DeleteItem($TableName, $Id);
     30    $Values['ItemId'] = $Id;
    2931    $Values['Author'] = $this->System->Modules['User']->User['Id'];
    3032    $Values['CreationTime'] = 'NOW()';
  • global.php

    r14 r15  
    172172}
    173173
     174function SystemMessage($Title, $Text)
     175{
     176  return('<table align="center"><tr><td><div class="SystemMessage"><h3>'.$Title.'</h3><div>'.$Text.'</div></div></td></tr></table>');
     177  //ShowFooter();
     178  //die();
     179}
     180
    174181?>
  • page.php

    r9 r15  
    99
    1010  function SystemMessage($Title, $Text)
    11   { 
     11  {
    1212    return('<table align="center"><tr><td><div class="SystemMessage"><h3>'.$Title.'</h3><div>'.$Text.'</div></div></td></tr></table>');
    1313    //ShowFooter();
  • style.css

    r14 r15  
    4444  background-color: white;
    4545  margin: 0px 0px 5px 0px;
     46  width: auto;
    4647}
    4748
  • types/PointerOneToOne.php

    r12 r15  
    55  global $Database, $Lists;
    66
     7  //print_r($Item);
    78  $Columns = '';
    89  $TargetTable = $Type['Parameters'][0];
     
    1011  foreach($Lists[$TargetTable]['Items'] as $ListItem)
    1112    if($ListItem['VisibleInPointer'] == 1) $Columns .= '`'.$ListItem['Name'].'`," ",';
    12   $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, Id';
    13   $DbResult = $Database->select($TargetTable, $Columns, 'Id='.$Item['Value']);
     13  $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, ItemId, Id';
     14  $DbResult = $Database->select($TargetTable, $Columns, 'ItemId='.$Item['Value'].' AND (DeletionTime IS NULL) ORDER BY Id DESC LIMIT 1');
    1415  //echo($Database->LastQuery);
    1516  if($DbResult->num_rows > 0)
     
    2829  foreach($Lists[$TargetTable]['Items'] as $ListItem)
    2930    if($ListItem['VisibleInPointer'] == 1) $Columns .= 't1.`'.$ListItem['Name'].'`," ",';
    30   $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, t1.Id, t1.ItemId';
    31   $DbResult = $Database->query('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)');
     31  $Columns = 'CONCAT('.substr($Columns, 0, -1).') AS Name, t1.Id, t1.ItemId, t1.DeletionTime';
     32  $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');
    3233  //echo($Database->LastQuery);
    3334  if($DbResult->num_rows > 0)
     
    4748  $TargetTable = $Type['Parameters'][0];
    4849  $TargetName = GetTablePointerName($Type, $Item);
    49   $Output = '<a href="?Action=ViewItem&amp;Table='.$TargetTable.'&amp;Item='.$TargetName['Id'].'">'.$TargetName['Name'].'</a>';
     50  $Output = '<a href="?Action=ViewItem&amp;Table='.$TargetTable.'&amp;Item='.$TargetName['ItemId'].'">'.$TargetName['Name'].'</a>';
    5051  return($Output);
    5152}
     
    6162  foreach($TargetNameList as $TargetName)
    6263  {
    63     if($Item['Value'] == $TargetName['Id']) $Selected = ' selected="1"'; else $Selected = '';
    64     $Output .= '<option value="'.$TargetName['Id'].'"'.$Selected.'>'.$TargetName['Name'].'</option>';
     64    if($Item['Value'] == $TargetName['ItemId']) $Selected = ' selected="1"'; else $Selected = '';
     65    $Output .= '<option value="'.$TargetName['ItemId'].'"'.$Selected.'>'.$TargetName['Name'].'</option>';
    6566  }
    6667  $Output .= '</select>';
  • user.php

    r9 r15  
    6969    {
    7070      $this->Database->delete($this->TableUserOnline, 'User='.$DbRow['User']);
    71       $this->System->Modules['Log']->NewRecord('User', 'Logout');
     71      //$this->System->Modules['Log']->Add('User', 'Logout');
    7272    }
    7373    //$this->LoadPermission($this->User['Role']);
     
    102102          mail($Email, $Subject, $Message, $AdditionalHeaders);
    103103          $Result = USER_REGISTRATED;
    104           $this->System->Modules['Log']->NewRecord('User', 'NewRegistration', $Nick);
     104          //$this->System->Modules['Log']->NewRecord('User', 'NewRegistration', $Nick);
    105105        }
    106106      }
     
    119119        $this->Database->update($this->TableUser, 'Id='.$Row['Id'], array('Locked' => 0));
    120120        $Output = USER_REGISTRATION_CONFIRMED;
    121         $this->System->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'UserName='.$Row['Name']);
     121        //$this->System->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'UserName='.$Row['Name']);
    122122      } else $Output = PASSWORDS_UNMATCHED;
    123123    } else $Output = USER_NOT_FOUND;
     
    141141        // načtení stavu stromu
    142142        $Result = USER_LOGGED_IN;
    143         $this->System->Modules['Log']->NewRecord('User', 'Login', 'Nick='.$Nick.',Host='.gethostbyaddr(GetRemoteAddress()));
     143        //$this->System->Modules['Log']->NewRecord('User', 'Login', 'Nick='.$Nick.',Host='.gethostbyaddr(GetRemoteAddress()));
    144144      }
    145145    } else $Result = USER_NOT_REGISTRED;
     
    154154    $SID = session_id();
    155155    $this->Database->update($this->TableUserOnline, 'SessionId="'.$SID.'"', array('User' => 0));
    156     $this->System->Modules['Log']->NewRecord('User', 'Logout', $this->User['Name']);
     156    //$this->System->Modules['Log']->NewRecord('User', 'Logout', $this->User['Name']);
    157157    $this->Check();
    158158    return(USER_LOGGED_OUT);
    159   }
    160 
    161   function LoadRoles()
    162   {
    163     $this->Roles = array();
    164     $DbResult = $this->Database->select('UserRole', '*');
    165     while($DbRow = $DbResult->fetch_array())
    166       $this->Roles[] = $DbRow;
    167   }
    168 
    169   function LoadPermission($Role)
    170   {
    171     $this->User['Permission'] = array();
    172     $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description` FROM `UserRolePermission` JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` WHERE `UserRolePermission`.`Role` = '.$Role);
    173     if($DbResult->num_rows > 0)
    174     while($DbRow = $DbResult->fetch_array())
    175       $this->User['Permission'][$DbRow['Operation']] = $DbRow;
    176   }
    177 
    178   function PermissionMatrix()
    179   {
    180     $Result = array();
    181     $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description`, `UserRole`.`Title` FROM `UserRolePermission` LEFT JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` LEFT JOIN `UserRole` ON `UserRole`.`Id` = `UserRolePermission`.`Role`');
    182     while($DbRow = $DbResult->fetch_array())
    183     {
    184       $Value = '';
    185       if($DbRow['Read']) $Value .= 'R';
    186       if($DbRow['Write']) $Value .= 'W';
    187       $Result[$DbRow['Description']][$DbRow['Title']] = $Value;
    188     }
    189     return($Result);
    190   }
    191 
    192   function CheckGroupPermission($GroupId, $OperationId)
    193   {
    194     // Check group-group relation
    195     $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `Type`="Group"');
    196     while($DbRow = $DbResult->fetch_array())
    197     {
    198        if($this->CheckGroupPermission($DbRow['GroupOrOperation'], $OperationId) == true) return(true);
    199     }
    200 
    201     // Check group-operation relation
    202     $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `GroupOrOperation`="'.$OperationId.'" AND `Type`="Operation"');
    203     if($DbResult->num_rows > 0) return(true);
    204     return(false);
    205   }
    206 
    207   function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
    208   {
    209     $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
    210     if($DbResult->num_rows > 0)
    211     {
    212       $DbRow = $DbResult->fetch_array();
    213       $OperationId = $DbRow['Id'];
    214 
    215       // Check user-operation relation
    216       $DbResult = $this->Database->select('PermissionUserAssignment', '*', '`User`="'.$this->User['Id'].'" AND `GroupOrOperation`="'.$OperationId.'" AND `Type`="Operation"');
    217       if($DbResult->num_rows > 0) return(true);
    218 
    219       // Check user-group relation
    220       $DbResult = $this->Database->select('PermissionUserAssignment', 'GroupOrOperation', '`User`="'.$this->User['Id'].'" AND `Type`="Group"');
    221       while($DbRow = $DbResult->fetch_array())
    222       {
    223          if($this->CheckGroupPermission($DbRow['GroupOrOperation'], $OperationId) == true) return(true);
    224       }
    225       return(false);
    226     } else return(false);
    227159  }
    228160
     
    242174      mail($Row['Email'], $Subject, $Message, $AdditionalHeaders);
    243175      $Output = USER_PASSWORD_RECOVERY_SUCCESS;
    244       $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'UserName='.$Name.',Email='.$Email);
     176      //$this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'UserName='.$Name.',Email='.$Email);
    245177    } else $Output = USER_PASSWORD_RECOVERY_FAIL;
    246178    return($Output);
     
    258190        $this->Database->update($this->TableUser, 'Id='.$Row['Id'], array('Password' => sha1($NewPassword), 'Locked' => 0));
    259191        $Output = USER_PASSWORD_RECOVERY_CONFIRMED;
    260         $this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'UserName='.$Row['Name']);
     192        //$this->System->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'UserName='.$Row['Name']);
    261193      } else $Output = PASSWORDS_UNMATCHED;
    262194    } else $Output = USER_NOT_FOUND;
Note: See TracChangeset for help on using the changeset viewer.