00001 <?php
00002
00019
00020
00021 import('install.Install');
00022 import('site.VersionCheck');
00023 import('form.Form');
00024
00025 class InstallForm extends Form {
00026
00028 var $supportedLocales;
00029
00031 var $localesComplete;
00032
00034 var $supportedClientCharsets;
00035
00037 var $supportedConnectionCharsets;
00038
00040 var $supportedDatabaseCharsets;
00041
00043 var $supportedDatabaseDrivers;
00044
00048 function InstallForm() {
00049 parent::Form('install/install.tpl');
00050
00051
00052 $this->supportedLocales = AppLocale::getAllLocales();
00053 $this->localesComplete = array();
00054 foreach ($this->supportedLocales as $key => $name) {
00055 $this->localesComplete[$key] = AppLocale::isLocaleComplete($key);
00056 }
00057
00058 $this->supportedClientCharsets = array (
00059 'utf-8' => 'Unicode (UTF-8)',
00060 'iso-8859-1' => 'Western (ISO-8859-1)'
00061 );
00062
00063 $this->supportedConnectionCharsets = array (
00064 '' => __('common.notApplicable'),
00065 'utf8' => 'Unicode (UTF-8)'
00066 );
00067
00068 $this->supportedDatabaseCharsets = array (
00069 '' => __('common.notApplicable'),
00070 'utf8' => 'Unicode (UTF-8)'
00071 );
00072
00073 $this->supportedEncryptionAlgorithms = array (
00074 'md5' => 'MD5'
00075 );
00076 if (function_exists('sha1')) {
00077 $this->supportedEncryptionAlgorithms['sha1'] = 'SHA1';
00078 }
00079
00080 $this->supportedDatabaseDrivers = array (
00081
00082 'mysql' => array('mysql', 'MySQL'),
00083 'postgres' => array('pgsql', 'PostgreSQL'),
00084 'oracle' => array('oci8', 'Oracle'),
00085 'mssql' => array('mssql', 'MS SQL Server'),
00086 'fbsql' => array('fbsql', 'FrontBase'),
00087 'ibase' => array('ibase', 'Interbase'),
00088 'firebird' => array('ibase', 'Firebird'),
00089 'informix' => array('ifx', 'Informix'),
00090 'sybase' => array('sybase', 'Sybase'),
00091 'odbc' => array('odbc', 'ODBC'),
00092 );
00093
00094
00095 $this->addCheck(new FormValidatorInSet($this, 'locale', 'required', 'installer.form.localeRequired', array_keys($this->supportedLocales)));
00096 $this->addCheck(new FormValidatorCustom($this, 'locale', 'required', 'installer.form.localeRequired', array('AppLocale', 'isLocaleValid')));
00097 $this->addCheck(new FormValidatorInSet($this, 'clientCharset', 'required', 'installer.form.clientCharsetRequired', array_keys($this->supportedClientCharsets)));
00098 $this->addCheck(new FormValidator($this, 'filesDir', 'required', 'installer.form.filesDirRequired'));
00099 $this->addCheck(new FormValidatorInSet($this, 'encryption', 'required', 'installer.form.encryptionRequired', array_keys($this->supportedEncryptionAlgorithms)));
00100 $this->addCheck(new FormValidator($this, 'adminUsername', 'required', 'installer.form.usernameRequired'));
00101 $this->addCheck(new FormValidatorAlphaNum($this, 'adminUsername', 'required', 'installer.form.usernameAlphaNumeric'));
00102 $this->addCheck(new FormValidator($this, 'adminPassword', 'required', 'installer.form.passwordRequired'));
00103 $this->addCheck(new FormValidatorCustom($this, 'adminPassword', 'required', 'installer.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'adminPassword2\');'), array(&$this)));
00104 $this->addCheck(new FormValidatorEmail($this, 'adminEmail', 'required', 'installer.form.emailRequired'));
00105 $this->addCheck(new FormValidatorInSet($this, 'databaseDriver', 'required', 'installer.form.databaseDriverRequired', array_keys($this->supportedDatabaseDrivers)));
00106 $this->addCheck(new FormValidator($this, 'databaseName', 'required', 'installer.form.databaseNameRequired'));
00107 $this->addCheck(new FormValidatorPost($this));
00108 }
00109
00113 function display() {
00114 $templateMgr =& TemplateManager::getManager();
00115 $templateMgr->assign('localeOptions', $this->supportedLocales);
00116 $templateMgr->assign('localesComplete', $this->localesComplete);
00117 $templateMgr->assign('clientCharsetOptions', $this->supportedClientCharsets);
00118 $templateMgr->assign('connectionCharsetOptions', $this->supportedConnectionCharsets);
00119 $templateMgr->assign('databaseCharsetOptions', $this->supportedDatabaseCharsets);
00120 $templateMgr->assign('encryptionOptions', $this->supportedEncryptionAlgorithms);
00121 $templateMgr->assign('databaseDriverOptions', $this->checkDBDrivers());
00122 $templateMgr->assign('supportsMBString', String::hasMBString() ? __('common.yes') : __('common.no'));
00123 $templateMgr->assign('phpIsSupportedVersion', version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1);
00124 $templateMgr->assign('phpRequiredVersion', PHP_REQUIRED_VERSION);
00125 $templateMgr->assign('phpVersion', PHP_VERSION);
00126 $templateMgr->assign('version', VersionCheck::getCurrentCodeVersion());
00127
00128 parent::display();
00129 }
00130
00134 function initData() {
00135 $cwd = getcwd();
00136 if (Core::isWindows()) {
00137
00138 $cwd = str_replace('\\', '/', $cwd);
00139 }
00140
00141 $this->_data = array(
00142 'locale' => AppLocale::getLocale(),
00143 'additionalLocales' => array(),
00144 'clientCharset' => 'utf-8',
00145 'connectionCharset' => '',
00146 'databaseCharset' => '',
00147 'encryption' => 'md5',
00148 'filesDir' => $cwd . '/files',
00149 'skipFilesDir' => 0,
00150 'databaseDriver' => 'mysql',
00151 'databaseHost' => 'localhost',
00152 'databaseUsername' => 'ocs',
00153 'databasePassword' => '',
00154 'databaseName' => 'ocs',
00155 'createDatabase' => 1,
00156 'oaiRepositoryId' => 'ocs.' . Request::getServerHost()
00157 );
00158 }
00159
00163 function readInputData() {
00164 $this->readUserVars(array(
00165 'locale',
00166 'additionalLocales',
00167 'clientCharset',
00168 'connectionCharset',
00169 'databaseCharset',
00170 'filesDir',
00171 'skipFilesDir',
00172 'encryption',
00173 'adminUsername',
00174 'adminPassword',
00175 'adminPassword2',
00176 'adminEmail',
00177 'databaseDriver',
00178 'databaseHost',
00179 'databaseUsername',
00180 'databasePassword',
00181 'databaseName',
00182 'createDatabase',
00183 'oaiRepositoryId'
00184 ));
00185
00186 if ($this->getData('additionalLocales') == null || !is_array($this->getData('additionalLocales'))) {
00187 $this->setData('additionalLocales', array());
00188 }
00189 }
00190
00194 function execute() {
00195 $templateMgr =& TemplateManager::getManager();
00196 $installer = new Install($this->_data);
00197
00198
00199
00200 if ($installer->execute()) {
00201 if (!$installer->wroteConfig()) {
00202
00203 $templateMgr->assign(array('writeConfigFailed' => true, 'configFileContents' => $installer->getConfigContents()));
00204 }
00205
00206 $templateMgr->display('install/installComplete.tpl');
00207
00208 } else {
00209 switch ($installer->getErrorType()) {
00210 case INSTALLER_ERROR_DB:
00211 $this->dbInstallError($installer->getErrorMsg());
00212 break;
00213 default:
00214 $this->installError($installer->getErrorMsg());
00215 break;
00216 }
00217 }
00218
00219 $installer->destroy();
00220 }
00221
00227 function checkDBDrivers() {
00228 $dbDrivers = array();
00229 foreach ($this->supportedDatabaseDrivers as $driver => $info) {
00230 list($module, $name) = $info;
00231 if (!extension_loaded($module)) {
00232 $name = '[ ' . $name . ' ]';
00233 }
00234 $dbDrivers[$driver] = $name;
00235 }
00236 return $dbDrivers;
00237 }
00238
00243 function installError($errorMsg) {
00244 $templateMgr =& TemplateManager::getManager();
00245 $templateMgr->assign(array('isInstallError' => true, 'errorMsg' => $errorMsg));
00246 $this->display();
00247 }
00248
00253 function dbInstallError($errorMsg) {
00254 $templateMgr =& TemplateManager::getManager();
00255 $templateMgr->assign(array('isInstallError' => true, 'dbErrorMsg' => empty($errorMsg) ? __('common.error.databaseErrorUnknown') : $errorMsg));
00256 $this->display();
00257 }
00258
00259 }
00260
00261 ?>