Changeset 592
- Timestamp:
- Nov 2, 2013, 7:56:09 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
- 5 copied
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/System.php
r590 r592 1 1 <?php 2 2 3 include_once(dirname(__FILE__).'/Application.php'); 4 include_once(dirname(__FILE__).'/Global.php'); 3 include_once(dirname(__FILE__).'/../Common/Application.php'); 4 include_once(dirname(__FILE__).'/Version.php'); 5 include_once(dirname(__FILE__).'/../Common/Global.php'); 6 include_once(dirname(__FILE__).'/FormClasses.php'); 5 7 6 8 class System extends Application … … 17 19 var $RootURLFolder; 18 20 var $ShowPage; 21 var $Setup; 19 22 20 23 function __construct() … … 145 148 146 149 // Register and start existing modules 147 include_once(dirname(__FILE__).'/../Modules/Setup/Setup.php'); 148 $this->ModuleManager->RegisterModule(new ModuleSetup($this)); 149 $this->ModuleManager->Modules['Setup']->Installed = true; 150 $this->ModuleManager->Modules['Setup']->Start(); 151 if($this->ModuleManager->Modules['Setup']->CheckState()) 150 $this->Setup = new Setup($this); 151 $this->Setup->Start(); 152 if($this->Setup->CheckState()) 152 153 { 153 $this->ModuleManager->LoadModules(); 154 $this->ModuleManager->Modules['Setup']->Installed = true; 155 $this->ModuleManager->Modules['Setup']->Start(); 156 $this->ModuleManager->StartAll(); 154 $this->ModuleManager->Start(); 157 155 } 158 156 if($this->ShowPage) -
trunk/Application/Version.php
r591 r592 1 1 <?php 2 2 3 $Revision = 59 1; // Subversion revision3 $Revision = 592; // Subversion revision 4 4 $DatabaseRevision = 591; // SQL structure revision 5 5 $ReleaseTime = '2013-11-02'; -
trunk/Common/AppModule.php
r590 r592 41 41 var $InstalledVersion; 42 42 var $Running; 43 var $Enabled; 43 44 /** @var ModuleType */ 44 45 var $Type; 45 var $Enabled;46 46 var $Dependencies; 47 47 /** @var Database */ … … 70 70 $this->DoInstall(); 71 71 $this->Installed = true; 72 $this->Manager->Modules[$this->Name] = $this; 72 73 } 73 74 … … 77 78 $this->Stop(); 78 79 $this->Installed = false; 80 unset($this->Manager->Modules[$this->Name]); 79 81 $List = array(); 80 82 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Installed)); … … 86 88 { 87 89 $this->Uninstall(); 90 // TODO: Install also back dependecies 88 91 $this->Install(); 89 92 } … … 108 111 $this->Manager->Perform($List, array(ModuleAction::Stop), array(ModuleCondition::Running)); 109 112 $this->DoStop(); 110 } 113 } 111 114 112 115 function Restart() … … 116 119 } 117 120 121 function Enable() 122 { 123 if($this->Enabled) return; 124 if(!$this->Installed) return; 125 $List = array(); 126 $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotEnabled)); 127 $this->Manager->Perform($List, array(ModuleAction::Enable), array(ModuleCondition::NotEnabled)); 128 $this->Enabled = true; 129 } 130 131 function Disable() 132 { 133 if(!$this->Enabled) return; 134 $this->Stop(); 135 $this->Enabled = false; 136 $List = array(); 137 $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Enabled)); 138 $this->Manager->Perform($List, array(ModuleAction::Disable), array(ModuleCondition::Enabled)); 139 } 140 118 141 protected function DoStart() 119 142 { … … 121 144 122 145 protected function DoStop() 123 { 124 146 { 125 147 } 126 148 … … 134 156 } 135 157 158 /* Manage installed modules */ 136 159 class AppModuleManager 137 160 { 138 161 var $Modules; 139 var $ModulesAvail;140 162 var $System; 141 var $OnLoadModules; 163 var $Repository; 164 var $FileName; 142 165 143 166 function __construct($System) 144 167 { 145 168 $this->Modules = array(); 146 $this->System = &$System; 169 $this->System = &$System; 170 $this->Repository = new AppModuleRepository($System); 171 $this->Repository->Manager = $this; 172 $this->FileName = 'Config.php'; 147 173 } 148 174 … … 155 181 (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or 156 182 ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or 157 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))) 183 (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)) or 184 ($Module->Enabled and in_array(ModuleCondition::Enabled, $Conditions)) or 185 (!$Module->Enabled and in_array(ModuleCondition::NotEnabled, $Conditions))) 158 186 { 159 187 foreach($Actions as $Action) … … 163 191 if($Action == ModuleAction::Install) $Module->Install(); 164 192 if($Action == ModuleAction::Uninstall) $Module->Uninstall(); 193 if($Action == ModuleAction::Enable) $Module->Enable(); 194 if($Action == ModuleAction::Disable) $Module->Disable(); 165 195 } 166 196 } … … 203 233 } 204 234 235 function Start() 236 { 237 $this->Repository->LoadModules(); 238 $this->Load(); 239 $this->StartEnabled(); 240 } 241 205 242 function StartAll() 206 243 { 207 foreach($this->Modules as $Index => $Module) 208 { 209 $this->Modules[$Index]->Start(); 210 } 244 $this->Perform($this->Modules, array(ModuleAction::Start)); 245 } 246 247 function StartEnabled() 248 { 249 $this->Perform($this->Modules, array(ModuleAction::Start), array(ModuleCondition::Enabled)); 211 250 } 212 251 213 252 function StopAll() 214 253 { 215 foreach($this->Modules as $Index => $Module) 216 { 217 $this->Modules[$Index]->Stop(); 218 } 254 $this->Perform($this->Modules, array(ModuleAction::Stop)); 219 255 } 220 256 … … 222 258 { 223 259 return(array_key_exists($Name, $this->Modules)); 224 }225 226 function RegisterModule(AppModule $Module)227 {228 $this->Modules[$Module->Name] = &$Module;229 $Module->Manager = &$this;230 $Module->OnChange = &$this->OnModuleChange;231 }232 233 function UnregisterModule($Module)234 {235 unset($this->Modules[array_search($Module, $this->Modules)]);236 260 } 237 261 … … 246 270 return(''); 247 271 } 272 273 function Load() 274 { 275 include($this->FileName); 276 $this->Modules = array(); 277 foreach($ConfigModules as $Mod) 278 { 279 if(array_key_exists($Mod['Name'], $this->Repository->Modules)) 280 { 281 $this->Modules[$Mod['Name']] = $this->Repository->Modules[$Mod['Name']]; 282 $this->Modules[$Mod['Name']]->Enabled = $Mod['Enabled']; 283 $this->Modules[$Mod['Name']]->Version = $Mod['Version']; 284 } 285 } 286 } 287 288 function Save() 289 { 290 $Data = array(); 291 foreach($this->Modules as $Module) 292 { 293 $Data[] = array('Name' => $Module->Name, 'Enabled' => $Module->Enabled, 294 'Version' => $Module->Version); 295 } 296 file_put_contents($this->FileName, "<?php \n\n\$ConfigModules = ".var_export($Data).";\n"); 297 } 298 } 299 300 /* Manager available modules for installation */ 301 class AppModuleRepository 302 { 303 var $Modules; 304 var $System; 305 var $Manager; 306 var $OnLoadModules; 307 308 function __construct($System) 309 { 310 $this->Modules = array(); 311 $this->System = &$System; 312 } 313 314 function RegisterModule(AppModule $Module) 315 { 316 $this->Modules[$Module->Name] = &$Module; 317 $Module->Manager = &$this->Manager; 318 $Module->OnChange = &$this->OnModuleChange; 319 } 320 321 function UnregisterModule($Module) 322 { 323 unset($this->Modules[array_search($Module, $this->Modules)]); 324 } 248 325 249 326 function LoadModulesFromDir($Directory) 250 327 { 251 252 253 254 255 {256 257 258 259 260 328 $List = scandir($Directory); 329 foreach($List as $Item) 330 { 331 if(is_dir($Directory.'/'.$Item) and ($Item != '.') and ($Item != '..') and ($Item != '.svn')) 332 { 333 include_once($Directory.'/'.$Item.'/'.$Item.'.php'); 334 $ModuleName = 'Module'.$Item; 335 $this->RegisterModule(new $ModuleName($this->System)); 336 } 337 } 261 338 } 262 339 263 340 function LoadModules() 264 341 { 265 if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 266 $this->OnLoadModules(); 267 else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules'); 268 } 269 } 342 if(method_exists($this->OnLoadModules[0], $this->OnLoadModules[1])) 343 $this->OnLoadModules(); 344 else $this->LoadModulesFromDir(dirname(__FILE__).'/../Modules'); 345 } 346 } 347 -
trunk/Common/Config.php
r582 r592 47 47 function SaveToFile($FileName) 48 48 { 49 file_put_content ("<?php \n\n\$ConfigData = ".var_export($this->Data).";\n");49 file_put_contents($FileName, "<?php \n\n\$ConfigData = ".var_export($this->Data).";\n"); 50 50 } 51 51 -
trunk/Common/Global.php
r589 r592 8 8 $ConfigFileName = dirname(__FILE__).'/../config.php'; 9 9 if(file_exists($ConfigFileName)) include_once($ConfigFileName); 10 include_once(dirname(__FILE__).'/Version.php');11 10 include_once(dirname(__FILE__).'/VarDumper.php'); 12 11 include_once(dirname(__FILE__).'/Base.php'); … … 14 13 include_once(dirname(__FILE__).'/Database.php'); 15 14 include_once(dirname(__FILE__).'/UTF8.php'); 16 include_once(dirname(__FILE__).'/System.php');17 15 include_once(dirname(__FILE__).'/Mail.php'); 18 16 include_once(dirname(__FILE__).'/Page.php'); 19 17 include_once(dirname(__FILE__).'/Form/Form.php'); 20 include_once(dirname(__FILE__).'/../FormClasses.php');21 18 include_once(dirname(__FILE__).'/Config.php'); 19 include_once(dirname(__FILE__).'/Setup/Setup.php'); 22 20 23 21 $MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', -
trunk/Common/Setup/Setup.php
r590 r592 8 8 class PageSetup extends Page 9 9 { 10 var $UpdateManager; 11 var $ConfigDefinition; 12 var $Config; 13 var $DatabaseRevision; 14 var $Revision; 15 var $Updates; 16 var $ConfigDir; 17 10 18 function __construct($System) 11 19 { … … 14 22 $this->ShortTitle = 'Instalátor'; 15 23 //$this->ParentClass = 'PagePortal'; 16 } 17 18 function Show() 19 { 24 $this->ConfigDir = dirname(__FILE__).'/../..'; 25 } 26 27 function LoginPanel() 28 { 29 $Output = '<h3>Přihlášení k instalaci</h3>'. 30 '<form action="" method="post">'. 31 '<table>'. 32 '<tr><td>Systémové heslo:</td><td> <input type="password" name="SystemPassword" value=""/></td></tr>'. 33 '</table>'. 34 '<input type="submit" name="login" value="Přihlásit"/>'. 35 '</form>'; 36 return($Output); 37 } 38 39 function ControlPanel() 40 { 41 $YesNo = array(false => 'Ne', true => 'Ano'); 42 $Output = '<form action="" method="post">'; 43 44 $Output .= 'Je připojení k databázi: '.$YesNo[$this->UpdateManager->Database->Connected()].'<br/>'; 45 if($this->UpdateManager->Database->Connected()) 46 { 47 $Output .= 'Je instalováno: '.$YesNo[$this->UpdateManager->IsInstalled()].'<br/>'; 48 if($this->UpdateManager->IsInstalled()) 49 $Output .= 'Je aktuální: '.$YesNo[$this->UpdateManager->IsUpToDate()].'<br/>'. 50 'Verze databáze: '.$this->UpdateManager->GetDbVersion().'<br/>'; 51 $Output .= 'Verze databáze kódu: '.$this->UpdateManager->Revision.'<br/>'; 52 if($this->UpdateManager->IsInstalled()) 53 { 54 if(!$this->UpdateManager->IsUpToDate()) 55 $Output .= '<input type="submit" name="update" value="Aktualizovat"/> '; 56 $Output .= '<input type="submit" name="insert_sample_data" value="Vložit vzorová data"/> '; 57 $Output .= '<input type="submit" name="uninstall" value="Odinstalovat"/><br/><br/>'; 58 $Output .= 'Nainstalované moduly'.$this->ShowList(); 59 $Output .= 'Dostupné moduly<br>'.$this->ShowListAvail(); 60 } else $Output .= '<input type="submit" name="install" value="Instalovat"/> '; 61 } 62 $Output .= '<input type="submit" name="configure" value="Nastavit"/> '; 63 $Output .= '<input type="submit" name="logout" value="Odhlásit"/> '; 64 $Output .= '</form>'; 65 return($Output); 66 } 67 68 function Show() 69 { 20 70 global $ConfigDefinition, $DatabaseRevision, $Config, $Updates; 21 71 22 $UpdateInterface = new UpdateInterface();23 72 $DefaultConfig = new DefaultConfig(); 24 $UpdateInterface->Database = $this->Database; 25 $UpdateInterface->ConfigDefinition = $DefaultConfig->Get(); 26 $UpdateInterface->DatabaseRevision = $DatabaseRevision; 27 $UpdateInterface->Config = &$Config; 73 $this->ConfigDefinition = $DefaultConfig->Get(); 74 $this->DatabaseRevision = $DatabaseRevision; 75 $this->Config = &$Config; 28 76 $Updates = new Updates(); 29 $UpdateInterface->Updates = $Updates->Get(); 30 return($UpdateInterface->Show()); 31 } 77 $this->Updates = $Updates->Get(); 78 79 $Output = ''; 80 if(isset($this->Config)) 81 { 82 if(!array_key_exists('SystemPassword', $_SESSION)) $_SESSION['SystemPassword'] = ''; 83 if(array_key_exists('login', $_POST)) $_SESSION['SystemPassword'] = $_POST['SystemPassword']; 84 if(sha1($_SESSION['SystemPassword']) != $this->Config['SystemPassword']) 85 { 86 $Output .= $this->LoginPanel(); 87 } else 88 { 89 $this->UpdateManager = new UpdateManager(); 90 $this->UpdateManager->Database = $this->Database; 91 $this->UpdateManager->Revision = $this->DatabaseRevision; 92 $this->UpdateManager->Trace = $this->Updates; 93 $this->UpdateManager->InstallMethod = 'FullInstall'; 94 95 if(array_key_exists('logout', $_POST)) 96 { 97 $_SESSION['SystemPassword'] = ''; 98 $Output .= 'Odhlášen'; 99 $Output .= $this->LoginPanel(); 100 } else 101 if(array_key_exists('update', $_POST)) 102 { 103 $Output .= '<h3>Aktualizace</h3>'; 104 $Output .= $this->UpdateManager->Update(); 105 $Output .= $this->ControlPanel(); 106 } else 107 if(array_key_exists('install', $_POST)) 108 { 109 $Output .= '<h3>Instalace</h3>'; 110 $this->UpdateManager->Install(); 111 $Output .= $this->UpdateManager->Update(); 112 $Output .= $this->ControlPanel(); 113 } else 114 if(array_key_exists('uninstall', $_POST)) 115 { 116 $Output .= '<h3>Odinstalace</h3>'; 117 $this->UpdateManager->Uninstall(); 118 $Output .= $this->ControlPanel(); 119 } else 120 if(array_key_exists('insert_sample_data', $_POST)) 121 { 122 $Output .= '<h3>Vložení vzorových dat</h3>'; 123 $this->UpdateManager->InsertSampleData(); 124 $Output .= $this->ControlPanel(); 125 } else 126 if(array_key_exists('configure_save', $_POST)) 127 { 128 $Output .= $this->ConfigSave($this->Config); 129 $Output .= $this->ControlPanel(); 130 } else 131 if(array_key_exists('configure', $_POST)) 132 { 133 $Output .= $this->PrepareConfig($this->Config); 134 } else 135 { 136 $Output .= $this->ControlPanel(); 137 } 138 } 139 } else 140 { 141 if(array_key_exists('configure_save', $_POST)) 142 { 143 $Output .= $this->ConfigSave(array()); 144 $Output .= 'Pokračujte k přihlášení <a href="">zde</a>'; 145 } else { 146 $Output .= $this->PrepareConfig(array()); 147 } 148 } 149 return($Output); 150 } 151 152 function ShowList() 153 { 154 $Output = ''; 155 $PageList = GetPageList(count($this->System->ModuleManager->Modules)); 156 157 $Output .= $PageList['Output']; 158 $Output .= '<table class="WideTable" style="font-size: small;">'; 159 160 $TableColumns = array( 161 array('Name' => 'Name', 'Title' => 'Jméno'), 162 array('Name' => 'Creator', 'Title' => 'Tvůrce'), 163 array('Name' => 'Version', 'Title' => 'Verze'), 164 array('Name' => 'License', 'Title' => 'Licence'), 165 array('Name' => 'Enabled', 'Title' => 'Povoleno'), 166 array('Name' => 'Description', 'Title' => 'Popis'), 167 array('Name' => 'Dependencies', 'Title' => 'Závislosti'), 168 array('Name' => '', 'Title' => 'Akce'), 169 ); 170 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); 171 $Output .= $Order['Output']; 172 173 foreach($this->System->ModuleManager->Modules as $Module) 174 { 175 if(($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies); 176 else $Dependencies = ' '; 177 if($Module->Enabled == true) $Enabled = 'Ano'; 178 else $Enabled = 'Ne'; 179 $Actions = '<a href="?A=Uninstall&Name='.$Module->Name.'">Odinstalovat</a>'; 180 if($Module->Enabled == true) $Actions .= ' <a href="?A=Disable&Name='.$Module->Name.'">Zakázat</a>'; 181 else $Actions .= ' <a href="?A=Enable&Name='.$Module->Name.'">Povolit</a>'; 182 $Output .= '<tr><td>'.$Module->Name.'</td>'. 183 '<td>'.$Module->Creator.'</td>'. 184 '<td>'.$Module->Version.'</td>'. 185 '<td>'.$Module->License.'</td>'. 186 '<td>'.$Enabled.'</td>'. 187 '<td>'.$Module->Description.'</td>'. 188 '<td>'.$Dependencies.'</td>'. 189 '<td>'.$Actions.'</td></tr>'; 190 } 191 $Output .= '</table>'; 192 $Output .= $PageList['Output']; 193 //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>'; 194 return($Output); 195 } 196 197 function ShowListAvail() 198 { 199 $Output = ''; 200 $PageList = GetPageList(count($this->System->ModuleManager->Repository->Modules)); 201 202 $Output .= $PageList['Output']; 203 $Output .= '<table class="WideTable" style="font-size: small;">'; 204 205 $TableColumns = array( 206 array('Name' => 'Name', 'Title' => 'Jméno'), 207 array('Name' => 'Creator', 'Title' => 'Tvůrce'), 208 array('Name' => 'Version', 'Title' => 'Verze'), 209 array('Name' => 'License', 'Title' => 'Licence'), 210 array('Name' => 'Installed', 'Title' => 'Instalováno'), 211 array('Name' => 'Description', 'Title' => 'Popis'), 212 array('Name' => 'Dependencies', 'Title' => 'Závislosti'), 213 array('Name' => '', 'Title' => 'Akce'), 214 ); 215 $Order = GetOrderTableHeader($TableColumns, 'Name', 0); 216 $Output .= $Order['Output']; 217 218 foreach($this->System->ModuleManager->Repository->Modules as $Module) 219 { 220 if(($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies); 221 else $Dependencies = ' '; 222 if($Module->Installed == true) $Installed = 'Ano'; 223 else $Installed = 'Ne'; 224 if($Module->Installed == true) $Actions = '<a href="?A=Uninstall&Name='.$Module->Name.'">Odinstalovat</a>'; 225 else $Actions = '<a href="?A=Install&Name='.$Module->Name.'">Instalovat</a>'; 226 $Output .= '<tr><td>'.$Module->Name.'</td>'. 227 '<td>'.$Module->Creator.'</td>'. 228 '<td>'.$Module->Version.'</td>'. 229 '<td>'.$Module->License.'</td>'. 230 '<td>'.$Installed.'</td>'. 231 '<td>'.$Module->Description.'</td>'. 232 '<td>'.$Dependencies.'</td>'. 233 '<td>'.$Actions.'</td></tr>'; 234 } 235 $Output .= '</table>'; 236 $Output .= $PageList['Output']; 237 //$Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>'; 238 return($Output); 239 } 240 241 function PrepareConfig($Config) 242 { 243 $Output = ''; 244 if(!file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir)) 245 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože složka není povolená pro zápis!'; 246 if(file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir.'/config.php')) 247 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor config.php není povolen pro zápis!'; 248 $Output .= '<h3>Nastavení systému</h3>'. 249 '<form action="" method="post">'. 250 '<table>'; 251 foreach($this->ConfigDefinition as $Def) 252 { 253 $PathParts = explode('/', $Def['Name']); 254 $TempConfig = &$Config; 255 foreach($PathParts as $Part) 256 if(array_key_exists($Part, $TempConfig)) 257 { 258 $TempConfig = &$TempConfig[$Part]; 259 } 260 if(!is_array($TempConfig)) $Value = $TempConfig; 261 else $Value = $Def['Default']; 262 $Output .= '<tr><td>'.$Def['Title'].'</td><td>'; 263 if($Def['Type'] == 'String') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>'; 264 if($Def['Type'] == 'Password') $Output .= '<input type="password" name="'.$Def['Name'].'"/>'; 265 if($Def['Type'] == 'PasswordEncoded') $Output .= '<input type="password" name="'.$Def['Name'].'"/>'; 266 if($Def['Type'] == 'Integer') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>'; 267 if($Def['Type'] == 'Float') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>'; 268 if($Def['Type'] == 'Boolean') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>'; 269 } 270 $Output .= '</td></tr>'. 271 '<tr><td colspan="2"><input type="submit" name="configure_save" value="Nastavit"/></td></tr>'. 272 '</table>'. 273 '</form>'; 274 return($Output); 275 } 276 277 function ConfigSave($DefaultConfig) 278 { 279 $Config = $DefaultConfig; 280 foreach($this->ConfigDefinition as $Def) 281 { 282 $Value = null; 283 if($Def['Type'] == 'String') if(array_key_exists($Def['Name'], $_POST)) 284 $Value = $_POST[$Def['Name']]; 285 if($Def['Type'] == 'Password') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != '')) 286 $Value = $_POST[$Def['Name']]; 287 if($Def['Type'] == 'PasswordEncoded') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != '')) 288 $Value = sha1($_POST[$Def['Name']]); 289 if($Def['Type'] == 'Integer') if(array_key_exists($Def['Name'], $_POST)) 290 $Value = $_POST[$Def['Name']]; 291 if($Def['Type'] == 'Float') if(array_key_exists($Def['Name'], $_POST)) 292 $Value = $_POST[$Def['Name']]; 293 if($Def['Type'] == 'Boolean') if(array_key_exists($Def['Name'], $_POST)) 294 $Value = $_POST[$Def['Name']]; 295 if(!is_null($Value)) 296 { 297 $PathParts = explode('/', $Def['Name']); 298 $TempConfig = &$Config; 299 foreach($PathParts as $Part) 300 { 301 $TempConfig = &$TempConfig[$Part]; 302 } 303 if(!is_array($TempConfig)) $TempConfig = $Value; 304 else $Value = $Def['Default']; 305 } 306 } 307 $ConfigText = $this->CreateConfig($Config); 308 file_put_contents($this->ConfigDir.'/config.php', $ConfigText); 309 $Output .= 'Konfigurace nastavena<br/>'; 310 return($Output); 311 } 312 313 function CreateConfig($Config) 314 { 315 316 $Output = "<?php\n\n". 317 "\$IsDeveloper = in_array(\$_SERVER['REMOTE_ADDR'], array('127.0.0.1'));\n\n"; 318 319 foreach($this->ConfigDefinition as $Def) 320 { 321 $PathParts = explode('/', $Def['Name']); 322 $Output .= "\$Config"; 323 foreach($PathParts as $Part) 324 $Output .= "['".$Part."']"; 325 $TempConfig = &$Config; 326 foreach($PathParts as $Part) 327 if(array_key_exists($Part, $TempConfig)) 328 { 329 $TempConfig = &$TempConfig[$Part]; 330 } 331 if(!is_array($TempConfig)) $Value = $TempConfig; 332 else $Value = $Def['Default']; 333 $Output .= " = '".$Value."';\n"; 334 } 335 $Output .= "\n\n"; 336 return($Output); 337 } 32 338 } 33 339 … … 39 345 if(!$this->Database->Connected()) $Output .= 'Nelze se připojit k databázi.<br>'; 40 346 else { 41 if(!$this->System-> ModuleManager->Modules['Setup']->UpdateManager->IsInstalled())347 if(!$this->System->Setup->UpdateManager->IsInstalled()) 42 348 $Output .= 'Systém vyžaduje instalaci databáze.<br>'; 43 349 else 44 if(!$this->System-> ModuleManager->Modules['Setup']->UpdateManager->IsUpToDate())350 if(!$this->System->Setup->UpdateManager->IsUpToDate()) 45 351 $Output .= 'Systém vyžaduje aktualizaci databáze.<br>'; 46 352 } … … 50 356 } 51 357 52 class ModuleSetup extends AppModule358 class Setup extends Model 53 359 { 54 360 var $UpdateManager; 55 361 56 function __construct($System) 57 { 58 parent::__construct($System); 59 $this->Name = 'Setup'; 60 $this->Version = '1.0'; 61 $this->Creator = 'Chronos'; 62 $this->License = 'GNU/GPL'; 63 $this->Description = 'Basic setup and application installation'; 64 $this->Dependencies = array(); 65 } 66 67 function DoStart() 362 function Start() 68 363 { 69 364 global $DatabaseRevision; … … 78 373 } 79 374 80 function DoStop()375 function Stop() 81 376 { 82 377 unset($this->UpdateManager); -
trunk/Common/Setup/Update.php
r590 r592 80 80 } 81 81 } 82 83 class UpdateInterface84 {85 var $UpdateManager;86 var $ConfigDefinition;87 var $Config;88 var $DatabaseRevision;89 var $Revision;90 var $Updates;91 var $Database;92 var $ConfigDir;93 94 function __construct()95 {96 $this->ConfigDir = dirname(__FILE__).'/../..';97 }98 99 function LoginPanel()100 {101 $Output = '<h3>Přihlášení k instalaci</h3>'.102 '<form action="" method="post">'.103 '<table>'.104 '<tr><td>Systémové heslo:</td><td> <input type="password" name="SystemPassword" value=""/></td></tr>'.105 '</table>'.106 '<input type="submit" name="login" value="Přihlásit"/>'.107 '</form>';108 return($Output);109 }110 111 function ControlPanel()112 {113 $YesNo = array(false => 'Ne', true => 'Ano');114 $Output = '<form action="" method="post">';115 116 $Output .= 'Je připojení k databázi: '.$YesNo[$this->UpdateManager->Database->Connected()].'<br/>';117 if($this->UpdateManager->Database->Connected())118 {119 $Output .= 'Je instalováno: '.$YesNo[$this->UpdateManager->IsInstalled()].'<br/>';120 if($this->UpdateManager->IsInstalled())121 $Output .= 'Je aktuální: '.$YesNo[$this->UpdateManager->IsUpToDate()].'<br/>'.122 'Verze databáze: '.$this->UpdateManager->GetDbVersion().'<br/>';123 $Output .= 'Verze databáze kódu: '.$this->UpdateManager->Revision.'<br/>';124 if($this->UpdateManager->IsInstalled())125 {126 if(!$this->UpdateManager->IsUpToDate())127 $Output .= '<input type="submit" name="update" value="Aktualizovat"/> ';128 $Output .= '<input type="submit" name="insert_sample_data" value="Vložit vzorová data"/> ';129 $Output .= '<input type="submit" name="uninstall" value="Odinstalovat"/> ';130 //$Output .= $this->ShowList();131 } else $Output .= '<input type="submit" name="install" value="Instalovat"/> ';132 }133 $Output .= '<input type="submit" name="configure" value="Nastavit"/> ';134 $Output .= '<input type="submit" name="logout" value="Odhlásit"/> ';135 $Output .= '</form>';136 return($Output);137 }138 139 function Show()140 {141 $Output = '<?xml version="1.0" encoding="utf-8"?>142 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">143 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cz">'.144 '<head>'.145 '<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />'.146 '<title>Správa instance</title>'.147 '</head><body>';148 if(isset($this->Config))149 {150 if(!array_key_exists('SystemPassword', $_SESSION)) $_SESSION['SystemPassword'] = '';151 if(array_key_exists('login', $_POST)) $_SESSION['SystemPassword'] = $_POST['SystemPassword'];152 if(sha1($_SESSION['SystemPassword']) != $this->Config['SystemPassword'])153 {154 $Output .= $this->LoginPanel();155 } else156 {157 $this->UpdateManager = new UpdateManager();158 $this->UpdateManager->Database = $this->Database;159 $this->UpdateManager->Revision = $this->DatabaseRevision;160 $this->UpdateManager->Trace = $this->Updates;161 $this->UpdateManager->InstallMethod = 'FullInstall';162 163 if(array_key_exists('logout', $_POST))164 {165 $_SESSION['SystemPassword'] = '';166 $Output .= 'Odhlášen';167 $Output .= $this->LoginPanel();168 } else169 if(array_key_exists('update', $_POST))170 {171 $Output .= '<h3>Aktualizace</h3>';172 $Output .= $this->UpdateManager->Update();173 $Output .= $this->ControlPanel();174 } else175 if(array_key_exists('install', $_POST))176 {177 $Output .= '<h3>Instalace</h3>';178 $this->UpdateManager->Install();179 $Output .= $this->UpdateManager->Update();180 $Output .= $this->ControlPanel();181 } else182 if(array_key_exists('uninstall', $_POST))183 {184 $Output .= '<h3>Odinstalace</h3>';185 $this->UpdateManager->Uninstall();186 $Output .= $this->ControlPanel();187 } else188 if(array_key_exists('insert_sample_data', $_POST))189 {190 $Output .= '<h3>Vložení vzorových dat</h3>';191 $this->UpdateManager->InsertSampleData();192 $Output .= $this->ControlPanel();193 } else194 if(array_key_exists('configure_save', $_POST))195 {196 $Output .= $this->ConfigSave($this->Config);197 $Output .= $this->ControlPanel();198 } else199 if(array_key_exists('configure', $_POST))200 {201 $Output .= $this->PrepareConfig($this->Config);202 } else203 {204 $Output .= $this->ControlPanel();205 }206 }207 } else208 {209 if(array_key_exists('configure_save', $_POST))210 {211 $Output .= $this->ConfigSave(array());212 $Output .= 'Pokračujte k přihlášení <a href="">zde</a>';213 } else {214 $Output .= $this->PrepareConfig(array());215 }216 }217 $Output .= '</body></html>';218 return($Output);219 }220 221 function ShowList()222 {223 $Output = '';224 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Module`');225 $DbRow = $DbResult->fetch_row();226 $PageList = GetPageList($DbRow[0]);227 228 $Output .= $PageList['Output'];229 $Output .= '<table class="WideTable" style="font-size: small;">';230 231 $TableColumns = array(232 array('Name' => 'Name', 'Title' => 'Jméno'),233 array('Name' => 'Creator', 'Title' => 'Tvůrce'),234 array('Name' => 'Version', 'Title' => 'Verze'),235 array('Name' => 'License', 'Title' => 'Licence'),236 array('Name' => 'Installed', 'Title' => 'Instalováno'),237 array('Name' => 'Description', 'Title' => 'Popis'),238 array('Name' => 'Dependencies', 'Title' => 'Závislosti'),239 array('Name' => '', 'Title' => 'Akce'),240 );241 $Order = GetOrderTableHeader($TableColumns, 'Name', 0);242 $Output .= $Order['Output'];243 $Query = 'SELECT *, (SELECT GROUP_CONCAT(`T1`.`Name` SEPARATOR ", ") FROM `SystemModuleDependency` '.244 'LEFT JOIN `SystemModule` AS `T1` ON `T1`.`Id` = `SystemModuleDependency`.`DependencyModule` '.245 'WHERE `SystemModuleDependency`.`Module` = `SystemModule`.`Id`) AS `Dependencies` '.246 'FROM `SystemModule` '.$Order['SQL'].$PageList['SQLLimit'];247 248 $DbResult = $this->Database->query($Query);249 while($Module = $DbResult->fetch_assoc())250 {251 if($Module['Dependencies'] != '') $Dependencies = $Module['Dependencies'];252 else $Dependencies = ' ';253 if($Module['Installed'] == 1) $Installed = 'Ano';254 else $Installed = 'Ne';255 if($Module['Installed'] == 1) $Actions = '<a href="?A=Uninstall&Id='.$Module['Id'].'">Odinstalovat</a>';256 else $Actions = '<a href="?A=Install&Id='.$Module['Id'].'">Instalovat</a>';257 $Output .= '<tr><td>'.$Module['Name'].'</td>'.258 '<td>'.$Module['Creator'].'</td>'.259 '<td>'.$Module['Version'].'</td>'.260 '<td>'.$Module['License'].'</td>'.261 '<td>'.$Installed.'</td>'.262 '<td>'.$Module['Description'].'</td>'.263 '<td>'.$Dependencies.'</td>'.264 '<td>'.$Actions.'</td></tr>';265 }266 $Output .= '</table>';267 $Output .= $PageList['Output'];268 $Output .= '<p><a href="?A=SaveToDb">Uložit do databáze</a></p>';269 return($Output);270 }271 272 function PrepareConfig($Config)273 {274 $Output = '';275 if(!file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir))276 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože složka není povolená pro zápis!';277 if(file_exists($this->ConfigDir.'/config.php') and !is_writable($this->ConfigDir.'/config.php'))278 $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor config.php není povolen pro zápis!';279 $Output .= '<h3>Nastavení systému</h3>'.280 '<form action="" method="post">'.281 '<table>';282 foreach($this->ConfigDefinition as $Def)283 {284 $PathParts = explode('/', $Def['Name']);285 $TempConfig = &$Config;286 foreach($PathParts as $Part)287 if(array_key_exists($Part, $TempConfig))288 {289 $TempConfig = &$TempConfig[$Part];290 }291 if(!is_array($TempConfig)) $Value = $TempConfig;292 else $Value = $Def['Default'];293 $Output .= '<tr><td>'.$Def['Title'].'</td><td>';294 if($Def['Type'] == 'String') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';295 if($Def['Type'] == 'Password') $Output .= '<input type="password" name="'.$Def['Name'].'"/>';296 if($Def['Type'] == 'PasswordEncoded') $Output .= '<input type="password" name="'.$Def['Name'].'"/>';297 if($Def['Type'] == 'Integer') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';298 if($Def['Type'] == 'Float') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';299 if($Def['Type'] == 'Boolean') $Output .= '<input type="text" name="'.$Def['Name'].'" value="'.$Value.'"/>';300 }301 $Output .= '</td></tr>'.302 '<tr><td colspan="2"><input type="submit" name="configure_save" value="Nastavit"/></td></tr>'.303 '</table>'.304 '</form>';305 return($Output);306 }307 308 function ConfigSave($DefaultConfig)309 {310 $Config = $DefaultConfig;311 foreach($this->ConfigDefinition as $Def)312 {313 $Value = null;314 if($Def['Type'] == 'String') if(array_key_exists($Def['Name'], $_POST))315 $Value = $_POST[$Def['Name']];316 if($Def['Type'] == 'Password') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != ''))317 $Value = $_POST[$Def['Name']];318 if($Def['Type'] == 'PasswordEncoded') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != ''))319 $Value = sha1($_POST[$Def['Name']]);320 if($Def['Type'] == 'Integer') if(array_key_exists($Def['Name'], $_POST))321 $Value = $_POST[$Def['Name']];322 if($Def['Type'] == 'Float') if(array_key_exists($Def['Name'], $_POST))323 $Value = $_POST[$Def['Name']];324 if($Def['Type'] == 'Boolean') if(array_key_exists($Def['Name'], $_POST))325 $Value = $_POST[$Def['Name']];326 if(!is_null($Value))327 {328 $PathParts = explode('/', $Def['Name']);329 $TempConfig = &$Config;330 foreach($PathParts as $Part)331 {332 $TempConfig = &$TempConfig[$Part];333 }334 if(!is_array($TempConfig)) $TempConfig = $Value;335 else $Value = $Def['Default'];336 }337 }338 $ConfigText = $this->CreateConfig($Config);339 file_put_contents($this->ConfigDir.'/config.php', $ConfigText);340 $Output .= 'Konfigurace nastavena<br/>';341 return($Output);342 }343 344 function CreateConfig($Config)345 {346 347 $Output = "<?php\n\n".348 "\$IsDeveloper = in_array(\$_SERVER['REMOTE_ADDR'], array('127.0.0.1'));\n\n";349 350 foreach($this->ConfigDefinition as $Def)351 {352 $PathParts = explode('/', $Def['Name']);353 $Output .= "\$Config";354 foreach($PathParts as $Part)355 $Output .= "['".$Part."']";356 $TempConfig = &$Config;357 foreach($PathParts as $Part)358 if(array_key_exists($Part, $TempConfig))359 {360 $TempConfig = &$TempConfig[$Part];361 }362 if(!is_array($TempConfig)) $Value = $TempConfig;363 else $Value = $Def['Default'];364 $Output .= " = '".$Value."';\n";365 }366 $Output .= "\n\n";367 return($Output);368 }369 } -
trunk/index.php
r578 r592 1 1 <?php 2 2 3 include_once(' Common/System.php');3 include_once('Application/System.php'); 4 4 5 5 $System = new System();
Note:
See TracChangeset
for help on using the changeset viewer.