source: trunk/Modules/IS/IS.php

Last change on this file was 983, checked in by chronos, 3 weeks ago
  • Fixed: IS form unknown items error handling.
  • Modified: Ping redirection to Inext local network.
File size: 45.7 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Common/Global.php');
4
5class PageIS extends Page
6{
7 public array $MenuItems;
8 public bool $HideMenu;
9 public bool $ShowActionName;
10
11 function __construct($System)
12 {
13 parent::__construct($System);
14 $this->Title = 'Správa dat';
15 $this->ParentClass = 'PagePortal';
16
17 $this->MenuItems = array();
18 $this->HideMenu = false;
19 $this->ShowActionName = false;
20 }
21
22 function Show(): string
23 {
24 if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('IS', 'Manage'))
25 return 'Nemáte oprávnění';
26 $this->System->FormManager->ShowRelation = true;
27
28 // a - action
29 if (array_key_exists('a', $_GET)) $Action = $_GET['a'];
30 else $Action = '';
31 // t - table
32 if (array_key_exists('t', $_GET)) $Table = $_GET['t'];
33 else $Table = '';
34 // i - index of item
35 if (array_key_exists('i', $_GET)) $ItemId = $_GET['i'];
36 else $ItemId = 0;
37 // fc - preset colum
38 if (array_key_exists('fn', $_GET)) $FilterName = $_GET['fn'];
39 else $FilterName = '';
40 if (array_key_exists('fv', $_GET)) $FilterValue = $_GET['fv'];
41 else $FilterValue = '';
42 if (array_key_exists('menutype', $_COOKIE)) $MenuType = $_COOKIE['menutype'];
43 else $MenuType = 0;
44 if (array_key_exists('menutype', $_GET) and is_numeric($_GET['menutype'])) $MenuType = $_GET['menutype'] * 1;
45 setcookie('menutype', $MenuType, time() + 60 * 60 * 24 * 365);
46
47 if ($Action == 'list') {
48 if ($FilterName == '') $Content = $this->ShowList($Table);
49 else $Content = $this->ShowList($Table, '', '', $FilterName, $FilterValue);
50 }
51 else if ($Action == 'select') $Content = $this->ShowSelect($Table);
52 else if ($Action == 'mapselect') $Content = $this->ShowMapSelect($Table);
53 else if ($Action == 'edit') $Content = $this->ShowEdit($Table, $ItemId);
54 else if ($Action == 'clone') $Content = $this->ShowClone($Table, $ItemId);
55 else if ($Action == 'add') $Content = $this->ShowAdd($Table);
56 else if ($Action == 'addsub') $Content = $this->ShowAddSub($Table);
57 else if ($Action == 'view') $Content = $this->ShowView($Table, $ItemId);
58 else if ($Action == 'delete') $Content = $this->ShowDelete($Table, $ItemId);
59 else if ($Action == 'fav_add') $Content = $this->ShowFavoriteAdd($Table, $ItemId);
60 else if ($Action == 'fav_del') $Content = $this->ShowFavoriteDel($Table, $ItemId);
61 else $Content = $this->Dashboard();
62 if ($this->HideMenu == false)
63 {
64 $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
65 $MenuTypeText = '<a href="?menutype=0">Nabídka</a>';
66 if ($MenuType == 0) $MenuTypeText = '<strong>'.$MenuTypeText.'</strong>';
67 $Output .= $MenuTypeText.' ';
68 $MenuTypeText = '<a href="?menutype=1">Oblíbené</a>';
69 if ($MenuType == 1) $MenuTypeText = '<strong>'.$MenuTypeText.'</strong>';
70 $Output .= $MenuTypeText.' ';
71 if ($MenuType == 0) $Output .= $this->ShowMenu();
72 if ($MenuType == 1) $Output .= $this->ShowFavorites();
73 $Output .= '</td><td style="width: 80%; vertical-align: top;">';
74 $Output .= $Content;
75 $Output .= '</td></tr></table>';
76 } else $Output = $Content;
77
78 return $Output;
79 }
80
81 function Dashboard(): string
82 {
83 $Output = '<strong>Nástěnka:</strong><br/>';
84 foreach (ModuleIS::Cast($this->System->GetModule('IS'))->DashboardItems as $Item)
85 {
86 if (is_string($Item['Callback'][0]))
87 {
88 $Class = new $Item['Callback'][0]($this->System);
89 $Method = $Item['Callback'][1];
90 $Output .= $Class->$Method();
91 } else $Output .= call_user_func($Item['Callback']);
92 }
93 return $Output;
94 }
95
96 function ShowFavoriteAdd(string $Table, string $ItemId): string
97 {
98 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
99 if ($DbResult->num_rows > 0)
100 {
101 $Output = $this->SystemMessage('Oblíbené', 'Již existuje v oblíbených');
102 } else
103 {
104 $this->Database->insert('MenuItemFavorite', array('MenuItem' => ($_GET['i'] * 1), 'User' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']));
105 $Output = $this->SystemMessage('Oblíbené', 'Přidáno do oblíbených');
106 }
107 $Output .= $this->ShowList($Table);
108 return $Output;
109 }
110
111 function ShowFavoriteDel(string $Table, string $ItemId): string
112 {
113 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
114 if ($DbResult->num_rows > 0)
115 {
116 $DbRow = $DbResult->fetch_assoc();
117 $this->Database->delete('MenuItemFavorite', '`Id`= '.$DbRow['Id']);
118 $Output = $this->SystemMessage('Oblíbené', 'Odstraněno z oblíbených');
119 } else
120 {
121 $Output = $this->SystemMessage('Oblíbené', 'Nenalezeno v oblíbených');
122 }
123 $Output .= $this->ShowList($Table);
124 return $Output;
125 }
126
127 function LogChange(Form $Form, string $Action, string $NewId, string $OldId): void
128 {
129 $Values = $Form->Definition['Table'].' (Id: '.$OldId.' => '.$NewId.'):'."\n";
130 // Compare old values loaded from database with new values in Form variable
131 $NewValues = $Form->Values;
132 if ($OldId != 0)
133 {
134 $FormOld = new Form($this->System->FormManager);
135 $FormOld->SetClass($Form->Definition['Table']);
136 $FormOld->LoadValuesFromDatabase($OldId);
137 $OldValues = $FormOld->Values;
138 // Keep only changes values
139 foreach ($NewValues as $Index => $Value)
140 {
141 if ($OldValues[$Index] != $NewValues[$Index])
142 {
143 $Values .= $Index.': '.$FormOld->GetValue($Index);
144 if ($NewId != 0) $Values .= ' => '.$Form->GetValue($Index);
145 $Values .= "\n";
146 }
147 }
148 } else
149 {
150 foreach ($NewValues as $Index => $Value)
151 {
152 $Values .= $Index.': '.$Form->GetValue($Index)."\n";
153 }
154 }
155 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('IS', $Action, $Values);
156 }
157
158 function ShowEdit(string $Table, string $Id): string
159 {
160 $Output = '';
161 if (!array_key_exists($Table, $this->System->FormManager->Classes))
162 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
163 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
164 return $this->SystemMessage('Oprávnění', 'Nemáte oprávnění');
165 $Form = new Form($this->System->FormManager);
166 $Form->SetClass($Table);
167 if ($Form->HasAllPostVariables())
168 {
169 $Form->LoadValuesFromForm();
170 $this->Title .= ' - '.$Form->Definition['Title'].' úprava';
171 try
172 {
173 $Form->Validate();
174 if (array_key_exists('BeforeModify', $Form->Definition))
175 {
176 $Class = $Form->Definition['BeforeModify'][0];
177 $Method = $Form->Definition['BeforeModify'][1];
178 $Form->Values = $Class->$Method($Form, $Id);
179 }
180 $this->LogChange($Form, 'Edit', $Id, $Id);
181 $Form->SaveValuesToDatabase($Id);
182 $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
183 $Output .= $this->ShowView($Table, $Id);
184 if (array_key_exists('AfterModify', $Form->Definition))
185 {
186 $Class = $Form->Definition['AfterModify'][0];
187 $Method = $Form->Definition['AfterModify'][1];
188 $Form->Values = $Class->$Method($Form, $Id);
189 }
190 } catch (Exception $E)
191 {
192 $Output .= $this->SystemMessage('Úprava položky', 'Položku se nepodařilo uložit. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
193 $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'];
194 $Output .= $Form->ShowEditForm();
195 $Output .= '<ul class="ActionMenu">';
196 $Output .= '<li>'.$this->ShowAction('Prohlížet', '?a=view&amp;t='.$Table.'&amp;i='.$Id,
197 $this->System->Link('/images/view.png'));
198 $Output .= '<li>'.$this->ShowAction('Duplikovat', '?a=clone&amp;t='.$Table.'&amp;i='.$Id,
199 $this->System->Link('/images/clone.png'));
200 $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
201 $this->System->Link('/images/list.png'));
202 $Output .= '<li>'.$this->ShowAction('Odstranit', '?a=delete&amp;t='.$Table.'&amp;i='.$Id,
203 $this->System->Link('/images/delete.png'), 'Opravdu smazat položku');
204 $Output .= '</ul>';
205 }
206 } else
207 {
208 $Form->LoadValuesFromDatabase($Id);
209 $this->Title .= ' - '.$Form->Definition['Title'].' úprava';
210 $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;i='.$_GET['i'];
211 $Output .= $Form->ShowEditForm();
212 $Output .= '<ul class="ActionMenu">';
213 $Output .= '<li>'.$this->ShowAction('Prohlížet', '?a=view&amp;t='.$Table.'&amp;i='.$Id,
214 $this->System->Link('/images/view.png'));
215 $Output .= '<li>'.$this->ShowAction('Duplikovat', '?a=clone&amp;t='.$Table.'&amp;i='.$Id,
216 $this->System->Link('/images/clone.png'));
217 $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
218 $this->System->Link('/images/list.png'));
219 $Output .= '<li>'.$this->ShowAction('Odstranit', '?a=delete&amp;t='.$Table.'&amp;i='.$Id,
220 $this->System->Link('/images/delete.png'), 'Opravdu smazat položku?');
221 $Output .= '</ul>';
222 }
223 return $Output;
224 }
225
226 function ShowClone(string $Table, string $Id, array $Actions = array()): string
227 {
228 $Output = '';
229 if (!array_key_exists($Table, $this->System->FormManager->Classes))
230 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
231 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
232 return 'Nemáte oprávnění';
233 $Form = new Form($this->System->FormManager);
234 $Form->SetClass($Table);
235 if ($Form->HasAllPostVariables())
236 {
237 $Form = new Form($this->System->FormManager);
238 $Form->SetClass($Table);
239 $Form->LoadValuesFromForm();
240 $this->Title .= ' - '.$Form->Definition['Title'].' duplikování';
241 try
242 {
243 $Form->Validate();
244 if (array_key_exists('BeforeInsert', $Form->Definition))
245 {
246 $Class = $Form->Definition['BeforeInsert'][0];
247 $Method = $Form->Definition['BeforeInsert'][1];
248 $Form->Values = $Class->$Method($Form);
249 }
250 $Form->Validate();
251 $Form->SaveValuesToDatabase(0);
252 $Id = $this->Database->insert_id;
253 $this->LogChange($Form, 'Clone', $Id, 0);
254 $Output .= $this->SystemMessage('Duplikování položky', 'Nová kopie položky vytvořena');
255 $Output .= $this->ShowView($Table, $Id, $_GET['a'] == 'addsub');
256 if (array_key_exists('AfterInsert', $Form->Definition))
257 {
258 $Class = $Form->Definition['AfterInsert'][0];
259 $Method = $Form->Definition['AfterInsert'][1];
260 $Form->Values = $Class->$Method($Form, $Id);
261 }
262
263 //$this->Database->update($Table, 'Id='.$Id,
264 // array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
265 // 'TimeCreate' => 'NOW()'));
266 } catch (Exception $E)
267 {
268 $Output .= $this->SystemMessage('Duplikování položky', 'Položku se nepodařilo duplikovat. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
269 $Form->OnSubmit = '?a=clone&amp;t='.$Table;
270 $Output .= $Form->ShowEditForm();
271 $Actions[] = '<a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
272 $this->System->Link('/images/list.png').'"/>Seznam</a>';
273 }
274 } else
275 {
276 $Form->LoadValuesFromDatabase($Id);
277 $this->Title .= ' - '.$Form->Definition['Title'].' duplikování';
278 $Form->OnSubmit = '?a='.$_GET['a'].'&amp;t='.$Table;
279 $Output .= $Form->ShowEditForm();
280 $Actions[] = $this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
281 $this->System->Link('/images/list.png'));
282 }
283 $Output .= '<ul class="ActionMenu">';
284 foreach ($Actions as $Action)
285 {
286 $Output .= '<li>'.$Action.'</li>';
287 }
288 $Output .= '</ul>';
289 return $Output;
290 }
291
292 function ShowDelete(string $Table, string $Id): string
293 {
294 $Output = '';
295 if (!array_key_exists($Table, $this->System->FormManager->Classes))
296 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
297 $FormClass = $this->System->FormManager->Classes[$Table];
298 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
299 return 'Nemáte oprávnění';
300 $DbResult = $this->Database->select($Table, '*', '`Id`='.$Id);
301 if ($DbResult->num_rows > 0)
302 {
303 $DbRow = $DbResult->fetch_assoc();
304 try
305 {
306 $Form = new Form($this->System->FormManager);
307 $Form->SetClass($Table);
308 $Form->LoadValuesFromDatabase($Id);
309 $this->Title .= ' - '.$Form->Definition['Title'].' odstranění';
310 if (array_key_exists('BeforeDelete', $Form->Definition))
311 {
312 call_user_func($Form->Definition['BeforeDelete'], $Form, $Id);
313 }
314 $this->LogChange($Form, 'Delete', 0, $Id);
315 $this->Database->delete($Table, '`Id`='.$Id);
316 $Output .= $this->SystemMessage('Smazání položky', 'Položka odstraněna');
317 if (array_key_exists('AfterDelete', $Form->Definition))
318 {
319 $Class = $Form->Definition['AfterDelete'][0];
320 $Method = $Form->Definition['AfterDelete'][1];
321 $Class->$Method($Form, $Id);
322 }
323 } catch (Exception $E)
324 {
325 $Output .= $this->SystemMessage('Smazání položky', 'Položku se nepodařilo smazat. Pravděpodobně na ni závisejí další položky.<br/>'.$E->getMessage());
326 }
327 } else $Output .= $this->SystemMessage('Smazání položky', 'Položka nenalezena');
328 $Output .= $this->ShowList($Table);
329 return $Output;
330 }
331
332 function ShowAdd(string $Table, array $Actions = array()): string
333 {
334 $Output = '';
335 if (!array_key_exists($Table, $this->System->FormManager->Classes))
336 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
337 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
338 return 'Nemáte oprávnění';
339 $Form = new Form($this->System->FormManager);
340 $Form->SetClass($Table);
341 if ($Form->HasAllPostVariables())
342 {
343 $Form->LoadValuesFromForm();
344 $this->Title .= ' - '.$Form->Definition['Title'].' přidání';
345 try
346 {
347 $Form->Validate();
348 if (array_key_exists('BeforeInsert', $Form->Definition))
349 {
350 $Class = $Form->Definition['BeforeInsert'][0];
351 $Method = $Form->Definition['BeforeInsert'][1];
352 $Form->Values = $Class->$Method($Form);
353 }
354 $Form->Validate();
355 $Form->SaveValuesToDatabase(0);
356 $Id = $this->Database->insert_id;
357 $this->LogChange($Form, 'Add', $Id, 0);
358 $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
359 $Output .= $this->ShowView($Table, $Id, $_GET['a'] == 'addsub');
360 if (array_key_exists('AfterInsert', $Form->Definition))
361 {
362 $Class = $Form->Definition['AfterInsert'][0];
363 $Method = $Form->Definition['AfterInsert'][1];
364 $Form->Values = $Class->$Method($Form, $Id);
365 }
366 // Add action to update caller form
367 if ($_GET['a'] == 'addsub')
368 {
369 $Type = $this->System->FormManager->FormTypes[$_GET['rt']];
370 $DbResult = $this->Database->select($Table, '('.$Type['Name'].') AS Name', 'Id='.$Id);
371 $DbRow = $DbResult->fetch_assoc();
372 $Actions[] = '<a href="javascript:window.close();" onclick="add_select_item('.$Id.',&quot;'.$DbRow['Name'].'&quot;,&quot;'.
373 $_GET['r'].'&quot;); set_return ('.$Id.',&quot;'.
374 $_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
375 $this->System->Link('/images/select.png').'"/> Vybrat</a>';
376 }
377
378 //$this->Database->update($Table, 'Id='.$Id,
379 // array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
380 // 'TimeCreate' => 'NOW()'));
381 } catch (Exception $E)
382 {
383 $Output .= $this->SystemMessage('Přidání položky', 'Položku se nepodařilo přidat. Opravte problém a opakujte akci.<br/>'.$E->getMessage());
384 $Form->OnSubmit = '?a=add&amp;t='.$Table;
385 $Output .= $Form->ShowEditForm();
386 $Actions[] = '<a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
387 $this->System->Link('/images/list.png').'"/>Seznam</a>';
388 }
389 } else
390 {
391 $Form = new Form($this->System->FormManager);
392 $Form->SetClass($Table);
393 $this->Title .= ' - '.$Form->Definition['Title'].' přidání';
394 // Load presets from URL
395 foreach ($_GET as $Key => $Value)
396 {
397 if (substr($Key, 0, 6) == 'preset')
398 {
399 $Key = substr($Key, 6);
400 if (($Key != '') and array_key_exists($Key, $Form->Values))
401 $Form->Values[$Key] = $Value;
402 }
403 }
404 if (array_key_exists('r', $_GET)) $URL = '&amp;r='.$_GET['r'].'&amp;rt='.$_GET['rt'];
405 else $URL = '';
406 $Form->OnSubmit = '?a='.$_GET['a'].'&amp;t='.$Table.$URL;
407 $Output .= $Form->ShowEditForm();
408 $Actions[] = $this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
409 $this->System->Link('/images/list.png'));
410 }
411 $Output .= '<ul class="ActionMenu">';
412 foreach ($Actions as $Action)
413 {
414 $Output .= '<li>'.$Action.'</li>';
415 }
416 $Output .= '</ul>';
417 return $Output;
418 }
419
420 function ShowAddSub(string $Table, string $Filter = '', string $Title = ''): string
421 {
422 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
423 return 'Nemáte oprávnění';
424 $this->BasicHTML = true;
425 $this->HideMenu = true;
426 $Output = $this->ShowAdd($Table);
427 return $Output;
428 }
429
430 function ShowTabs(array $Tabs, string $QueryParamName, string $TabContent): string
431 {
432 $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
433 $QueryItems['a'] = 'view';
434
435 if (array_key_exists($QueryParamName, $_GET)) $TabIndex = $_GET[$QueryParamName];
436 else $TabIndex = 0;
437
438 $Output = '<div class="Tab">'.
439 '<ul>';
440 foreach ($Tabs as $Index => $Tab)
441 {
442 $QueryItems[$QueryParamName] = $Index;
443 if ($Index == $TabIndex) $Selected = ' id="selected"';
444 else $Selected = '';
445 $Output .= '<li'.$Selected.'><a href="?'.SetQueryStringArray($QueryItems).'">'.$Tab.'</a></li>';
446 }
447 $Output .= '</ul></div><div class="TabContent">'.$TabContent.'</div>';
448 return $Output;
449 }
450
451 function ShowView(string $Table, string $Id, bool $WithoutActions = false): string
452 {
453 if (!array_key_exists($Table, $this->System->FormManager->Classes))
454 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
455 $FormClass = $this->System->FormManager->Classes[$Table];
456 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
457 return 'Nemáte oprávnění';
458
459 $FormClass = $this->System->FormManager->Classes[$Table];
460 if (array_key_exists('BaseTable', $FormClass)) $TableModify = $FormClass['BaseTable'];
461 else $TableModify = $Table;
462
463 $Form = new Form($this->System->FormManager);
464 $Form->SetClass($Table);
465 $this->Title .= ' - '.$Form->Definition['Title'].' položka';
466 try
467 {
468 $Form->LoadValuesFromDatabase($Id);
469 } catch (Exception $E)
470 {
471 return $this->SystemMessage('Chyba', 'Položka '.$Id.' nenalezena.');
472 }
473 $Form->OnSubmit = '?a=view';
474 $Output = $Form->ShowViewForm();
475 if ($WithoutActions == false)
476 {
477 $Actions = array(
478 $this->ShowAction('Upravit', '?a=edit&amp;t='.$TableModify.'&amp;i='.$Id,
479 $this->System->Link('/images/edit.png')),
480 $this->ShowAction('Duplikovat', '?a=clone&amp;t='.$TableModify.'&amp;i='.$Id,
481 $this->System->Link('/images/clone.png')),
482 $this->ShowAction('Seznam', '?a=list&amp;t='.$Table,
483 $this->System->Link('/images/list.png')),
484 $this->ShowAction('Odstranit', '?a=delete&amp;t='.$Table.'&amp;i='.$Id,
485 $this->System->Link('/images/delete.png'), 'Opravdu smazat položku?'),
486 $this->ShowAction('Přidat', '?a=add&amp;t='.$TableModify,
487 $this->System->Link('/images/add.png'))
488 );
489 if (array_key_exists('ItemActions', $FormClass))
490 {
491 foreach ($FormClass['ItemActions'] as $Action)
492 {
493 $URL = str_replace('#RowId', $Id, $this->System->Link($Action['URL']));
494 $Actions[] = $this->ShowAction($Action['Caption'], $URL,
495 $this->System->Link('/images/action.png'));
496 }
497 }
498 $Output .= '<ul class="ActionMenu">';
499 foreach ($Actions as $Action)
500 {
501 $Output .= '<li>'.$Action.'</li>';
502 }
503 $Output .= '</ul><br/>';
504 }
505
506 // Show ManyToOne relations
507 $Tabs = array();
508 foreach ($Form->Definition['Items'] as $Index => $Item)
509 {
510 if ((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
511 ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
512 {
513 $Tabs[] = $Item['Caption'];
514 }
515 }
516 if (count($Tabs) > 0)
517 {
518 if (count($Tabs) > 1)
519 {
520 $Tabs[] = 'Vše';
521 }
522 if (array_key_exists('tab', $_GET))
523 {
524 $TabIndex = $_GET['tab'];
525 if (($TabIndex < 0) or ($TabIndex >= count($Tabs)))
526 {
527 $TabIndex = 0;
528 }
529 } else $TabIndex = 0;
530
531 $TabContent = '';
532 $I = 0;
533 foreach ($Form->Definition['Items'] as $Index => $Item)
534 if ((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
535 ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
536 {
537 $TypeItem = $this->System->FormManager->FormTypes[$Item['Type']];
538 if (($TabIndex == $I) or ((count($Tabs) > 1) and ($TabIndex == (count($Tabs) - 1))))
539 {
540 if ($TypeItem['Ref'] == null)
541 {
542 $Filter = $TypeItem['Filter'];
543 $Filter = str_replace('#Id', $Id, $Filter);
544 $TabContent .= $this->ShowList($TypeItem['Table'],
545 $Filter, $Item['Caption']).'<br/>';
546 } else $TabContent .= $this->ShowList($TypeItem['Table'], '`'.
547 $TypeItem['Ref'].'`='.$Id, $Item['Caption'],
548 $TypeItem['Ref'], $Id).'<br/>';
549 }
550 $I++;
551 }
552
553 $Output .= $this->ShowTabs($Tabs, 'tab', $TabContent);
554 }
555 return $Output;
556 }
557
558 function GetParam(string $Name, string $Default): string
559 {
560 $Result = $Default;
561 if (array_key_exists($Name, $_POST) and ($_POST[$Name] != ''))
562 {
563 $Result = $_POST[$Name];
564 }
565 if (array_key_exists($Name, $_GET) and ($_GET[$Name] != ''))
566 {
567 $Result = $_GET[$Name];
568 }
569 return $Result;
570 }
571
572 function ShowTable(string $Table, string $Filter = '', string $Title = '', string $RowActions = '', string $ExcludeColumn = ''): string
573 {
574 if (!array_key_exists($Table, $this->System->FormManager->Classes))
575 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
576 $FormClass = $this->System->FormManager->Classes[$Table];
577
578 if (array_key_exists('SQL', $FormClass))
579 $SourceTable = '('.$FormClass['SQL'].') AS `TX`';
580 else $SourceTable = '`'.$FormClass['Table'].'` AS `TX`';
581
582 $WhereFilter = $Filter;
583 $HavingFilter = '';
584
585 // Build form type filter
586 $TypeFilter = '';
587 foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
588 if (!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
589 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
590 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
591 if (array_key_exists('Filter', $FormItem) and ($FormItem['Filter'] == true))
592 {
593 if ($TypeFilter != '') $TypeFilter .= ' AND ';
594 $TypeFilter .= '(`'.$ItemIndex.'` = "'.$FormItem['Default'].'")';
595 }
596 if ($TypeFilter != '')
597 {
598 if ($HavingFilter != '') $HavingFilter = ' AND';
599 $HavingFilter .= ' '.$TypeFilter;
600 }
601
602 // Build user filter
603 $UserFilter = '';
604 $Columns = array('Id' => '`Id`');
605 if (array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
606 {
607 foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
608 if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
609 if (!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
610 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
611 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
612 {
613 $UseType = $UseType = $FormItem['Type'];
614 if (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
615 {
616 if (!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
617 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
618 $this->System->FormManager->FormTypes[$FormItem['Type']]);
619 if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
620 $UseType = 'OneToMany';
621 else
622 if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
623 $UseType = 'Enumeration';
624 }
625 $FilterName = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterName',
626 array('Name' => $ItemIndex, 'Type' => $FormItem['Type']));
627
628 $SqlOperator = array(
629 'like' => 'LIKE',
630 'notlike' => 'NOT LIKE',
631 'equal' => '=',
632 'notequal' => '!=',
633 'less' => '<',
634 'lessorequal' => '<=',
635 'greater' => '>',
636 'greaterorequal' => '>=',
637 'isnull' => 'IS NULL',
638 'isnotnull' => 'IS NOT NULL',
639 );
640 $Operator = $this->GetParam('FilterOp'.$ItemIndex, 'like');
641 if (array_key_exists($Operator, $SqlOperator))
642 {
643 $OperatorSql = $SqlOperator[$Operator];
644 } else $OperatorSql = $SqlOperator['like'];
645
646 $FilterValue = $this->GetParam('Filter'.$ItemIndex, '');
647 if ($FilterValue != '')
648 {
649 if ($UserFilter != '') $UserFilter .= ' AND ';
650 $UserFilter .= '('.$FilterName.' '.$OperatorSql;
651 if (($Operator == 'like') or ($Operator == 'notlike')) $UserFilter .= ' "%'.$FilterValue.'%")';
652 else if (($Operator == 'isnull') or ($Operator == 'isnotnull')) $UserFilter .= ')';
653 else $UserFilter .= ' "'.$FilterValue.'")';
654 }
655 }
656 }
657 if ($UserFilter != '')
658 {
659 if ($HavingFilter != '') $HavingFilter .= ' AND';
660 $HavingFilter .= ' '.$UserFilter;
661 }
662 if ($WhereFilter != '') $Filter = ' WHERE '.$WhereFilter;
663 if ($HavingFilter != '') $Filter = ' HAVING '.$HavingFilter;
664
665
666 foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
667 if (!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
668 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
669 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
670 {
671 if ($ExcludeColumn != $ItemIndex)
672 if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
673 if (!array_key_exists('NotInList', $FormItem) or ($FormItem['NotInList'] == false))
674 $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
675 $UseType = $UseType = $FormItem['Type'];
676 if (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
677 {
678 if (!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
679 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
680 $this->System->FormManager->FormTypes[$FormItem['Type']]);
681 if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
682 $UseType = 'OneToMany';
683 else
684 if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
685 $UseType = 'Enumeration';
686 }
687 if (array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
688 $Value = $_POST['Filter'.$ItemIndex];
689 else $Value = '';
690 if ($ItemIndex == 'Id') unset($Columns['Id']);
691
692 if (!array_key_exists('SQL', $FormItem)) $FormItem['SQL'] = '';
693 else $FormItem['SQL'] = str_replace('#Id', '`TX`.`Id`', $FormItem['SQL']);
694 $Columns[] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
695 array('Value' => $Value, 'Name' => $ItemIndex,
696 'Type' => $FormItem['Type'], 'SQL' => $FormItem['SQL']));
697 }
698
699 // Get total item count in database
700 $Query = 'SELECT COUNT(*) FROM '.$SourceTable;
701 $DbResult = $this->Database->query($Query);
702 $DbRow = $DbResult->fetch_assoc();
703 $TotalCount = $DbRow['COUNT(*)'];
704
705 // Get total filtered item count in database
706 $Columns = implode(',', $Columns);
707 if ($Filter != '')
708 {
709 $Query = 'SELECT COUNT(*) FROM (SELECT '.$Columns.' FROM '.$SourceTable.' '.$Filter.') AS `TS`';
710 $DbResult = $this->Database->query($Query);
711 $DbRow = $DbResult->fetch_row();
712 $TotalFilteredCount = $DbRow[0];
713 } else $TotalFilteredCount = $TotalCount;
714 $PageList = GetPageList($Table, $TotalFilteredCount);
715
716 $Output = $PageList['Output'];
717 $Output .= '<table class="WideTable" style="font-size: small;">';
718
719 $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
720 if (!array_key_exists('DefaultSortColumn', $FormClass))
721 $FormClass['DefaultSortColumn'] = 'Id';
722 if (!array_key_exists('DefaultSortOrder', $FormClass))
723 $FormClass['DefaultSortOrder'] = 0;
724 $Order = GetOrderTableHeader($Table, $TableColumns, $FormClass['DefaultSortColumn'], $FormClass['DefaultSortOrder']);
725 $Output .= $Order['Output'];
726
727 // Show search fields
728 if (array_key_exists('r', $_GET)) $Addition = '&amp;r='.$_GET['r'];
729 else $Addition = '';
730 $Output .= '<tr><form action="?a='.$_GET['a'].'&amp;t='.$Table.'&amp;filter=1'.$Addition.'" method="post">';
731 foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
732 if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
733 if (!array_key_exists('NotInList', $FormItem) or ($FormItem['NotInList'] == false))
734 if ((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
735 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
736 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) and
737 ($ExcludeColumn != $ItemIndex))
738 {
739 if (array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
740 $Value = $_POST['Filter'.$ItemIndex];
741 else $Value = '';
742 $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';
743 }
744 $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
745
746 // Load and show items
747 $Query = 'SELECT '.$Columns.' FROM '.$SourceTable.' '.
748 $Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
749 $VisibleItemCount = 0;
750 $DbResult = $this->Database->query($Query);
751 while ($Row = $DbResult->fetch_assoc())
752 {
753 $Output .= '<tr>';
754 foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
755 if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
756 if (!array_key_exists('NotInList', $FormItem) or ($FormItem['NotInList'] == false))
757 if ((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
758 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
759 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) and
760 ($ExcludeColumn != $ItemIndex))
761 {
762 //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
763 $UseType = $UseType = $FormItem['Type'];
764 if (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
765 {
766 if (!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
767 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
768 $this->System->FormManager->FormTypes[$FormItem['Type']]);
769 if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
770 $UseType = 'OneToMany';
771 else
772 if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
773 $UseType = 'Enumeration';
774 }
775 $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
776 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
777 'Type' => $FormItem['Type']));
778 $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
779 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
780 'Type' => $FormItem['Type'], 'Filter' => $Row[$ItemIndex.'_Filter']));
781 if ($Value == '') $Value = '&nbsp;';
782 $Output .= '<td>'.$Value.'</td>';
783 }
784 $Output .= '<td>'.str_replace('#RowId', $Row['Id'], $RowActions).'</td></tr>';
785 $VisibleItemCount = $VisibleItemCount + 1;
786 }
787 $Output .= '<tr><td colspan="'.count($TableColumns).'" style="text-align: right;">Zobrazeno <strong>'.$VisibleItemCount.'</strong>';
788 if ($UserFilter != '') $Output .= ' z filtrovaných <strong>'.$TotalFilteredCount.'</strong>';
789 $Output .= ' z celkem <strong>'.$TotalCount.'</strong></td></tr>';
790 $Output .= '</table>';
791 $Output .= $PageList['Output'];
792 return $Output;
793 }
794
795 function ShowSelect(string $Table, string $Filter = '', string $Title = ''): string
796 {
797 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
798 return 'Nemáte oprávnění';
799 $this->BasicHTML = true;
800 $this->HideMenu = true;
801 $RowActions = '<a href="javascript:window.close();" onclick="set_return (#RowId,&quot;'.
802 $_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
803 $this->System->Link('/images/select.png').'"/></a>';
804 $Output = $this->ShowTable($Table, $Filter, $Title, $RowActions);
805 return $Output;
806 }
807
808 function ShowMapSelect(string $Table, string $Filter = '', string $Title = ''): string
809 {
810 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
811 return 'Nemáte oprávnění';
812 $Map = new MapOpenStreetMaps($this->System);
813 $Map->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
814 'Lng' => $this->System->Config['Map']['DefaultLongitude']);
815 $Map->Zoom = $this->System->Config['Map']['DefaultZoom'];
816 $Map->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
817 $Map->OnClickObject = $_GET['r'];
818 //$MapApi->ShowMarker = true;
819 $Output = $Map->ShowPage($this);
820 return $Output;
821 }
822
823 function ShowList(string $Table, string $Filter = '', string $Title = '', string $ExcludeColumn = '', string $ExcludeValue = ''): string
824 {
825 $Output = '';
826 if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
827 return 'Nemáte oprávnění';
828 if (!array_key_exists($Table, $this->System->FormManager->Classes))
829 return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
830 $FormClass = $this->System->FormManager->Classes[$Table];
831 if (array_key_exists('BaseTable', $FormClass)) $TableModify = $FormClass['BaseTable'];
832 else $TableModify = $Table;
833
834 $RowActions =
835 $this->ShowAction('Ukázat', '?a=view&amp;t='.$Table.'&amp;i=#RowId', $this->System->Link('/images/view.png')).
836 $this->ShowAction('Upravit', '?a=edit&amp;t='.$TableModify.'&amp;i=#RowId', $this->System->Link('/images/edit.png')).
837 $this->ShowAction('Duplikovat', '?a=clone&amp;t='.$TableModify.'&amp;i=#RowId', $this->System->Link('/images/clone.png')).
838 $this->ShowAction('Odstranit', '?a=delete&amp;t='.$Table.'&amp;i=#RowId', $this->System->Link('/images/delete.png'), 'Opravdu smazat položku?;');
839 if (($Table != '') and (array_key_exists($Table, $this->System->FormManager->Classes)))
840 $FormClass = $this->System->FormManager->Classes[$Table];
841 else return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
842 if ($ExcludeColumn == '') $this->Title .= ' - '.$FormClass['Title'];
843 if (array_key_exists('ItemActions', $FormClass))
844 {
845 foreach ($FormClass['ItemActions'] as $Action)
846 {
847 $URL = $this->System->Link($Action['URL']);
848 $RowActions .= '<a href="'.$URL.'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
849 $this->System->Link('/images/action.png').'"/></a>';
850 }
851 }
852 $Output .= '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
853 $Output .= '<ul class="ActionMenu">';
854 $Output .= '<li>'.$this->ShowAction('Přidat', '?a=add&amp;t='.$TableModify.'&amp;preset'.$ExcludeColumn.'='.$ExcludeValue, $this->System->Link('/images/add.png')).'</li>';
855 $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&amp;t='.$Table, $this->System->Link('/images/list.png')).'</li>';
856 $MI = 0;
857 if (array_key_exists('mi', $_GET))
858 {
859 $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['mi'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
860 if ($DbResult->num_rows > 0)
861 {
862 $DbRow = $DbResult->fetch_assoc();
863 $Fav = $DbRow['Id'];
864 $Output .= '<li>'.$this->ShowAction('Odebrat z oblíbených', '?a=fav_del&amp;t='.$Table.'&amp;i='.$_GET['mi'].'&amp;mi='.$_GET['mi'],
865 $this->System->Link('/images/Favorite-Del.png')).'</li>';
866 } else $Output .= '<li>'.$this->ShowAction('Přidat do oblíbených', '?a=fav_add&amp;t='.$Table.'&amp;i='.$_GET['mi'].'&amp;mi='.$_GET['mi'],
867 $this->System->Link('/images/Favorite-Add.png')).'</li>';
868 }
869 if (array_key_exists('Actions', $FormClass))
870 {
871 foreach ($FormClass['Actions'] as $Action)
872 {
873 $Output .= '<li>'.$this->ShowAction($Action['Caption'], $this->System->Link($Action['URL']),
874 $this->System->Link('/images/action.png')).'</li>';
875 }
876 }
877 $Output .= '</ul>';
878 $Output .= $this->ShowTable($Table, $Filter, $Title, $RowActions, $ExcludeColumn);
879 return $Output;
880 }
881
882 function ShowFavorites(): string
883 {
884 $this->MenuItems = array();
885 $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName`, `Action`.`PermissionOperation` AS `Permission` FROM `MenuItemFavorite` ' .
886 'LEFT JOIN `MenuItem` ON `MenuItem`.`Id` = `MenuItemFavorite`.`MenuItem` '.
887 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
888 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
889 'WHERE `MenuItemFavorite`.`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].' '.
890 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
891 while ($DbRow = $DbResult->fetch_assoc())
892 {
893 //if ($DbRow['Permission'] != '')
894 $this->MenuItems[$DbRow['Id']] = $DbRow;
895 }
896 return $this->ShowMenuItem('', true);
897 }
898
899 function ShowMenu(): string
900 {
901 $this->MenuItems = array();
902 $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName`, `Action`.`PermissionOperation` AS `Permission` FROM `MenuItem` '.
903 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
904 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
905 'WHERE `MenuItem`.`Menu`=1 '.
906 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
907 while ($DbRow = $DbResult->fetch_assoc())
908 {
909 //if ($DbRow['Permission'] != '')
910 $this->MenuItems[$DbRow['Id']] = $DbRow;
911 }
912 return $this->ShowMenuItem('');
913 }
914
915 function ShowMenuItem(string $Parent, bool $All = false): string
916 {
917 $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
918 foreach ($this->MenuItems as $MenuItem)
919 {
920 if (($MenuItem['Parent'] == $Parent) or $All)
921 {
922 $LinkTitle = $MenuItem['Name'];
923 if ($MenuItem['URL'] != '')
924 {
925 $Icon = 'Device.png';
926 if (substr($MenuItem['URL'], 0, 4) != 'http') $MenuItem['URL'] = $this->System->Link($MenuItem['URL']);
927 $LinkTitle = MakeLink($MenuItem['URL'].'&amp;mi='.$MenuItem['Id'], $LinkTitle);
928 } else $Icon = 'Folder.png';
929 if ($MenuItem['IconName'] != '') $Image = '<img src="'.$this->System->Link('/images/favicons/'.$MenuItem['IconName']).'"/>&nbsp;';
930 else $Image = '<img src="'.$this->System->Link('/images/favicons/'.$Icon).'"/>&nbsp;';
931 //if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write') or !defined('NEW_PERMISSION'))
932 $Output .= '<li>'.$Image.$LinkTitle.'</li>';
933 if ($All == false) $Output .= $this->ShowMenuItem($MenuItem['Id']);
934 }
935 }
936 $Output .= '</ul>';
937 return $Output;
938 }
939
940 function TableToModule(string $Table): string
941 {
942 $DbResult = $this->Database->query('SELECT (SELECT `Name` FROM `Module` '.
943 'WHERE `Module`.`Id`=`Model`.`Module`) AS `Name` FROM `Model` WHERE `Name`="'.$Table.'"');
944 if ($DbResult->num_rows == 1)
945 {
946 $DbRow = $DbResult->fetch_assoc();
947 return $DbRow['Name'];
948 } else return '';
949 }
950
951 function ShowAction(string $Name, string $Target, string $Icon, string $Confirm = ''): string
952 {
953 $Output = '<img alt="'.$Name.'" title="'.$Name.'" src="'.
954 $Icon.'"/>';
955 if ($this->ShowActionName) $Output .= $Name;
956 if ($Confirm != '')
957 $Confirm = ' onclick="return confirmAction(\''.$Confirm.'\');"';
958 $Output = '<a href="'.$Target.'"'.$Confirm.'>'.$Output.'</a>';
959 return $Output;
960 }
961}
962
963class Menu extends Model
964{
965 static function GetModelDesc(): ModelDesc
966 {
967 $Desc = new ModelDesc(self::GetClassName());
968 $Desc->AddString('Name');
969 return $Desc;
970 }
971}
972
973class MenuItem extends Model
974{
975 static function GetModelDesc(): ModelDesc
976 {
977 $Desc = new ModelDesc(self::GetClassName());
978 $Desc->AddString('Name');
979 $Desc->AddReference('Parent', MenuItem::GetClassName());
980 $Desc->AddReference('Action', Action::GetClassName());
981 $Desc->AddReference('Menu', Menu::GetClassName());
982 return $Desc;
983 }
984}
985
986class MenuItemFavorite extends Model
987{
988 static function GetModelDesc(): ModelDesc
989 {
990 $Desc = new ModelDesc(self::GetClassName());
991 $Desc->AddReference('User', User::GetClassName());
992 $Desc->AddReference('MenuItem', MenuItem::GetClassName());
993 return $Desc;
994 }
995}
996
997class ModuleIS extends Module
998{
999 public array $DashboardItems;
1000
1001 function __construct(System $System)
1002 {
1003 parent::__construct($System);
1004 $this->Name = 'IS';
1005 $this->Title = 'Information system';
1006 $this->Version = '1.0';
1007 $this->Creator = 'Chronos';
1008 $this->License = 'GNU/GPLv3';
1009 $this->Description = 'User interface for generic information system';
1010 $this->Dependencies = array(ModuleUser::GetName());
1011 $this->Models = array(Menu::GetClassName(), MenuItem::GetClassName(), MenuItemFavorite::GetClassName());
1012
1013 $this->DashboardItems = array();
1014 }
1015
1016 function DoStart(): void
1017 {
1018 $this->System->RegisterPage(['is'], 'PageIS');
1019 $this->System->FormManager->RegisterClass('MenuItem', array(
1020 'Title' => 'Položky nabídky',
1021 'Table' => 'MenuItem',
1022 'Items' => array(
1023 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
1024 'Parent' => array('Type' => 'TMenuItem', 'Caption' => 'Rodič', 'Default' => '', 'Null' => true),
1025 'Action' => array('Type' => 'TAction', 'Caption' => 'Akce', 'Default' => ''),
1026 'Menu' => array('Type' => 'TMenu', 'Caption' => 'Nabídka', 'Default' => ''),
1027 'Items' => array('Type' => 'TMenuItemListParent', 'Caption' => 'Položky'),
1028 ),
1029 ));
1030 $this->System->FormManager->RegisterClass('MenuItemFavorite', array(
1031 'Title' => 'Oblíbené položky nabídky',
1032 'Table' => 'MenuItemFavorite',
1033 'Items' => array(
1034 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatele', 'Default' => '0'),
1035 'MenuItem' => array('Type' => 'TMenuItem', 'Caption' => 'Položka nabídky', 'Default' => '0'),
1036 ),
1037 ));
1038 $this->System->FormManager->RegisterClass('Menu', array(
1039 'Title' => 'Nabídky',
1040 'Table' => 'Menu',
1041 'Items' => array(
1042 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
1043 'Items' => array('Type' => 'TMenuItemListMenu', 'Caption' => 'Položky'),
1044 ),
1045 ));
1046 $this->System->FormManager->RegisterFormType('TMenuItem', array(
1047 'Type' => 'Reference',
1048 'Table' => 'MenuItem',
1049 'Id' => 'Id',
1050 'Name' => 'Name',
1051 'Filter' => '1',
1052 ));
1053 $this->System->FormManager->RegisterFormType('TMenu', array(
1054 'Type' => 'Reference',
1055 'Table' => 'Menu',
1056 'Id' => 'Id',
1057 'Name' => 'Name',
1058 'Filter' => '1',
1059 ));
1060 }
1061
1062 function RegisterDashboardItem(string $Name, callable $Callback): void
1063 {
1064 $this->DashboardItems[$Name] = array('Callback' => $Callback);
1065 }
1066
1067 function UnregisterDashboardItem(string $Name): void
1068 {
1069 unset($this->DashboardItems[$Name]);
1070 }
1071
1072 static function Cast(Module $Module): ModuleIS
1073 {
1074 if ($Module instanceof ModuleIS)
1075 {
1076 return $Module;
1077 }
1078 throw new Exception('Expected ModuleIS type but '.gettype($Module));
1079 }
1080}
Note: See TracBrowser for help on using the repository browser.