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

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