Changeset 13
- Timestamp:
- Oct 13, 2008, 1:56:05 PM (16 years ago)
- Files:
-
- 3 added
- 6 edited
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'], -
database.php
r9 r13 2 2 3 3 // Extended database class 4 // Date: 200 7-07-194 // Date: 2008-10-13 5 5 6 6 class Database extends mysqli … … 8 8 var $Prefix = ''; 9 9 var $LastQuery = ''; 10 10 var $ShowError = 0; 11 11 12 function query($Query) 12 13 { 13 14 $this->LastQuery = $Query; 14 return(parent::query($Query)); 15 $DbResult = parent::query($Query); 16 if(($this->ShowError == TRUE) and ($this->error != '')) 17 { 18 echo('<strong>Database error:</strong> '.$this->error.'<br /><strong>Query:</strong> '.$Query.'<br />'); 19 //echo('<pre>'); print_r(debug_backtrace()); echo('</pre>'); 20 } 21 return($DbResult); 15 22 } 16 23 17 24 function select($Table, $What = '*', $Condition = 1) 18 25 { 19 $this->LastQuery = "SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition; 20 return($this->query($this->LastQuery)); 26 return($this->query("SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition)); 21 27 } 22 28 23 29 function delete($Table, $Condition) 24 30 { 25 $this->LastQuery = "DELETE FROM `".$this->Prefix.$Table."` WHERE ".$Condition; 26 $this->query($this->LastQuery); 31 $this->query("DELETE FROM `".$this->Prefix.$Table."` WHERE ".$Condition); 27 32 } 28 33 29 34 function insert($Table, $Data) 30 35 { … … 35 40 $Value = strtr($Value, '"', '\"'); 36 41 $Name .= ',`'.$Key.'`'; 37 38 42 if($Value == 'NOW()') $Values .= ",".$Value; 43 else $Values .= ",'".$Value."'"; 39 44 } 40 45 $Name = substr($Name, 1); 41 46 $Values = substr($Values, 1); 42 $this->LastQuery = 'INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'; 43 $this->query($this->LastQuery); 47 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 44 48 } 45 49 46 50 function update($Table, $Condition, $Data) 47 51 { … … 49 53 foreach($Data as $Key => $Value) 50 54 { 51 55 $Value = strtr($Value, '"', '\"'); 52 56 if($Value != 'NOW()') $Value = "'".$Value."'"; 53 57 $Values .= ", ".$Key."=".$Value; 54 58 } 55 $Values = substr($Values, 2); 56 $this->LastQuery = 'UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'; 57 $this->query($this->LastQuery); 59 $Values = substr($Values, 2); 60 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 58 61 } 59 62 60 63 function replace($Table, $Data) 61 64 { … … 72 75 $Values = substr($Values, 1); 73 76 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br>'); 74 $this->LastQuery = 'REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'; 75 $this->query($this->LastQuery); 76 //echo($this->error().'<br>'); 77 $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 77 78 } 78 79 79 80 function charset($Charset) 80 81 { 81 $this->LastQuery = 'SET CHARACTER SET '.$Charset; 82 $this->query($this->LastQuery); 82 $this->query('SET CHARACTER SET '.$Charset); 83 83 } 84 84 -
forms.php
r11 r13 28 28 function ShowEditBlock($Context = '') 29 29 { 30 global $Database, $Types ;30 global $Database, $Types, $TypeNames; 31 31 32 32 $Table = array( … … 37 37 foreach($this->Definition['Items'] as $Item) 38 38 { 39 if($Item['Type'] != 'Hidden')39 if($Item['Type'] != $TypeNames['Hidden']) 40 40 { 41 41 if(!array_key_exists($Index, $this->Values) and isset($Item['Value'])) $this->Values[$Index] = $Item['Value']; … … 49 49 function ShowHiddenBlock($Context = '') 50 50 { 51 global $Database, $Types ;51 global $Database, $Types, $TypeNames; 52 52 53 53 $Output = ''; … … 55 55 foreach($this->Definition['Items'] as $Item) 56 56 { 57 if($Item['Type'] == 'Hidden')57 if($Item['Type'] == $TypeNames['Hidden']) 58 58 { 59 59 if(!array_key_exists($Item['Name'], $this->Values) and isset($Item['Value'])) $this->Values[$Item['Name']] = $Item['Value']; -
global.php
r9 r13 12 12 $Database->Prefix = $Config['Database']['Prefix']; 13 13 $Database->charset($Config['Database']['Charset']); 14 $Database->ShowError = TRUE; 14 15 include_once('module.php'); 15 16 include_once('page.php'); 16 17 include_once('forms.php'); 18 include_once('types/include.php'); 19 include_once('lists/include.php'); 17 20 include_once('base.php'); 18 21 … … 39 42 $System = new System(); 40 43 $System->Config = $Config; 44 include_once('database_list.php'); 45 $System->AddModule(new DatabaseList()); 41 46 include_once('log.php'); 42 47 $System->AddModule(new Log()); -
lists/SystemListItem.php
r10 r13 5 5 global $Database; 6 6 7 print_r($Parameters);7 //print_r($Parameters); 8 8 $DbResult = $Database->select('SystemType', 'DbDataType', 'Id='.$Parameters['Type']); 9 9 //echo($Database->LastQuery); 10 10 $DbRow = $DbResult->fetch_assoc(); 11 11 $DbResult = $Database->select('SystemList', 'TableName', 'Id='.$Parameters[$Parameters['Column']]); 12 echo($Database->LastQuery);12 //echo($Database->LastQuery); 13 13 $DbRow2 = $DbResult->fetch_assoc(); 14 14 $Database->query('ALTER TABLE `'.$DbRow2['TableName'].'` ADD `'.$Parameters['Name'].'` '.$DbRow['DbDataType'].' NOT NULL ;'); 15 echo($Database->LastQuery);15 //echo($Database->LastQuery); 16 16 } 17 17 -
log.php
r8 r13 1 1 <?php 2 3 $LogActionType = array('Add' => 0, 'Edit' => 1, 'Delete' => 2); 2 4 3 5 class Log extends Module 4 6 { 5 var $Dependencies = array('User'); 7 var $Dependencies = array('User', 'DatabaseList'); 8 var $TableName = 'SystemLog'; 6 9 7 function NewRecord($Module, $Operation, $Value = '')10 function Add($List, $Item, $Action) 8 11 { 9 $ this->Database->insert('is`.`Log', array('Time' => 'NOW()', 'User' => $this->System->Modules['User']->User['Id'], 'Module' => $Module, 'Operation' => $Operation, 'Value' => $Value));10 //echo($this->Database->LastQuery);12 $Values = array('User' => $this->System->Modules['User']->User['Id'], 'List' => $List, 'Item' => $Item, 'Action' => $Action); 13 $this->System->Modules['DatabaseList']->AddItem($this->TableName, $Values); 11 14 } 12 15
Note:
See TracChangeset
for help on using the changeset viewer.