Title = T('Application setup'); //$this->ParentClass = 'PagePortal'; $this->ConfigDir = dirname(dirname(dirname(__FILE__))).'/Config'; $this->YesNo = array(false => T('No'), true => T('Yes')); } function LoginPanel() { $Output = '

Přihlášení k instalaci

'. '
'. ''. ''. '
Systémové heslo:
'. ''. '
'; return($Output); } function ControlPanel() { $Output = '

'.T('Instance management').'

'; $Output .= 'Je připojení k databázi: '.$this->YesNo[$this->UpdateManager->Database->Connected()].'
'; if($this->UpdateManager->Database->Connected()) { $Output .= 'Je instalováno: '.$this->YesNo[$this->UpdateManager->IsInstalled()].'
'; if($this->UpdateManager->IsInstalled()) $Output .= 'Je aktuální: '.$this->YesNo[$this->UpdateManager->IsUpToDate()].'
'. 'Verze databáze: '.$this->UpdateManager->GetDbVersion().'
'; $Output .= 'Verze databáze kódu: '.$this->UpdateManager->Revision.'
'; if($this->UpdateManager->IsInstalled()) { if(!$this->UpdateManager->IsUpToDate()) $Output .= ''.T('Upgrade').' '; $Output .= 'Vložit vzorová data '; $Output .= 'Obnovit seznam modulů '; $Output .= 'Odinstalovat '; $Output .= 'Správa modulů '; $Output .= 'Přegenerovat modely '; } else $Output .= 'Instalovat '; } $Output .= 'Nastavit '; $Output .= 'Odhlásit '; $Output .= ''.T('Go to main page').' '; $Output .= ''; return($Output); } function Show() { global $ConfigDefinition, $DatabaseRevision, $Config, $Updates; $this->UpdateManager = $this->System->Setup->UpdateManager; $DefaultConfig = new DefaultConfig(); $this->ConfigDefinition = $DefaultConfig->Get(); $this->DatabaseRevision = $DatabaseRevision; $this->Config = &$Config; $Output = ''; if(isset($this->Config)) { if(!array_key_exists('SystemPassword', $_SESSION)) $_SESSION['SystemPassword'] = ''; if(array_key_exists('login', $_POST)) $_SESSION['SystemPassword'] = $_POST['SystemPassword']; if(sha1($_SESSION['SystemPassword']) != $this->Config['SystemPassword']) { $Output .= $this->LoginPanel(); } else { if(array_key_exists('action', $_GET)) $Action = $_GET['action']; else $Action = ''; if($Action == 'logout') { $_SESSION['SystemPassword'] = ''; $Output .= 'Odhlášen'; $Output .= $this->LoginPanel(); } else if($Action == 'models') { $this->System->FormManager->UpdateSQLMeta(); } else if($Action == 'upgrade') { $Output .= '

Povýšení

'; try { $Output .= $this->System->Setup->Upgrade(); } catch (Exception $E) { $Output .= $this->SystemMessage('Chyba aktualizace', 'Došlo k chybě v SQL dotazu při aktualizaci:
'.$E->getMessage()); } $Output .= $this->ControlPanel(); } else if($Action == 'install') { $Output .= '

Instalace

'; $this->System->Setup->Install(); $this->System->ModuleManager->LoadModules(); $this->System->ModuleManager->SaveState(); //$Output .= $this->System->Setup->Upgrade(); $Output .= $this->ControlPanel(); } else if($Action == 'uninstall') { $Output .= '

Odinstalace

'; $this->System->Setup->Uninstall(); $Output .= $this->ControlPanel(); } else if($Action == 'reload_modules') { $Output .= '

Znovunačtení seznamu modulů

'; $this->System->ModuleManager->LoadModules(); $this->System->ModuleManager->SaveState(); $Output .= $this->ControlPanel(); } else if($Action == 'insert_sample_data') { $Output .= '

Vložení vzorových dat

