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