- Timestamp:
- Oct 10, 2012, 9:29:20 AM (12 years ago)
- Location:
- branches/Modular
- Files:
-
- 4 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Modular/.htaccess
r404 r424 11 11 RewriteCond %{REQUEST_FILENAME} !-f 12 12 RewriteCond %{REQUEST_FILENAME} !-d 13 #RewriteRule ^(.*)$ centrala/index.php?$114 RewriteRule ^(.*)$ dev/centrala/branches/Modular/index.php?$113 RewriteRule ^(.*)$ centrala_modular/index.php?$1 14 #RewriteRule ^(.*)$ dev/centrala/branches/Modular/index.php?$1 15 15 16 16 # Pretty urls -
branches/Modular/Common/Database.php
r401 r424 70 70 $this->Error = $E->getMessage(); 71 71 if(($this->Error != '') and ($this->ShowSQLError == true)) 72 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 72 //echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 73 throw new Exception($this->Error); 73 74 } 74 75 return($Result); … … 82 83 function delete($Table, $Condition) 83 84 { 84 $this-> PDO->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);85 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 85 86 } 86 87 … … 97 98 $Name = substr($Name, 1); 98 99 $Values = substr($Values, 1); 99 $this-> PDO->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');100 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 100 101 $this->insert_id = $this->PDO->lastInsertId(); 101 102 } … … 110 111 } 111 112 $Values = substr($Values, 2); 112 $this-> PDO->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');113 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 113 114 } 114 115 … … 126 127 $Values = substr($Values, 1); 127 128 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br />'); 128 $this-> PDO->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');129 $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 129 130 //echo($this->error().'<br>'); 130 131 } … … 132 133 function charset($Charset) 133 134 { 134 $this-> PDO->query('SET NAMES "'.$Charset.'"');135 $this->query('SET NAMES "'.$Charset.'"'); 135 136 } 136 137 -
branches/Modular/Common/Global.php
r405 r424 27 27 include_once('Localization.php'); 28 28 include_once('Navigation.php'); 29 29 include_once('Modules/System/System.php'); 30 30 31 31 32 class System extends ModularSystem … … 50 51 global $Config; 51 52 52 return($ Config['Web']['RootFolder'].$Target);53 return($this->RootFolder.$Target); 53 54 } 54 55 } 56 57 $System = NULL; 55 58 56 59 function GlobalInit() … … 79 82 $System->Localization->Load(); 80 83 $System->Navigation = new Navigation(); 84 85 //if(!$System->IsInstalled()) die('System not installed.'); 86 $ModuleSystem = new ModuleSystem($System->Database, $System); 87 $System->RegisterModule($ModuleSystem); 88 if($System->Modules['System']->IsInstalled()) $System->Modules['System']->Start(); 81 89 } 82 90 -
branches/Modular/Common/Module.php
r405 r424 14 14 var $Models = array(); 15 15 var $SupportedModels = array(); 16 /** @var Database */ 16 17 var $Database; 17 18 var $Installed; 18 var $Initialized; 19 var $System; 19 var $Running; 20 /** @var ModularSystem */ 21 var $ModularSystem; 22 20 23 21 24 function __construct($Database, $System) … … 23 26 $this->Database = &$Database; 24 27 $this->System = &$System; 25 $this-> Initialized= false;28 $this->Running = false; 26 29 $this->Installed = false; 27 30 } … … 29 32 function Install() 30 33 { 31 if($this->I nstalled) return;34 if($this->IsInstalled()) return; 32 35 DebugLog('Installing module '.$this->Name.'...'); 33 36 $this->Installed = true; … … 35 38 // Install dependencies first 36 39 foreach($this->Dependencies as $Dependency) 37 $this->System->Modules[$Dependency]->Install(); 38 39 $this->LoadModels(); 40 foreach($this->Models as $Index => $Module) 41 { 42 $this->Models[$Index]->Install(); 43 } 44 $this->Database->query('UPDATE SystemModule SET Installed=1 WHERE Name="'.$this->Name.'"'); 40 $this->ModularSystem->Modules[$Dependency]->Install(); 41 $this->DoChange(); 45 42 } 46 43 47 44 function UnInstall() 48 45 { 46 if($this->IsInstalled() == false) return; 49 47 DebugLog('Uninstalling module '.$this->Name.'...'); 48 if($this->Running) $this->Stop(); 50 49 $this->Installed = false; 51 50 … … 55 54 if(($Dependency == $this->Name) and ($Module->Installed)) $this->System->Modules[$Module->Name]->UnInstall(); 56 55 56 $this->DoChange(); 57 } 58 59 function IsInstalled() 60 { 61 return($this->Installed); 62 } 63 64 function Start() 65 { 66 if($this->Running) return; 67 if($this->IsInstalled() == false) return; 68 $this->Running = true; 69 foreach($this->Dependencies as $Dependency) 70 $this->System->Modules[$Dependency]->Start(); 57 71 $this->LoadModels(); 58 foreach(array_reverse($this->Models, true) as $Index => $Model) 59 { 60 $this->Models[$Index]->UnInstall(); 61 } 62 $this->Database->query('UPDATE SystemModule SET Installed=0 WHERE Name="'.$this->Name.'"'); 63 } 64 65 function Init() 66 { 67 if($this->Initialized) return; 68 $this->Initialized = true; 69 foreach($this->Dependencies as $Dependency) 70 $this->System->Modules[$Dependency]->Init(); 72 $this->DoChange(); 71 73 } 72 74 75 function Stop() 76 { 77 if(!$this->Running) return; 78 $this->Running = false; 79 foreach($this->System->Modules as $Module) 80 foreach($Module->Dependencies as $Dependency) 81 if(($Dependency == $this->Name) and ($Module->Running)) 82 $this->System->Modules[$Module->Name]->Stop(); 83 $this->DoChange(); 84 } 85 86 private function DoChange() 87 { 88 if($this->ModularSystem->OnModuleChange) 89 call_user_func_array($this->ModularSystem->OnModuleChange, array($this)); 90 } 91 92 function RegisterModel($ModelName) 93 { 94 $this->SupportedModels[] = $ModelName; 95 } 96 97 function UnregisterModel($ModelName) 98 { 99 unset($this->SupportedModels[$ModelName]); 100 } 101 73 102 function LoadModels() 74 103 { … … 85 114 class ModularSystem 86 115 { 116 /** @var Database */ 87 117 var $Database; 88 118 var $Modules = array(); 89 119 var $Models = array(); 90 120 var $Menu = array(); 121 var $OnModuleChange; 91 122 92 123 function __construct($Database) … … 95 126 } 96 127 97 function ModulePresent($Name) 98 { 99 return(array_key_exists($Name, $this->Modules)); 100 } 101 102 function LoadModules($Installed = true) 103 { 104 //DebugLog('Loading modules...'); 105 $this->Modules = array(); 106 $Query = 'SELECT `Id`, `Name`,`Installed` FROM `SystemModule`'; 107 if($Installed) $Query .= ' WHERE `Installed`=1'; 108 else $Query .= ''; // WHERE `Installed`=0'; 109 $DbResult = $this->Database->query($Query); 110 while($Module = $DbResult->fetch_array()) 111 { 112 //echo($Module['Name'].','); 113 include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php'); 114 $ModuleClassName = 'Module'.$Module['Name']; 115 $NewModule = new $ModuleClassName($this->Database, $this); 116 $NewModule->Id = $Module['Id']; 117 $NewModule->Installed = $Module['Installed']; 118 $this->Modules[$Module['Name']] = $NewModule; 119 } 120 } 121 122 function Init() 128 function StartAll() 123 129 { 124 130 $this->LoadModules(); … … 126 132 { 127 133 //DebugLog('Init module '.$Module->Name); 128 $this->Modules[$Index]->Init(); 129 } 130 } 131 134 $this->Modules[$Index]->Start(); 135 } 136 } 137 138 function StopAll() 139 { 140 foreach($this->Modules as $Index => $Module) 141 { 142 //DebugLog('Init module '.$Module->Name); 143 $this->Modules[$Index]->Stop(); 144 } 145 } 146 132 147 function Install() 133 148 { 134 149 //DebugLog('Installing modular system core...'); 135 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (136 `Id` int(11) NOT NULL AUTO_INCREMENT,137 `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,138 `Description` datetime NOT NULL,139 PRIMARY KEY (`Id`)140 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');141 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` (142 `Id` int(11) NOT NULL AUTO_INCREMENT,143 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,144 `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL,145 `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,146 `License` varchar(255) COLLATE utf8_czech_ci NOT NULL,147 `Installed` int(11) NOT NULL,148 `Description` text COLLATE utf8_czech_ci NOT NULL,149 PRIMARY KEY (`Id`)150 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');151 152 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` (153 `Id` int(11) NOT NULL AUTO_INCREMENT,154 `Module` int(11) NOT NULL,155 `DependencyModule` int(11) NOT NULL,156 PRIMARY KEY (`Id`),157 KEY (`Module`),158 KEY (`DependencyModule`),159 UNIQUE (`Module` , `DependencyModule`)160 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');161 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');162 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');163 164 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` (165 `Id` int(11) NOT NULL AUTO_INCREMENT,166 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,167 `Module` int(11) NOT NULL,168 KEY (`Module`),169 PRIMARY KEY (`Id`)170 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');171 $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');172 173 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` (174 `Id` int(11) NOT NULL AUTO_INCREMENT,175 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,176 `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL,177 `Model` int(11) NOT NULL,178 KEY (`Model`),179 PRIMARY KEY (`Id`)180 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');181 $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');182 150 183 151 $this->ReloadList(); … … 190 158 } 191 159 192 function UnInstall ()160 function UnInstallAll() 193 161 { 194 162 DebugLog('Uninstalling modular system core...'); 195 foreach(array_reverse($this->Modules, true) as $Index => $Module) 196 $this->Modules[$Index]->UnInstall(); 197 198 // Delete tables with reverse order 199 $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`'); 200 $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`'); 201 $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`'); 202 $this->Database->query('DROP TABLE IF EXISTS `SystemModel`'); 203 $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`'); 204 $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`'); 205 $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`'); 206 $this->Database->query('DROP TABLE IF EXISTS `SystemModule`'); 207 $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`'); 208 } 209 210 function IsInstalled() 211 { 212 $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables 213 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";'); 214 if($DbResult->num_rows > 0) return(true); 215 else return(false); 216 } 217 218 function ReloadList() 219 { 220 // Load list of modules from database 221 $Modules = array(); 222 $DbResult = $this->Database->query('SELECT * FROM `SystemModule`'); 223 while($DbRow = $DbResult->fetch_assoc()) 224 $Modules[$DbRow['Name']] = $DbRow; 225 163 foreach($this->Modules as $Index => $Module) 164 { 165 //DebugLog('Init module '.$Module->Name); 166 $this->Modules[$Index]->Uninstall(); 167 } 168 } 169 170 /* @return Module */ 171 function SearchModuleById($Id) 172 { 173 foreach($this->Modules as $Module) 174 { 175 //DebugLog($Module->Name.' '.$Module->Id); 176 if($Module->Id == $Id) return($Module->Name); 177 } 178 return(''); 179 } 180 181 function ModulePresent($Name) 182 { 183 return(array_key_exists($Name, $this->Modules)); 184 } 185 186 function RegisterModule(Module $Module) 187 { 188 $this->Modules[$Module->Name] = &$Module; 189 $Module->ModularSystem = $this; 190 $Module->OnChange = &$this->OnModuleChange; 191 } 192 193 function UnregisterModule($Module) 194 { 195 unset($this->Modules[array_search($Module, $this->Modules)]); 196 } 197 198 function ReloadFromDisk() 199 { 226 200 // Load list of modules on disk 227 201 $ModulesOnDisk = array(); … … 235 209 // Add new 236 210 foreach($ModulesOnDisk as $ModuleName) 237 if(!array_key_exists($ModuleName, $ Modules))238 { 239 DebugLog('Adding module '.$ModuleName.' to list');211 if(!array_key_exists($ModuleName, $this->Modules)) 212 { 213 //DebugLog('Adding module '.$ModuleName.' to list'); 240 214 include_once('Modules/'.$ModuleName.'/'.$ModuleName.'.php'); 241 215 $ModuleClassName = 'Module'.$ModuleName; 242 216 if(class_exists($ModuleClassName)) 243 217 { 244 $Module = new $ModuleClassName($this->Database, $this); 245 $this->Database->insert('SystemModule', array('Name' => $Module->Name, 246 'Version' => $Module->Version, 'Creator' => $Module->Creator, 247 'Description' => $Module->Description, 'License' => $Module->License, 248 'Installed' => 0)); 249 unset($Module); 218 $NewModule = new $ModuleClassName($this->Database, $this); 219 $this->RegisterModule($NewModule); 250 220 } else throw new Exception('Missing class '.$ModuleClassName.' in module '.$ModuleName); 251 } 221 } 252 222 253 // Remove missing254 foreach($Modules as $Module)255 if(($Module['Installed'] == 0) and !in_array($Module['Name'], $ModulesOnDisk))256 {257 DebugLog('Removing module '.$Module['Name'].' from list');258 $this->Database->query('DELETE FROM `SystemModule` WHERE `Id` = '.$Module['Id']);259 }260 261 // Reload dependencies262 $this->LoadModules(false);263 223 foreach($this->Modules as $Module) 264 { 265 foreach($Module->Dependencies as $Dependency) 266 { 267 $this->Database->insert('SystemModuleDependency', array('Module' => $Module->Id, 268 'DependencyModule' => $this->Modules[$Dependency]->Id)); 269 } 270 } 271 } 272 273 function SearchModuleById($Id) 274 { 275 foreach($this->Modules as $Module) 276 { 277 DebugLog($Module->Name.' '.$Module->Id); 278 if($Module->Id == $Id) return($Module->Name); 279 } 280 return(''); 281 } 224 if(array_key_exists($Module->Name, $ModulesOnDisk)) 225 { 226 $this->ModularSystem->UnregisterModule($Module); 227 } 228 } 282 229 } 283 230 -
branches/Modular/Common/Page.php
r404 r424 5 5 class Page 6 6 { 7 /** @var Database */ 7 8 var $Database; 9 /** @var System */ 8 10 var $System; 9 11 var $Config; … … 14 16 var $NavigationPath = array(); 15 17 16 function __construct() 18 public static function Cast(Page &$Object = NULL) 19 { 20 return $Object; 21 } 22 23 function __construct() 17 24 { 18 25 global $Config; … … 55 62 <div id="Title">'.$Title.'</div> 56 63 <div class="Navigation"><span class="MenuItem"><strong>Navigace :: </strong> '.$Navigation.'</span><div class="MenuItem2">'; 57 if(array_key_exists('User', $this->System->Modules) )64 if(array_key_exists('User', $this->System->Modules) and $this->System->Modules['User']->Installed) 58 65 { 59 66 if($this->System->Modules['User']->Models['User']->User['Id'] == $this->System->Modules['User']->Models['User']->AnonymousUserId) -
branches/Modular/Install.php
r403 r424 2 2 3 3 include_once('Common/Global.php'); 4 /* @var $System System */ 5 $System = NULL; 4 6 GlobalInit(); 7 8 function ModuleTable() 9 { 10 global $System; 11 12 $Output = '<table border="1" style="border: 1px" class="WideTable">'. 13 '<tr><th>Name</th><th>Installed</th><th>Version</th><th>Dependency</th><th>Actions</th></tr>'; 14 foreach($System->Modules as $Module) 15 { 16 if($Module->Installed) $Actions = '<a href="?a=uninstall&m='.$Module->Name.'">Odinstalovat</td>'; 17 else $Actions = '<a href="?a=install&m='.$Module->Name.'">Instalovat</td>'; 18 if($Module->Installed) $Installed = 'Ano'; 19 else $Installed = 'Ne'; 20 $Deps = implode(', ', $Module->Dependencies); 21 if($Deps == '') $Deps = ' '; 22 $Output .= '<tr><td>'.$Module->Name.'</td><td>'.$Installed.'</td><td>'. 23 $Module->Version.'</td><td>'.$Deps.'</td><td>'.$Actions.'</td></tr>'; 24 } 25 $Output .= '</table>'; 26 return($Output); 27 } 5 28 6 29 function ShowDefault() … … 8 31 global $System; 9 32 10 if($System->IsInstalled()) 11 { 12 echo('System je již nainstalován.<br/>'); 13 echo('<a href="?a=uninstall">Odinstalovat systém</a>'); 33 if($System->Modules['System']->IsInstalled()) 34 { 35 $Output = ModuleTable(); 36 $Output .= '<a href="?a=uninstall">Odinstalovat systém</a>'; 37 $Output .= ' <a href="?a=reload">Aktualizovat seznam z disku</a>'; 14 38 } else 15 39 { 16 echo('System ještě není instalován.<br/>'); 17 echo('<a href="?a=install">Instalovat systém</a>'); 18 } 40 $Output = 'System ještě není instalován.<br/>'; 41 $Output .= '<a href="?a=install">Instalovat systém</a>'; 42 } 43 echo($Output); 19 44 } 20 45 46 if($System->Modules['System']->IsInstalled()) 47 $System->Modules['System']->LoadFromDatabase(); 48 49 if($Config['Web']['SystemAdministration'] == true) 50 { 21 51 if(array_key_exists('a', $_GET)) 22 52 { 23 53 if($_GET['a'] == 'install') 24 54 { 25 $System->Install(); 26 $System->Init(); 55 if(array_key_exists('m', $_GET)) 56 { 57 $Module = $System->Modules[$_GET['m']]; 58 $Module->Install(); 59 } else 60 { 61 $System->Modules['System']->Install(); 62 $System->ReloadFromDisk(); 63 $System->Modules['System']->SaveToDatabase(); 64 } 27 65 ShowDefault(); 28 66 } 29 67 else if($_GET['a'] == 'uninstall') 30 68 { 31 $System->Init(); 32 $System->Uninstall(); 69 if(array_key_exists('m', $_GET)) 70 { 71 $Module = $System->Modules[$_GET['m']]; 72 $Module->Uninstall(); 73 //$System->Modules['System']->SaveToDatabase(); 74 } else 75 { 76 $System->Modules['System']->Uninstall(); 77 } 78 ShowDefault(); 79 } else if($_GET['a'] == 'reload') 80 { 81 $System->ReloadFromDisk(); 82 $System->Modules['System']->SaveToDatabase(); 33 83 ShowDefault(); 34 84 } 35 85 else ShowDefault(); 36 86 } else ShowDefault(); 87 } else echo('Access denied'); 37 88 38 89 ?> -
branches/Modular/Modules/Chat/Chat.php
r385 r424 99 99 } 100 100 101 function Init()101 function Start() 102 102 { 103 parent::Start(); 103 104 $this->System->Pages['chat'] = 'ChatHistory'; 104 105 } -
branches/Modular/Modules/EmailQueue/EmailQueue.php
r378 r424 40 40 } 41 41 42 function Init()42 function Start() 43 43 { 44 parent::Start(); 45 } 46 47 function Stop() 48 { 49 parent::Start(); 44 50 } 45 51 -
branches/Modular/Modules/Finance/Finance.php
r405 r424 294 294 } 295 295 296 function Init() 297 { 296 function Start() 297 { 298 parent::Start(); 298 299 $this->System->Pages['finance'] = 'FinancePage'; 299 300 $this->LoadMonthParameters(0); -
branches/Modular/Modules/FrontPage/FrontPage.php
r386 r424 369 369 } 370 370 371 function Init() 372 { 371 function Start() 372 { 373 parent::Start(); 373 374 $this->System->Pages[''] = 'IndexPage'; 374 375 } -
branches/Modular/Modules/Hosting/Hosting.php
r403 r424 37 37 } 38 38 39 function Init()39 function Start() 40 40 { 41 parent::Start(); 41 42 $this->System->Pages['hosting'] = 'PageHosting'; 42 43 } -
branches/Modular/Modules/Log/Log.php
r383 r424 105 105 } 106 106 107 function Init()107 function Start() 108 108 { 109 parent::Start(); 109 110 $this->System->Pages['log'] = 'LogShow'; 110 111 } -
branches/Modular/Modules/Map/Map.php
r378 r424 151 151 } 152 152 153 function Init()153 function Start() 154 154 { 155 parent::Start(); 155 156 $this->System->Pages['map'] = 'NetworkMap'; 156 157 } -
branches/Modular/Modules/Meals/Meals.php
r378 r424 229 229 } 230 230 231 function Init() 232 { 231 function Start() 232 { 233 parent::Start(); 233 234 $this->System->Pages['jidelna'] = 'EatingPlace'; 234 235 } -
branches/Modular/Modules/Member/Member.php
r398 r424 94 94 } 95 95 96 function Init()96 function Start() 97 97 { 98 parent::Start(); 98 99 } 99 100 } -
branches/Modular/Modules/Network/Network.php
r386 r424 265 265 } 266 266 267 function Init() 268 { 267 function Start() 268 { 269 parent::Start(); 269 270 $this->System->Pages['sit'] = 'NetworkPage'; 270 271 } -
branches/Modular/Modules/NetworkConfig/NetworkConfig.php
r383 r424 42 42 } 43 43 44 function Init()44 function Start() 45 45 { 46 parent::Start(); 46 47 } 47 48 } -
branches/Modular/Modules/NetworkConfigLinux/NetworkConfigLinux.php
r382 r424 25 25 } 26 26 27 function Init()27 function Start() 28 28 { 29 parent::Start(); 29 30 } 30 31 } -
branches/Modular/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php
r383 r424 64 64 } 65 65 66 function Init()66 function Start() 67 67 { 68 parent::Start(); 68 69 } 69 70 } -
branches/Modular/Modules/NetworkShare/NetworkShare.php
r378 r424 56 56 } 57 57 58 function Init()58 function Start() 59 59 { 60 parent::Start(); 60 61 $this->System->Pages['sdileni'] = 'SharePage'; 61 62 } -
branches/Modular/Modules/NetworkTopology/NetworkTopology.php
r378 r424 154 154 } 155 155 156 function Init()156 function Start() 157 157 { 158 parent::Start(); 158 159 $this->System->Pages['topologie'] = 'NetworkTopologyPage'; 159 160 } -
branches/Modular/Modules/News/News.php
r383 r424 115 115 } 116 116 117 function Init() 118 { 117 function Start() 118 { 119 parent::Start(); 119 120 $this->System->Pages['aktuality'] = 'NewsPage'; 120 121 } -
branches/Modular/Modules/OpeningHours/OpeningHours.php
r378 r424 252 252 } 253 253 254 function Init() 255 { 254 function Start() 255 { 256 parent::Start(); 256 257 $this->System->Pages['otviraci-doby'] = 'SubjectOpenTimePage'; 257 258 } -
branches/Modular/Modules/Project/Project.php
r385 r424 73 73 } 74 74 75 function Init()75 function Start() 76 76 { 77 parent::Start(); 77 78 $this->System->Pages['projekt'] = 'ProjectPage'; 78 79 } -
branches/Modular/Modules/Subject/Subject.php
r378 r424 45 45 } 46 46 47 function Init()47 function Start() 48 48 { 49 parent::Start(); 49 50 } 50 51 } -
branches/Modular/Modules/System/System.php
r405 r424 109 109 function Install() 110 110 { 111 // Do nothing, already installed by ModuleManager112 111 } 113 112 114 113 function UnInstall() 115 114 { 116 // Do nothing, managed by ModuleManager 117 } 115 } 118 116 } 119 117 … … 135 133 function Install() 136 134 { 135 if($this->IsInstalled()) return; 137 136 parent::Install(); 137 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` ( 138 `Id` int(11) NOT NULL AUTO_INCREMENT, 139 `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL, 140 `Description` datetime NOT NULL, 141 PRIMARY KEY (`Id`) 142 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 143 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` ( 144 `Id` int(11) NOT NULL AUTO_INCREMENT, 145 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, 146 `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL, 147 `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL, 148 `License` varchar(255) COLLATE utf8_czech_ci NOT NULL, 149 `Installed` int(11) NOT NULL, 150 `Description` text COLLATE utf8_czech_ci NOT NULL, 151 PRIMARY KEY (`Id`) 152 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 153 154 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` ( 155 `Id` int(11) NOT NULL AUTO_INCREMENT, 156 `Module` int(11) NOT NULL, 157 `DependencyModule` int(11) NOT NULL, 158 PRIMARY KEY (`Id`), 159 KEY (`Module`), 160 KEY (`DependencyModule`), 161 UNIQUE (`Module` , `DependencyModule`) 162 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 163 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)'); 164 $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)'); 165 166 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` ( 167 `Id` int(11) NOT NULL AUTO_INCREMENT, 168 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, 169 `Module` int(11) NOT NULL, 170 KEY (`Module`), 171 PRIMARY KEY (`Id`) 172 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 173 $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)'); 174 175 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` ( 176 `Id` int(11) NOT NULL AUTO_INCREMENT, 177 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, 178 `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL, 179 `Model` int(11) NOT NULL, 180 KEY (`Model`), 181 PRIMARY KEY (`Id`) 182 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 183 $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)'); 138 184 } 139 185 … … 141 187 { 142 188 parent::UnInstall(); 143 } 144 145 function Init() 146 { 147 $this->System->Pages['modules'] = 'PageModules'; 148 } 189 if(!$this->IsInstalled()) return; 190 191 // Delete tables with reverse order 192 $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`'); 193 $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`'); 194 $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`'); 195 $this->Database->query('DROP TABLE IF EXISTS `SystemModel`'); 196 $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`'); 197 $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`'); 198 $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`'); 199 $this->Database->query('DROP TABLE IF EXISTS `SystemModule`'); 200 $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`'); 201 } 202 203 function Start() 204 { 205 parent::Start(); 206 $this->System->Pages['module'] = 'PageModules'; 207 $this->ModularSystem->OnModuleChange = array($this, 'ModuleChange'); 208 $this->LoadFromDatabase(); 209 } 210 211 function Stop() 212 { 213 parent::Stop(); 214 } 215 216 function IsInstalled() 217 { 218 $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables 219 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";'); 220 if($DbResult->num_rows > 0) return(true); 221 else return(false); 222 } 223 224 function ModuleChange($Module) 225 { 226 if($this->IsInstalled()) 227 { 228 if($Module->Installed) 229 $this->Database->query('UPDATE `SystemModule` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"'); 230 else $this->Database->query('UPDATE `SystemModule` SET `Installed`=0 WHERE `Name`="'.$Module->Name.'"'); 231 } 232 } 233 234 function LoadFromDatabase() 235 { 236 //DebugLog('Loading modules...'); 237 $this->Modules = array(); 238 $Query = 'SELECT `Id`, `Name`,`Installed` FROM `SystemModule`'; 239 $DbResult = $this->Database->query($Query); 240 while($Module = $DbResult->fetch_array()) 241 { 242 //echo($Module['Name'].','); 243 include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php'); 244 $ModuleClassName = 'Module'.$Module['Name']; 245 $NewModule = new $ModuleClassName($this->Database, $this); 246 $NewModule->Id = $Module['Id']; 247 $NewModule->Installed = $Module['Installed']; 248 $this->ModularSystem->RegisterModule($NewModule); 249 } 250 } 251 252 function SaveToDatabase() 253 { 254 $Modules = array(); 255 $DbResult = $this->Database->query('SELECT * FROM `SystemModule`'); 256 while($DbRow = $DbResult->fetch_assoc()) 257 $Modules[$DbRow['Name']] = $DbRow; 258 259 // Add missing 260 foreach($this->ModularSystem->Modules as $Module) 261 { 262 if(!array_key_exists($Module->Name, $Modules)) 263 $this->Database->insert('SystemModule', array('Name' => $Module->Name, 264 'Version' => $Module->Version, 'Creator' => $Module->Creator, 265 'Description' => $Module->Description, 'License' => $Module->License, 266 'Installed' => $Module->Installed)); 267 else $this->Database->update('SystemModule', 'Name = "'.$Module->Name.'"', array( 268 'Version' => $Module->Version, 'Creator' => $Module->Creator, 269 'Description' => $Module->Description, 'License' => $Module->License, 270 'Installed' => $Module->Installed)); 271 } 272 273 // Remove exceeding 274 foreach($Modules as $Module) 275 if(!$this->ModularSystem->ModulePresent($Module['Name'])) 276 { 277 DebugLog('Removing module '.$Module['Name'].' from list'); 278 $this->Database->query('DELETE FROM `SystemModule` WHERE `Id` = '.$Module['Id']); 279 } 280 281 // Reload dependencies 282 $DbDependency = array(); 283 $DbResult = $this->Database->query('SELECT * FROM `SystemModuleDependency`'); 284 while($DbRow = $DbResult->fetch_assoc()) 285 $DbDependency[$DbRow['Module']][] = $DbRow['DependencyModule']; 286 287 foreach($this->ModularSystem->Modules as $Module) 288 { 289 // Add missing 290 foreach($Module->Dependencies as $Dependency) 291 { 292 if(!array_key_exists($Module->Id, $DbDependency) or 293 !in_array($this->ModularSystem->Modules[$Dependency]->Id, $DbDependency[$Module->Id])) 294 $this->Database->insert('SystemModuleDependency', array('Module' => $Module->Id, 295 'DependencyModule' => $this->ModularSystem->Modules[$Dependency]->Id)); 296 } 297 298 // Remove exceeding 299 if(array_key_exists($Module->Id, $DbDependency)) 300 foreach($DbDependency[$Module->Id] as $Dep) 301 { 302 $DepModName = $this->ModularSystem->SearchModuleById($Dep); 303 if(!in_array($DepModName, $Module->Dependencies)) 304 $this->Database->query('DELETE FROM `SystemModuleDependency` WHERE `Module` = '. 305 $Module->Id.' AND DependencyModule='.$Dep); 306 } 307 } 308 } 149 309 } 150 310 -
branches/Modular/Modules/TV/TV.php
r378 r424 132 132 } 133 133 134 function Init()134 function Start() 135 135 { 136 parent::Start(); 136 137 $this->System->Pages['tv'] = 'TVChannelsPage'; 137 138 } -
branches/Modular/Modules/TimeMeasure/TimeMeasure.php
r378 r424 46 46 } 47 47 48 function Init()48 function Start() 49 49 { 50 parent::Start(); 50 51 } 51 52 } -
branches/Modular/Modules/User/User.php
r405 r424 378 378 } 379 379 380 function Init()380 function Start() 381 381 { 382 parent::Start(); 382 383 $this->System->Modules['User']->Models['User'] = new User($this->Database, $this->System); 383 384 $thus->System->Modules['User']->Models['User']->AnonymousUserId = ANONYMOUS_ID; -
branches/Modular/Modules/WebCam/WebCam.php
r378 r424 57 57 } 58 58 59 function Init()59 function Start() 60 60 { 61 parent::Start(); 61 62 $this->System->Pages['webcam'] = 'WebcamPage'; 62 63 } -
branches/Modular/config.sample.php
r405 r424 16 16 'Web' => array 17 17 ( 18 'Locale' => ' csCZ',18 'Locale' => 'en', 19 19 'Style' => 'simple', 20 20 'FormatHTML' => false, … … 22 22 'Host' => 'localhost', 23 23 'RootFolder' => '', 24 'Description' => ' Komunitní počítačová síť',25 'Title' => ' Síť',24 'Description' => 'Community network', 25 'Title' => 'Network', 26 26 'Admin' => 'Admin', 27 27 'AdminEmail' => 'admin@localhost', … … 31 31 'ShowRuntimeInfo' => false, 32 32 'ShowDebug' => $IsDeveloper, 33 'ErrorLogFile' => '/var/www/html/dev/centrala/www/php_script_error.log', 33 'SystemAdministration' => $IsDeveloper, 34 'ErrorLogFile' => 'php_script_error.log', 34 35 'WebcamPassword' => '', 35 36 'WebcamRefresh' => 5, -
branches/Modular/index.php
r405 r424 2 2 3 3 include_once('Common/Global.php'); 4 /* @var $System System */ 5 $System = NULL; 4 6 GlobalInit(); 5 if(!$System->IsInstalled()) die('System not installed.');6 $System->Init();7 7 $System->PathItems = ProcessURL(); 8 8 //print_r($_GET); … … 16 16 $PageClass = $System->Pages[$Page]; 17 17 } else $PageClass = 'MissingPage'; 18 $PageObject = new $PageClass();18 $PageObject = Page::Cast(new $PageClass()); 19 19 $PageObject->Database = &$Database; 20 20 $PageObject->System = &$System;
Note:
See TracChangeset
for help on using the changeset viewer.