Legend:
- Unmodified
- Added
- Removed
-
base.php
r8 r9 27 27 $Output .= '<th>Akce</th></tr>'; 28 28 29 $Where = ''; 30 29 31 if(($Column != '') and ($ColumnValue != 0)) 30 32 { 31 $Where = $Column.'='.$ColumnValue;33 $Where .= ' AND (t1.'.$Column.'='.$ColumnValue.')'; 32 34 $ColumnSelection = '&Column='.$Column.'&ColumnValue='.$ColumnValue; 33 35 $FullListLink = '<a href="?Action=ViewList&Table='.$List['TableName'].'">Celkový seznam</a>'; 34 } else 35 { 36 $Where = '1'; 36 } else 37 { 37 38 $ColumnSelection = ''; 38 39 $FullListLink = ''; … … 52 53 { 53 54 $OrderDirection = array('ASC', 'DESC'); 54 $Order = 'ORDER BY `'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];55 $Order = 'ORDER BY t1.`'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']]; 55 56 } else $Order = ''; 56 57 … … 58 59 //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))'; 59 60 $Where .= ' '.$Order; 60 $DbResult = $Database-> select($List['TableName'], 'COUNT(*)', $Where);61 //echo($Database->LastQuery );61 $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'); 62 //echo($Database->LastQuery.'<br>'); 62 63 $DbRow = $DbResult->fetch_array(); 63 64 $TotalItemCount = $DbRow[0]; 64 65 65 $DbResult = $Database->select($List['TableName'], '*', $Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']); 66 $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']); 67 //echo($Database->LastQuery.'<br>'); 66 68 while($DbRow = $DbResult->fetch_array()) 67 69 { … … 87 89 } 88 90 91 function ShowHistory($List, $Id, $Title = '') 92 { 93 global $Database, $Types, $Config; 94 95 if($Title == '') $Output = '<div>'.$List['Title'].'</div>'; 96 else $Output = '<div>'.$Title.'</div>'; 97 $Output .= '<table class="WideTable"><tr>'; 98 foreach($List['Items'] as $Item) 99 { 100 if($Item['VisibleInList'] == 1) 101 $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'">'.$Item['TextBefore'].'</a></th>'; 102 } 103 $Output .= '<th>Akce</th></tr>'; 104 105 $Where = ' AND (ItemId='.$Id.')'; 106 107 // Handle ordering 108 if(array_key_exists('OrderColumn', $_GET)) 109 { 110 if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse orded 111 $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2; 112 if($_SESSION['OrderTable'] != $List['TableName']) // Different table => set ascending order 113 $_SESSION['OrderDirection'] = 0; 114 $_SESSION['OrderColumn'] = $_GET['OrderColumn']; 115 $_SESSION['OrderTable'] = $List['TableName']; 116 } 117 if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['TableName'])) 118 { 119 $OrderDirection = array('ASC', 'DESC'); 120 $Order = 'ORDER BY t1.`'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']]; 121 } else $Order = ''; 122 123 if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0; 124 //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))'; 125 $Where .= ' '.$Order; 126 $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'); 127 //echo($Database->LastQuery.'<br>'); 128 $DbRow = $DbResult->fetch_array(); 129 $TotalItemCount = $DbRow[0]; 130 131 $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` WHERE 1'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']); 132 //echo($Database->LastQuery.'<br>'); 133 while($DbRow = $DbResult->fetch_array()) 134 { 135 $Output .= '<tr>'; 136 foreach($List['Items'] as $Index => $Item) 137 { 138 if($Item['VisibleInList'] == 1) 139 { 140 $ItemType = explode(':', $Item['Type']); 141 $Type = $Types[$ItemType[0]]; 142 $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']); 143 if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition); 144 else $Value = $Type['CallbackView']; 145 $Output .= '<td>'.$Value.'</td>'; 146 } 147 } 148 $Output .= '<td><a href="?Action=ViewItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Zobrazit</a> </td></tr>'; 149 } 150 $Output .= '</table>'; 151 $Output .= PagesList($Page, $TotalItemCount); 152 $Output .= '<a href="?Action=AddItem&Table='.$List['TableName'].$ColumnSelection.'">Přidat</a> '.$FullListLink; 153 return($Output); 154 } 155 89 156 function ShowEditItem($List, $Id) 90 157 { 91 158 global $Database, $Types; 92 159 93 $Output = '<form action="?Action=EditItemFinish&Item='.$Id.'" method="post"><table class="WideTable">';94 $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';95 160 $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id); 96 161 while($DbRow = $DbResult->fetch_array()) 97 162 { 163 $DefinitionItems = array(); 98 164 foreach($List['Items'] as $Index => $Item) 99 165 { … … 101 167 if($ItemType[0] != 'PointerOneToMany') 102 168 { 103 $Type = $Types[$ItemType[0]]; 104 $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']); 105 if(is_callable($Type['CallbackEdit'])) $Value = $Type['CallbackEdit']($Type, $ItemDefinition); 106 else $Value = $Type['CallbackEdit']; 107 if($Item['Required'] == 1) $Required = '*'; else $Required = ''; 108 $Output .= '<tr><td>'.$Item['TextBefore'].':'.$Required.'</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>'; 109 } 110 } 111 } 112 $Output .= '</table><input type="submit" value="Uložit"></form>'; 169 $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']); 170 } 171 } 172 } 173 $Form = new Form(); 174 $Form->Definition = array 175 ( 176 'Title' => 'Titulek', 177 'SubmitBuffonText' => 'Uložit', 178 'Items' => $DefinitionItems, 179 ); 180 $Form->OnSubmit = '?Action=EditItemFinish&Item='.$Id; 181 $Output .= $Form->ShowEditForm(); 113 182 if(($Column != '') and ($ColumnValue != 0)) 114 183 { … … 118 187 $Output .= '<a href="?Action=ShowList&Table='.$List['TableName'].'">Celkový seznam</a>'; 119 188 } 120 121 189 return($Output); 122 190 } … … 124 192 function ShowEditItemFinish($List, $Id) 125 193 { 126 global $Database, $Types ;194 global $Database, $Types, $System; 127 195 128 196 $Values = array(); … … 135 203 } 136 204 } 137 $Database->update($List['TableName'], 'Id='.$Id, $Values); 205 $DbResult = $Database->select($List['TableName'], 'ItemId', 'Id='.$Id); 206 $DbRow = $DbResult->fetch_assoc(); 207 $Values['ItemId'] = $DbRow['ItemId']; 208 $Values['Author'] = $System->Modules['User']->User['Id']; 209 $Values['CreationTime'] = 'NOW()'; 210 $Values['ValidTimeFrom'] = 'NOW()'; 211 $Database->insert($List['TableName'], $Values); 138 212 //echo($Database->LastQuery); 139 213 $Output = 'Změny uloženy.'; … … 182 256 function ShowAddItemFinish($List) 183 257 { 184 global $Database, $Types ;258 global $Database, $Types, $System; 185 259 186 260 $Values = array(); … … 193 267 } 194 268 } 269 $Values['Author'] = $System->Modules['User']->User['Id']; 270 $Values['CreationTime'] = 'NOW()'; 271 $Values['ValidTimeFrom'] = 'NOW()'; 272 $DbResult = $Database->select($List['TableName'], 'MAX(ItemId)'); 273 $DbRow = $DbResult->fetch_row(); 274 $AutoincrementId = $DbRow[0]; 275 $Values['ItemId'] = $AutoincrementId + 1; 195 276 $Database->insert($List['TableName'], $Values); 196 277 //echo($Database->LastQuery); … … 208 289 while($DbRow = $DbResult->fetch_array()) 209 290 { 210 $Output = '<table class="WideTable">'; 211 $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>'; 291 $DefinitionItems = array(); 212 292 foreach($List['Items'] as $Index => $Item) 213 293 { … … 215 295 if($ItemType[0] != 'PointerOneToMany') 216 296 { 217 $Type = $Types[$ItemType[0]]; 218 $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']); 219 if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition); 220 else $Value = $Type['CallbackView']; 221 $Output .= '<tr><td>'.$Item['TextBefore'].':</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>'; 222 } 223 } 224 $Output .= '</table>'; 297 $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => 0); 298 } 299 } 300 $Form = new Form(); 301 $Form->Definition = array 302 ( 303 'Title' => 'Titulek', 304 'Items' => $DefinitionItems, 305 ); 306 $Output .= $Form->ShowReadOnlyForm(); 225 307 $Output .= '<a href="?Action=EditItem&Table='.$List['TableName'].'&Item='.$DbRow['Id'].'">Editovat</a> '; 226 308 … … 232 314 $Output .= '<a href="?Action=ShowList&Table='.$List['TableName'].'">Celkový seznam</a>'; 233 315 } 316 $Output .= ' <a href="?Action=ShowHistory&Table='.$List['TableName'].'&Item='.$DbRow['ItemId'].'">Historie</a>'; 234 317 $Output .= '<div class="line"></div>'; 235 236 318 foreach($List['Items'] as $Index => $Item) 237 319 { … … 306 388 case 'AddItemFinish': 307 389 $Output = ShowAddItemFinish($List); 390 break; 391 case 'ShowHistory': 392 $Output = ShowHistory($List, $_SESSION['Item']); 308 393 break; 309 394 case 'ShowList':
Note:
See TracChangeset
for help on using the changeset viewer.