1 | <?php
|
---|
2 |
|
---|
3 | class PageModules extends Page
|
---|
4 | {
|
---|
5 | function __construct($System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->FullTitle = 'Správa modulů';
|
---|
9 | $this->ShortTitle = 'Moduly';
|
---|
10 | $this->ParentClass = 'PagePortal';
|
---|
11 | }
|
---|
12 |
|
---|
13 | function ShowList()
|
---|
14 | {
|
---|
15 | $Output = '';
|
---|
16 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Module`');
|
---|
17 | $DbRow = $DbResult->fetch_row();
|
---|
18 | $PageList = GetPageList($DbRow[0]);
|
---|
19 |
|
---|
20 | $Output .= $PageList['Output'];
|
---|
21 | $Output .= '<table class="WideTable" style="font-size: small;">';
|
---|
22 |
|
---|
23 | $TableColumns = array(
|
---|
24 | array('Name' => 'Name', 'Title' => 'Jméno'),
|
---|
25 | array('Name' => 'Creator', 'Title' => 'Tvůrce'),
|
---|
26 | array('Name' => 'Version', 'Title' => 'Verze'),
|
---|
27 | array('Name' => 'License', 'Title' => 'Licence'),
|
---|
28 | array('Name' => 'Installed', 'Title' => 'Instalováno'),
|
---|
29 | array('Name' => 'Description', 'Title' => 'Popis'),
|
---|
30 | array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
|
---|
31 | array('Name' => '', 'Title' => 'Akce'),
|
---|
32 | );
|
---|
33 | $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
|
---|
34 | $Output .= $Order['Output'];
|
---|
35 | $Query = 'SELECT *, (SELECT GROUP_CONCAT(`T1`.`Name` SEPARATOR ", ") FROM `ModuleLink` '.
|
---|
36 | 'LEFT JOIN `Module` AS `T1` ON `T1`.`Id` = `ModuleLink`.`LinkedModule` '.
|
---|
37 | 'WHERE `ModuleLink`.`Module` = `Module`.`Id`) AS `Dependencies` '.
|
---|
38 | 'FROM `Module` '.$Order['SQL'].$PageList['SQLLimit'];
|
---|
39 |
|
---|
40 | $DbResult = $this->Database->query($Query);
|
---|
41 | while($Module = $DbResult->fetch_assoc())
|
---|
42 | {
|
---|
43 | if($Module['Dependencies'] != '') $Dependencies = $Module['Dependencies'];
|
---|
44 | else $Dependencies = ' ';
|
---|
45 | if($Module['Installed'] == 1) $Installed = 'Ano';
|
---|
46 | else $Installed = 'Ne';
|
---|
47 | if($Module['Installed'] == 1) $Actions = '<a href="?A=Uninstall&Id='.$Module['Id'].'">Odinstalovat</a>';
|
---|
48 | else $Actions = '<a href="?A=Install&Id='.$Module['Id'].'">Instalovat</a>';
|
---|
49 | $Output .= '<tr><td>'.$Module['Name'].'</td>'.
|
---|
50 | '<td>'.$Module['Creator'].'</td>'.
|
---|
51 | '<td>'.$Module['Version'].'</td>'.
|
---|
52 | '<td>'.$Module['License'].'</td>'.
|
---|
53 | '<td>'.$Installed.'</td>'.
|
---|
54 | '<td>'.$Module['Description'].'</td>'.
|
---|
55 | '<td>'.$Dependencies.'</td>'.
|
---|
56 | '<td>'.$Actions.'</td></tr>';
|
---|
57 | }
|
---|
58 | $Output .= '</table>';
|
---|
59 | $Output .= $PageList['Output'];
|
---|
60 | $Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';
|
---|
61 | return($Output);
|
---|
62 | }
|
---|
63 |
|
---|
64 | function Show()
|
---|
65 | {
|
---|
66 | $Output = '';
|
---|
67 | if(array_key_exists('A', $_GET))
|
---|
68 | {
|
---|
69 | if($_GET['A'] == 'SaveToDb')
|
---|
70 | {
|
---|
71 | $Output .= $this->System->ModuleManager->Modules['System']->SaveToDatabase();
|
---|
72 | $Output .= $this->SystemMessage('Načtení modulů', 'Seznam modulů v databázi zaktualizován');
|
---|
73 | } else
|
---|
74 | if($_GET['A'] == 'Install')
|
---|
75 | {
|
---|
76 | $this->System->ModuleManager->LoadModules(false);
|
---|
77 | $ModuleName = $this->System->ModuleManager->SearchModuleById($_GET['Id']);
|
---|
78 | if($ModuleName != '')
|
---|
79 | {
|
---|
80 | $this->System->Modules[$ModuleName]->Install();
|
---|
81 | $this->System->ModuleManager->Init();
|
---|
82 | } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen';
|
---|
83 |
|
---|
84 | } else
|
---|
85 | if($_GET['A'] == 'Uninstall')
|
---|
86 | {
|
---|
87 | $ModuleName = $this->System->ModuleManager->SearchModuleById($_GET['Id']);
|
---|
88 | if($ModuleName != '')
|
---|
89 | {
|
---|
90 | $this->System->ModuleManager->Modules[$ModuleName]->UnInstall();
|
---|
91 | $this->System->ModuleManager->Init();
|
---|
92 | } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen';
|
---|
93 | } else $Output .= 'Neplatná akce';
|
---|
94 | }
|
---|
95 | $Output .= $this->ShowList();
|
---|
96 | return($Output);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | class ModuleSystem extends AppModule
|
---|
101 | {
|
---|
102 | var $InstalledChecked;
|
---|
103 |
|
---|
104 | function __construct($System)
|
---|
105 | {
|
---|
106 | parent::__construct($System);
|
---|
107 | $this->Name = 'System';
|
---|
108 | $this->Version = '1.0';
|
---|
109 | $this->Creator = 'Chronos';
|
---|
110 | $this->License = 'GNU/GPL';
|
---|
111 | $this->Description = 'Base system module';
|
---|
112 | $this->Dependencies = array();
|
---|
113 | }
|
---|
114 |
|
---|
115 | function DoInstall()
|
---|
116 | {
|
---|
117 | $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (
|
---|
118 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
119 | `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
120 | `Description` datetime NOT NULL,
|
---|
121 | PRIMARY KEY (`Id`)
|
---|
122 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
|
---|
123 | $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` (
|
---|
124 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
125 | `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
126 | `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
127 | `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
128 | `License` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
129 | `Installed` int(11) NOT NULL,
|
---|
130 | `Description` text COLLATE utf8_czech_ci NOT NULL,
|
---|
131 | PRIMARY KEY (`Id`)
|
---|
132 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
|
---|
133 |
|
---|
134 | $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` (
|
---|
135 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
136 | `Module` int(11) NOT NULL,
|
---|
137 | `DependencyModule` int(11) NOT NULL,
|
---|
138 | PRIMARY KEY (`Id`),
|
---|
139 | KEY (`Module`),
|
---|
140 | KEY (`DependencyModule`),
|
---|
141 | UNIQUE (`Module` , `DependencyModule`)
|
---|
142 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
|
---|
143 | $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
|
---|
144 | $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');
|
---|
145 |
|
---|
146 | $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` (
|
---|
147 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
148 | `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
149 | `Module` int(11) NOT NULL,
|
---|
150 | KEY (`Module`),
|
---|
151 | PRIMARY KEY (`Id`)
|
---|
152 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
|
---|
153 | $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
|
---|
154 |
|
---|
155 | $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` (
|
---|
156 | `Id` int(11) NOT NULL AUTO_INCREMENT,
|
---|
157 | `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
158 | `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL,
|
---|
159 | `Model` int(11) NOT NULL,
|
---|
160 | KEY (`Model`),
|
---|
161 | PRIMARY KEY (`Id`)
|
---|
162 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
|
---|
163 | $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');
|
---|
164 | }
|
---|
165 |
|
---|
166 | function DoUnInstall()
|
---|
167 | {
|
---|
168 | // Delete tables with reverse order
|
---|
169 | $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`');
|
---|
170 | $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`');
|
---|
171 | $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`');
|
---|
172 | $this->Database->query('DROP TABLE IF EXISTS `SystemModel`');
|
---|
173 | $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`');
|
---|
174 | $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`');
|
---|
175 | $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`');
|
---|
176 | $this->Database->query('DROP TABLE IF EXISTS `SystemModule`');
|
---|
177 | $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`');
|
---|
178 | }
|
---|
179 |
|
---|
180 | function DoStart()
|
---|
181 | {
|
---|
182 | $this->System->RegisterPage('module', 'PageModules');
|
---|
183 | $this->System->FormManager->RegisterClass('Action', array(
|
---|
184 | 'Title' => 'Akce',
|
---|
185 | 'Table' => 'Action',
|
---|
186 | 'Items' => array(
|
---|
187 | //'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
188 | 'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
189 | 'URL' => array('Type' => 'Hyperlink', 'Caption' => 'Odkaz', 'Default' => ''),
|
---|
190 | 'Icon' => array('Type' => 'TActionIcon', 'Caption' => 'Ikony', 'Default' => '', 'Null' => true),
|
---|
191 | 'Type' => array('Type' => 'TActionType', 'Caption' => 'Typ', 'Default' => ''),
|
---|
192 | 'Group' => array('Type' => 'TActionGroup', 'Caption' => 'Skupina', 'Default' => '', 'Null' => true),
|
---|
193 | 'PermissionOperation' => array('Type' => 'TPermissionOperation', 'Caption' => 'Operace oprávnění', 'Default' => ''),
|
---|
194 | 'Enable' => array('Type' => 'Boolean', 'Caption' => 'Povolení', 'Default' => ''),
|
---|
195 | ),
|
---|
196 | ));
|
---|
197 | $this->System->FormManager->RegisterClass('ActionIcon', array(
|
---|
198 | 'Title' => 'Ikony akcí',
|
---|
199 | 'Table' => 'ActionIcon',
|
---|
200 | 'Items' => array(
|
---|
201 | 'Name' => array('Type' => 'Image', 'Caption' => 'Název souboru', 'Default' => ''),
|
---|
202 | 'Items' => array('Type' => 'TActionListIcon', 'Caption' => 'Položky', 'Default' => ''),
|
---|
203 | ),
|
---|
204 | ));
|
---|
205 | $this->System->FormManager->RegisterClass('ActionGroup', array(
|
---|
206 | 'Title' => 'Skupiny akcí',
|
---|
207 | 'Table' => 'ActionGroup',
|
---|
208 | 'Items' => array(
|
---|
209 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
210 | 'Items' => array('Type' => 'TActionListGroup', 'Caption' => 'Položky', 'Default' => ''),
|
---|
211 | ),
|
---|
212 | ));
|
---|
213 | $this->System->FormManager->RegisterClass('ActionType', array(
|
---|
214 | 'Title' => 'Typy akcí',
|
---|
215 | 'Table' => 'ActionType',
|
---|
216 | 'Items' => array(
|
---|
217 | 'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
218 | 'Items' => array('Type' => 'TActionListType', 'Caption' => 'Položky', 'Default' => ''),
|
---|
219 | ),
|
---|
220 | ));
|
---|
221 | $this->System->FormManager->RegisterClass('Module', array(
|
---|
222 | 'Title' => 'Moduly',
|
---|
223 | 'Table' => 'Module',
|
---|
224 | 'Items' => array(
|
---|
225 | 'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
|
---|
226 | 'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
227 | 'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
|
---|
228 | 'Version' => array('Type' => 'String', 'Caption' => 'Verze', 'Default' => ''),
|
---|
229 | 'License' => array('Type' => 'String', 'Caption' => 'Licence', 'Default' => ''),
|
---|
230 | 'Creator' => array('Type' => 'String', 'Caption' => 'Tvůrce', 'Default' => ''),
|
---|
231 | 'HomePage' => array('Type' => 'Hyperlink', 'Caption' => 'Domovské stránky', 'Default' => ''),
|
---|
232 | 'Installed' => array('Type' => 'Boolean', 'Caption' => 'Instalováno', 'Default' => '', 'ReadOnly' => true),
|
---|
233 | 'Models' => array('Type' => 'TModelListModule', 'Caption' => 'Modely', 'Default' => ''),
|
---|
234 | 'Links' => array('Type' => 'TModuleLinkListModule', 'Caption' => 'Vazby', 'Default' => ''),
|
---|
235 | ),
|
---|
236 | 'Actions' => array(
|
---|
237 | array('Caption' => 'Aktualizovat z disku', 'URL' => '/module/?A=SaveToDb'),
|
---|
238 | ),
|
---|
239 | ));
|
---|
240 | $this->System->FormManager->RegisterFormType('TModule', array(
|
---|
241 | 'Type' => 'Reference',
|
---|
242 | 'Table' => 'Module',
|
---|
243 | 'Id' => 'Id',
|
---|
244 | 'Name' => 'Title',
|
---|
245 | 'Filter' => '1',
|
---|
246 | ));
|
---|
247 | $this->System->FormManager->RegisterFormType('TModelListModule', array(
|
---|
248 | 'Type' => 'ManyToOne',
|
---|
249 | 'Table' => 'Model',
|
---|
250 | 'Id' => 'Id',
|
---|
251 | 'Ref' => 'Module',
|
---|
252 | 'Filter' => '1',
|
---|
253 | ));
|
---|
254 | $this->System->FormManager->RegisterClass('Model', array(
|
---|
255 | 'Title' => 'Modely',
|
---|
256 | 'Table' => 'Model',
|
---|
257 | 'Items' => array(
|
---|
258 | 'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
|
---|
259 | 'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
260 | 'Module' => array('Type' => 'TModule', 'Caption' => 'Module', 'Default' => ''),
|
---|
261 | 'Query' => array('Type' => 'String', 'Caption' => 'SQL dotaz', 'Default' => ''),
|
---|
262 | 'DefaultSortColumn' => array('Type' => 'String', 'Caption' => 'Výchozí sloupce řazení', 'Default' => ''),
|
---|
263 | 'DefaultSortOrder' => array('Type' => 'Text', 'Caption' => 'Výchozí směr řazení', 'Default' => ''),
|
---|
264 | 'Fields' => array('Type' => 'TModelFieldListModel', 'Caption' => 'Pole', 'Default' => ''),
|
---|
265 | ),
|
---|
266 | ));
|
---|
267 | $this->System->FormManager->RegisterFormType('TModel', array(
|
---|
268 | 'Type' => 'Reference',
|
---|
269 | 'Table' => 'Model',
|
---|
270 | 'Id' => 'Id',
|
---|
271 | 'Name' => 'Title',
|
---|
272 | 'Filter' => '1',
|
---|
273 | ));
|
---|
274 | $this->System->FormManager->RegisterFormType('TModelFieldListModel', array(
|
---|
275 | 'Type' => 'ManyToOne',
|
---|
276 | 'Table' => 'ModelField',
|
---|
277 | 'Id' => 'Id',
|
---|
278 | 'Ref' => 'Model',
|
---|
279 | 'Filter' => '1',
|
---|
280 | ));
|
---|
281 | $this->System->FormManager->RegisterClass('ModelField', array(
|
---|
282 | 'Title' => 'Pole modelu',
|
---|
283 | 'Table' => 'ModelField',
|
---|
284 | 'Items' => array(
|
---|
285 | 'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
|
---|
286 | 'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
|
---|
287 | 'Model' => array('Type' => 'TModel', 'Caption' => 'Model', 'Default' => ''),
|
---|
288 | 'Query' => array('Type' => 'String', 'Caption' => 'SQL dotaz', 'Default' => ''),
|
---|
289 | 'Type' => array('Type' => 'String', 'Caption' => 'Typ', 'Default' => ''),
|
---|
290 | 'DefaultValue' => array('Type' => 'String', 'Caption' => 'Výchozí hodnota', 'Default' => ''),
|
---|
291 | 'IsNull' => array('Type' => 'Boolean', 'Caption' => 'Také nulová hodnota', 'Default' => ''),
|
---|
292 | 'Suffix' => array('Type' => 'String', 'Caption' => 'Text za', 'Default' => ''),
|
---|
293 | ),
|
---|
294 | ));
|
---|
295 | $this->System->FormManager->RegisterFormType('TModuleLink', array(
|
---|
296 | 'Type' => 'Reference',
|
---|
297 | 'Table' => 'ModuleLink',
|
---|
298 | 'Id' => 'Id',
|
---|
299 | 'Name' => 'Module',
|
---|
300 | 'Filter' => '1',
|
---|
301 | ));
|
---|
302 | $this->System->FormManager->RegisterFormType('TModuleLinkListModule', array(
|
---|
303 | 'Type' => 'ManyToOne',
|
---|
304 | 'Table' => 'ModuleLink',
|
---|
305 | 'Id' => 'Id',
|
---|
306 | 'Ref' => 'Module',
|
---|
307 | 'Filter' => '1',
|
---|
308 | ));
|
---|
309 | $this->System->FormManager->RegisterClass('ModuleLink', array(
|
---|
310 | 'Title' => 'Vazby modulu',
|
---|
311 | 'Table' => 'ModuleLink',
|
---|
312 | 'Items' => array(
|
---|
313 | 'Module' => array('Type' => 'TModule', 'Caption' => 'Modul', 'Default' => ''),
|
---|
314 | 'LinkedModule' => array('Type' => 'TModule', 'Caption' => 'Vázaný modul', 'Default' => ''),
|
---|
315 | 'Type' => array('Type' => 'String', 'Caption' => 'Typ vazby', 'Default' => ''),
|
---|
316 | ),
|
---|
317 | ));
|
---|
318 | $this->System->FormManager->RegisterClass('Language', array(
|
---|
319 | 'Title' => 'Jazyky',
|
---|
320 | 'Table' => 'Language',
|
---|
321 | 'DefaultSortColumn' => 'Name',
|
---|
322 | 'Items' => array(
|
---|
323 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
324 | ),
|
---|
325 | ));
|
---|
326 | $this->System->FormManager->RegisterClass('UnitOfMeasure', array(
|
---|
327 | 'Title' => 'Měrné jednotky',
|
---|
328 | 'Table' => 'UnitOfMeasure',
|
---|
329 | 'DefaultSortColumn' => 'Name',
|
---|
330 | 'Items' => array(
|
---|
331 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
332 | 'Unit' => array('Type' => 'String', 'Caption' => 'Jednotka', 'Default' => ''),
|
---|
333 | ),
|
---|
334 | ));
|
---|
335 | $this->System->FormManager->RegisterClass('Country', array(
|
---|
336 | 'Title' => 'Země',
|
---|
337 | 'Table' => 'Country',
|
---|
338 | 'DefaultSortColumn' => 'Name',
|
---|
339 | 'Items' => array(
|
---|
340 | 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
|
---|
341 | ),
|
---|
342 | ));
|
---|
343 | $this->System->FormManager->RegisterFormType('TCountry', array(
|
---|
344 | 'Type' => 'Reference',
|
---|
345 | 'Table' => 'Country',
|
---|
346 | 'Id' => 'Id',
|
---|
347 | 'Name' => 'Name',
|
---|
348 | 'Filter' => '1',
|
---|
349 | ));
|
---|
350 | $this->System->FormManager->RegisterFormType('TUnitOfMeasure', array(
|
---|
351 | 'Type' => 'Reference',
|
---|
352 | 'Table' => 'UnitOfMeasure',
|
---|
353 | 'Id' => 'Id',
|
---|
354 | 'Name' => 'Name',
|
---|
355 | 'Filter' => '1',
|
---|
356 | ));
|
---|
357 | $this->System->FormManager->RegisterFormType('TLanguage', array(
|
---|
358 | 'Type' => 'Reference',
|
---|
359 | 'Table' => 'Language',
|
---|
360 | 'Id' => 'Id',
|
---|
361 | 'Name' => 'Name',
|
---|
362 | 'Filter' => '1',
|
---|
363 | ));
|
---|
364 | $this->System->FormManager->RegisterFormType('TAction', array(
|
---|
365 | 'Type' => 'Reference',
|
---|
366 | 'Table' => 'Action',
|
---|
367 | 'Id' => 'Id',
|
---|
368 | 'Name' => 'Title',
|
---|
369 | 'Filter' => '1',
|
---|
370 | ));
|
---|
371 | $this->System->FormManager->RegisterFormType('TActionIcon', array(
|
---|
372 | 'Type' => 'Reference',
|
---|
373 | 'Table' => 'ActionIcon',
|
---|
374 | 'Id' => 'Id',
|
---|
375 | 'Name' => 'Name',
|
---|
376 | 'Filter' => '1',
|
---|
377 | ));
|
---|
378 | $this->System->FormManager->RegisterFormType('TActionType', array(
|
---|
379 | 'Type' => 'Reference',
|
---|
380 | 'Table' => 'ActionType',
|
---|
381 | 'Id' => 'Id',
|
---|
382 | 'Name' => 'Name',
|
---|
383 | 'Filter' => '1',
|
---|
384 | ));
|
---|
385 | $this->System->FormManager->RegisterFormType('TActionGroup', array(
|
---|
386 | 'Type' => 'Reference',
|
---|
387 | 'Table' => 'ActionGroup',
|
---|
388 | 'Id' => 'Id',
|
---|
389 | 'Name' => 'Name',
|
---|
390 | 'Filter' => '1',
|
---|
391 | ));
|
---|
392 | $this->System->FormManager->RegisterFormType('TModule', array(
|
---|
393 | 'Type' => 'Reference',
|
---|
394 | 'Table' => 'Module',
|
---|
395 | 'Id' => 'Id',
|
---|
396 | 'Name' => 'Name',
|
---|
397 | 'Filter' => '1',
|
---|
398 | ));
|
---|
399 |
|
---|
400 | //$this->Manager->OnModuleChange = array($this, 'ModuleChange');
|
---|
401 | //$this->LoadFromDatabase();
|
---|
402 | }
|
---|
403 |
|
---|
404 | function DoStop()
|
---|
405 | {
|
---|
406 | }
|
---|
407 |
|
---|
408 | function IsInstalled()
|
---|
409 | {
|
---|
410 | if($this->InstalledChecked == false)
|
---|
411 | {
|
---|
412 | $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables
|
---|
413 | WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";');
|
---|
414 | if($DbResult->num_rows > 0) $this->Installed = true;
|
---|
415 | else $this->Installed = false;
|
---|
416 | $this->InstalledChecked = true;
|
---|
417 | }
|
---|
418 | return($this->Installed);
|
---|
419 | }
|
---|
420 |
|
---|
421 | function ModuleChange($Module)
|
---|
422 | {
|
---|
423 | //if($this->IsInstalled())
|
---|
424 | {
|
---|
425 |
|
---|
426 | if($Module->IsInstalled()) $Installed = 1;
|
---|
427 | else $Installed = 0;
|
---|
428 | $this->Database->query('UPDATE `Module` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"');
|
---|
429 | }
|
---|
430 | }
|
---|
431 |
|
---|
432 | function LoadFromDatabase()
|
---|
433 | {
|
---|
434 | //DebugLog('Loading modules...');
|
---|
435 | $this->Modules = array();
|
---|
436 | $Query = 'SELECT `Id`, `Name`,`Installed` FROM `Module`';
|
---|
437 | $DbResult = $this->Database->query($Query);
|
---|
438 | while($Module = $DbResult->fetch_array())
|
---|
439 | {
|
---|
440 | //echo($Module['Name'].',');
|
---|
441 | include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php');
|
---|
442 | $ModuleClassName = 'Module'.$Module['Name'];
|
---|
443 | $NewModule = new $ModuleClassName($this->Database, $this->Manager);
|
---|
444 | $NewModule->Id = $Module['Id'];
|
---|
445 | $NewModule->Installed = $Module['Installed'];
|
---|
446 | $this->Manager->RegisterModule($NewModule);
|
---|
447 | }
|
---|
448 | }
|
---|
449 |
|
---|
450 | function SaveToDatabase()
|
---|
451 | {
|
---|
452 | $Output = '';
|
---|
453 | $Modules = array();
|
---|
454 | $DbResult = $this->Database->query('SELECT * FROM `Module`');
|
---|
455 | while($DbRow = $DbResult->fetch_assoc())
|
---|
456 | {
|
---|
457 | $Modules[$DbRow['Name']] = $DbRow;
|
---|
458 | if($this->System->ModuleManager->ModulePresent($DbRow['Name']))
|
---|
459 | $this->System->ModuleManager->Modules[$DbRow['Name']]->Id = $DbRow['Id'];
|
---|
460 | }
|
---|
461 |
|
---|
462 | // Add missing
|
---|
463 | foreach($this->System->ModuleManager->Modules as $Module)
|
---|
464 | {
|
---|
465 | if(!array_key_exists($Module->Name, $Modules))
|
---|
466 | {
|
---|
467 | $this->Database->insert('Module', array('Name' => $Module->Name,
|
---|
468 | 'Version' => $Module->Version, 'Creator' => $Module->Creator,
|
---|
469 | 'HomePage' => $Module->HomePage, 'Title' => $Module->Title,
|
---|
470 | 'Description' => $Module->Description, 'License' => $Module->License,
|
---|
471 | 'Installed' => $Module->Installed));
|
---|
472 | $this->System->ModuleManager->Modules[$Module->Name]->Id = $this->Database->insert_id;
|
---|
473 | }
|
---|
474 | else $this->Database->update('Module', 'Name = "'.$Module->Name.'"', array(
|
---|
475 | 'Version' => $Module->Version, 'Creator' => $Module->Creator,
|
---|
476 | 'HomePage' => $Module->HomePage, 'Title' => $Module->Title,
|
---|
477 | 'Description' => $Module->Description, 'License' => $Module->License,
|
---|
478 | 'Installed' => $Module->Installed));
|
---|
479 | }
|
---|
480 |
|
---|
481 | // Remove exceeding
|
---|
482 | foreach($Modules as $Module)
|
---|
483 | if(!$this->System->ModuleManager->ModulePresent($Module['Name']))
|
---|
484 | {
|
---|
485 | $Output .= 'Removing module '.$Module['Name'].' from list</br/>';
|
---|
486 | $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '.$Module['Id']);
|
---|
487 | $this->Database->query('DELETE FROM `ModuleLink` WHERE `LinkedModule` = '.$Module['Id']);
|
---|
488 | $DbResult = $this->Database->query('SELECT Id FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']);
|
---|
489 | while($DbRow = $DbResult->fetch_assoc())
|
---|
490 | {
|
---|
491 | $this->Database->query('DELETE FROM `PermissionGroupAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']);
|
---|
492 | $this->Database->query('DELETE FROM `PermissionUserAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']);
|
---|
493 | }
|
---|
494 | $this->Database->query('DELETE FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']);
|
---|
495 | $this->Database->query('DELETE FROM `Model` WHERE `Module` = '.$Module['Id']);
|
---|
496 | $DbResult = $this->Database->query('SELECT Id FROM `Model` WHERE `Module` = '.$Module['Id']);
|
---|
497 | while($DbRow = $DbResult->fetch_assoc())
|
---|
498 | $this->Database->query('DELETE FROM `ModelField` WHERE `Model` = '.$DbRow['Id']);
|
---|
499 | $this->Database->query('DELETE FROM `Module` WHERE `Id` = '.$Module['Id']);
|
---|
500 | }
|
---|
501 |
|
---|
502 | // Reload dependencies
|
---|
503 | $DbDependency = array();
|
---|
504 | $DbResult = $this->Database->query('SELECT * FROM `ModuleLink`');
|
---|
505 | while($DbRow = $DbResult->fetch_assoc())
|
---|
506 | $DbDependency[$DbRow['Module']][] = $DbRow['LinkedModule'];
|
---|
507 |
|
---|
508 | foreach($this->System->ModuleManager->Modules as $Module)
|
---|
509 | {
|
---|
510 | // Add missing
|
---|
511 | foreach($Module->Dependencies as $Dependency)
|
---|
512 | {
|
---|
513 | if(!array_key_exists($Module->Id, $DbDependency) or
|
---|
514 | !in_array($this->System->ModuleManager->Modules[$Dependency]->Id, $DbDependency[$Module->Id]))
|
---|
515 | {
|
---|
516 | if(array_key_exists($Dependency, $this->System->ModuleManager->Modules))
|
---|
517 | $DependencyId = $this->System->ModuleManager->Modules[$Dependency]->Id;
|
---|
518 | else throw new Exception('Dependent module '.$Dependency.' not found');
|
---|
519 | $this->Database->insert('ModuleLink', array('Module' => $Module->Id,
|
---|
520 | 'LinkedModule' => $DependencyId, 'Type' => 'DependOn'));
|
---|
521 | }
|
---|
522 | }
|
---|
523 |
|
---|
524 | // Remove exceeding
|
---|
525 | if(array_key_exists($Module->Id, $DbDependency))
|
---|
526 | foreach($DbDependency[$Module->Id] as $Dep)
|
---|
527 | {
|
---|
528 | $DepModName = $this->System->ModuleManager->SearchModuleById($Dep);
|
---|
529 | if(!in_array($DepModName, $Module->Dependencies))
|
---|
530 | $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '.
|
---|
531 | $Module->Id.' AND LinkedModule='.$Dep);
|
---|
532 | }
|
---|
533 | }
|
---|
534 | return($Output);
|
---|
535 | }
|
---|
536 | }
|
---|