Changeset 592 for trunk/Common/Setup/Update.php
- Timestamp:
- Nov 2, 2013, 7:56:09 PM (11 years ago)
- Location:
- trunk/Common/Setup
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.