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