1 | <?php
|
---|
2 |
|
---|
3 | include_once('../Common/Global.php');
|
---|
4 |
|
---|
5 |
|
---|
6 | class PageIS extends Page
|
---|
7 | {
|
---|
8 | var $FullTitle = 'Správa dat';
|
---|
9 | var $ShortTitle = 'Správa dat';
|
---|
10 | var $MenuItems = array();
|
---|
11 |
|
---|
12 | function Show()
|
---|
13 | {
|
---|
14 | global $FormClasses;
|
---|
15 |
|
---|
16 | if(!$this->System->Modules['User']->CheckPermission('IS', 'Manage'))
|
---|
17 | return('Nemáte oprávnění');
|
---|
18 |
|
---|
19 | $DbResult = $this->Database->select('ISMenuItem', '*');
|
---|
20 | while($DbRow = $DbResult->fetch_assoc())
|
---|
21 | {
|
---|
22 | $this->MenuItems[$DbRow['Id']] = $DbRow;
|
---|
23 | }
|
---|
24 |
|
---|
25 | $Output = '<table style="width: 100%"><tr><td style="width: 20%; vertical-align: top;">';
|
---|
26 | $Output .= '<strong>Nabídka:</strong><br/>'.$this->ShowMenuItem('');
|
---|
27 | $Output .= '</td><td style="width: 80%; vertical-align: top;">';
|
---|
28 |
|
---|
29 | if(array_key_exists('t', $_GET)) $_SESSION['Table'] = $_GET['t'];
|
---|
30 | if(!array_key_exists('Table', $_SESSION)) $_SESSION['Table'] = '';
|
---|
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 |
|
---|
36 | if($_SESSION['Action'] == 'list') $Output .= $this->ShowList($_SESSION['Table']);
|
---|
37 | else if($_SESSION['Action'] == 'edit') $Output .= $this->ShowEdit($_SESSION['Table'], $_SESSION['Id']);
|
---|
38 | else if($_SESSION['Action'] == 'add') $Output .= $this->ShowAdd($_SESSION['Table']);
|
---|
39 | else if($_SESSION['Action'] == 'view') $Output .= $this->ShowView($_SESSION['Table'], $_SESSION['Id']);
|
---|
40 | else if($_SESSION['Action'] == 'delete') $Output .= $this->ShowDelete($_SESSION['Table'], $_SESSION['Id']);
|
---|
41 | $Output .= '</td></tr></table>';
|
---|
42 |
|
---|
43 | return($Output);
|
---|
44 | }
|
---|
45 |
|
---|
46 | function ShowEdit($Table, $Id)
|
---|
47 | {
|
---|
48 | $Output = '';
|
---|
49 | if(array_key_exists('o', $_GET))
|
---|
50 | {
|
---|
51 | if($_GET['o'] == 'save')
|
---|
52 | {
|
---|
53 | $Form = new Form($Table);
|
---|
54 | $Form->LoadValuesFromForm();
|
---|
55 | $Form->SaveValuesToDatabase($Id);
|
---|
56 | $Output .= $this->SystemMessage('Úprava položky', 'Položka upravena');
|
---|
57 | $_SESSION['Action'] = 'view';
|
---|
58 | $Output .= $this->ShowView($Table, $Id);
|
---|
59 | }
|
---|
60 | } else
|
---|
61 | {
|
---|
62 | $Form = new Form($Table);
|
---|
63 | $Form->LoadValuesFromDatabase($Id);
|
---|
64 | $Form->OnSubmit = '?a=edit&o=save';
|
---|
65 | $Output .= $Form->ShowEditForm();
|
---|
66 | $Output .= '<br/><div style="text-align: center;">';
|
---|
67 | $Output .= '<a href="?a=view"><img alt="Prohlížet" title="Prohlížet" src="'.
|
---|
68 | $this->System->Link('/images/view.png').'"/></a>';
|
---|
69 | $Output .= '<a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
|
---|
70 | $this->System->Link('/images/list.png').'"/></a>';
|
---|
71 | $Output .= '<a href="?a=delete" ><img alt="Odstranit" title="Odstranit" src="'.
|
---|
72 | $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
|
---|
73 | $Output .= '</div>';
|
---|
74 | }
|
---|
75 | return($Output);
|
---|
76 | }
|
---|
77 |
|
---|
78 | function ShowDelete($Table, $Id)
|
---|
79 | {
|
---|
80 | $Output = '';
|
---|
81 | $this->Database->delete($Table, 'Id='.$Id);
|
---|
82 | $Output .= $this->SystemMessage('Odstranění položky', 'Položka odstraněna');
|
---|
83 | $_SESSION['Action'] = 'list';
|
---|
84 | $Output .= $this->ShowList($Table);
|
---|
85 | return($Output);
|
---|
86 | }
|
---|
87 |
|
---|
88 | function ShowAdd($Table)
|
---|
89 | {
|
---|
90 | $Output = '';
|
---|
91 | if(array_key_exists('o', $_GET))
|
---|
92 | {
|
---|
93 | if($_GET['o'] == 'save')
|
---|
94 | {
|
---|
95 | $Form = new Form($Table);
|
---|
96 | $Form->LoadValuesFromForm();
|
---|
97 | $Form->SaveValuesToDatabase(0);
|
---|
98 | $Output .= $this->SystemMessage('Přidání položky', 'Nová položka vytvořena');
|
---|
99 | $_SESSION['Action'] = 'view';
|
---|
100 | $Id = $this->Database->insert_id;
|
---|
101 | $_SESSION['Id'] = $Id;
|
---|
102 | $this->Database->update($Table, 'Id='.$Id,
|
---|
103 | array('UserCreate' => $this->System->Modules['User']->User['Id'],
|
---|
104 | 'TimeCreate' => 'NOW()'));
|
---|
105 | $Output .= $this->ShowView($Table, $Id);
|
---|
106 | }
|
---|
107 | } else
|
---|
108 | {
|
---|
109 | $Form = new Form($Table);
|
---|
110 | $Form->OnSubmit = '?a=add&o=save';
|
---|
111 | $Output .= $Form->ShowEditForm();
|
---|
112 | $Output .= '<br/><div style="text-align: center;">';
|
---|
113 | $Output .= '<a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
|
---|
114 | $this->System->Link('/images/list.png').'"/></a>';
|
---|
115 | $Output .= '</div>';
|
---|
116 | }
|
---|
117 | return($Output);
|
---|
118 | }
|
---|
119 |
|
---|
120 | function ShowView($Table, $Id)
|
---|
121 | {
|
---|
122 | global $FormTypes;
|
---|
123 |
|
---|
124 | $Form = new Form($Table);
|
---|
125 | $Form->LoadValuesFromDatabase($Id);
|
---|
126 | $Form->OnSubmit = '?a=view';
|
---|
127 | $Output = $Form->ShowViewForm();
|
---|
128 | $Output .= '<br/><div style="text-align: center;">';
|
---|
129 | $Output .= '<a href="?a=edit"><img alt="Upravit" title="Upravit" src="'.
|
---|
130 | $this->System->Link('/images/edit.png').'"/></a>';
|
---|
131 | $Output .= '<a href="?a=list"><img alt="Seznam" title="Seznam" src="'.
|
---|
132 | $this->System->Link('/images/list.png').'"/></a>';
|
---|
133 | $Output .= '<a href="?a=delete"><img alt="Odstranit" title="Odstranit" src="'.
|
---|
134 | $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a>';
|
---|
135 | $Output .= '</div><br/>';
|
---|
136 |
|
---|
137 | // Show ManyToOne relations
|
---|
138 | foreach($Form->Definition['Items'] as $Index => $Item)
|
---|
139 | if((array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] == 'ManyToOne')))
|
---|
140 | {
|
---|
141 | $Output .= '<div style="text-align: center;">'.$Form->Definition['Title'].'</div>';
|
---|
142 | $Output .= $this->ShowList($FormTypes[$Item['Type']]['Table'], '`'.$FormTypes[$Item['Type']]['Ref'].'`='.$Id).'<br/>';
|
---|
143 | }
|
---|
144 | return($Output);
|
---|
145 | }
|
---|
146 |
|
---|
147 | function ShowList($Table, $Filter = '')
|
---|
148 | {
|
---|
149 | global $Type, $FormTypes, $FormClasses;
|
---|
150 |
|
---|
151 | if($Table != '') $FormClass = $FormClasses[$Table];
|
---|
152 | else return($this->SystemMessage('Chyba', 'Tabulka nenalezena'));
|
---|
153 | if($Filter != '') $Filter = ' WHERE '.$Filter;
|
---|
154 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `'.$FormClass['Table'].'`'.$Filter);
|
---|
155 | $DbRow = $DbResult->fetch_row();
|
---|
156 | $PageList = GetPageList($DbRow[0]);
|
---|
157 |
|
---|
158 | $Output = $PageList['Output'];
|
---|
159 | $Output .= '<table class="WideTable" style="font-size: small;">';
|
---|
160 |
|
---|
161 | foreach($FormClass['Items'] as $ItemIndex => $FormItem)
|
---|
162 | if(!array_key_exists($FormItem['Type'], $FormTypes) or
|
---|
163 | (array_key_exists($FormItem['Type'], $FormTypes) and ($FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
|
---|
164 | $TableColumns[] = array('Name' => $ItemIndex, 'Title' => $FormItem['Caption']);
|
---|
165 | $TableColumns[] = array('Name' => '', 'Title' => 'Akce');
|
---|
166 | if(!array_key_exists('DefaultSortColumn', $FormClass))
|
---|
167 | $FormClass['DefaultSortColumn'] = 'Id';
|
---|
168 | $Order = GetOrderTableHeader($TableColumns, $FormClass['DefaultSortColumn'], 0);
|
---|
169 | $Output .= $Order['Output'];
|
---|
170 |
|
---|
171 | $Query = 'SELECT * FROM `'.$FormClass['Table'].'`'.$Filter.' '.$Order['SQL'].$PageList['SQLLimit'];
|
---|
172 |
|
---|
173 | $DbResult = $this->Database->query($Query);
|
---|
174 | while($Row = $DbResult->fetch_assoc())
|
---|
175 | {
|
---|
176 | $Output .= '<tr>';
|
---|
177 | foreach($FormClass['Items'] as $ItemIndex => $FormItem)
|
---|
178 | if(!array_key_exists($FormItem['Type'], $FormTypes) or
|
---|
179 | (array_key_exists($FormItem['Type'], $FormTypes) and ($FormTypes[$FormItem['Type']]['Type'] != 'ManyToOne')))
|
---|
180 | {
|
---|
181 | //$Output .= '<td>'.$Row[$ItemIndex].'</td>';
|
---|
182 | if(array_key_exists($FormItem['Type'], $FormTypes))
|
---|
183 | {
|
---|
184 | if(!array_key_exists($FormItem['Type'], $this->System->Type->TypeDefinitionList))
|
---|
185 | $this->System->Type->RegisterType($FormItem['Type'], '',
|
---|
186 | $FormTypes[$FormItem['Type']]);
|
---|
187 | if($FormTypes[$FormItem['Type']]['Type'] == 'Reference')
|
---|
188 | $Value = $this->System->Type->ExecuteTypeEvent('OneToMany', 'OnView',
|
---|
189 | array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
|
---|
190 | 'Type' => $FormItem['Type']));
|
---|
191 | else
|
---|
192 | if($FormTypes[$FormItem['Type']]['Type'] == 'Enumeration')
|
---|
193 | $Value = $this->System->Type->ExecuteTypeEvent('Enumeration', 'OnView',
|
---|
194 | array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex,
|
---|
195 | 'Type' => $FormItem['Type']));
|
---|
196 | } else $Value = $this->System->Type->ExecuteTypeEvent($FormItem['Type'], 'OnView',
|
---|
197 | array('Value' => $Row[$ItemIndex], 'Name' => $ItemIndex));
|
---|
198 | if($Value == '') $Value = ' ';
|
---|
199 | $Output .= '<td>'.$Value.'</td>';
|
---|
200 | }
|
---|
201 | $Output .= '<td><a href="?a=view&t='.$Table.'&id='.$Row['Id'].'"><img alt="Ukázat" title="Ukázat" src="'.
|
---|
202 | $this->System->Link('/images/view.png').'"/></a>'.
|
---|
203 | '<a href="?a=edit&t='.$Table.'&id='.$Row['Id'].'"><img alt="Upravit" title="Upravit" src="'.
|
---|
204 | $this->System->Link('/images/edit.png').'"/></a>'.
|
---|
205 | '<a href="?a=delete&t='.$Table.'&id='.$Row['Id'].'"><img alt="Smazat" title="Smazat" src="'.
|
---|
206 | $this->System->Link('/images/delete.png').'" onclick="return confirmAction(\'Opravdu smazat položku?\');"/></a></td>';
|
---|
207 | $Output .= '</tr>';
|
---|
208 | }
|
---|
209 | $Output .= '</table>';
|
---|
210 | $Output .= $PageList['Output'];
|
---|
211 | $Output .= '<br/><div style="text-align: center;">';
|
---|
212 | $Output .= '<a href="?a=add"><img alt="Přidat" title="Přidat" src="'.
|
---|
213 | $this->System->Link('/images/add.png').'"/></a>';
|
---|
214 | $Output .= '</div>';
|
---|
215 | return($Output);
|
---|
216 | }
|
---|
217 |
|
---|
218 | function ShowMenuItem($Parent)
|
---|
219 | {
|
---|
220 | $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
|
---|
221 | foreach($this->MenuItems as $MenuItem)
|
---|
222 | if($MenuItem['Parent'] == $Parent)
|
---|
223 | {
|
---|
224 | $LinkTitle = $MenuItem['Name'];
|
---|
225 | if($MenuItem['Table'] != '') $LinkTitle = MakeLink('?t='.$MenuItem['Table'].'&a=list', $LinkTitle);
|
---|
226 | $Output .= '<li>'.$LinkTitle.'</li>';
|
---|
227 | $Output .= $this->ShowMenuItem($MenuItem['Id']);
|
---|
228 | }
|
---|
229 | $Output .= '</ul>';
|
---|
230 | return($Output);
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | $System->AddModule(new PageIS());
|
---|
235 | $System->Modules['PageIS']->GetOutput();
|
---|
236 |
|
---|
237 | ?>
|
---|