Legend:
- Unmodified
- Added
- Removed
-
base.php
r11 r13 1 1 <?php 2 3 // Include type definitions4 include('types/Enumeration.php');5 include('types/Boolean.php');6 include('types/Integer.php');7 include('types/String.php');8 include('types/PointerOneToMany.php');9 include('types/PointerOneToOne.php');10 include('types/Date.php');11 include('types/Password.php');12 include('types/Float.php');13 include('types/Hyperlink.php');14 include('types/Hidden.php');15 16 // Include list events definitions17 include('lists/SystemList.php');18 include('lists/SystemListItem.php');19 2 20 3 function ShowList($List, $Column = '', $ColumnValue = 0, $Title = '') … … 44 27 $FullListLink = ''; 45 28 } 29 30 // Handle ordering 31 if(array_key_exists('OrderColumn', $_GET)) 32 { 33 if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse orded 34 $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2; 35 if($_SESSION['OrderTable'] != $List['TableName']) // Different table => set ascending order 36 $_SESSION['OrderDirection'] = 0; 37 $_SESSION['OrderColumn'] = $_GET['OrderColumn']; 38 $_SESSION['OrderTable'] = $List['TableName']; 39 } 40 if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['TableName'])) 41 { 42 $OrderDirection = array('ASC', 'DESC'); 43 $Order = 'ORDER BY t1.`'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']]; 44 } else $Order = ''; 45 46 if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0; 47 //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))'; 48 $Where .= ' '.$Order; 49 $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'); 50 $DbRow = $DbResult->fetch_row(); 51 $TotalItemCount = $DbRow[0]; 52 53 $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']); 54 while($DbRow = $DbResult->fetch_assoc()) 55 { 56 $Output .= '<tr>'; 57 foreach($List['Items'] as $Index => $Item) 58 { 59 if($Item['VisibleInList'] == 1) 60 { 61 $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']); 62 $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>'; 63 } 64 } 65 $Output .= '<td><a href="?Action=ViewItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Zobrazit</a> <a href="?Action=EditItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Editovat</a> <a href="?Action=DeleteItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Smazat</a></td></tr>'; 66 } 67 $Output .= '</table>'; 68 $PageList = PagesList($Page, $TotalItemCount); 69 if(strlen($PageList) != 0) $Output .= $PageList.'<br />'; 70 $Output .= ' <a href="?Action=AddItem&Table='.$List['TableName'].$ColumnSelection.'">Přidat</a> '.$FullListLink; 71 return($Output); 72 } 73 74 function ShowHistory($List, $Id, $Title = '') 75 { 76 global $Database, $Types, $Config; 77 78 if($Title == '') $Output = '<div>'.$List['Title'].'</div>'; 79 else $Output = '<div>'.$Title.'</div>'; 80 $Output .= '<table class="WideTable"><tr>'; 81 foreach($List['Items'] as $Item) 82 { 83 if($Item['VisibleInList'] == 1) 84 $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'">'.$Item['TextBefore'].'</a></th>'; 85 } 86 $Output .= '<th><a href="?OrderColumn=Author">Autor</a></th><th><a href="?OrderColumn=CreationTime">Čas vytvoření</a></th><th>Akce</th></tr>'; 87 88 $Where = ' AND (ItemId='.$Id.')'; 46 89 47 90 // Handle ordering … … 69 112 $TotalItemCount = $DbRow[0]; 70 113 71 $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']);72 //echo($Database->LastQuery.'<br>');73 while($DbRow = $DbResult->fetch_array())74 {75 $Output .= '<tr>';76 foreach($List['Items'] as $Index => $Item)77 {78 if($Item['VisibleInList'] == 1)79 {80 $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);81 $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';82 }83 }84 $Output .= '<td><a href="?Action=ViewItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Zobrazit</a> <a href="?Action=EditItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Editovat</a> <a href="?Action=DeleteItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Smazat</a></td></tr>';85 }86 $Output .= '</table>';87 $Output .= PagesList($Page, $TotalItemCount);88 $Output .= '<a href="?Action=AddItem&Table='.$List['TableName'].$ColumnSelection.'">Přidat</a> '.$FullListLink;89 return($Output);90 }91 92 function ShowHistory($List, $Id, $Title = '')93 {94 global $Database, $Types, $Config;95 96 if($Title == '') $Output = '<div>'.$List['Title'].'</div>';97 else $Output = '<div>'.$Title.'</div>';98 $Output .= '<table class="WideTable"><tr>';99 foreach($List['Items'] as $Item)100 {101 if($Item['VisibleInList'] == 1)102 $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'">'.$Item['TextBefore'].'</a></th>';103 }104 $Output .= '<th><a href="?OrderColumn=Author">Autor</a></th><th><a href="?OrderColumn=CreationTime">Čas vytvoření</a></th><th>Akce</th></tr>';105 106 $Where = ' AND (ItemId='.$Id.')';107 108 // Handle ordering109 if(array_key_exists('OrderColumn', $_GET))110 {111 if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse orded112 $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2;113 if($_SESSION['OrderTable'] != $List['TableName']) // Different table => set ascending order114 $_SESSION['OrderDirection'] = 0;115 $_SESSION['OrderColumn'] = $_GET['OrderColumn'];116 $_SESSION['OrderTable'] = $List['TableName'];117 }118 if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['TableName']))119 {120 $OrderDirection = array('ASC', 'DESC');121 $Order = 'ORDER BY t1.`'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];122 } else $Order = '';123 124 if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;125 //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))';126 $Where .= ' '.$Order;127 $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');128 //echo($Database->LastQuery.'<br>');129 $DbRow = $DbResult->fetch_array();130 $TotalItemCount = $DbRow[0];131 132 114 $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` AS t1 WHERE 1'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']); 133 115 //echo($Database->LastQuery.'<br>'); … … 156 138 $Output .= '</table>'; 157 139 $Output .= PagesList($Page, $TotalItemCount); 158 $Output .= ' <a href="?Action=ShowList&Table='.$List['TableName'].'">Celkový seznam</a>';140 $Output .= ' <a href="?Action=ShowList&Table='.$List['TableName'].'">Celkový seznam</a>'; 159 141 return($Output); 160 142 } … … 197 179 function ShowEditItemFinish($List, $Id) 198 180 { 199 global $Database, $Types, $System ;181 global $Database, $Types, $System, $LogActionType; 200 182 201 183 $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id); … … 219 201 ); 220 202 $Form->LoadValuesFromForm(); 221 222 $DbResult = $Database->select($List['TableName'], 'ItemId', 'Id='.$Id); 223 $DbRow = $DbResult->fetch_assoc(); 224 $Form->Values['ItemId'] = $DbRow['ItemId']; 225 $Form->Values['Author'] = $System->Modules['User']->User['Id']; 226 $Form->Values['CreationTime'] = 'NOW()'; 227 $Form->Values['ValidTimeFrom'] = 'NOW()'; 228 $Database->insert($List['TableName'], $Form->Values); 229 //echo($Database->LastQuery); 203 $System->Modules['DatabaseList']->EditItem($List['TableName'], $Form->Values, $Id); 204 $NewId = $Database->insert_id; 205 $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Edit']); 230 206 $Output = 'Změny uloženy.'; 231 $Output .= ShowViewItem($List, $ Database->insert_id);207 $Output .= ShowViewItem($List, $NewId); 232 208 $Form->Values['Column'] = $_POST['Column']; 233 209 ExecuteListEvent($List['TableName'], 'OnEdit', $Form->Values); … … 277 253 function ShowAddItemFinish($List) 278 254 { 279 global $Database, $Types, $System ;255 global $Database, $Types, $System, $LogActionType; 280 256 281 257 $DefinitionItems = array(); … … 294 270 } 295 271 } 296 $DefinitionItems[] = array('Name' => 'Column', 'Type' => 'Hidden', 'Caption' => '', 'Value' => $Column);297 272 298 273 $Form = new Form(); … … 304 279 ); 305 280 $Form->LoadValuesFromForm(); 306 $Form->Values['Author'] = $System->Modules['User']->User['Id']; 307 $Form->Values['CreationTime'] = 'NOW()'; 308 $Form->Values['ValidTimeFrom'] = 'NOW()'; 309 $DbResult = $Database->select($List['TableName'], 'MAX(ItemId)'); 310 $DbRow = $DbResult->fetch_row(); 311 $AutoincrementId = $DbRow[0]; 312 $Form->Values['ItemId'] = $AutoincrementId + 1; 313 $Database->insert($List['TableName'], $Form->Values); 314 //echo($Database->LastQuery); 281 $System->Modules['DatabaseList']->AddItem($List['TableName'], $Form->Values); 282 $NewId = $Database->insert_id; 283 $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Add']); 315 284 $Output = 'Položka přidána'; 316 $Output .= ShowViewItem($List, $ Database->insert_id);285 $Output .= ShowViewItem($List, $NewId); 317 286 $Form->Values['Column'] = $_POST['Column']; 318 287 ExecuteListEvent($List['TableName'], 'OnAdd', $Form->Values); … … 368 337 function ShowDeleteItem($List, $Id) 369 338 { 370 global $Database, $Lists; 371 372 $Database->update($List['TableName'], 'Id='.$Id, array('DeletionTime' => 'NOW()')); 339 global $Database, $Lists, $System, $LogActionType; 340 341 $System->Modules['Log']->Add($List['Id'], $Id, $LogActionType['Delete']); 342 $System->Modules['DatabaseList']->DeleteItem($List['TableName'], $Id); 373 343 $Output = 'Položka smazána.'; 374 344 $Output .= ShowList($Lists[$_SESSION['Table']], $Lists[$_SESSION['Column']], $Lists[$_SESSION['ColumnValue']]).'<br /><br />'; 345 ExecuteListEvent($List['TableName'], 'OnDelete', $Id); 375 346 return($Output); 376 347 } … … 396 367 397 368 $PermanentVar = array('Table', 'Item', 'Column', 'ColumnValue', 'Action'); 369 if($_GET['Table'] != $_SESSION['Table']) 370 { 371 $_SESSION['Column'] = ''; 372 $_SESSION['ColumnValue'] = ''; 373 } 398 374 foreach($PermanentVar as $Var) 399 375 { … … 446 422 { 447 423 $Items = array(); 448 $DbResult2 = $Database->select('SystemListItem', '` Name`, `TextBefore`, `TextAfter`, `Type`, `Default`, `Help`, `Required`, `Editable`, `VisibleInList`, `VisibleInPointer`', 'List='.$DbRow['Id']);424 $DbResult2 = $Database->select('SystemListItem', '`Id`, `Name`, `TextBefore`, `TextAfter`, `Type`, `Default`, `Help`, `Required`, `Editable`, `VisibleInList`, `VisibleInPointer`', 'List='.$DbRow['Id']); 449 425 while($DbRow2 = $DbResult2->fetch_assoc()) 450 426 { … … 452 428 } 453 429 $List = array( 430 'Id' => $DbRow['Id'], 454 431 'TableName' => $DbRow['TableName'], 455 432 'Title' => $DbRow['Title'],
Note:
See TracChangeset
for help on using the changeset viewer.