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

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