source: trunk/Modules/IS/IS.php@ 584

Last change on this file since 584 was 584, checked in by chronos, 11 years ago
  • Přidáno: Kontrola oprávnění při zobrazení informačního systému.
  • Přidáno: Tabulka Module pro seznam existujících modulů.
  • Upraveno: PermissionOperation se nyní odkazuje na id modulu.
File size: 25.3 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Common/Global.php');
4
5class PageIS extends Page
6{
7 var $FullTitle = 'Správa dat';
8 var $ShortTitle = 'Správa dat';
9 var $ParentClass = 'PagePortal';
10 var $MenuItems = array();
11 var $MenuItemsLoaded = false;
12 var $HideMenu = false;
13
14 function Show()
15 {
16 if(!$this->System->User->CheckPermission('IS', 'Manage'))
17 return('Nemáte oprávnění');
18 $this->System->FormManager->ShowRelation = true;
19
20 if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
21 else $Action = '';
22 if(array_key_exists('t', $_GET)) $Table = $_GET['t'];
23 else $Table = '';
24 if(array_key_exists('i', $_GET)) $ItemId = $_GET['i'];
25 else $ItemId = 0;
26
27 if($Action == 'list') $Content = $this->ShowList($Table);
28 else if($Action == 'select') $Content = $this->ShowSelect($Table);
29 else if($Action == 'mapselect') $Content = $this->ShowMapSelect($Table);
30 else if($Action == 'edit') $Content = $this->ShowEdit($Table, $ItemId);
31 else if($Action == 'add') $Content = $this->ShowAdd($Table);
32 else if($Action == 'view') $Content = $this->ShowView($Table, $ItemId);
33 else if($Action == 'delete') $Content = $this->ShowDelete($Table, $ItemId);
34 else $Content = $this->Dashboard();
35 if($this->HideMenu == false)
36 {
37 $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
38 $Output .= '<strong>Nabídka:</strong>'.$this->ShowMenuItem('');
39 $Output .= '</td><td style="width: 80%; vertical-align: top;">';
40 $Output .= $Content;
41 $Output .= '</td></tr></table>';
42 } else $Output = $Content;
43
44 return($Output);
45 }
46
47 function Dashboard()
48 {
49 $Output = '<strong>Nástěnka:</strong><br/>';
50 $DbResult = $this->Database->select('Task', 'COUNT(*)', 'Progress < 100');
51 $DbRow = $DbResult->fetch_row();
52 $Output .= 'Nedokončených úkolů: '.$DbRow['0'].'<br/>';
53 $DbResult = $this->Database->select('Member', 'COUNT(*)', '1');
54 $DbRow = $DbResult->fetch_row();
55 $Output .= 'Zákazníků: '.$DbRow['0'].'<br/>';
56 $DbResult = $this->Database->select('Subject', 'COUNT(*)', '1');
57 $DbRow = $DbResult->fetch_row();
58 $Output .= 'Subjektů: '.$DbRow['0'].'<br/>';
59 $DbResult = $this->Database->select('User', 'COUNT(*)', '1');
60 $DbRow = $DbResult->fetch_row();
61 $Output .= 'Uživatelů: '.$DbRow['0'].'<br/>';
62 $DbResult = $this->Database->select('NetworkDevice', 'COUNT(*)', '1');
63 $DbRow = $DbResult->fetch_row();
64 $Output .= 'Registrovaných zařízení: '.$DbRow['0'].'<br/>';
65 $DbResult = $this->Database->select('FinanceOperation', 'SUM(Value)', '1');
66 $DbRow = $DbResult->fetch_row();
67 $Output .= 'Stav placení: '.$DbRow['0'].'<br/>';
68 $DbResult = $this->Database->select('FinanceBankImport', 'COUNT(*)', 'FinanceOperation IS NULL');
69 $DbRow = $DbResult->fetch_row();
70 $Output .= 'Nezpárovaných plateb: '.$DbRow['0'].'<br/>';
71 return($Output);
72 }
73
74 function ShowEdit($Table, $Id)
75 {
76 $Output = '';
77 if(!$this->System->User->CheckPermission($Table, 'Write'))
78 return('Nemáte oprávnění');
79 if(array_key_exists('o', $_GET))
80 {
81 if($_GET['o'] == 'save')
82 {
83 $Form = new Form($this->System->FormManager);
84 $Form->SetClass($Table);
85 $Form->LoadValuesFromForm();
86 try {
87 $Form->SaveValuesToDatabase($Id);
88 $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
89 $Output .= $this->ShowView($Table, $Id);
90 } catch (Exception $E)
91 {
92 $Output .= $this->SystemMessage('Úprava položky', 'Položku se nepodařilo uložit. Opravte problém a opakujte akci.');
93 $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'].'&amp;o=save';
94 $Output .= $Form->ShowEditForm();
95 $Output .= '<ul class="ActionMenu">';
96 $Output .= '<li><a href="?a=view&amp;t='.$Table.'&amp;i='.$Id.'"><img alt="Prohlížet" title="Prohlížet" src="'.
97 $this->System->Link('/images/view.png').'"/>Prohlížet</a></li>';
98 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
99 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
100 $Output .= '<li><a href="?a=delete&amp;t='.$Table.'&amp;i='.$Id.'" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
101 $this->System->Link('/images/delete.png').'"/>Odstranit</a></li>';
102 $Output .= '</ul>';
103 }
104 }
105 } else
106 {
107 $Form = new Form($this->System->FormManager);
108 $Form->SetClass($Table);
109 $Form->LoadValuesFromDatabase($Id);
110 $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'].'&amp;o=save';
111 $Output .= $Form->ShowEditForm();
112 $Output .= '<ul class="ActionMenu">';
113 $Output .= '<li><a href="?a=view&amp;t='.$Table.'&amp;i='.$Id.'"><img alt="Prohlížet" title="Prohlížet" src="'.
114 $this->System->Link('/images/view.png').'"/>Prohlížet</a></li>';
115 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
116 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
117 $Output .= '<li><a href="?a=delete&amp;t='.$Table.'&amp;i='.$Id.'" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
118 $this->System->Link('/images/delete.png').'"/>Odstranit</a></li>';
119 $Output .= '</ul>';
120 }
121 return($Output);
122 }
123
124 function ShowDelete($Table, $Id)
125 {
126 $Output = '';
127 if(!$this->System->User->CheckPermission($Table, 'Write'))
128 return('Nemáte oprávnění');
129 $this->Database->delete($Table, 'Id='.$Id);
130 $Output .= $this->SystemMessage('Odstranění položky', 'Položka odstraněna');
131 $Output .= $this->ShowList($Table);
132 return($Output);
133 }
134
135 function ShowAdd($Table)
136 {
137 $Output = '';
138 if(!$this->System->User->CheckPermission($Table, 'Write'))
139 return('Nemáte oprávnění');
140 if(array_key_exists('o', $_GET))
141 {
142 if($_GET['o'] == 'save')
143 {
144 $Form = new Form($this->System->FormManager);
145 $Form->SetClass($Table);
146 $Form->LoadValuesFromForm();
147 try {
148 if(array_key_exists('BeforeInsert', $Form->Definition))
149 {
150 $Class = $Form->Definition['BeforeInsert'][0];
151 $Method = $Form->Definition['BeforeInsert'][1];
152 $this->Values = $Class->$Method($Form);
153 }
154 $Form->SaveValuesToDatabase(0);
155 $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
156 $Id = $this->Database->insert_id;
157 $Output .= $this->ShowView($Table, $Id);
158 //$this->Database->update($Table, 'Id='.$Id,
159 // array('UserCreate' => $this->System->User->User['Id'],
160 // 'TimeCreate' => 'NOW()'));
161 } catch (Exception $E)
162 {
163 $Output .= $this->SystemMessage('Přidání položky', 'Položku se nepodařilo přidat. Opravte problém a opakujte akci.');
164 $Form->OnSubmit = '?a=add&amp;t='.$Table.'&amp;o=save';
165 $Output .= $Form->ShowEditForm();
166 $Output .= '<ul class="ActionMenu">';
167 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
168 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
169 $Output .= '</ul>';
170 }
171 }
172 } else
173 {
174 $Form = new Form($this->System->FormManager);
175 $Form->SetClass($Table);
176 $Form->OnSubmit = '?a=add&amp;t='.$Table.'&amp;o=save';
177 $Output .= $Form->ShowEditForm();
178 $Output .= '<ul class="ActionMenu">';
179 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
180 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
181 $Output .= '</ul>';
182 }
183 return($Output);
184 }
185
186 function ShowView($Table, $Id)
187 {
188 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
189 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
190 if(!$this->System->User->CheckPermission($Table, 'Read'))
191 return('Nemáte oprávnění');
192
193 $Form = new Form($this->System->FormManager);
194 $Form->SetClass($Table);
195 $Form->LoadValuesFromDatabase($Id);
196 $Form->OnSubmit = '?a=view';
197 $Output = $Form->ShowViewForm();
198 $Output .= '<ul class="ActionMenu">';
199 $Output .= '<li><a href="?a=edit&amp;t='.$Table.'&amp;i='.$Id.'"><img alt="Upravit" title="Upravit" src="'.
200 $this->System->Link('/images/edit.png').'"/>Upravit</a></li>';
201 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
202 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
203 $Output .= '<li><a href="?a=delete&amp;t='.$Table.'&amp;i='.$Id.'" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
204 $this->System->Link('/images/delete.png').'" />Odstranit</a></li>';
205 $Output .= '<li><a href="?a=add&amp;t='.$Table.'"><img alt="Přidat" title="Přidat" src="'.
206 $this->System->Link('/images/add.png').'"/>Přidat</a></li>';
207 if(array_key_exists('ItemActions', $FormClass))
208 {
209 foreach($FormClass['ItemActions'] as $Action)
210 {
211 $URL = $this->System->Link($Action['URL']);
212 if(strpos('?', $URL) === false) $URL .= '?';
213 else if((substr($URL, -5, 5) !== '&amp;') and (substr($URL, -1, 1) !== '?')) $URL .= '&amp;';
214 $URL .= '&amp;i='.$Id;
215 $Output .= '<li><a href="'.$URL.'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
216 $this->System->Link('/images/action.png').'"/>'.$Action['Caption'].'</a></li>';
217 }
218 }
219 $Output .= '</ul><br/>';
220
221 // Show ManyToOne relations
222 foreach($Form->Definition['Items'] as $Index => $Item)
223 if((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
224 ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
225 {
226 $Output .= $this->ShowList($this->System->FormManager->FormTypes[$Item['Type']]['Table'], '`'.
227 $this->System->FormManager->FormTypes[$Item['Type']]['Ref'].'`='.$Id, $Item['Caption'],
228 $this->System->FormManager->FormTypes[$Item['Type']]['Ref']).'<br/>';
229 }
230 return($Output);
231 }
232
233 function ShowTable($Table, $Filter = '', $Title = '', $RowActions = array(), $ExcludeColumn = '')
234 {
235 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
236 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
237
238 // Build user filter
239 $UserFilter = '';
240 $Columns = array('Id' => '`Id`');
241 if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
242 {
243 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
244 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
245 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
246 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
247 {
248 $UseType = $UseType = $FormItem['Type'];
249 if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
250 {
251 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
252 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
253 $this->System->FormManager->FormTypes[$FormItem['Type']]);
254 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
255 $UseType = 'OneToMany';
256 else
257 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
258 $UseType = 'Enumeration';
259 }
260 $FilterName = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterName',
261 array('Name' => $ItemIndex, 'Type' => $FormItem['Type']));
262 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
263 $UserFilter .= ' AND ('.$FilterName.' LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
264 }
265 }
266 if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
267 if($Filter != '') $Filter = ' WHERE '.$Filter;
268
269 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
270 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
271 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
272 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
273 {
274 if($ExcludeColumn != $ItemIndex)
275 $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
276 $UseType = $UseType = $FormItem['Type'];
277 if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
278 {
279 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
280 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
281 $this->System->FormManager->FormTypes[$FormItem['Type']]);
282 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
283 $UseType = 'OneToMany';
284 else
285 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
286 $UseType = 'Enumeration';
287 }
288 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
289 $Value = $_POST['Filter'.$ItemIndex];
290 else $Value = '';
291 if($ItemIndex == 'Id') unset($Columns['Id']);
292
293 if(!array_key_exists('SQL', $FormItem)) $FormItem['SQL'] = '';
294 else $FormItem['SQL'] = str_replace('#Id', '`'.$FormClass['Table'].'`.`Id`', $FormItem['SQL']);
295 $Columns[] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
296 array('Value' => $Value, 'Name' => $ItemIndex,
297 'Type' => $FormItem['Type'], 'SQL' => $FormItem['SQL']));
298 }
299
300 // Get total item count in database
301 $Query = 'SELECT COUNT(*) FROM `'.$FormClass['Table'].'`';
302 $DbResult = $this->Database->query($Query);
303 $DbRow = $DbResult->fetch_assoc();
304 $TotalCount = $DbRow['COUNT(*)'];
305
306 // Get total filtered item count in database
307 $Columns = implode(',', $Columns);
308 if($Filter != '')
309 {
310 $Query = 'SELECT COUNT(*) FROM (SELECT '.$Columns.' FROM `'.$FormClass['Table'].'`) AS `TS` '.$Filter;
311 $DbResult = $this->Database->query($Query);
312 $DbRow = $DbResult->fetch_row();
313 $TotalFilteredCount = $DbRow[0];
314 } else $TotalFilteredCount = $TotalCount;
315 $PageList = GetPageList($TotalFilteredCount);
316
317 $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
318 $Output .= $PageList['Output'];
319 $Output .= '<table class="WideTable" style="font-size: small;">';
320
321 $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
322 if(!array_key_exists('DefaultSortColumn', $FormClass))
323 $FormClass['DefaultSortColumn'] = 'Id';
324 $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
325 $Output .= $Order['Output'];
326
327 // Show search fields
328 if(array_key_exists('r', $_GET)) $Addition = '&amp;r='.$_GET['r'];
329 else $Addition = '';
330 $Output .= '<tr><form action="?a='.$_GET['a'].'&amp;t='.$Table.'&amp;filter=1'.$Addition.'" method="post">';
331 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
332 if((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
333 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
334 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) and
335 ($ExcludeColumn != $ItemIndex))
336 {
337 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
338 $Value = $_POST['Filter'.$ItemIndex];
339 else $Value = '';
340 $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';
341 }
342 $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
343
344 // Load and show items
345 $Query = 'SELECT * FROM (SELECT '.$Columns.' FROM `'.$FormClass['Table'].'`) AS `TS` '.
346 $Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
347 $VisibleItemCount = 0;
348 $DbResult = $this->Database->query($Query);
349 while($Row = $DbResult->fetch_assoc())
350 {
351 $Output .= '<tr>';
352 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
353 if((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
354 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
355 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) and
356 ($ExcludeColumn != $ItemIndex))
357 {
358 //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
359 $UseType = $UseType = $FormItem['Type'];
360 if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
361 {
362 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
363 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
364 $this->System->FormManager->FormTypes[$FormItem['Type']]);
365 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
366 $UseType = 'OneToMany';
367 else
368 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
369 $UseType = 'Enumeration';
370 }
371 $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
372 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
373 'Type' => $FormItem['Type']));
374 $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
375 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
376 'Type' => $FormItem['Type'], 'Filter' => $Row[$ItemIndex.'_Filter']));
377 if($Value == '') $Value = '&nbsp;';
378 $Output .= '<td>'.$Value.'</td>';
379 }
380 $Output .= '<td>'.str_replace('#RowId', $Row['Id'], $RowActions).'</td></tr>';
381 $VisibleItemCount = $VisibleItemCount + 1;
382 }
383 $Output .= '<tr><td colspan="'.count($TableColumns).'" style="text-align: right;">Zobrazeno <strong>'.$VisibleItemCount.'</strong>';
384 if($UserFilter != '') $Output .= ' z filtrovaných <strong>'.$TotalFilteredCount.'</strong>';
385 $Output .= ' z celkem <strong>'.$TotalCount.'</strong></td></tr>';
386 $Output .= '</table>';
387 $Output .= $PageList['Output'];
388 return($Output);
389 }
390
391 function ShowSelect($Table, $Filter = '', $Title = '')
392 {
393 if(!$this->System->User->CheckPermission($Table, 'Read'))
394 return('Nemáte oprávnění');
395 $this->BasicHTML = true;
396 $this->HideMenu = true;
397 $RowActions = '<a href="javascript:window.close();" onclick="set_return(#RowId,&quot;'.
398 $_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
399 $this->System->Link('/images/select.png').'"/></a>';
400 $Output = $this->ShowTable($Table, $Filter, $Title, $RowActions);
401 return($Output);
402 }
403
404 function ShowMapSelect($Table, $Filter = '', $Title = '')
405 {
406 if(!$this->System->User->CheckPermission($Table, 'Write'))
407 return('Nemáte oprávnění');
408 $MapApi = new MapApiGoogle($this->System);
409 $MapApi->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
410 'Lng' => $this->System->Config['Map']['DefaultLongitude']);
411 $MapApi->Zoom = $this->System->Config['Map']['DefaultZoom'];
412 $MapApi->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
413 $MapApi->OnClickObject = $_GET['r'];
414 //$MapApi->ShowMarker = true;
415 $Output = $MapApi->ShowPage($this);
416 return($Output);
417 }
418
419 function ShowList($Table, $Filter = '', $Title = '', $ExcludeColumn = '')
420 {
421 if(!$this->System->User->CheckPermission($Table, 'Read'))
422 return('Nemáte oprávnění');
423 $RowActions = '<a href="?a=view&amp;t='.$Table.'&amp;i=#RowId"><img alt="Ukázat" title="Ukázat" src="'.
424 $this->System->Link('/images/view.png').'"/></a>'.
425 '<a href="?a=edit&amp;t='.$Table.'&amp;i=#RowId"><img alt="Upravit" title="Upravit" src="'.
426 $this->System->Link('/images/edit.png').'"/></a>'.
427 '<a href="?a=delete&amp;t='.$Table.'&amp;i=#RowId"><img alt="Smazat" title="Smazat" src="'.
428 $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
429 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
430 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
431 if(array_key_exists('ItemActions', $FormClass))
432 {
433 foreach($FormClass['ItemActions'] as $Action)
434 {
435 $URL = $this->System->Link($Action['URL']);
436 if(strpos('?', $URL) === false) $URL .= '?';
437 else if((substr($URL, -5, 5) !== '&amp;') and (substr($URL, -1, 1) !== '?')) $URL .= '&amp;';
438 $URL .= '&amp;i=#RowId';
439 $RowActions .= '<a href="'.$URL.'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
440 $this->System->Link('/images/action.png').'"/></a>';
441 }
442 }
443 $Output = $this->ShowTable($Table, $Filter, $Title, $RowActions, $ExcludeColumn);
444 $Output .= '<ul class="ActionMenu">';
445 $Output .= '<li><a href="?a=add&amp;t='.$Table.'"><img alt="Přidat" title="Přidat" src="'.
446 $this->System->Link('/images/add.png').'"/>Přidat</a></li>';
447 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
448 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
449 if(array_key_exists('Actions', $FormClass))
450 {
451 foreach($FormClass['Actions'] as $Action)
452 $Output .= '<li><a href="'.$this->System->Link($Action['URL']).'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
453 $this->System->Link('/images/action.png').'"/>'.$Action['Caption'].'</a></li>';
454 }
455 $Output .= '</ul>';
456 return($Output);
457 }
458
459 function ShowMenuItem($Parent)
460 {
461 if($this->MenuItemsLoaded == false)
462 {
463 $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName` FROM `MenuItem` '.
464 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
465 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
466 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
467 while($DbRow = $DbResult->fetch_assoc())
468 {
469 $this->MenuItems[$DbRow['Id']] = $DbRow;
470 }
471 $this->MenuItemsLoaded = true;
472 }
473
474 $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
475 foreach($this->MenuItems as $MenuItem)
476 if($MenuItem['Parent'] == $Parent)
477 {
478 $LinkTitle = $MenuItem['Name'];
479 if($MenuItem['URL'] != '')
480 {
481 if(substr($MenuItem['URL'], 0, 4) != 'http') $MenuItem['URL'] = $this->System->Link($MenuItem['URL']);
482 $LinkTitle = MakeLink($MenuItem['URL'], $LinkTitle);
483 }
484 if($MenuItem['IconName'] != '') $Image = '<img src="../images/favicons/'.$MenuItem['IconName'].'"/>&nbsp;';
485 else $Image = '<img src="../images/favicons/blank.png"/>&nbsp;';
486 $Output .= '<li>'.$Image.$LinkTitle.'</li>';
487 $Output .= $this->ShowMenuItem($MenuItem['Id']);
488 }
489 $Output .= '</ul>';
490 return($Output);
491 }
492}
493
494class ModuleIS extends AppModule
495{
496 function __construct($System)
497 {
498 parent::__construct($System);
499 $this->Name = 'Information system';
500 $this->Version = '1.0';
501 $this->Creator = 'Chronos';
502 $this->License = 'GNU/GPLv3';
503 $this->Description = 'User interface for generic information system';
504 $this->Dependencies = array();
505 }
506
507 function Install()
508 {
509 }
510
511 function Uninstall()
512 {
513 }
514
515 function Start()
516 {
517 parent::Start();
518 $this->System->RegisterPage('is', 'PageIS');
519 $this->System->FormManager->RegisterClass('MenuItem', array(
520 'Title' => 'Položky nabídky',
521 'Table' => 'MenuItem',
522 'Items' => array(
523 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
524 'Parent' => array('Type' => 'TMenuItem', 'Caption' => 'Rodič', 'Default' => '', 'Null' => true),
525 'Action' => array('Type' => 'TAction', 'Caption' => 'Akce', 'Default' => ''),
526 'Menu' => array('Type' => 'TMenu', 'Caption' => 'Nabídka', 'Default' => ''),
527 'Items' => array('Type' => 'TMenuItemListParent', 'Caption' => 'Položky'),
528 ),
529 ));
530 $this->System->FormManager->RegisterClass('Menu', array(
531 'Title' => 'Nabídky',
532 'Table' => 'Menu',
533 'Items' => array(
534 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
535 'Items' => array('Type' => 'TMenuItemListMenu', 'Caption' => 'Položky'),
536 ),
537 ));
538 }
539
540 function Stop()
541 {
542 }
543}
Note: See TracBrowser for help on using the repository browser.