source: trunk/base.php

Last change on this file was 38, checked in by george, 16 years ago
  • Přidáno: Typy Color pro výběr barvy a Text pro psaní obsáhlejších textů.
  • Opraveno: Ukládání položek do jiných databází než v které je systém.
File size: 27.0 KB
Line 
1<?php
2
3$Types = array();
4$TypeDefinitionList = array();
5$Lists = array();
6
7function GetListTableName($List)
8{
9 if($List['Database'] != '') return('`'.$List['Database'].'`.`'.$List['TableName'].'`');
10 else return('`'.$List['TableName'].'`');
11}
12
13function ShowList($List, $Column = '', $ColumnValue = 0, $Title = '', $Filter = '')
14{
15 global $Database, $Config;
16
17 //echo($Column.','.$ColumnValue.' ');
18
19 if(!CheckPermission('Read', $List['Id']))
20 {
21 if($Column != '') return('');
22 else return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
23 }
24
25 if(!array_key_exists('OrderDirection', $_SESSION)) $_SESSION['OrderDirection'] = 0;
26 if($Title == '') $Output = '<div>'.$List['Title'].'</div>';
27 else $Output = '<div>'.$Title.'</div>';
28 $Output .= '<table class="WideTable"><tr>';
29 foreach($List['Items'] as $Item)
30 {
31 if(($Item['VisibleInList'] == 1) and ($Item['Name'] != $Column))
32 $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'&amp;OrderDirection='.(($_SESSION['OrderDirection'] + 1) % 2).'">'.$Item['TextBefore'].'</a></th>';
33 }
34 $Output .= '<th>Akce</th></tr>';
35
36 $Where = '1';
37
38 if(($Column != '') and ($ColumnValue != 0))
39 {
40 $Where .= ' AND ('.$Column.'='.$ColumnValue.')';
41 $ColumnSelection = '&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue;
42 $FullListLink = '<a href="?Action=ViewList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
43 } else
44 {
45 $ColumnSelection = '';
46 $FullListLink = '';
47 }
48 if($Filter != '') $Where .= ' AND '.$Filter;
49
50 // Handle ordering
51 if(array_key_exists('OrderColumn', $_GET))
52 {
53 if(array_key_exists('OrderTable', $_SESSION) and ($_SESSION['OrderTable'] != $List['Id'])) // Different table => set ascending order
54 $_SESSION['OrderDirection'] = 0;
55 $_SESSION['OrderColumn'] = $_GET['OrderColumn'];
56 $_SESSION['OrderTable'] = $List['Id'];
57 $_SESSION['OrderDirection'] = $_GET['OrderDirection'];
58 }
59 //echo(';'.$_SESSION['OrderTable'].','.$_SESSION['OrderColumn']);
60 if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['Id']))
61 {
62 $OrderDirection = array('ASC', 'DESC');
63 $Order = 'ORDER BY `'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
64 } else $Order = '';
65 if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
66 //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))';
67 $Where .= ' '.$Order;
68 $DbResult = $Database->query('SELECT COUNT(*) AS Count FROM '.GetListTableName($List).' WHERE '.$Where);
69 $DbRow = $DbResult->fetch_row();
70 $TotalItemCount = $DbRow[0];
71
72 $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
73 //echo($Database->LastQuery);
74 while($DbRow = $DbResult->fetch_assoc())
75 {
76 $Output .= '<tr>';
77 foreach($List['Items'] as $Index => $Item)
78 {
79 if(($Item['VisibleInList'] == 1) and ($Item['Name'] != $Column))
80 {
81 $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow[$List['IdName']], 'Type' => $Item['Type']);
82 $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
83 }
84 }
85 $Output .= '<td>';
86 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>';
87 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>';
88 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>';
89 $Output .= '</td></tr>';
90 }
91 $Output .= '</table>';
92 $PageList = PagesList($Page, $TotalItemCount);
93 if(strlen($PageList) != 0) $Output .= $PageList.'<br />';
94 if(CheckPermission('Write', $List['Id'])) $Output .= ' <a href="?Action=AddItem&amp;Table='.$List['Id'].$ColumnSelection.'">Přidat</a> '.$FullListLink;
95 if(CheckPermission('Read', $List['Id'])) $Output .= ' <a href="?Action=ShowSearch&amp;Table='.$List['Id'].$ColumnSelection.'">Hledat</a> '.$FullListLink;
96 return($Output);
97}
98
99/*
100function ShowHistory($List, $Id, $Title = '')
101{
102 global $Database, $Config;
103
104 if($Title == '') $Output = '<div>'.$List['Title'].'</div>';
105 else $Output = '<div>'.$Title.'</div>';
106 $Output .= '<table class="WideTable"><tr>';
107 foreach($List['Items'] as $Item)
108 {
109 if($Item['VisibleInList'] == 1)
110 $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'">'.$Item['TextBefore'].'</a></th>';
111 }
112 $Output .= '<th><a href="?OrderColumn=Author">Autor</a></th><th><a href="?OrderColumn=CreationTime">Čas vytvoření</a></th><th><a href="?OrderColumn=CreationTime">Čas odstranění</a></th><th>Akce</th></tr>';
113
114 $Where = ' AND (ItemId='.$Id.')';
115
116 // Handle ordering
117 if(array_key_exists('OrderColumn', $_GET))
118 {
119 if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse orded
120 $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2;
121 if($_SESSION['OrderTable'] != $List['ItemId']) // Different table => set ascending order
122 $_SESSION['OrderDirection'] = 0;
123 $_SESSION['OrderColumn'] = $_GET['OrderColumn'];
124 $_SESSION['OrderTable'] = $List['ItemId'];
125 }
126 if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['ItemId']))
127 {
128 $OrderDirection = array('ASC', 'DESC');
129 $Order = 'ORDER BY t1.`'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
130 } else $Order = '';
131
132 if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
133 //$Where .= ' AND (ValidFromTime <= NOW()) AND ((ValidToTime >= NOW()) OR (ValidToTime IS NULL))';
134 $Where .= ' '.$Order;
135 $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');
136 //echo($Database->LastQuery.'<br>');
137 $DbRow = $DbResult->fetch_row();
138 $TotalItemCount = $DbRow[0];
139
140 $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` AS t1 WHERE 1'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
141 //echo($Database->LastQuery.'<br>');
142 while($DbRow = $DbResult->fetch_assoc())
143 {
144 $Output .= '<tr>';
145 foreach($List['Items'] as $Item)
146 {
147 if($Item['VisibleInList'] == 1)
148 {
149 $ItemDefinition = array('Name' => $Item['Name'], 'Value' => $DbRow[$Item['Name']], 'SourceTable' => $List['ItemId'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
150 $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
151 }
152 }
153 $Item = array('Name' => 'Author', 'Type' => TypePointerToUserId);
154 $ItemDefinition = array('Name' => $Item['Name'], 'Value' => $DbRow[$Item['Name']], 'SourceTable' => $List['ItemId'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
155 $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
156
157 $Output .= '<td>'.$DbRow['CreationTime'].'</td><td>'.$DbRow['DeletionTime'].'</td>';
158 $Output .= '<td><a href="?Action=ViewItem&amp;Table='.$List['ItemId'].'&amp;Item='.$DbRow['Id'].'"><img border="0" src="images/view.png" alt="Zobrazit" title="Zobrazit"></a></td></tr>';
159 }
160 $Output .= '</table>';
161 $Output .= PagesList($Page, $TotalItemCount);
162 $Output .= ' <a href="?Action=ShowList&amp;Table='.$List['ItemId'].'">Celkový seznam</a>';
163 return($Output);
164}
165*/
166
167function ShowEditItem($List, $Id)
168{
169 global $Database;
170
171 if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
172 $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$List['IdName'].'='.$Id);
173 while($DbRow = $DbResult->fetch_assoc())
174 {
175 $DefinitionItems = array();
176 foreach($List['Items'] as $Index => $Item)
177 {
178 $Type = GetTypeDefinition($Item['Type']);
179 if($Type['BaseType'] != 'PointerOneToMany')
180 {
181 if($Item['Required'] == 1) $Required = '*'; else $Required = '';
182 if($Item['Editable'] == 1)
183 {
184 $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow[$List['IdName']], 'Type' => $Item['Type']);
185 } else $DefinitionItems[] = array('Name' => $Index, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $DbRow[$Index]);
186 }
187 }
188 }
189 $Form = new Form();
190 $Form->Definition = array
191 (
192 'Title' => '',
193 'SubmitButtonText' => 'Uložit',
194 'Items' => $DefinitionItems,
195 );
196 $Form->OnSubmit = '?Action=EditItemFinish&amp;Item='.$Id;
197 $Output = $Form->ShowEditForm();
198 if(array_key_exists('Column', $_GET)) $Column = $_GET['Column']; else $Column = '';
199 if(array_key_exists('ColumnValue', $_GET)) $ColumnValue = $_GET['ColumnValue']; else $ColumnValue = '';
200 if(($Column != '') and ($ColumnValue != 0))
201 {
202 $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
203 } else
204 {
205 $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
206 }
207 return($Output);
208}
209
210function ShowEditItemFinish($List, $Id)
211{
212 global $Database, $System, $LogActionType;
213
214 if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
215 $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$List['IdName'].'='.$Id);
216 while($DbRow = $DbResult->fetch_assoc())
217 {
218 $DefinitionItems = array();
219 foreach($List['Items'] as $Index => $Item)
220 {
221 $Type = GetTypeDefinition($Item['Type']);
222 if($Type['BaseType'] != 'PointerOneToMany')
223 {
224 if($Item['Editable'] == 1)
225 {
226 $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'], 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => $DbRow[$List['IdName']], 'Type' => $Item['Type']);
227 } else $DefinitionItems[] = array('Name' => $Index, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $DbRow[$Index]);
228 }
229 }
230 }
231 $Form = new Form();
232 $Form->Definition = array
233 (
234 'Title' => '',
235 'SubmitButtonText' => 'Uložit',
236 'Items' => $DefinitionItems,
237 );
238 $Form->LoadValuesFromForm();
239 $System->Modules['DatabaseList']->EditItem($List['Id'], $Form->Values, $Id);
240 $NewId = $Database->insert_id;
241 $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Edit']);
242 $Output = 'Změny uloženy.';
243 $Output .= ShowViewItem($List, $Id);
244 if(array_key_exists('Column', $_POST)) $Form->Values['Column'] = $_POST['Column'];
245 else $Form->Values['Column'] = '';
246 $Form->Values['Id'] = $Id;
247 $Form->Values['ListTableName'] = $List['TableName'];
248 $Form->Values['ListDatabaseName'] = $List['Database'];
249 ExecuteListEvent($List['Id'], 'OnEdit', $Form->Values);
250 return($Output);
251}
252
253function ShowAddItem($List, $Column = '', $ColumnValue = 0)
254{
255 global $Database;
256
257 if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
258 $DefinitionItems = array();
259 $AfterTableOutput = '';
260 foreach($List['Items'] as $Item)
261 {
262 //echo($Item['Name'].',');
263 $Type = GetTypeDefinition($Item['Type']);
264 if(($Type['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
265 {
266 if($Item['Required'] == 1) $Required = '*'; else $Required = '';
267 if($Item['Editable'] == 1)
268 $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
269 } else
270 if($Item['Name'] == $Column)
271 {
272 $DefinitionItems[] = array('Name' => $Column, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $ColumnValue);
273 }
274 }
275 $DefinitionItems[] = array('Name' => 'Column', 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $Column);
276
277 $Form = new Form();
278 $Form->Definition = array
279 (
280 'Title' => '',
281 'SubmitButtonText' => 'Přidat',
282 'Items' => $DefinitionItems,
283 );
284 $Form->OnSubmit = '?Action=AddItemFinish';
285 $Output = $Form->ShowEditForm().$AfterTableOutput;
286 if(($Column != '') and ($ColumnValue != 0))
287 {
288 $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
289 } else
290 {
291 $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
292 }
293 return($Output);
294}
295
296function ShowAddItemFinish($List)
297{
298 global $Database, $System, $LogActionType;
299
300 if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
301 $DefinitionItems = array();
302 $AfterTableOutput = '';
303 if(array_key_exists('Column', $_GET)) $Column = $_GET['Column']; else $Column = '';
304 foreach($List['Items'] as $Item)
305 {
306 //echo($Item['Name'].',');
307 $Type = GetTypeDefinition($Item['Type']);
308 if(($Type['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
309 {
310 if($Item['Required'] == 1) $Required = '*'; else $Required = '';
311 $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
312 } else
313 if($Item['Name'] == $Column)
314 {
315 $DefinitionItems[] = array('Name' => $Column, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $ColumnValue);
316 }
317 }
318
319 $Form = new Form();
320 $Form->Definition = array
321 (
322 'Title' => '',
323 'SubmitButtonText' => 'Přidat',
324 'Items' => $DefinitionItems,
325 );
326 $Form->LoadValuesFromForm();
327 $NewItemId = $System->Modules['DatabaseList']->AddItem($List['Id'], $Form->Values);
328 $NewId = $Database->insert_id;
329 $System->Modules['Log']->Add($List['Id'], $NewId, $LogActionType['Add']);
330 $Output = 'Položka přidána';
331 $Output .= ShowViewItem($List, $NewItemId);
332 $Form->Values['Column'] = $_POST['Column'];
333 ExecuteListEvent($List['Id'], 'OnAdd', $Form->Values);
334 return($Output);
335}
336
337function ShowViewItem($List, $Id, $Column = '', $ColumnValue = 0)
338{
339 global $Database;
340
341 if(!CheckPermission('Read', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
342 $Output = '';
343 $DbResult = $Database->query('SELECT * FROM '.GetListTableName($List).' WHERE '.$List['IdName'].'='.$Id);
344 while($DbRow = $DbResult->fetch_assoc())
345 {
346 $DefinitionItems = array();
347 $Required = '';
348 foreach($List['Items'] as $Index => $Item)
349 {
350 $Type = GetTypeDefinition($Item['Type']);
351 if($Type['BaseType'] != 'PointerOneToMany')
352 {
353 $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
354 }
355 }
356 $Form = new Form();
357 $Form->Definition = array
358 (
359 'Title' => '',
360 'Items' => $DefinitionItems,
361 );
362 $Output .= $Form->ShowReadOnlyForm();
363 if(CheckPermission('Write', $List['Id'])) $Output .= '<a href="?Action=EditItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'">Editovat</a> ';
364
365 if(($Column != '') and ($ColumnValue != 0))
366 {
367 $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'&amp;Column='.$Column.'&amp;ColumnValue='.$ColumnValue.'">Celkový seznam</a>';
368 } else
369 {
370 $Output .= '<a href="?Action=ShowList&amp;Table='.$List['Id'].'">Celkový seznam</a>';
371 }
372 $Output .= ' <a href="?Action=ShowHistory&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'">Historie</a>';
373 $Output .= ' <a href="?Action=DeleteItem&amp;Table='.$List['Id'].'&amp;Item='.$DbRow[$List['IdName']].'" onclick="return confirmAction(\'Opravdu smazat položku?\');">Smazat</a>';
374 $Output .= '<div class="line"></div>';
375 foreach($List['Items'] as $Index => $Item)
376 {
377 $Type = GetTypeDefinition($Item['Type']);
378 if($Type['BaseType'] == 'PointerOneToMany')
379 {
380 $SubList = GetListDefinition($Type['Parameters'][0]);
381 $Output .= ShowList($SubList, $Type['Parameters'][1], $DbRow[$List['IdName']], $Item['TextBefore']).'<br /><br />';
382 }
383 }
384 }
385 return($Output);
386}
387
388function ShowDeleteItem($List, $Id)
389{
390 global $Database, $System, $LogActionType;
391
392 if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
393 $System->Modules['Log']->Add($List['Id'], $Id, $LogActionType['Delete']);
394 $System->Modules['DatabaseList']->DeleteItem($List['Id'], $Id);
395 $Output = 'Položka smazána.';
396 $Output .= ShowList($List, $_SESSION['Column'], $_SESSION['ColumnValue']).'<br /><br />';
397 ExecuteListEvent($List['Id'], 'OnDelete', $Id);
398 return($Output);
399}
400
401function ShowSearch($List)
402{
403 global $Database;
404
405 if(!CheckPermission('Read', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
406 $DefinitionItems = array();
407 $AfterTableOutput = '';
408 if(array_key_exists('Column', $_GET)) $Column = $_GET['Column']; else $Column = '';
409 foreach($List['Items'] as $Item)
410 {
411 //echo($Item['Name'].',');
412 $Type = GetTypeDefinition($Item['Type']);
413 if(($Type['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
414 {
415 if($Item['Editable'] == 1)
416 $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'], 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
417 } else
418 if($Item['Name'] == $Column)
419 {
420 $DefinitionItems[] = array('Name' => $Column, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $ColumnValue);
421 }
422 }
423 $DefinitionItems[] = array('Name' => 'Column', 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $Column);
424
425 $Form = new Form();
426 $Form->Definition = array
427 (
428 'Title' => 'Hledání',
429 'SubmitButtonText' => 'Vyhledat',
430 'Items' => $DefinitionItems,
431 );
432 $Form->OnSubmit = '?Action=Search';
433 $Output = $Form->ShowEditForm();
434 return($Output);
435}
436
437function Search($List)
438{
439 global $Database, $System, $LogActionType;
440
441 if(!CheckPermission('Write', $List['Id'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
442 $DefinitionItems = array();
443 $AfterTableOutput = '';
444 if(array_key_exists('Column', $_GET)) $Column = $_GET['Column']; else $Column = '';
445 foreach($List['Items'] as $Item)
446 {
447 //echo($Item['Name'].',');
448 $Type = GetTypeDefinition($Item['Type']);
449 if(($Type['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
450 {
451 if($Item['Required'] == 1) $Required = '*'; else $Required = '';
452 $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['Id'], 'SourceItemId' => 0);
453 } else
454 if($Item['Name'] == $Column)
455 {
456 $DefinitionItems[] = array('Name' => $Column, 'Type' => TypeHiddenId, 'Caption' => '', 'Value' => $ColumnValue);
457 }
458 }
459
460 $Form = new Form();
461 $Form->Definition = array
462 (
463 'Title' => '',
464 'SubmitButtonText' => 'Přidat',
465 'Items' => $DefinitionItems,
466 );
467 $Form->LoadValuesFromForm();
468 $Filter = '1';
469 print_r($Form);
470 foreach($Form->Definition['Items'] as $Item)
471 {
472 //if($Item['Editable'] == 1)
473 {
474 //echo($Item['Name'].',');
475 $Type = GetTypeDefinition($Item['Type']);
476 $TypeObject = $Type['Class'];
477 $Filter .= ' AND (`'.$Item['Name'].'` LIKE '.$TypeObject->DatabaseEscape($Form->Values[$Item['Name']]).')';
478 }
479 }
480 echo('d'.$Filter.'d');
481 $Output = ShowList($List, $_SESSION['Column'], $_SESSION['ColumnValue'], '', $Filter).'<br /><br />';
482 return($Output);
483}
484
485function ShowMenu()
486{
487 global $Database;
488
489 $Output = '';
490 $DbResult = $Database->query('SELECT * FROM `SystemMenu`');
491 while($DbRow = $DbResult->fetch_assoc())
492 {
493 $Group = '';
494 $DbResult2 = $Database->query('SELECT * FROM `SystemList` WHERE `Menu` = '.$DbRow['Id']);
495 while($DbRow2 = $DbResult2->fetch_assoc())
496 {
497 $List = GetListDefinition($DbRow2['Id']);
498 if(CheckPermission('Read', $DbRow2[$List['IdName']]))
499 $Group .= '<a href="?Action=ShowList&amp;Table='.$DbRow2['Id'].'">'.$DbRow2['Title'].'</a><br />';
500 }
501 if($Group != '')
502 $Output .= '<strong>'.$DbRow['Name'].'</strong><br />'.$Group.'<br />';
503 }
504 $Output .= '<br />';
505 return($Output);
506}
507
508
509function Output()
510{
511 //print_r($_SESSION);
512 $PermanentVar = array('Table', 'Item', 'Column', 'ColumnValue', 'Action');
513 if(array_key_exists('Table', $_GET))
514 if($_GET['Table'] != $_SESSION['Table'])
515 {
516 $_SESSION['Column'] = '';
517 $_SESSION['ColumnValue'] = '';
518 }
519 foreach($PermanentVar as $Var)
520 {
521 if(array_key_exists($Var, $_GET)) $_SESSION[$Var] = $_GET[$Var];
522 }
523 $Output = '';
524 if(array_key_exists('Table', $_SESSION) and ($_SESSION['Table'] != ''))
525 {
526 $List = GetListDefinition($_SESSION['Table']);
527 if(is_null($List)) $Output .= SystemMessage('Zobrazení stránky', 'Seznam id '.$_SESSION['Table'].' nenalezen!');
528 else if(array_key_exists('Action', $_SESSION))
529 {
530 switch($_SESSION['Action'])
531 {
532 case 'ShowSearch':
533 $Output = ShowSearch($List);
534 break;
535 case 'Search':
536 $Output = Search($List);
537 break;
538 case 'EditItem':
539 $Output = ShowEditItem($List, $_SESSION['Item']);
540 break;
541 case 'EditItemFinish':
542 $Output = ShowEditItemFinish($List, $_SESSION['Item']);
543 break;
544 case 'DeleteItem':
545 $Output = ShowDeleteItem($List, $_SESSION['Item']);
546 break;
547 case 'ViewItem':
548 $Output = ShowViewItem($List, $_SESSION['Item'], $_SESSION['Column'], $_SESSION['ColumnValue']);
549 break;
550 case 'AddItem':
551 $Output = ShowAddItem($List, $_SESSION['Column'], $_SESSION['ColumnValue']);
552 break;
553 case 'AddItemFinish':
554 $Output = ShowAddItemFinish($List);
555 break;
556 case 'ShowHistory':
557 $Output = ShowHistory($List, $_SESSION['Item']);
558 break;
559 case 'ShowList':
560 default:
561 $Output = ShowList($List, $_SESSION['Column'], $_SESSION['ColumnValue']);
562 }
563 } else $Output = ShowList($List, $_SESSION['Column'], $_SESSION['ColumnValue']);
564 }
565 return($Output);
566}
567
568function GetListDefinition($Id)
569{
570 global $Database, $Lists;
571
572 if(!array_key_exists($Id, $Lists))
573 {
574 $DbResult = $Database->query('SELECT * FROM `SystemList` WHERE `Id`='.$Id);
575 if($DbResult->num_rows > 0)
576 {
577 $DbRow = $DbResult->fetch_assoc();
578 $Items = array();
579 $DbResult2 = $Database->query('SELECT * FROM `SystemListItem` WHERE `List`='.$DbRow['Id'].' ORDER BY `Sequence`');
580 while($DbRow2 = $DbResult2->fetch_assoc())
581 {
582 $Items[$DbRow2['Name']] = $DbRow2;
583 }
584 $List = array(
585 'Id' => $DbRow['Id'],
586 'TableName' => $DbRow['TableName'],
587 'Database' => $DbRow['Database'],
588 'Title' => $DbRow['Title'],
589 'IdName' => $DbRow['IdName'],
590 'Items' => $Items,
591 );
592 //if(!array_key_exists($List['ItemId'], $TypeDefinitionList))
593 {
594 $ClassName = 'List'.$DbRow['TableName'];
595 if(class_exists($ClassName)) $List['Class'] = new $ClassName;
596 }
597 $Lists[$List['Id']] = $List;
598 } else
599 {
600 $Lists[$Id] = NULL;
601 }
602 }
603 return($Lists[$Id]);
604 //print_r($Lists);
605}
606
607function GetTypeDefinition($Id)
608{
609 global $Database, $Types, $TypeDefinitionList;
610
611 if(!array_key_exists($Id, $Types))
612 {
613 $DbResult = $Database->query('SELECT * FROM `SystemType` WHERE `Id`='.$Id);
614 if($DbResult->num_rows > 0)
615 {
616 $DbRow = $DbResult->fetch_assoc();
617 $DbRow['Parameters'] = explode('|', $DbRow['Parameters']);
618 if(($DbRow['ParentType'] == TypePointerOneToOneId) or ($DbRow['ParentType'] == TypePointerOneToManyId))
619 {
620 $DbResult2 = $Database->query('SELECT * FROM `SystemList` WHERE `TableName`="'.$DbRow['Parameters'][0].'"');
621 $DbRow2 = $DbResult2->fetch_assoc();
622 //echo($DbRow['ParentType'].'-'.$DbRow['Parameters'][0].'='.$DbRow2['ItemId'].'<br>');
623 $DbRow['Parameters'][0] = $DbRow2['Id'];
624 }
625 $DbRow['BaseType'] = $DbRow['Name'];
626
627 // Merge parent type definition
628 if($DbRow['ParentType'] != 0)
629 {
630 $ParentType = GetTypeDefinition($DbRow['ParentType']);
631 foreach($DbRow as $Index => $Item)
632 if($Item == '')
633 {
634 $DbRow[$Index] = $ParentType[$Index];
635 }
636 $DbRow['BaseType'] = $ParentType['Name'];
637 }
638 if(!array_key_exists($DbRow['BaseType'], $TypeDefinitionList))
639 {
640 $ClassName = 'Type'.$DbRow['BaseType'];
641 $TypeDefinitionList[$DbRow['BaseType']] = new $ClassName;
642 }
643 $DbRow['Class'] = &$TypeDefinitionList[$DbRow['BaseType']];
644 $Types[$DbRow['Id']] = $DbRow;
645 } else $Types[$DbRow['Id']] = NULL;
646 }
647 //print_r($Types);
648 return($Types[$Id]);
649}
650
651function ExecuteListEvent($Table, $Event, $Parameters)
652{
653 $ListDefinition = GetListDefinition($Table);
654 if(array_key_exists('Class', $ListDefinition))
655 {
656 $ListObject = $ListDefinition['Class'];
657 if(is_callable(array($ListObject, $Event))) return($ListObject->$Event($Parameters));
658 else return($ListDefinition['TableName'].'->'.$Event.'('.$Table.')');
659 } else return($ListDefinition['TableName'].'->'.$Event.'('.$Table.')');
660}
661
662function ExecuteTypeEvent($Type, $Event, $Parameters)
663{
664 $TypeDefinition = GetTypeDefinition($Type);
665 $TypeObject = $TypeDefinition['Class'];
666 if(is_callable(array($TypeObject, $Event))) return($TypeObject->$Event($Parameters));
667 else return($TypeDefinition['BaseType'].'->'.$Event.'('.$Type.')');
668}
669
670function ModifyAllTables($Query)
671{
672 global $Database;
673
674 $DbResult = $Database->select(array('Table' => 'SystemList'));
675 while($DbRow = $DbResult->fetch_assoc())
676 {
677 $Database->query($Query);
678 }
679}
680
681function CheckPermission($Right, $ListId, $ItemId = 0)
682{
683 global $Database, $System;
684
685 $Result = FALSE;
686 return(TRUE);
687 $DbResult = $Database->query('SELECT t1.* FROM `Permission` AS t1 WHERE t1.PermissionGroup = (SELECT PermissionGroup.Id FROM PermissionGroup WHERE PermissionGroup.Id=(SELECT User.PermissionGroup FROM User WHERE User.Id='.$System->Modules['User']->User['Id'].')) AND t1.List='.$ListId);
688 if($DbResult->num_rows > 0)
689 {
690 $DbRow = $DbResult->fetch_assoc();
691 switch($DbRow['Right'])
692 {
693 case 0: $Privileges = array('Read' => FALSE, 'Write' => FALSE); break;
694 case 1: $Privileges = array('Read' => TRUE, 'Write' => FALSE); break;
695 case 2: $Privileges = array('Read' => TRUE, 'Write' => TRUE); break;
696 }
697 $Result = $Privileges[$Right];
698 }
699 //print_r($Privileges);
700 //echo($DbRow['Right'].' '.$Result.'<br>');
701 return($Result);
702}
703
704?>
Note: See TracBrowser for help on using the repository browser.