Changeset 738 for trunk/Modules/System/System.php
- Timestamp:
- Apr 14, 2015, 10:20:16 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/System/System.php
r731 r738 2 2 3 3 class PageModules extends Page 4 { 4 { 5 5 function __construct($System) 6 6 { … … 10 10 $this->ParentClass = 'PagePortal'; 11 11 } 12 12 13 13 function ShowList() 14 14 { … … 17 17 $DbRow = $DbResult->fetch_row(); 18 18 $PageList = GetPageList($DbRow[0]); 19 19 20 20 $Output .= $PageList['Output']; 21 21 $Output .= '<table class="WideTable" style="font-size: small;">'; 22 22 23 23 $TableColumns = array( 24 24 array('Name' => 'Name', 'Title' => 'Jméno'), … … 37 37 'WHERE `ModuleLink`.`Module` = `Module`.`Id`) AS `Dependencies` '. 38 38 'FROM `Module` '.$Order['SQL'].$PageList['SQLLimit']; 39 39 40 40 $DbResult = $this->Database->query($Query); 41 41 while($Module = $DbResult->fetch_assoc()) … … 59 59 $Output .= $PageList['Output']; 60 60 $Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>'; 61 return($Output); 62 } 63 61 return($Output); 62 } 63 64 64 function Show() 65 { 65 { 66 66 $Output = ''; 67 67 if(array_key_exists('A', $_GET)) 68 68 { 69 if($_GET['A'] == 'SaveToDb') 69 if($_GET['A'] == 'SaveToDb') 70 70 { 71 71 $Output .= $this->System->ModuleManager->Modules['System']->SaveToDatabase(); 72 $Output .= $this->SystemMessage('Načtení modulů', 'Seznam modulů v databázi zaktualizován'); 72 $Output .= $this->SystemMessage('Načtení modulů', 'Seznam modulů v databázi zaktualizován'); 73 73 } else 74 if($_GET['A'] == 'Install') 74 if($_GET['A'] == 'Install') 75 75 { 76 76 $this->System->ModuleManager->LoadModules(false); 77 77 $ModuleName = $this->System->ModuleManager->SearchModuleById($_GET['Id']); 78 if($ModuleName != '') 78 if($ModuleName != '') 79 79 { 80 80 $this->System->Modules[$ModuleName]->Install(); 81 81 $this->System->ModuleManager->Init(); 82 82 } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen'; 83 83 84 84 } else 85 if($_GET['A'] == 'Uninstall') 85 if($_GET['A'] == 'Uninstall') 86 86 { 87 87 $ModuleName = $this->System->ModuleManager->SearchModuleById($_GET['Id']); 88 if($ModuleName != '') 88 if($ModuleName != '') 89 89 { 90 90 $this->System->ModuleManager->Modules[$ModuleName]->UnInstall(); 91 91 $this->System->ModuleManager->Init(); 92 92 } else $Output .= 'Modul id '.$_GET['Id'].' nenalezen'; 93 } else $Output .= 'Neplatná akce'; 93 } else $Output .= 'Neplatná akce'; 94 94 } 95 95 $Output .= $this->ShowList(); 96 return($Output); 97 } 98 } 96 return($Output); 97 } 98 } 99 99 100 100 class ModuleSystem extends AppModule 101 101 { 102 102 var $InstalledChecked; 103 103 104 104 function __construct($System) 105 105 { … … 112 112 $this->Dependencies = array(); 113 113 } 114 114 115 115 function DoInstall() 116 116 { … … 131 131 PRIMARY KEY (`Id`) 132 132 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 133 133 134 134 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` ( 135 135 `Id` int(11) NOT NULL AUTO_INCREMENT, … … 143 143 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)'); 144 144 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)'); 145 145 146 146 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` ( 147 147 `Id` int(11) NOT NULL AUTO_INCREMENT, … … 152 152 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 153 153 $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)'); 154 154 155 155 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` ( 156 156 `Id` int(11) NOT NULL AUTO_INCREMENT, … … 163 163 $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)'); 164 164 } 165 165 166 166 function DoUnInstall() 167 167 { … … 220 220 )); 221 221 $this->System->FormManager->RegisterClass('Module', array( 222 223 224 225 226 227 228 229 230 231 'HomePage' => array('Type' => 'Hyperlink', 'Caption' => 'Domovské stránky', 'Default' => ''), 232 233 234 235 236 237 238 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 239 )); 240 240 $this->System->FormManager->RegisterFormType('TModule', array( 241 242 243 244 245 241 'Type' => 'Reference', 242 'Table' => 'Module', 243 'Id' => 'Id', 244 'Name' => 'Title', 245 'Filter' => '1', 246 246 )); 247 247 $this->System->FormManager->RegisterFormType('TModelListModule', array( … … 253 253 )); 254 254 $this->System->FormManager->RegisterClass('Model', array( 255 256 257 258 259 260 261 262 263 264 265 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 266 )); 267 267 $this->System->FormManager->RegisterFormType('TModel', array( 268 269 270 271 272 268 'Type' => 'Reference', 269 'Table' => 'Model', 270 'Id' => 'Id', 271 'Name' => 'Title', 272 'Filter' => '1', 273 273 )); 274 274 $this->System->FormManager->RegisterFormType('TModelFieldListModel', array( … … 280 280 )); 281 281 $this->System->FormManager->RegisterClass('ModelField', array( 282 283 284 285 286 287 288 289 290 291 292 293 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 294 )); 295 295 $this->System->FormManager->RegisterFormType('TModuleLink', array( 296 297 298 299 300 296 'Type' => 'Reference', 297 'Table' => 'ModuleLink', 298 'Id' => 'Id', 299 'Name' => 'Module', 300 'Filter' => '1', 301 301 )); 302 302 $this->System->FormManager->RegisterFormType('TModuleLinkListModule', array( … … 308 308 )); 309 309 $this->System->FormManager->RegisterClass('ModuleLink', array( 310 311 312 313 314 315 316 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 317 )); 318 318 $this->System->FormManager->RegisterClass('Language', array( 319 320 321 322 323 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),324 319 'Title' => 'Jazyky', 320 'Table' => 'Language', 321 'DefaultSortColumn' => 'Name', 322 'Items' => array( 323 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 324 ), 325 325 )); 326 326 $this->System->FormManager->RegisterClass('UnitOfMeasure', array( 327 328 329 330 331 332 333 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 334 )); 335 335 $this->System->FormManager->RegisterClass('Country', array( 336 337 338 339 340 341 336 'Title' => 'Země', 337 'Table' => 'Country', 338 'DefaultSortColumn' => 'Name', 339 'Items' => array( 340 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''), 341 ), 342 342 )); 343 343 $this->System->FormManager->RegisterFormType('TCountry', array( 344 345 346 347 348 344 'Type' => 'Reference', 345 'Table' => 'Country', 346 'Id' => 'Id', 347 'Name' => 'Name', 348 'Filter' => '1', 349 349 )); 350 350 $this->System->FormManager->RegisterFormType('TUnitOfMeasure', array( 351 352 353 354 355 351 'Type' => 'Reference', 352 'Table' => 'UnitOfMeasure', 353 'Id' => 'Id', 354 'Name' => 'Name', 355 'Filter' => '1', 356 356 )); 357 357 $this->System->FormManager->RegisterFormType('TLanguage', array( 358 359 360 361 362 358 'Type' => 'Reference', 359 'Table' => 'Language', 360 'Id' => 'Id', 361 'Name' => 'Name', 362 'Filter' => '1', 363 363 )); 364 364 $this->System->FormManager->RegisterFormType('TAction', array( 365 366 367 368 369 365 'Type' => 'Reference', 366 'Table' => 'Action', 367 'Id' => 'Id', 368 'Name' => 'Title', 369 'Filter' => '1', 370 370 )); 371 371 $this->System->FormManager->RegisterFormType('TActionIcon', array( 372 373 374 375 376 372 'Type' => 'Reference', 373 'Table' => 'ActionIcon', 374 'Id' => 'Id', 375 'Name' => 'Name', 376 'Filter' => '1', 377 377 )); 378 378 $this->System->FormManager->RegisterFormType('TActionType', array( 379 380 381 382 383 379 'Type' => 'Reference', 380 'Table' => 'ActionType', 381 'Id' => 'Id', 382 'Name' => 'Name', 383 'Filter' => '1', 384 384 )); 385 385 $this->System->FormManager->RegisterFormType('TActionGroup', array( 386 387 388 389 390 391 )); 386 'Type' => 'Reference', 387 'Table' => 'ActionGroup', 388 'Id' => 'Id', 389 'Name' => 'Name', 390 'Filter' => '1', 391 )); 392 392 $this->System->FormManager->RegisterFormType('TModule', array( 393 394 395 396 397 398 )); 399 393 'Type' => 'Reference', 394 'Table' => 'Module', 395 'Id' => 'Id', 396 'Name' => 'Name', 397 'Filter' => '1', 398 )); 399 400 400 //$this->Manager->OnModuleChange = array($this, 'ModuleChange'); 401 401 //$this->LoadFromDatabase(); 402 402 } 403 403 404 404 function DoStop() 405 405 { 406 406 } 407 407 408 408 function IsInstalled() 409 409 { … … 411 411 { 412 412 $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables 413 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";'); 413 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";'); 414 414 if($DbResult->num_rows > 0) $this->Installed = true; 415 415 else $this->Installed = false; 416 416 $this->InstalledChecked = true; 417 417 } 418 return($this->Installed); 419 } 420 418 return($this->Installed); 419 } 420 421 421 function ModuleChange($Module) 422 422 { 423 423 //if($this->IsInstalled()) 424 424 { 425 425 426 426 if($Module->IsInstalled()) $Installed = 1; 427 else $Installed = 0; 427 else $Installed = 0; 428 428 $this->Database->query('UPDATE `Module` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"'); 429 429 } 430 430 } 431 431 432 432 function LoadFromDatabase() 433 433 { … … 441 441 include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php'); 442 442 $ModuleClassName = 'Module'.$Module['Name']; 443 $NewModule = new $ModuleClassName($this->Database, $this->Manager); 443 $NewModule = new $ModuleClassName($this->Database, $this->Manager); 444 444 $NewModule->Id = $Module['Id']; 445 $NewModule->Installed = $Module['Installed']; 445 $NewModule->Installed = $Module['Installed']; 446 446 $this->Manager->RegisterModule($NewModule); 447 } 448 } 449 447 } 448 } 449 450 450 function SaveToDatabase() 451 451 { 452 452 $Output = ''; 453 453 $Modules = array(); 454 454 $DbResult = $this->Database->query('SELECT * FROM `Module`'); … … 461 461 462 462 // Add missing 463 foreach($this->System->ModuleManager->Modules as $Module) 464 { 463 foreach($this->System->ModuleManager->Modules as $Module) 464 { 465 465 if(!array_key_exists($Module->Name, $Modules)) 466 466 { 467 $this->Database->insert('Module', array('Name' => $Module->Name, 467 $this->Database->insert('Module', array('Name' => $Module->Name, 468 468 'Version' => $Module->Version, 'Creator' => $Module->Creator, 469 469 'HomePage' => $Module->HomePage, 'Title' => $Module->Title, 470 470 'Description' => $Module->Description, 'License' => $Module->License, 471 471 'Installed' => $Module->Installed)); … … 474 474 else $this->Database->update('Module', 'Name = "'.$Module->Name.'"', array( 475 475 'Version' => $Module->Version, 'Creator' => $Module->Creator, 476 476 'HomePage' => $Module->HomePage, 'Title' => $Module->Title, 477 477 'Description' => $Module->Description, 'License' => $Module->License, 478 478 'Installed' => $Module->Installed)); 479 479 } 480 480 481 481 // Remove exceeding 482 foreach($Modules as $Module) 482 foreach($Modules as $Module) 483 483 if(!$this->System->ModuleManager->ModulePresent($Module['Name'])) 484 484 { … … 487 487 $this->Database->query('DELETE FROM `ModuleLink` WHERE `LinkedModule` = '.$Module['Id']); 488 488 $DbResult = $this->Database->query('SELECT Id FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']); 489 while($DbRow = $DbResult->fetch_assoc()) 489 while($DbRow = $DbResult->fetch_assoc()) 490 490 { 491 491 $this->Database->query('DELETE FROM `PermissionGroupAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']); … … 498 498 $this->Database->query('DELETE FROM `ModelField` WHERE `Model` = '.$DbRow['Id']); 499 499 $this->Database->query('DELETE FROM `Module` WHERE `Id` = '.$Module['Id']); 500 } 501 500 } 501 502 502 // Reload dependencies 503 503 $DbDependency = array(); … … 505 505 while($DbRow = $DbResult->fetch_assoc()) 506 506 $DbDependency[$DbRow['Module']][] = $DbRow['LinkedModule']; 507 507 508 508 foreach($this->System->ModuleManager->Modules as $Module) 509 509 { … … 517 517 $DependencyId = $this->System->ModuleManager->Modules[$Dependency]->Id; 518 518 else throw new Exception('Dependent module '.$Dependency.' not found'); 519 $this->Database->insert('ModuleLink', array('Module' => $Module->Id, 519 $this->Database->insert('ModuleLink', array('Module' => $Module->Id, 520 520 'LinkedModule' => $DependencyId, 'Type' => 'DependOn')); 521 } 521 } 522 522 } 523 523 524 524 // Remove exceeding 525 525 if(array_key_exists($Module->Id, $DbDependency)) … … 530 530 $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '. 531 531 $Module->Id.' AND LinkedModule='.$Dep); 532 } 532 } 533 533 } 534 534 return($Output); 535 } 535 } 536 536 }
Note:
See TracChangeset
for help on using the changeset viewer.