| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | include_once(dirname(__FILE__).'/../../Common/Global.php');
|
|---|
| 4 |
|
|---|
| 5 | class 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&t='.$Table.'&i='.$_GET['i'];
|
|---|
| 194 | $Output .= $Form->ShowEditForm();
|
|---|
| 195 | $Output .= '<ul class="ActionMenu">';
|
|---|
| 196 | $Output .= '<li>'.$this->ShowAction('Prohlížet', '?a=view&t='.$Table.'&i='.$Id,
|
|---|
| 197 | $this->System->Link('/images/view.png'));
|
|---|
| 198 | $Output .= '<li>'.$this->ShowAction('Duplikovat', '?a=clone&t='.$Table.'&i='.$Id,
|
|---|
| 199 | $this->System->Link('/images/clone.png'));
|
|---|
| 200 | $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&t='.$Table,
|
|---|
| 201 | $this->System->Link('/images/list.png'));
|
|---|
| 202 | $Output .= '<li>'.$this->ShowAction('Odstranit', '?a=delete&t='.$Table.'&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&t='.$Table.'&i='.$_GET['i'];
|
|---|
| 211 | $Output .= $Form->ShowEditForm();
|
|---|
| 212 | $Output .= '<ul class="ActionMenu">';
|
|---|
| 213 | $Output .= '<li>'.$this->ShowAction('Prohlížet', '?a=view&t='.$Table.'&i='.$Id,
|
|---|
| 214 | $this->System->Link('/images/view.png'));
|
|---|
| 215 | $Output .= '<li>'.$this->ShowAction('Duplikovat', '?a=clone&t='.$Table.'&i='.$Id,
|
|---|
| 216 | $this->System->Link('/images/clone.png'));
|
|---|
| 217 | $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&t='.$Table,
|
|---|
| 218 | $this->System->Link('/images/list.png'));
|
|---|
| 219 | $Output .= '<li>'.$this->ShowAction('Odstranit', '?a=delete&t='.$Table.'&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&t='.$Table;
|
|---|
| 270 | $Output .= $Form->ShowEditForm();
|
|---|
| 271 | $Actions[] = '<a href="?a=list&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'].'&t='.$Table;
|
|---|
| 279 | $Output .= $Form->ShowEditForm();
|
|---|
| 280 | $Actions[] = $this->ShowAction('Seznam', '?a=list&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.',"'.$DbRow['Name'].'","'.
|
|---|
| 373 | $_GET['r'].'"); set_return ('.$Id.',"'.
|
|---|
| 374 | $_GET['r'].'");"><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&t='.$Table;
|
|---|
| 385 | $Output .= $Form->ShowEditForm();
|
|---|
| 386 | $Actions[] = '<a href="?a=list&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 = '&r='.$_GET['r'].'&rt='.$_GET['rt'];
|
|---|
| 405 | else $URL = '';
|
|---|
| 406 | $Form->OnSubmit = '?a='.$_GET['a'].'&t='.$Table.$URL;
|
|---|
| 407 | $Output .= $Form->ShowEditForm();
|
|---|
| 408 | $Actions[] = $this->ShowAction('Seznam', '?a=list&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 | $Form->LoadValuesFromDatabase($Id);
|
|---|
| 467 | $Form->OnSubmit = '?a=view';
|
|---|
| 468 | $Output = $Form->ShowViewForm();
|
|---|
| 469 | if ($WithoutActions == false)
|
|---|
| 470 | {
|
|---|
| 471 | $Actions = array(
|
|---|
| 472 | $this->ShowAction('Upravit', '?a=edit&t='.$TableModify.'&i='.$Id,
|
|---|
| 473 | $this->System->Link('/images/edit.png')),
|
|---|
| 474 | $this->ShowAction('Duplikovat', '?a=clone&t='.$TableModify.'&i='.$Id,
|
|---|
| 475 | $this->System->Link('/images/clone.png')),
|
|---|
| 476 | $this->ShowAction('Seznam', '?a=list&t='.$Table,
|
|---|
| 477 | $this->System->Link('/images/list.png')),
|
|---|
| 478 | $this->ShowAction('Odstranit', '?a=delete&t='.$Table.'&i='.$Id,
|
|---|
| 479 | $this->System->Link('/images/delete.png'), 'Opravdu smazat položku?'),
|
|---|
| 480 | $this->ShowAction('Přidat', '?a=add&t='.$TableModify,
|
|---|
| 481 | $this->System->Link('/images/add.png'))
|
|---|
| 482 | );
|
|---|
| 483 | if (array_key_exists('ItemActions', $FormClass))
|
|---|
| 484 | {
|
|---|
| 485 | foreach ($FormClass['ItemActions'] as $Action)
|
|---|
| 486 | {
|
|---|
| 487 | $URL = str_replace('#RowId', $Id, $this->System->Link($Action['URL']));
|
|---|
| 488 | $Actions[] = $this->ShowAction($Action['Caption'], $URL,
|
|---|
| 489 | $this->System->Link('/images/action.png'));
|
|---|
| 490 | }
|
|---|
| 491 | }
|
|---|
| 492 | $Output .= '<ul class="ActionMenu">';
|
|---|
| 493 | foreach ($Actions as $Action)
|
|---|
| 494 | {
|
|---|
| 495 | $Output .= '<li>'.$Action.'</li>';
|
|---|
| 496 | }
|
|---|
| 497 | $Output .= '</ul><br/>';
|
|---|
| 498 | }
|
|---|
| 499 |
|
|---|
| 500 | // Show ManyToOne relations
|
|---|
| 501 | $Tabs = array();
|
|---|
| 502 | foreach ($Form->Definition['Items'] as $Index => $Item)
|
|---|
| 503 | {
|
|---|
| 504 | if ((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 505 | ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
|
|---|
| 506 | {
|
|---|
| 507 | $Tabs[] = $Item['Caption'];
|
|---|
| 508 | }
|
|---|
| 509 | }
|
|---|
| 510 | if (count($Tabs) > 0)
|
|---|
| 511 | {
|
|---|
| 512 | if (count($Tabs) > 1)
|
|---|
| 513 | {
|
|---|
| 514 | $Tabs[] = 'Vše';
|
|---|
| 515 | }
|
|---|
| 516 | if (array_key_exists('tab', $_GET))
|
|---|
| 517 | {
|
|---|
| 518 | $TabIndex = $_GET['tab'];
|
|---|
| 519 | if (($TabIndex < 0) or ($TabIndex >= count($Tabs)))
|
|---|
| 520 | {
|
|---|
| 521 | $TabIndex = 0;
|
|---|
| 522 | }
|
|---|
| 523 | } else $TabIndex = 0;
|
|---|
| 524 |
|
|---|
| 525 | $TabContent = '';
|
|---|
| 526 | $I = 0;
|
|---|
| 527 | foreach ($Form->Definition['Items'] as $Index => $Item)
|
|---|
| 528 | if ((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 529 | ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
|
|---|
| 530 | {
|
|---|
| 531 | $TypeItem = $this->System->FormManager->FormTypes[$Item['Type']];
|
|---|
| 532 | if (($TabIndex == $I) or ((count($Tabs) > 1) and ($TabIndex == (count($Tabs) - 1))))
|
|---|
| 533 | {
|
|---|
| 534 | if ($TypeItem['Ref'] == null)
|
|---|
| 535 | {
|
|---|
| 536 | $Filter = $TypeItem['Filter'];
|
|---|
| 537 | $Filter = str_replace('#Id', $Id, $Filter);
|
|---|
| 538 | $TabContent .= $this->ShowList($TypeItem['Table'],
|
|---|
| 539 | $Filter, $Item['Caption']).'<br/>';
|
|---|
| 540 | } else $TabContent .= $this->ShowList($TypeItem['Table'], '`'.
|
|---|
| 541 | $TypeItem['Ref'].'`='.$Id, $Item['Caption'],
|
|---|
| 542 | $TypeItem['Ref'], $Id).'<br/>';
|
|---|
| 543 | }
|
|---|
| 544 | $I++;
|
|---|
| 545 | }
|
|---|
| 546 |
|
|---|
| 547 | $Output .= $this->ShowTabs($Tabs, 'tab', $TabContent);
|
|---|
| 548 | }
|
|---|
| 549 | return $Output;
|
|---|
| 550 | }
|
|---|
| 551 |
|
|---|
| 552 | function GetParam(string $Name, string $Default): string
|
|---|
| 553 | {
|
|---|
| 554 | $Result = $Default;
|
|---|
| 555 | if (array_key_exists($Name, $_POST) and ($_POST[$Name] != ''))
|
|---|
| 556 | {
|
|---|
| 557 | $Result = $_POST[$Name];
|
|---|
| 558 | }
|
|---|
| 559 | if (array_key_exists($Name, $_GET) and ($_GET[$Name] != ''))
|
|---|
| 560 | {
|
|---|
| 561 | $Result = $_GET[$Name];
|
|---|
| 562 | }
|
|---|
| 563 | return $Result;
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | function ShowTable(string $Table, string $Filter = '', string $Title = '', string $RowActions = '', string $ExcludeColumn = ''): string
|
|---|
| 567 | {
|
|---|
| 568 | if (!array_key_exists($Table, $this->System->FormManager->Classes))
|
|---|
| 569 | return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
|
|---|
| 570 | $FormClass = $this->System->FormManager->Classes[$Table];
|
|---|
| 571 |
|
|---|
| 572 | if (array_key_exists('SQL', $FormClass))
|
|---|
| 573 | $SourceTable = '('.$FormClass['SQL'].') AS `TX`';
|
|---|
| 574 | else $SourceTable = '`'.$FormClass['Table'].'` AS `TX`';
|
|---|
| 575 |
|
|---|
| 576 | $WhereFilter = $Filter;
|
|---|
| 577 | $HavingFilter = '';
|
|---|
| 578 |
|
|---|
| 579 | // Build form type filter
|
|---|
| 580 | $TypeFilter = '';
|
|---|
| 581 | foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
|
|---|
| 582 | if (!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
|
|---|
| 583 | (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 584 | ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
|
|---|
| 585 | if (array_key_exists('Filter', $FormItem) and ($FormItem['Filter'] == true))
|
|---|
| 586 | {
|
|---|
| 587 | if ($TypeFilter != '') $TypeFilter .= ' AND ';
|
|---|
| 588 | $TypeFilter .= '(`'.$ItemIndex.'` = "'.$FormItem['Default'].'")';
|
|---|
| 589 | }
|
|---|
| 590 | if ($TypeFilter != '')
|
|---|
| 591 | {
|
|---|
| 592 | if ($HavingFilter != '') $HavingFilter = ' AND';
|
|---|
| 593 | $HavingFilter .= ' '.$TypeFilter;
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | // Build user filter
|
|---|
| 597 | $UserFilter = '';
|
|---|
| 598 | $Columns = array('Id' => '`Id`');
|
|---|
| 599 | if (array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
|
|---|
| 600 | {
|
|---|
| 601 | foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
|
|---|
| 602 | if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
|
|---|
| 603 | if (!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
|
|---|
| 604 | (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 605 | ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
|
|---|
| 606 | {
|
|---|
| 607 | $UseType = $UseType = $FormItem['Type'];
|
|---|
| 608 | if (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
|
|---|
| 609 | {
|
|---|
| 610 | if (!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
|
|---|
| 611 | $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
|
|---|
| 612 | $this->System->FormManager->FormTypes[$FormItem['Type']]);
|
|---|
| 613 | if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
|
|---|
| 614 | $UseType = 'OneToMany';
|
|---|
| 615 | else
|
|---|
| 616 | if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
|
|---|
| 617 | $UseType = 'Enumeration';
|
|---|
| 618 | }
|
|---|
| 619 | $FilterName = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterName',
|
|---|
| 620 | array('Name' => $ItemIndex, 'Type' => $FormItem['Type']));
|
|---|
| 621 |
|
|---|
| 622 | $SqlOperator = array(
|
|---|
| 623 | 'like' => 'LIKE',
|
|---|
| 624 | 'notlike' => 'NOT LIKE',
|
|---|
| 625 | 'equal' => '=',
|
|---|
| 626 | 'notequal' => '!=',
|
|---|
| 627 | 'less' => '<',
|
|---|
| 628 | 'lessorequal' => '<=',
|
|---|
| 629 | 'greater' => '>',
|
|---|
| 630 | 'greaterorequal' => '>=',
|
|---|
| 631 | 'isnull' => 'IS NULL',
|
|---|
| 632 | 'isnotnull' => 'IS NOT NULL',
|
|---|
| 633 | );
|
|---|
| 634 | $Operator = $this->GetParam('FilterOp'.$ItemIndex, 'like');
|
|---|
| 635 | if (array_key_exists($Operator, $SqlOperator))
|
|---|
| 636 | {
|
|---|
| 637 | $OperatorSql = $SqlOperator[$Operator];
|
|---|
| 638 | } else $OperatorSql = $SqlOperator['like'];
|
|---|
| 639 |
|
|---|
| 640 | $FilterValue = $this->GetParam('Filter'.$ItemIndex, '');
|
|---|
| 641 | if ($FilterValue != '')
|
|---|
| 642 | {
|
|---|
| 643 | if ($UserFilter != '') $UserFilter .= ' AND ';
|
|---|
| 644 | $UserFilter .= '('.$FilterName.' '.$OperatorSql;
|
|---|
| 645 | if (($Operator == 'like') or ($Operator == 'notlike')) $UserFilter .= ' "%'.$FilterValue.'%")';
|
|---|
| 646 | else if (($Operator == 'isnull') or ($Operator == 'isnotnull')) $UserFilter .= ')';
|
|---|
| 647 | else $UserFilter .= ' "'.$FilterValue.'")';
|
|---|
| 648 | }
|
|---|
| 649 | }
|
|---|
| 650 | }
|
|---|
| 651 | if ($UserFilter != '')
|
|---|
| 652 | {
|
|---|
| 653 | if ($HavingFilter != '') $HavingFilter .= ' AND';
|
|---|
| 654 | $HavingFilter .= ' '.$UserFilter;
|
|---|
| 655 | }
|
|---|
| 656 | if ($WhereFilter != '') $Filter = ' WHERE '.$WhereFilter;
|
|---|
| 657 | if ($HavingFilter != '') $Filter = ' HAVING '.$HavingFilter;
|
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 | foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
|
|---|
| 661 | if (!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
|
|---|
| 662 | (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 663 | ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
|
|---|
| 664 | {
|
|---|
| 665 | if ($ExcludeColumn != $ItemIndex)
|
|---|
| 666 | if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
|
|---|
| 667 | if (!array_key_exists('NotInList', $FormItem) or ($FormItem['NotInList'] == false))
|
|---|
| 668 | $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
|
|---|
| 669 | $UseType = $UseType = $FormItem['Type'];
|
|---|
| 670 | if (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
|
|---|
| 671 | {
|
|---|
| 672 | if (!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
|
|---|
| 673 | $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
|
|---|
| 674 | $this->System->FormManager->FormTypes[$FormItem['Type']]);
|
|---|
| 675 | if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
|
|---|
| 676 | $UseType = 'OneToMany';
|
|---|
| 677 | else
|
|---|
| 678 | if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
|
|---|
| 679 | $UseType = 'Enumeration';
|
|---|
| 680 | }
|
|---|
| 681 | if (array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
|
|---|
| 682 | $Value = $_POST['Filter'.$ItemIndex];
|
|---|
| 683 | else $Value = '';
|
|---|
| 684 | if ($ItemIndex == 'Id') unset($Columns['Id']);
|
|---|
| 685 |
|
|---|
| 686 | if (!array_key_exists('SQL', $FormItem)) $FormItem['SQL'] = '';
|
|---|
| 687 | else $FormItem['SQL'] = str_replace('#Id', '`TX`.`Id`', $FormItem['SQL']);
|
|---|
| 688 | $Columns[] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery',
|
|---|
| 689 | array('Value' => $Value, 'Name' => $ItemIndex,
|
|---|
| 690 | 'Type' => $FormItem['Type'], 'SQL' => $FormItem['SQL']));
|
|---|
| 691 | }
|
|---|
| 692 |
|
|---|
| 693 | // Get total item count in database
|
|---|
| 694 | $Query = 'SELECT COUNT(*) FROM '.$SourceTable;
|
|---|
| 695 | $DbResult = $this->Database->query($Query);
|
|---|
| 696 | $DbRow = $DbResult->fetch_assoc();
|
|---|
| 697 | $TotalCount = $DbRow['COUNT(*)'];
|
|---|
| 698 |
|
|---|
| 699 | // Get total filtered item count in database
|
|---|
| 700 | $Columns = implode(',', $Columns);
|
|---|
| 701 | if ($Filter != '')
|
|---|
| 702 | {
|
|---|
| 703 | $Query = 'SELECT COUNT(*) FROM (SELECT '.$Columns.' FROM '.$SourceTable.' '.$Filter.') AS `TS`';
|
|---|
| 704 | $DbResult = $this->Database->query($Query);
|
|---|
| 705 | $DbRow = $DbResult->fetch_row();
|
|---|
| 706 | $TotalFilteredCount = $DbRow[0];
|
|---|
| 707 | } else $TotalFilteredCount = $TotalCount;
|
|---|
| 708 | $PageList = GetPageList($Table, $TotalFilteredCount);
|
|---|
| 709 |
|
|---|
| 710 | $Output = $PageList['Output'];
|
|---|
| 711 | $Output .= '<table class="WideTable" style="font-size: small;">';
|
|---|
| 712 |
|
|---|
| 713 | $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
|
|---|
| 714 | if (!array_key_exists('DefaultSortColumn', $FormClass))
|
|---|
| 715 | $FormClass['DefaultSortColumn'] = 'Id';
|
|---|
| 716 | if (!array_key_exists('DefaultSortOrder', $FormClass))
|
|---|
| 717 | $FormClass['DefaultSortOrder'] = 0;
|
|---|
| 718 | $Order = GetOrderTableHeader($Table, $TableColumns, $FormClass['DefaultSortColumn'], $FormClass['DefaultSortOrder']);
|
|---|
| 719 | $Output .= $Order['Output'];
|
|---|
| 720 |
|
|---|
| 721 | // Show search fields
|
|---|
| 722 | if (array_key_exists('r', $_GET)) $Addition = '&r='.$_GET['r'];
|
|---|
| 723 | else $Addition = '';
|
|---|
| 724 | $Output .= '<tr><form action="?a='.$_GET['a'].'&t='.$Table.'&filter=1'.$Addition.'" method="post">';
|
|---|
| 725 | foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
|
|---|
| 726 | if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
|
|---|
| 727 | if (!array_key_exists('NotInList', $FormItem) or ($FormItem['NotInList'] == false))
|
|---|
| 728 | if ((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
|
|---|
| 729 | (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 730 | ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) and
|
|---|
| 731 | ($ExcludeColumn != $ItemIndex))
|
|---|
| 732 | {
|
|---|
| 733 | if (array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
|
|---|
| 734 | $Value = $_POST['Filter'.$ItemIndex];
|
|---|
| 735 | else $Value = '';
|
|---|
| 736 | $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';
|
|---|
| 737 | }
|
|---|
| 738 | $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
|
|---|
| 739 |
|
|---|
| 740 | // Load and show items
|
|---|
| 741 | $Query = 'SELECT '.$Columns.' FROM '.$SourceTable.' '.
|
|---|
| 742 | $Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
|
|---|
| 743 | $VisibleItemCount = 0;
|
|---|
| 744 | $DbResult = $this->Database->query($Query);
|
|---|
| 745 | while ($Row = $DbResult->fetch_assoc())
|
|---|
| 746 | {
|
|---|
| 747 | $Output .= '<tr>';
|
|---|
| 748 | foreach ($FormClass['Items'] as $ItemIndex => $FormItem)
|
|---|
| 749 | if (!array_key_exists('Hidden', $FormItem) or ($FormItem['Hidden'] == false))
|
|---|
| 750 | if (!array_key_exists('NotInList', $FormItem) or ($FormItem['NotInList'] == false))
|
|---|
| 751 | if ((!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
|
|---|
| 752 | (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
|
|---|
| 753 | ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne'))) and
|
|---|
| 754 | ($ExcludeColumn != $ItemIndex))
|
|---|
| 755 | {
|
|---|
| 756 | //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
|
|---|
| 757 | $UseType = $UseType = $FormItem['Type'];
|
|---|
| 758 | if (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
|
|---|
| 759 | {
|
|---|
| 760 | if (!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
|
|---|
| 761 | $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
|
|---|
| 762 | $this->System->FormManager->FormTypes[$FormItem['Type']]);
|
|---|
| 763 | if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
|
|---|
| 764 | $UseType = 'OneToMany';
|
|---|
| 765 | else
|
|---|
| 766 | if ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
|
|---|
| 767 | $UseType = 'Enumeration';
|
|---|
| 768 | }
|
|---|
| 769 | $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
|
|---|
| 770 | array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
|
|---|
| 771 | 'Type' => $FormItem['Type']));
|
|---|
| 772 | $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
|
|---|
| 773 | array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
|
|---|
| 774 | 'Type' => $FormItem['Type'], 'Filter' => $Row[$ItemIndex.'_Filter']));
|
|---|
| 775 | if ($Value == '') $Value = ' ';
|
|---|
| 776 | $Output .= '<td>'.$Value.'</td>';
|
|---|
| 777 | }
|
|---|
| 778 | $Output .= '<td>'.str_replace('#RowId', $Row['Id'], $RowActions).'</td></tr>';
|
|---|
| 779 | $VisibleItemCount = $VisibleItemCount + 1;
|
|---|
| 780 | }
|
|---|
| 781 | $Output .= '<tr><td colspan="'.count($TableColumns).'" style="text-align: right;">Zobrazeno <strong>'.$VisibleItemCount.'</strong>';
|
|---|
| 782 | if ($UserFilter != '') $Output .= ' z filtrovaných <strong>'.$TotalFilteredCount.'</strong>';
|
|---|
| 783 | $Output .= ' z celkem <strong>'.$TotalCount.'</strong></td></tr>';
|
|---|
| 784 | $Output .= '</table>';
|
|---|
| 785 | $Output .= $PageList['Output'];
|
|---|
| 786 | return $Output;
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| 789 | function ShowSelect(string $Table, string $Filter = '', string $Title = ''): string
|
|---|
| 790 | {
|
|---|
| 791 | if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
|
|---|
| 792 | return 'Nemáte oprávnění';
|
|---|
| 793 | $this->BasicHTML = true;
|
|---|
| 794 | $this->HideMenu = true;
|
|---|
| 795 | $RowActions = '<a href="javascript:window.close();" onclick="set_return (#RowId,"'.
|
|---|
| 796 | $_GET['r'].'");"><img alt="Vybrat" title="Vybrat" src="'.
|
|---|
| 797 | $this->System->Link('/images/select.png').'"/></a>';
|
|---|
| 798 | $Output = $this->ShowTable($Table, $Filter, $Title, $RowActions);
|
|---|
| 799 | return $Output;
|
|---|
| 800 | }
|
|---|
| 801 |
|
|---|
| 802 | function ShowMapSelect(string $Table, string $Filter = '', string $Title = ''): string
|
|---|
| 803 | {
|
|---|
| 804 | if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
|
|---|
| 805 | return 'Nemáte oprávnění';
|
|---|
| 806 | $Map = new MapOpenStreetMaps($this->System);
|
|---|
| 807 | $Map->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
|
|---|
| 808 | 'Lng' => $this->System->Config['Map']['DefaultLongitude']);
|
|---|
| 809 | $Map->Zoom = $this->System->Config['Map']['DefaultZoom'];
|
|---|
| 810 | $Map->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
|
|---|
| 811 | $Map->OnClickObject = $_GET['r'];
|
|---|
| 812 | //$MapApi->ShowMarker = true;
|
|---|
| 813 | $Output = $Map->ShowPage($this);
|
|---|
| 814 | return $Output;
|
|---|
| 815 | }
|
|---|
| 816 |
|
|---|
| 817 | function ShowList(string $Table, string $Filter = '', string $Title = '', string $ExcludeColumn = '', string $ExcludeValue = ''): string
|
|---|
| 818 | {
|
|---|
| 819 | $Output = '';
|
|---|
| 820 | if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
|
|---|
| 821 | return 'Nemáte oprávnění';
|
|---|
| 822 | if (!array_key_exists($Table, $this->System->FormManager->Classes))
|
|---|
| 823 | return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
|
|---|
| 824 | $FormClass = $this->System->FormManager->Classes[$Table];
|
|---|
| 825 | if (array_key_exists('BaseTable', $FormClass)) $TableModify = $FormClass['BaseTable'];
|
|---|
| 826 | else $TableModify = $Table;
|
|---|
| 827 |
|
|---|
| 828 | $RowActions =
|
|---|
| 829 | $this->ShowAction('Ukázat', '?a=view&t='.$Table.'&i=#RowId', $this->System->Link('/images/view.png')).
|
|---|
| 830 | $this->ShowAction('Upravit', '?a=edit&t='.$TableModify.'&i=#RowId', $this->System->Link('/images/edit.png')).
|
|---|
| 831 | $this->ShowAction('Duplikovat', '?a=clone&t='.$TableModify.'&i=#RowId', $this->System->Link('/images/clone.png')).
|
|---|
| 832 | $this->ShowAction('Odstranit', '?a=delete&t='.$Table.'&i=#RowId', $this->System->Link('/images/delete.png'), 'Opravdu smazat položku?;');
|
|---|
| 833 | if (($Table != '') and (array_key_exists($Table, $this->System->FormManager->Classes)))
|
|---|
| 834 | $FormClass = $this->System->FormManager->Classes[$Table];
|
|---|
| 835 | else return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
|
|---|
| 836 | if ($ExcludeColumn == '') $this->Title .= ' - '.$FormClass['Title'];
|
|---|
| 837 | if (array_key_exists('ItemActions', $FormClass))
|
|---|
| 838 | {
|
|---|
| 839 | foreach ($FormClass['ItemActions'] as $Action)
|
|---|
| 840 | {
|
|---|
| 841 | $URL = $this->System->Link($Action['URL']);
|
|---|
| 842 | $RowActions .= '<a href="'.$URL.'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
|
|---|
| 843 | $this->System->Link('/images/action.png').'"/></a>';
|
|---|
| 844 | }
|
|---|
| 845 | }
|
|---|
| 846 | $Output .= '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
|
|---|
| 847 | $Output .= '<ul class="ActionMenu">';
|
|---|
| 848 | $Output .= '<li>'.$this->ShowAction('Přidat', '?a=add&t='.$TableModify.'&preset'.$ExcludeColumn.'='.$ExcludeValue, $this->System->Link('/images/add.png')).'</li>';
|
|---|
| 849 | $Output .= '<li>'.$this->ShowAction('Seznam', '?a=list&t='.$Table, $this->System->Link('/images/list.png')).'</li>';
|
|---|
| 850 | $MI = 0;
|
|---|
| 851 | if (array_key_exists('mi', $_GET))
|
|---|
| 852 | {
|
|---|
| 853 | $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['mi'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
|
|---|
| 854 | if ($DbResult->num_rows > 0)
|
|---|
| 855 | {
|
|---|
| 856 | $DbRow = $DbResult->fetch_assoc();
|
|---|
| 857 | $Fav = $DbRow['Id'];
|
|---|
| 858 | $Output .= '<li>'.$this->ShowAction('Odebrat z oblíbených', '?a=fav_del&t='.$Table.'&i='.$_GET['mi'].'&mi='.$_GET['mi'],
|
|---|
| 859 | $this->System->Link('/images/Favorite-Del.png')).'</li>';
|
|---|
| 860 | } else $Output .= '<li>'.$this->ShowAction('Přidat do oblíbených', '?a=fav_add&t='.$Table.'&i='.$_GET['mi'].'&mi='.$_GET['mi'],
|
|---|
| 861 | $this->System->Link('/images/Favorite-Add.png')).'</li>';
|
|---|
| 862 | }
|
|---|
| 863 | if (array_key_exists('Actions', $FormClass))
|
|---|
| 864 | {
|
|---|
| 865 | foreach ($FormClass['Actions'] as $Action)
|
|---|
| 866 | {
|
|---|
| 867 | $Output .= '<li>'.$this->ShowAction($Action['Caption'], $this->System->Link($Action['URL']),
|
|---|
| 868 | $this->System->Link('/images/action.png')).'</li>';
|
|---|
| 869 | }
|
|---|
| 870 | }
|
|---|
| 871 | $Output .= '</ul>';
|
|---|
| 872 | $Output .= $this->ShowTable($Table, $Filter, $Title, $RowActions, $ExcludeColumn);
|
|---|
| 873 | return $Output;
|
|---|
| 874 | }
|
|---|
| 875 |
|
|---|
| 876 | function ShowFavorites(): string
|
|---|
| 877 | {
|
|---|
| 878 | $this->MenuItems = array();
|
|---|
| 879 | $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` ' .
|
|---|
| 880 | 'LEFT JOIN `MenuItem` ON `MenuItem`.`Id` = `MenuItemFavorite`.`MenuItem` '.
|
|---|
| 881 | 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
|
|---|
| 882 | 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
|
|---|
| 883 | 'WHERE `MenuItemFavorite`.`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].' '.
|
|---|
| 884 | 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
|
|---|
| 885 | while ($DbRow = $DbResult->fetch_assoc())
|
|---|
| 886 | {
|
|---|
| 887 | //if ($DbRow['Permission'] != '')
|
|---|
| 888 | $this->MenuItems[$DbRow['Id']] = $DbRow;
|
|---|
| 889 | }
|
|---|
| 890 | return $this->ShowMenuItem('', true);
|
|---|
| 891 | }
|
|---|
| 892 |
|
|---|
| 893 | function ShowMenu(): string
|
|---|
| 894 | {
|
|---|
| 895 | $this->MenuItems = array();
|
|---|
| 896 | $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` '.
|
|---|
| 897 | 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
|
|---|
| 898 | 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
|
|---|
| 899 | 'WHERE `MenuItem`.`Menu`=1 '.
|
|---|
| 900 | 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
|
|---|
| 901 | while ($DbRow = $DbResult->fetch_assoc())
|
|---|
| 902 | {
|
|---|
| 903 | //if ($DbRow['Permission'] != '')
|
|---|
| 904 | $this->MenuItems[$DbRow['Id']] = $DbRow;
|
|---|
| 905 | }
|
|---|
| 906 | return $this->ShowMenuItem('');
|
|---|
| 907 | }
|
|---|
| 908 |
|
|---|
| 909 | function ShowMenuItem(string $Parent, bool $All = false): string
|
|---|
| 910 | {
|
|---|
| 911 | $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
|
|---|
| 912 | foreach ($this->MenuItems as $MenuItem)
|
|---|
| 913 | {
|
|---|
| 914 | if (($MenuItem['Parent'] == $Parent) or $All)
|
|---|
| 915 | {
|
|---|
| 916 | $LinkTitle = $MenuItem['Name'];
|
|---|
| 917 | if ($MenuItem['URL'] != '')
|
|---|
| 918 | {
|
|---|
| 919 | $Icon = 'Device.png';
|
|---|
| 920 | if (substr($MenuItem['URL'], 0, 4) != 'http') $MenuItem['URL'] = $this->System->Link($MenuItem['URL']);
|
|---|
| 921 | $LinkTitle = MakeLink($MenuItem['URL'].'&mi='.$MenuItem['Id'], $LinkTitle);
|
|---|
| 922 | } else $Icon = 'Folder.png';
|
|---|
| 923 | if ($MenuItem['IconName'] != '') $Image = '<img src="'.$this->System->Link('/images/favicons/'.$MenuItem['IconName']).'"/> ';
|
|---|
| 924 | else $Image = '<img src="'.$this->System->Link('/images/favicons/'.$Icon).'"/> ';
|
|---|
| 925 | //if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write') or !defined('NEW_PERMISSION'))
|
|---|
| 926 | $Output .= '<li>'.$Image.$LinkTitle.'</li>';
|
|---|
| 927 | if ($All == false) $Output .= $this->ShowMenuItem($MenuItem['Id']);
|
|---|
| 928 | }
|
|---|
| 929 | }
|
|---|
| 930 | $Output .= '</ul>';
|
|---|
| 931 | return $Output;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | function TableToModule(string $Table): string
|
|---|
| 935 | {
|
|---|
| 936 | $DbResult = $this->Database->query('SELECT (SELECT `Name` FROM `Module` '.
|
|---|
| 937 | 'WHERE `Module`.`Id`=`Model`.`Module`) AS `Name` FROM `Model` WHERE `Name`="'.$Table.'"');
|
|---|
| 938 | if ($DbResult->num_rows == 1)
|
|---|
| 939 | {
|
|---|
| 940 | $DbRow = $DbResult->fetch_assoc();
|
|---|
| 941 | return $DbRow['Name'];
|
|---|
| 942 | } else return '';
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 | function ShowAction(string $Name, string $Target, string $Icon, string $Confirm = ''): string
|
|---|
| 946 | {
|
|---|
| 947 | $Output = '<img alt="'.$Name.'" title="'.$Name.'" src="'.
|
|---|
| 948 | $Icon.'"/>';
|
|---|
| 949 | if ($this->ShowActionName) $Output .= $Name;
|
|---|
| 950 | if ($Confirm != '')
|
|---|
| 951 | $Confirm = ' onclick="return confirmAction(\''.$Confirm.'\');"';
|
|---|
| 952 | $Output = '<a href="'.$Target.'"'.$Confirm.'>'.$Output.'</a>';
|
|---|
| 953 | return $Output;
|
|---|
| 954 | }
|
|---|
| 955 | }
|
|---|
| 956 |
|
|---|
| 957 | class Menu extends Model
|
|---|
| 958 | {
|
|---|
| 959 | static function GetModelDesc(): ModelDesc
|
|---|
| 960 | {
|
|---|
| 961 | $Desc = new ModelDesc(self::GetClassName());
|
|---|
| 962 | $Desc->AddString('Name');
|
|---|
| 963 | return $Desc;
|
|---|
| 964 | }
|
|---|
| 965 | }
|
|---|
| 966 |
|
|---|
| 967 | class MenuItem extends Model
|
|---|
| 968 | {
|
|---|
| 969 | static function GetModelDesc(): ModelDesc
|
|---|
| 970 | {
|
|---|
| 971 | $Desc = new ModelDesc(self::GetClassName());
|
|---|
| 972 | $Desc->AddString('Name');
|
|---|
| 973 | $Desc->AddReference('Parent', MenuItem::GetClassName());
|
|---|
| 974 | $Desc->AddReference('Action', Action::GetClassName());
|
|---|
| 975 | $Desc->AddReference('Menu', Menu::GetClassName());
|
|---|
| 976 | return $Desc;
|
|---|
| 977 | }
|
|---|
| 978 | }
|
|---|
| 979 |
|
|---|
| 980 | class MenuItemFavorite extends Model
|
|---|
| 981 | {
|
|---|
| 982 | static function GetModelDesc(): ModelDesc
|
|---|
| 983 | {
|
|---|
| 984 | $Desc = new ModelDesc(self::GetClassName());
|
|---|
| 985 | $Desc->AddReference('User', User::GetClassName());
|
|---|
| 986 | $Desc->AddReference('MenuItem', MenuItem::GetClassName());
|
|---|
| 987 | return $Desc;
|
|---|
| 988 | }
|
|---|
| 989 | }
|
|---|
| 990 |
|
|---|
| 991 | class ModuleIS extends Module
|
|---|
| 992 | {
|
|---|
| 993 | public array $DashboardItems;
|
|---|
| 994 |
|
|---|
| 995 | function __construct(System $System)
|
|---|
| 996 | {
|
|---|
| 997 | parent::__construct($System);
|
|---|
| 998 | $this->Name = 'IS';
|
|---|
| 999 | $this->Title = 'Information system';
|
|---|
| 1000 | $this->Version = '1.0';
|
|---|
| 1001 | $this->Creator = 'Chronos';
|
|---|
| 1002 | $this->License = 'GNU/GPLv3';
|
|---|
| 1003 | $this->Description = 'User interface for generic information system';
|
|---|
| 1004 | $this->Dependencies = array(ModuleUser::GetName());
|
|---|
| 1005 | $this->Models = array(Menu::GetClassName(), MenuItem::GetClassName(), MenuItemFavorite::GetClassName());
|
|---|
| 1006 |
|
|---|
| 1007 | $this->DashboardItems = array();
|
|---|
| 1008 | }
|
|---|
| 1009 |
|
|---|
| 1010 | function DoStart(): void
|
|---|
| 1011 | {
|
|---|
| 1012 | $this->System->RegisterPage(['is'], 'PageIS');
|
|---|
| 1013 | $this->System->FormManager->RegisterClass('MenuItem', array(
|
|---|
| 1014 | 'Title' => 'Položky nabídky',
|
|---|
| 1015 | 'Table' => 'MenuItem',
|
|---|
| 1016 | 'Items' => array(
|
|---|
| 1017 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
|---|
| 1018 | 'Parent' => array('Type' => 'TMenuItem', 'Caption' => 'Rodič', 'Default' => '', 'Null' => true),
|
|---|
| 1019 | 'Action' => array('Type' => 'TAction', 'Caption' => 'Akce', 'Default' => ''),
|
|---|
| 1020 | 'Menu' => array('Type' => 'TMenu', 'Caption' => 'Nabídka', 'Default' => ''),
|
|---|
| 1021 | 'Items' => array('Type' => 'TMenuItemListParent', 'Caption' => 'Položky'),
|
|---|
| 1022 | ),
|
|---|
| 1023 | ));
|
|---|
| 1024 | $this->System->FormManager->RegisterClass('MenuItemFavorite', array(
|
|---|
| 1025 | 'Title' => 'Oblíbené položky nabídky',
|
|---|
| 1026 | 'Table' => 'MenuItemFavorite',
|
|---|
| 1027 | 'Items' => array(
|
|---|
| 1028 | 'User' => array('Type' => 'TUser', 'Caption' => 'Uživatele', 'Default' => '0'),
|
|---|
| 1029 | 'MenuItem' => array('Type' => 'TMenuItem', 'Caption' => 'Položka nabídky', 'Default' => '0'),
|
|---|
| 1030 | ),
|
|---|
| 1031 | ));
|
|---|
| 1032 | $this->System->FormManager->RegisterClass('Menu', array(
|
|---|
| 1033 | 'Title' => 'Nabídky',
|
|---|
| 1034 | 'Table' => 'Menu',
|
|---|
| 1035 | 'Items' => array(
|
|---|
| 1036 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
|---|
| 1037 | 'Items' => array('Type' => 'TMenuItemListMenu', 'Caption' => 'Položky'),
|
|---|
| 1038 | ),
|
|---|
| 1039 | ));
|
|---|
| 1040 | $this->System->FormManager->RegisterFormType('TMenuItem', array(
|
|---|
| 1041 | 'Type' => 'Reference',
|
|---|
| 1042 | 'Table' => 'MenuItem',
|
|---|
| 1043 | 'Id' => 'Id',
|
|---|
| 1044 | 'Name' => 'Name',
|
|---|
| 1045 | 'Filter' => '1',
|
|---|
| 1046 | ));
|
|---|
| 1047 | $this->System->FormManager->RegisterFormType('TMenu', array(
|
|---|
| 1048 | 'Type' => 'Reference',
|
|---|
| 1049 | 'Table' => 'Menu',
|
|---|
| 1050 | 'Id' => 'Id',
|
|---|
| 1051 | 'Name' => 'Name',
|
|---|
| 1052 | 'Filter' => '1',
|
|---|
| 1053 | ));
|
|---|
| 1054 | }
|
|---|
| 1055 |
|
|---|
| 1056 | function RegisterDashboardItem(string $Name, callable $Callback): void
|
|---|
| 1057 | {
|
|---|
| 1058 | $this->DashboardItems[$Name] = array('Callback' => $Callback);
|
|---|
| 1059 | }
|
|---|
| 1060 |
|
|---|
| 1061 | function UnregisterDashboardItem(string $Name): void
|
|---|
| 1062 | {
|
|---|
| 1063 | unset($this->DashboardItems[$Name]);
|
|---|
| 1064 | }
|
|---|
| 1065 |
|
|---|
| 1066 | static function Cast(Module $Module): ModuleIS
|
|---|
| 1067 | {
|
|---|
| 1068 | if ($Module instanceof ModuleIS)
|
|---|
| 1069 | {
|
|---|
| 1070 | return $Module;
|
|---|
| 1071 | }
|
|---|
| 1072 | throw new Exception('Expected ModuleIS type but '.gettype($Module));
|
|---|
| 1073 | }
|
|---|
| 1074 | }
|
|---|