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

Last change on this file since 530 was 530, checked in by chronos, 12 years ago
  • Opraveno: Ve správce dat se nyní hodnoty položek z URL nepamatují, ale musí být nastaveny v každém URL.
File size: 20.0 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Common/Global.php');
4
5class PageIS extends Page
6{
7 var $FullTitle = 'Správa dat';
8 var $ShortTitle = 'Správa dat';
9 var $ParentClass = 'PagePortal';
10 var $MenuItems = array();
11 var $HideMenu = false;
12
13 function Show()
14 {
15 if(!$this->System->User->CheckPermission('IS', 'Manage'))
16 return('Nemáte oprávnění');
17
18 if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
19 else $Action = '';
20 if(array_key_exists('t', $_GET)) $Table = $_GET['t'];
21 else $Table = '';
22 if(array_key_exists('i', $_GET)) $ItemId = $_GET['i'];
23 else $ItemId = 0;
24
25 if($Action == 'list') $Content = $this->ShowList($Table);
26 else if($Action == 'select') $Content = $this->ShowSelect($Table);
27 else if($Action == 'edit') $Content = $this->ShowEdit($Table, $ItemId);
28 else if($Action == 'add') $Content = $this->ShowAdd($Table);
29 else if($Action == 'view') $Content = $this->ShowView($Table, $ItemId);
30 else if($Action == 'delete') $Content = $this->ShowDelete($Table, $ItemId);
31 else $Content = '';
32 if($this->HideMenu == false)
33 {
34 $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
35 $Output .= '<strong>Nabídka:</strong>'.$this->ShowMenuItem('');
36 $Output .= '</td><td style="width: 80%; vertical-align: top;">';
37 $Output .= $Content;
38 $Output .= '</td></tr></table>';
39 } else $Output = $Content;
40
41 return($Output);
42 }
43
44 function ShowEdit($Table, $Id)
45 {
46 $Output = '';
47 if(array_key_exists('o', $_GET))
48 {
49 if($_GET['o'] == 'save')
50 {
51 $Form = new Form($this->System->FormManager);
52 $Form->SetClass($Table);
53 $Form->LoadValuesFromForm();
54 $Form->SaveValuesToDatabase($Id);
55 $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
56 $Output .= $this->ShowView($Table, $Id);
57 }
58 } else
59 {
60 $Form = new Form($this->System->FormManager);
61 $Form->SetClass($Table);
62 $Form->LoadValuesFromDatabase($Id);
63 $Form->OnSubmit = '?a=edit&amp;t='.$Table.'&amp;o=save';
64 $Output .= $Form->ShowEditForm();
65 $Output .= '<ul class="ActionMenu">';
66 $Output .= '<li><a href="?a=view&amp;t='.$Table.'"><img alt="Prohlížet" title="Prohlížet" src="'.
67 $this->System->Link('/images/view.png').'"/>Prohlížet</a></li>';
68 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
69 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
70 $Output .= '<li><a href="?a=delete&amp;t='.$Table.'&amp;i='.$Id.'" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
71 $this->System->Link('/images/delete.png').'"/>Odstranit</a></li>';
72 $Output .= '</ul>';
73 }
74 return($Output);
75 }
76
77 function ShowDelete($Table, $Id)
78 {
79 $Output = '';
80 $this->Database->delete($Table, 'Id='.$Id);
81 $Output .= $this->SystemMessage('Odstranění položky', 'Položka odstraněna');
82 $Output .= $this->ShowList($Table);
83 return($Output);
84 }
85
86 function ShowAdd($Table)
87 {
88 $Output = '';
89 if(array_key_exists('o', $_GET))
90 {
91 if($_GET['o'] == 'save')
92 {
93 $Form = new Form($this->System->FormManager);
94 $Form->SetClass($Table);
95 $Form->LoadValuesFromForm();
96 $Form->SaveValuesToDatabase(0);
97 $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
98 $Id = $this->Database->insert_id;
99 //$this->Database->update($Table, 'Id='.$Id,
100 // array('UserCreate' => $this->System->User->User['Id'],
101 // 'TimeCreate' => 'NOW()'));
102 $Output .= $this->ShowView($Table, $Id);
103 }
104 } else
105 {
106 $Form = new Form($this->System->FormManager);
107 $Form->SetClass($Table);
108 $Form->OnSubmit = '?a=add&amp;t='.$Table.'&amp;o=save';
109 $Output .= $Form->ShowEditForm();
110 $Output .= '<ul class="ActionMenu">';
111 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
112 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
113 $Output .= '</ul>';
114 }
115 return($Output);
116 }
117
118 function ShowView($Table, $Id)
119 {
120 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
121 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
122
123 $Form = new Form($this->System->FormManager);
124 $Form->SetClass($Table);
125 $Form->LoadValuesFromDatabase($Id);
126 $Form->OnSubmit = '?a=view';
127 $Output = $Form->ShowViewForm();
128 $Output .= '<ul class="ActionMenu">';
129 $Output .= '<li><a href="?a=edit&amp;t='.$Table.'&amp;i='.$Id.'"><img alt="Upravit" title="Upravit" src="'.
130 $this->System->Link('/images/edit.png').'"/>Upravit</a></li>';
131 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
132 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
133 $Output .= '<li><a href="?a=delete&amp;t='.$Table.'&amp;i='.$Id.'" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
134 $this->System->Link('/images/delete.png').'" />Odstranit</a></li>';
135 $Output .= '<li><a href="?a=add&amp;t='.$Table.'"><img alt="Přidat" title="Přidat" src="'.
136 $this->System->Link('/images/add.png').'"/>Přidat</a></li>';
137 if(array_key_exists('ItemActions', $FormClass))
138 {
139 foreach($FormClass['ItemActions'] as $Action)
140 $Output .= '<li><a href="'.$this->System->Link($Action['URL']).'&amp;i='.$Id.'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
141 $this->System->Link('/images/action.png').'"/>'.$Action['Caption'].'</a></li>';
142 }
143 $Output .= '</ul><br/>';
144
145 // Show ManyToOne relations
146 foreach($Form->Definition['Items'] as $Index => $Item)
147 if((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
148 ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
149 {
150 $Output .= $this->ShowList($this->System->FormManager->FormTypes[$Item['Type']]['Table'], '`'.
151 $this->System->FormManager->FormTypes[$Item['Type']]['Ref'].'`='.$Id, $Item['Caption']).'<br/>';
152 }
153 return($Output);
154 }
155
156 function ShowSelect($Table, $Filter = '', $Title = '')
157 {
158 $this->BasicHTML = true;
159 $this->HideMenu = true;
160 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
161 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
162 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
163 $DbRow = $DbResult->fetch_row();
164 $PageList = GetPageList($DbRow[0]);
165
166 $Output = '<script type="text/javascript">
167 function set_return(id, obj)
168 {
169 window.opener.document.getElementById(obj).value = id;
170 }
171 </script>';
172 $Output .= '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
173 $Output .= $PageList['Output'];
174 $Output .= '<table class="WideTable" style="font-size: small;">';
175
176 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
177 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
178 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
179 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
180 {
181 $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
182 }
183 $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
184 if(!array_key_exists('DefaultSortColumn', $FormClass))
185 $FormClass['DefaultSortColumn'] = 'Id';
186 $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
187 $Output .= $Order['Output'];
188
189 // Show search fields
190 $UserFilter = '';
191 if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
192 {
193 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
194 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
195 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
196 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
197 {
198 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
199 $UserFilter .= ' AND (`'.$ItemIndex.'` LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
200 }
201 }
202 $Output .= '<tr><form action="?a=select&amp;filter=1" method="post">';
203 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
204 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
205 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
206 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
207 {
208 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
209 $Value = $_POST['Filter'.$ItemIndex];
210 else $Value = '';
211 $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';
212 }
213 $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
214
215 if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
216 if($Filter != '') $Filter = ' WHERE '.$Filter;
217 $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
218
219 $DbResult = $this->Database->query($Query);
220 while($Row = $DbResult->fetch_assoc())
221 {
222 $Output .= '<tr>';
223 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
224 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
225 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
226 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
227 {
228 //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
229 $UseType = $UseType = $FormItem['Type'];
230 if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
231 {
232 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
233 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
234 $this->System->FormManager->FormTypes[$FormItem['Type']]);
235 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
236 $UseType = 'OneToMany';
237 else
238 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
239 $UseType = 'Enumeration';
240 }
241 $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
242 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
243 'Type' => $FormItem['Type']));
244 $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
245 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
246 'Type' => $FormItem['Type']));
247 if($Value == '') $Value = '&nbsp;';
248 $Output .= '<td>'.$Value.'</td>';
249 }
250 $Output .= '<td><a href="javascript:window.close();" onclick="set_return('.$Row['Id'].',&quot;'.$_GET['r'].'&quot;);"><img alt="Vybrat" title="Vybrat" src="'.
251 $this->System->Link('/images/select.png').'"/></a>';
252 $Output .= '</td></tr>';
253 }
254 $Output .= '</table>';
255 $Output .= $PageList['Output'];
256 return($Output);
257 }
258
259 function ShowList($Table, $Filter = '', $Title = '')
260 {
261 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
262 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
263
264 // Build user filter
265 $UserFilter = '';
266 if(array_key_exists('filter', $_GET) and ($_GET['filter'] == 1))
267 {
268 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
269 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
270 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
271 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
272 {
273 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
274 $UserFilter .= ' AND (`'.$ItemIndex.'` LIKE "%'.$_POST['Filter'.$ItemIndex].'%")';
275 }
276 }
277 if(($Filter == '') and ($UserFilter != '')) $Filter = '1 '.$UserFilter;
278 if($Filter != '') $Filter = ' WHERE '.$Filter;
279
280 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
281 $DbRow = $DbResult->fetch_row();
282 $PageList = GetPageList($DbRow[0]);
283
284 $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
285 $Output .= $PageList['Output'];
286 $Output .= '<table class="WideTable" style="font-size: small;">';
287
288 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
289 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
290 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
291 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
292 {
293 $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
294 }
295 $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
296 if(!array_key_exists('DefaultSortColumn', $FormClass))
297 $FormClass['DefaultSortColumn'] = 'Id';
298 $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
299 $Output .= $Order['Output'];
300
301 // Show search fields
302 $Output .= '<tr><form action="?a=list&amp;t='.$Table.'&amp;filter=1" method="post">';
303 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
304 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
305 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
306 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
307 {
308 if(array_key_exists('Filter'.$ItemIndex, $_POST) and ($_POST['Filter'.$ItemIndex] != ''))
309 $Value = $_POST['Filter'.$ItemIndex];
310 else $Value = '';
311 $Output .= '<td><input type="text" name="Filter'.$ItemIndex.'" value="'.$Value.'" style="width: 100%"/></td>';
312 }
313 $Output .= '<td><input type="Submit" value="Hledat"/></td></form></tr>';
314
315 $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
316
317 $DbResult = $this->Database->query($Query);
318 while($Row = $DbResult->fetch_assoc())
319 {
320 $Output .= '<tr>';
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 //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
327 $UseType = $UseType = $FormItem['Type'];
328 if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
329 {
330 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
331 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
332 $this->System->FormManager->FormTypes[$FormItem['Type']]);
333 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
334 $UseType = 'OneToMany';
335 else
336 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
337 $UseType = 'Enumeration';
338 }
339 $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
340 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
341 'Type' => $FormItem['Type']));
342 $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
343 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
344 'Type' => $FormItem['Type']));
345 if($Value == '') $Value = '&nbsp;';
346 $Output .= '<td>'.$Value.'</td>';
347 }
348 $Output .= '<td><a href="?a=view&amp;t='.$Table.'&amp;i='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
349 $this->System->Link('/images/view.png').'"/></a>'.
350 '<a href="?a=edit&amp;t='.$Table.'&amp;i='.$Row['Id'].'"><img alt="Upravit" title="Upravit" src="'.
351 $this->System->Link('/images/edit.png').'"/></a>'.
352 '<a href="?a=delete&amp;t='.$Table.'&amp;i='.$Row['Id'].'"><img alt="Smazat" title="Smazat" src="'.
353 $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
354 if(array_key_exists('ItemActions', $FormClass))
355 {
356 foreach($FormClass['ItemActions'] as $Action)
357 $Output .= '<a href="'.$this->System->Link($Action['URL']).'&amp;i='.$Row['Id'].'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
358 $this->System->Link('/images/action.png').'"/></a>';
359 }
360 $Output .= '</td></tr>';
361 }
362 $Output .= '</table>';
363 $Output .= $PageList['Output'];
364 $Output .= '<ul class="ActionMenu">';
365 $Output .= '<li><a href="?a=add&amp;t='.$Table.'"><img alt="Přidat" title="Přidat" src="'.
366 $this->System->Link('/images/add.png').'"/>Přidat</a></li>';
367 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
368 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
369 if(array_key_exists('Actions', $FormClass))
370 {
371 foreach($FormClass['Actions'] as $Action)
372 $Output .= '<li><a href="'.$this->System->Link($Action['URL']).'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
373 $this->System->Link('/images/action.png').'"/>'.$Action['Caption'].'</a></li>';
374 }
375 $Output .= '</ul>';
376 return($Output);
377 }
378
379 function ShowMenuItem($Parent)
380 {
381 $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName` FROM `MenuItem` '.
382 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
383 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
384 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
385 while($DbRow = $DbResult->fetch_assoc())
386 {
387 $this->MenuItems[$DbRow['Id']] = $DbRow;
388 }
389
390 $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
391 foreach($this->MenuItems as $MenuItem)
392 if($MenuItem['Parent'] == $Parent)
393 {
394 $LinkTitle = $MenuItem['Name'];
395 if($MenuItem['URL'] != '')
396 {
397 if(substr($MenuItem['URL'], 0, 4) != 'http') $MenuItem['URL'] = $this->System->Link($MenuItem['URL']);
398 $LinkTitle = MakeLink($MenuItem['URL'], $LinkTitle);
399 }
400 if($MenuItem['IconName'] != '') $Image = '<img src="../images/favicons/'.$MenuItem['IconName'].'"/>&nbsp;';
401 else $Image = '';
402 $Output .= '<li>'.$Image.$LinkTitle.'</li>';
403 $Output .= $this->ShowMenuItem($MenuItem['Id']);
404 }
405 $Output .= '</ul>';
406 return($Output);
407 }
408}
409
410class ModuleIS extends AppModule
411{
412 function __construct($System)
413 {
414 parent::__construct($System);
415 $this->Name = 'Information system';
416 $this->Version = '1.0';
417 $this->Creator = 'Chronos';
418 $this->License = 'GNU/GPLv3';
419 $this->Description = 'User interface for generic information system';
420 $this->Dependencies = array();
421 }
422
423 function Install()
424 {
425 }
426
427 function Uninstall()
428 {
429 }
430
431 function Start()
432 {
433 parent::Start();
434 $this->System->RegisterPage('is', 'PageIS');
435 }
436
437 function Stop()
438 {
439 }
440}
441
442?>
Note: See TracBrowser for help on using the repository browser.