'; $this->System->Setup->InsertSampleData(); $Output .= $this->ControlPanel(); } else if($Action == 'modules') { $Output .= $this->ShowModules(); } else if($Action == 'configure_save') { $Output .= $this->ConfigSave($this->Config); $Output .= $this->ControlPanel(); } else if($Action == 'configure') { $Output .= $this->PrepareConfig($this->Config); } else { $Output .= $this->ControlPanel(); } } } else { if(array_key_exists('configure_save', $_POST)) { $Output .= $this->ConfigSave(array()); $Output .= 'Pokračujte k přihlášení zde'; } else { $Output .= $this->PrepareConfig(array()); } } return($Output); } function ShowModules() { $Output = ''; if(array_key_exists('op', $_GET)) $Operation = $_GET['op']; else $Operation = ''; if($Operation == 'install') { $this->System->ModuleManager->Modules[$_GET['name']]->Install(); $this->System->ModuleManager->SaveState(); $Output .= 'Modul '.$_GET['name'].' instalován
'; } else if($Operation == 'uninstall') { $this->System->ModuleManager->Modules[$_GET['name']]->Uninstall(); $this->System->ModuleManager->SaveState(); $Output .= 'Modul '.$_GET['name'].' odinstalován
'; } else if($Operation == 'enable') { $this->System->ModuleManager->Modules[$_GET['name']]->Enable(); $this->System->ModuleManager->SaveState(); $Output .= 'Modul '.$_GET['name'].' povolen
'; } else if($Operation == 'disable') { $this->System->ModuleManager->Modules[$_GET['name']]->Disable(); $this->System->ModuleManager->SaveState(); $Output .= 'Modul '.$_GET['name'].' zakázán
'; } else if($Operation == 'upgrade') { $this->System->ModuleManager->Modules[$_GET['name']]->Upgrade(); $this->System->ModuleManager->SaveState(); $Output .= 'Modul '.$_GET['name'].' povýšen
'; } $Output .= '

Správa modulů

'; $Output .= $this->ShowList(); return($Output); } function ShowList() { $Output = ''; $Pageing = new Paging($this->System); $Pageing->TotalCount = count($this->System->ModuleManager->Modules); $Table = new VisualTable($this->System); $Table->SetColumns(array( array('Name' => 'Name', 'Title' => 'Jméno'), array('Name' => 'Creator', 'Title' => 'Tvůrce'), array('Name' => 'Version', 'Title' => 'Verze'), array('Name' => 'License', 'Title' => 'Licence'), array('Name' => 'Installed', 'Title' => 'Instalováno'), array('Name' => 'Enabled', 'Title' => 'Povoleno'), array('Name' => 'Description', 'Title' => 'Popis'), array('Name' => 'Dependencies', 'Title' => 'Závislosti'), array('Name' => '', 'Title' => 'Akce'), )); foreach($this->System->ModuleManager->Modules as $Module) { if(($Module->Dependencies) > 0) $Dependencies = implode(',', $Module->Dependencies); else $Dependencies = ' '; $Actions = ''; if($Module->Installed == true) { $Actions .= ' Odinstalovat'; if($Module->Enabled == true) $Actions .= ' Zakázat'; else $Actions .= ' Povolit'; if($Module->InstalledVersion != $Module->Version) $Actions .= ' Povýšit'; } else $Actions .= ' Instalovat'; $Table->Table->Cells[] = array($Module->Name, $Module->Creator, $Module->Version, $Module->License, $this->YesNo[$Module->Installed], $this->YesNo[$Module->Enabled], $Module->Description, $Dependencies, $Actions); } $Output .= $Pageing->Show(); $Output .= $Table->Show(); $Output .= $Pageing->Show(); //$Output .= '

Uložit do databáze

'; return($Output); } function PrepareConfig($Config) { $Output = ''; if(!file_exists($this->ConfigDir.'/Config.php') and !is_writable($this->ConfigDir)) $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože složka "'.$this->ConfigDir.'" není povolená pro zápis!'; if(file_exists($this->ConfigDir.'/Config.php') and !is_writable($this->ConfigDir.'/Config.php')) $Output .= 'Varování: Konfigurační soubor nebude možné zapsat, protože soubor "'.$this->ConfigDir.'/Config.php" není povolen pro zápis!'; $Output .= '

Nastavení systému

