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

Last change on this file since 527 was 527, checked in by chronos, 12 years ago
  • Upraveno: Tabulka ISMenuItem přepracována na obecnější MenuItem odkazující se na Menu. Nově položky nabídky jsou vázány přímo na akce tabulku Action.
File size: 13.3 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
12 function Show()
13 {
14 if(!$this->System->User->CheckPermission('IS', 'Manage'))
15 return('Nemáte oprávnění');
16
17 $DbResult = $this->Database->query('SELECT `MenuItem`.`Id`, `MenuItem`.`Name`, `MenuItem`.`Parent`, `Action`.`URL` AS `URL`, `ActionIcon`.`Name` AS `IconName` FROM `MenuItem` '.
18 'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
19 'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
20 'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
21 while($DbRow = $DbResult->fetch_assoc())
22 {
23 $this->MenuItems[$DbRow['Id']] = $DbRow;
24 }
25
26 $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
27 $Output .= '<strong>Nabídka:</strong><br/>'.$this->ShowMenuItem('');
28 $Output .= '</td><td style="width: 80%; vertical-align: top;">';
29
30 if(array_key_exists('t', $_GET)) $_SESSION['Table'] = $_GET['t'];
31 if(array_key_exists('a', $_GET)) $_SESSION['Action'] = $_GET['a'];
32 if(array_key_exists('id', $_GET)) $_SESSION['Id'] = $_GET['id'];
33
34 if(!array_key_exists('Action', $_SESSION)) $_SESSION['Action'] = 'list';
35 if(!array_key_exists('Id', $_SESSION) or !array_key_exists('Table', $_SESSION) or
36 ($_SESSION['Table'] == '')) {
37 $_SESSION['Id'] = 0;
38 $_SESSION['Action'] = '';
39 $_SESSION['Table'] = '';
40 }
41
42 if($_SESSION['Action'] == 'list') $Output .= $this->ShowList($_SESSION['Table']);
43 else if($_SESSION['Action'] == 'edit') $Output .= $this->ShowEdit($_SESSION['Table'], $_SESSION['Id']);
44 else if($_SESSION['Action'] == 'add') $Output .= $this->ShowAdd($_SESSION['Table']);
45 else if($_SESSION['Action'] == 'view') $Output .= $this->ShowView($_SESSION['Table'], $_SESSION['Id']);
46 else if($_SESSION['Action'] == 'delete') $Output .= $this->ShowDelete($_SESSION['Table'], $_SESSION['Id']);
47 $Output .= '</td></tr></table>';
48
49 return($Output);
50 }
51
52 function ShowEdit($Table, $Id)
53 {
54 $Output = '';
55 if(array_key_exists('o', $_GET))
56 {
57 if($_GET['o'] == 'save')
58 {
59 $Form = new Form($this->System->FormManager);
60 $Form->SetClass($Table);
61 $Form->LoadValuesFromForm();
62 $Form->SaveValuesToDatabase($Id);
63 $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
64 $_SESSION['Action'] = 'view';
65 $Output .= $this->ShowView($Table, $Id);
66 }
67 } else
68 {
69 $Form = new Form($this->System->FormManager);
70 $Form->SetClass($Table);
71 $Form->LoadValuesFromDatabase($Id);
72 $Form->OnSubmit = '?a=edit&amp;o=save';
73 $Output .= $Form->ShowEditForm();
74 $Output .= '<ul class="ActionMenu">';
75 $Output .= '<li><a href="?a=view"><img alt="Prohlížet" title="Prohlížet" src="'.
76 $this->System->Link('/images/view.png').'"/>Prohlížet</a></li>';
77 $Output .= '<li><a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
78 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
79 $Output .= '<li><a href="?a=delete" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
80 $this->System->Link('/images/delete.png').'"/>Odstranit</a></li>';
81 $Output .= '</ul>';
82 }
83 return($Output);
84 }
85
86 function ShowDelete($Table, $Id)
87 {
88 $Output = '';
89 $this->Database->delete($Table, 'Id='.$Id);
90 $Output .= $this->SystemMessage('Odstranění položky', 'Položka odstraněna');
91 $_SESSION['Action'] = 'list';
92 $Output .= $this->ShowList($Table);
93 return($Output);
94 }
95
96 function ShowAdd($Table)
97 {
98 $Output = '';
99 if(array_key_exists('o', $_GET))
100 {
101 if($_GET['o'] == 'save')
102 {
103 $Form = new Form($this->System->FormManager);
104 $Form->SetClass($Table);
105 $Form->LoadValuesFromForm();
106 $Form->SaveValuesToDatabase(0);
107 $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
108 $_SESSION['Action'] = 'view';
109 $Id = $this->Database->insert_id;
110 $_SESSION['Id'] = $Id;
111 //$this->Database->update($Table, 'Id='.$Id,
112 // array('UserCreate' => $this->System->User->User['Id'],
113 // 'TimeCreate' => 'NOW()'));
114 $Output .= $this->ShowView($Table, $Id);
115 }
116 } else
117 {
118 $Form = new Form($this->System->FormManager);
119 $Form->SetClass($Table);
120 $Form->OnSubmit = '?a=add&amp;o=save';
121 $Output .= $Form->ShowEditForm();
122 $Output .= '<ul class="ActionMenu">';
123 $Output .= '<li><a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
124 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
125 $Output .= '</ul>';
126 }
127 return($Output);
128 }
129
130 function ShowView($Table, $Id)
131 {
132 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
133 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
134
135 $Form = new Form($this->System->FormManager);
136 $Form->SetClass($Table);
137 $Form->LoadValuesFromDatabase($Id);
138 $Form->OnSubmit = '?a=view';
139 $Output = $Form->ShowViewForm();
140 $Output .= '<ul class="ActionMenu">';
141 $Output .= '<li><a href="?a=edit"><img alt="Upravit" title="Upravit" src="'.
142 $this->System->Link('/images/edit.png').'"/>Upravit</a></li>';
143 $Output .= '<li><a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
144 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
145 $Output .= '<li><a href="?a=delete" onclick="return confirmAction(\'Opravdu smazat položku?\');"><img alt="Odstranit" title="Odstranit" src="'.
146 $this->System->Link('/images/delete.png').'" />Odstranit</a></li>';
147 $Output .= '<li><a href="?a=add"><img alt="Přidat" title="Přidat" src="'.
148 $this->System->Link('/images/add.png').'"/>Přidat</a></li>';
149 if(array_key_exists('ItemActions', $FormClass))
150 {
151 foreach($FormClass['ItemActions'] as $Action)
152 $Output .= '<li><a href="'.$this->System->Link($Action['URL']).'&amp;id='.$Id.'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
153 $this->System->Link('/images/action.png').'"/>'.$Action['Caption'].'</a></li>';
154 }
155 $Output .= '</ul><br/>';
156
157 // Show ManyToOne relations
158 foreach($Form->Definition['Items'] as $Index => $Item)
159 if((array_key_exists($Item['Type'], $this->System->FormManager->FormTypes) and
160 ($this->System->FormManager->FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
161 {
162 $Output .= $this->ShowList($this->System->FormManager->FormTypes[$Item['Type']]['Table'], '`'.
163 $this->System->FormManager->FormTypes[$Item['Type']]['Ref'].'`='.$Id, $Item['Caption']).'<br/>';
164 }
165 return($Output);
166 }
167
168 function ShowList($Table, $Filter = '', $Title = '')
169 {
170 if($Table != '') $FormClass = $this->System->FormManager->Classes[$Table];
171 else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
172 if($Filter != '') $Filter = ' WHERE '.$Filter;
173 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
174 $DbRow = $DbResult->fetch_row();
175 $PageList = GetPageList($DbRow[0]);
176
177 $Output = '<div style="text-align: center;">'.$FormClass['Title'].'</div>';
178 $Output .= $PageList['Output'];
179 $Output .= '<table class="WideTable" style="font-size: small;">';
180
181 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
182 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
183 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
184 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
185 {
186 $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
187 }
188 $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
189 if(!array_key_exists('DefaultSortColumn', $FormClass))
190 $FormClass['DefaultSortColumn'] = 'Id';
191 $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
192 $Output .= $Order['Output'];
193
194 $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
195
196 $DbResult = $this->Database->query($Query);
197 while($Row = $DbResult->fetch_assoc())
198 {
199 $Output .= '<tr>';
200 foreach($FormClass['Items'] as $ItemIndex => $FormItem)
201 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) or
202 (array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes) and
203 ($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
204 {
205 //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
206 $UseType = $UseType = $FormItem['Type'];
207 if(array_key_exists($FormItem['Type'], $this->System->FormManager->FormTypes))
208 {
209 if(!array_key_exists($FormItem['Type'], $this->System->FormManager->Type->TypeDefinitionList))
210 $this->System->FormManager->Type->RegisterType($FormItem['Type'], '',
211 $this->System->FormManager->FormTypes[$FormItem['Type']]);
212 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Reference')
213 $UseType = 'OneToMany';
214 else
215 if($this->System->FormManager->FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
216 $UseType = 'Enumeration';
217 }
218 $Row[$ItemIndex] = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
219 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
220 'Type' => $FormItem['Type']));
221 $Value = $this->System->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
222 array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
223 'Type' => $FormItem['Type']));
224 if($Value == '') $Value = '&nbsp;';
225 $Output .= '<td>'.$Value.'</td>';
226 }
227 $Output .= '<td><a href="?a=view&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
228 $this->System->Link('/images/view.png').'"/></a>'.
229 '<a href="?a=edit&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Upravit" title="Upravit" src="'.
230 $this->System->Link('/images/edit.png').'"/></a>'.
231 '<a href="?a=delete&amp;t='.$Table.'&amp;id='.$Row['Id'].'"><img alt="Smazat" title="Smazat" src="'.
232 $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
233 if(array_key_exists('ItemActions', $FormClass))
234 {
235 foreach($FormClass['ItemActions'] as $Action)
236 $Output .= '<a href="'.$this->System->Link($Action['URL']).'&amp;id='.$Row['Id'].'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
237 $this->System->Link('/images/action.png').'"/></a>';
238 }
239 $Output .= '</td></tr>';
240 }
241 $Output .= '</table>';
242 $Output .= $PageList['Output'];
243 $Output .= '<ul class="ActionMenu">';
244 $Output .= '<li><a href="?a=add&amp;t='.$Table.'"><img alt="Přidat" title="Přidat" src="'.
245 $this->System->Link('/images/add.png').'"/>Přidat</a></li>';
246 $Output .= '<li><a href="?a=list&amp;t='.$Table.'"><img alt="Seznam" title="Seznam" src="'.
247 $this->System->Link('/images/list.png').'"/>Seznam</a></li>';
248 if(array_key_exists('Actions', $FormClass))
249 {
250 foreach($FormClass['Actions'] as $Action)
251 $Output .= '<li><a href="'.$this->System->Link($Action['URL']).'"><img alt="'.$Action['Caption'].'" title="'.$Action['Caption'].'" src="'.
252 $this->System->Link('/images/action.png').'"/>'.$Action['Caption'].'</a></li>';
253 }
254 $Output .= '</ul>';
255 return($Output);
256 }
257
258 function ShowMenuItem($Parent)
259 {
260 $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
261 foreach($this->MenuItems as $MenuItem)
262 if($MenuItem['Parent'] == $Parent)
263 {
264 $LinkTitle = $MenuItem['Name'];
265 if($MenuItem['URL'] != '')
266 {
267 if(substr($MenuItem['URL'], 0, 4) != 'http') $MenuItem['URL'] = $this->System->Link($MenuItem['URL']);
268 $LinkTitle = MakeLink($MenuItem['URL'], $LinkTitle);
269 }
270 if($MenuItem['IconName'] != '') $Image = '<img src="../images/favicons/'.$MenuItem['IconName'].'"/>&nbsp;';
271 else $Image = '';
272 $Output .= '<li>'.$Image.$LinkTitle.'</li>';
273 $Output .= $this->ShowMenuItem($MenuItem['Id']);
274 }
275 $Output .= '</ul>';
276 return($Output);
277 }
278}
279
280class ModuleIS extends AppModule
281{
282 function __construct($System)
283 {
284 parent::__construct($System);
285 $this->Name = 'Information system';
286 $this->Version = '1.0';
287 $this->Creator = 'Chronos';
288 $this->License = 'GNU/GPLv3';
289 $this->Description = 'User interface for generic information system';
290 $this->Dependencies = array();
291 }
292
293 function Install()
294 {
295 }
296
297 function Uninstall()
298 {
299 }
300
301 function Start()
302 {
303 parent::Start();
304 $this->System->RegisterPage('is', 'PageIS');
305 }
306
307 function Stop()
308 {
309 }
310}
311
312?>
Note: See TracBrowser for help on using the repository browser.