'. '
'. ''; foreach($this->ConfigDefinition as $Def) { $PathParts = explode('/', $Def['Name']); $TempConfig = &$Config; foreach($PathParts as $Part) if(array_key_exists($Part, $TempConfig)) { $TempConfig = &$TempConfig[$Part]; } if(!is_array($TempConfig)) $Value = $TempConfig; else $Value = $Def['Default']; $Output .= ''. ''. '
'.$Def['Title'].''; if($Def['Type'] == 'String') $Output .= ''; if($Def['Type'] == 'Password') $Output .= ''; if($Def['Type'] == 'PasswordEncoded') $Output .= ''; if($Def['Type'] == 'Integer') $Output .= ''; if($Def['Type'] == 'Float') $Output .= ''; if($Def['Type'] == 'Boolean') $Output .= ''; if($Def['Type'] == 'Array') $Output .= ''; } $Output .= '
'. '
'; return($Output); } function ConfigSave($DefaultConfig) { $Config = $DefaultConfig; foreach($this->ConfigDefinition as $Def) { $Value = null; if($Def['Type'] == 'String') if(array_key_exists($Def['Name'], $_POST)) $Value = $_POST[$Def['Name']]; if($Def['Type'] == 'Password') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != '')) $Value = $_POST[$Def['Name']]; if($Def['Type'] == 'PasswordEncoded') if(array_key_exists($Def['Name'], $_POST) and ($_POST[$Def['Name']] != '')) $Value = sha1($_POST[$Def['Name']]); if($Def['Type'] == 'Integer') if(array_key_exists($Def['Name'], $_POST)) $Value = $_POST[$Def['Name']]; if($Def['Type'] == 'Float') if(array_key_exists($Def['Name'], $_POST)) $Value = $_POST[$Def['Name']]; if($Def['Type'] == 'Boolean') if(array_key_exists($Def['Name'], $_POST)) $Value = $_POST[$Def['Name']]; if($Def['Type'] == 'Array') if(array_key_exists($Def['Name'], $_POST)) $Value = explode(',', $_POST[$Def['Name']]); if(!is_null($Value)) { $PathParts = explode('/', $Def['Name']); $TempConfig = &$Config; foreach($PathParts as $Part) { $TempConfig = &$TempConfig[$Part]; } if(!is_array($TempConfig)) $TempConfig = $Value; else $Value = $Def['Default']; } } $ConfigText = $this->CreateConfig($Config); file_put_contents($this->ConfigDir.'/Config.php', $ConfigText); $Output = 'Konfigurace nastavena
'; return($Output); } function CreateConfig($Config) { $Output = "ConfigDefinition as $Def) { $PathParts = explode('/', $Def['Name']); $Output .= "\$Config"; foreach($PathParts as $Part) $Output .= "['".$Part."']"; $TempConfig = &$Config; $Output .= ' = '; foreach($PathParts as $Part) if(array_key_exists($Part, $TempConfig)) { $TempConfig = &$TempConfig[$Part]; } if(!is_array($TempConfig)) $Value = $TempConfig; else $Value = $Def['Default']; if($Def['Type'] == 'Array') { $Output .= ' array('; foreach($Value as $Index => $Item) $Output .= '\''.$Item.'\', '; $Output .= ')'; } else $Output .= "'".$Value."'"; $Output .= ";\n"; } $Output .= "\n\n"; return($Output); } } class PageSetupRedirect extends Page { function Show() { $Output = ''; if(!$this->Database->Connected()) $Output .= T('Can\'t connect to database').'
'; else { if(!$this->System->Setup->UpdateManager->IsInstalled()) $Output .= T('System requires database initialization').'
'; else if(!$this->System->Setup->UpdateManager->IsUpToDate()) $Output .= T('System requires database upgrade').'
'; } $Output .= sprintf(T('Front page was not configured. Continue to %s'), ''.T('setup').''); return($Output); } } class Setup extends Model { var $UpdateManager; function Start() { global $DatabaseRevision; $this->System->RegisterPage('', 'PageSetupRedirect'); $this->System->RegisterPage('setup', 'PageSetup'); // Check database persistence structure $this->UpdateManager = new UpdateManager(); $this->UpdateManager->Database = &$this->Database; $this->UpdateManager->Revision = $DatabaseRevision; $this->UpdateManager->InstallMethod = 'FullInstall'; } function Stop() { unset($this->UpdateManager); $this->System->UnregisterPage(''); $this->System->UnregisterPage('setup'); } function CheckState() { return($this->Database->Connected() and $this->UpdateManager->IsInstalled() and $this->UpdateManager->IsUpToDate()); } function Install() { global $DatabaseRevision; $this->Database->query('CREATE TABLE IF NOT EXISTS `'.$this->UpdateManager->VersionTable.'` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Revision` int(11) NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;'); $this->Database->query('INSERT INTO `'.$this->UpdateManager->VersionTable.'` (`Id`, `Revision`) VALUES (1, '.$DatabaseRevision.');'); $this->Database->query("CREATE TABLE IF NOT EXISTS `Module` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(255) NOT NULL, `Title` varchar(255) NOT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;"); } function Uninstall() { $this->System->ModuleManager->UninstallAll(); $this->Database->query('DROP TABLE IF EXISTS `Module`'); $this->Database->query('DROP TABLE IF EXISTS `'.$this->UpdateManager->VersionTable.'`'); } function IsInstalled() { $DbResult = $this->Database->query('SHOW TABLES LIKE "'.$this->UpdateManager->VersionTable.'"'); return($DbResult->num_rows > 0); } function Upgrade() { $Updates = new Updates(); $this->UpdateManager->Trace = $Updates->Get(); $Output = $this->UpdateManager->Upgrade(); return($Output); } }