00001 <?php
00002
00020
00021
00022
00023 import('install.Install');
00024 import('site.VersionCheck');
00025 import('form.Form');
00026
00027 define('PHP_REQUIRED_VERSION', '4.2.0');
00028
00029 class InstallForm extends Form {
00030
00032 var $supportedLocales;
00033
00035 var $supportedClientCharsets;
00036
00038 var $supportedConnectionCharsets;
00039
00041 var $supportedDatabaseCharsets;
00042
00044 var $supportedDatabaseDrivers;
00045
00049 function InstallForm() {
00050 parent::Form('install/install.tpl');
00051
00052
00053 $this->supportedLocales = Locale::getAllLocales();
00054
00055 $this->supportedClientCharsets = array (
00056 'utf-8' => 'Unicode (UTF-8)',
00057 'iso-8859-1' => 'Western (ISO-8859-1)'
00058 );
00059
00060 $this->supportedConnectionCharsets = array (
00061 '' => Locale::translate('common.notApplicable'),
00062 'utf8' => 'Unicode (UTF-8)'
00063 );
00064
00065 $this->supportedDatabaseCharsets = array (
00066 '' => Locale::translate('common.notApplicable'),
00067 'utf8' => 'Unicode (UTF-8)'
00068 );
00069
00070 $this->supportedEncryptionAlgorithms = array (
00071 'md5' => 'MD5'
00072 );
00073 if (function_exists('sha1')) {
00074 $this->supportedEncryptionAlgorithms['sha1'] = 'SHA1';
00075 }
00076
00077 $this->supportedDatabaseDrivers = array (
00078
00079 'mysql' => array('mysql', 'MySQL'),
00080 'postgres' => array('pgsql', 'PostgreSQL'),
00081 'oracle' => array('oci8', 'Oracle'),
00082 'mssql' => array('mssql', 'MS SQL Server'),
00083 'fbsql' => array('fbsql', 'FrontBase'),
00084 'ibase' => array('ibase', 'Interbase'),
00085 'firebird' => array('ibase', 'Firebird'),
00086 'informix' => array('ifx', 'Informix'),
00087 'sybase' => array('sybase', 'Sybase'),
00088 'odbc' => array('odbc', 'ODBC'),
00089 );
00090
00091
00092 $this->addCheck(new FormValidatorInSet($this, 'locale', 'required', 'installer.form.localeRequired', array_keys($this->supportedLocales)));
00093 $this->addCheck(new FormValidatorCustom($this, 'locale', 'required', 'installer.form.localeRequired', array('Locale', 'isLocaleValid')));
00094 $this->addCheck(new FormValidatorInSet($this, 'clientCharset', 'required', 'installer.form.clientCharsetRequired', array_keys($this->supportedClientCharsets)));
00095 $this->addCheck(new FormValidator($this, 'filesDir', 'required', 'installer.form.filesDirRequired'));
00096 $this->addCheck(new FormValidatorInSet($this, 'encryption', 'required', 'installer.form.encryptionRequired', array_keys($this->supportedEncryptionAlgorithms)));
00097 $this->addCheck(new FormValidator($this, 'adminUsername', 'required', 'installer.form.usernameRequired'));
00098 $this->addCheck(new FormValidatorAlphaNum($this, 'adminUsername', 'required', 'installer.form.usernameAlphaNumeric'));
00099 $this->addCheck(new FormValidator($this, 'adminPassword', 'required', 'installer.form.passwordRequired'));
00100 $this->addCheck(new FormValidatorCustom($this, 'adminPassword', 'required', 'installer.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'adminPassword2\');'), array(&$this)));
00101 $this->addCheck(new FormValidatorEmail($this, 'adminEmail', 'required', 'installer.form.emailRequired'));
00102 $this->addCheck(new FormValidatorInSet($this, 'databaseDriver', 'required', 'installer.form.databaseDriverRequired', array_keys($this->supportedDatabaseDrivers)));
00103 $this->addCheck(new FormValidator($this, 'databaseName', 'required', 'installer.form.databaseNameRequired'));
00104 $this->addCheck(new FormValidatorPost($this));
00105 }
00106
00110 function display() {
00111 $templateMgr = &TemplateManager::getManager();
00112 $templateMgr->assign('localeOptions', $this->supportedLocales);
00113 $templateMgr->assign('clientCharsetOptions', $this->supportedClientCharsets);
00114 $templateMgr->assign('connectionCharsetOptions', $this->supportedConnectionCharsets);
00115 $templateMgr->assign('databaseCharsetOptions', $this->supportedDatabaseCharsets);
00116 $templateMgr->assign('encryptionOptions', $this->supportedEncryptionAlgorithms);
00117 $templateMgr->assign('databaseDriverOptions', $this->checkDBDrivers());
00118 $templateMgr->assign('supportsMBString', String::hasMBString() ? Locale::translate('common.yes') : Locale::translate('common.no'));
00119 $templateMgr->assign('phpIsSupportedVersion', version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1);
00120 $templateMgr->assign('phpRequiredVersion', PHP_REQUIRED_VERSION);
00121 $templateMgr->assign('phpVersion', PHP_VERSION);
00122 $templateMgr->assign('version', VersionCheck::getCurrentCodeVersion());
00123
00124 parent::display();
00125 }
00126
00130 function initData() {
00131 $cwd = getcwd();
00132 if (Core::isWindows()) {
00133
00134 $cwd = str_replace('\\', '/', $cwd);
00135 }
00136
00137 $this->_data = array(
00138 'locale' => Locale::getLocale(),
00139 'additionalLocales' => array(),
00140 'clientCharset' => 'utf-8',
00141 'connectionCharset' => '',
00142 'databaseCharset' => '',
00143 'encryption' => 'md5',
00144 'filesDir' => $cwd . '/files',
00145 'skipFilesDir' => 0,
00146 'databaseDriver' => 'mysql',
00147 'databaseHost' => 'localhost',
00148 'databaseUsername' => 'ojs',
00149 'databasePassword' => '',
00150 'databaseName' => 'ojs',
00151 'createDatabase' => 1,
00152 'oaiRepositoryId' => 'ojs.' . Request::getServerHost()
00153 );
00154 }
00155
00159 function readInputData() {
00160 $this->readUserVars(array(
00161 'locale',
00162 'additionalLocales',
00163 'clientCharset',
00164 'connectionCharset',
00165 'databaseCharset',
00166 'filesDir',
00167 'skipFilesDir',
00168 'encryption',
00169 'adminUsername',
00170 'adminPassword',
00171 'adminPassword2',
00172 'adminEmail',
00173 'databaseDriver',
00174 'databaseHost',
00175 'databaseUsername',
00176 'databasePassword',
00177 'databaseName',
00178 'createDatabase',
00179 'oaiRepositoryId',
00180 'manualInstall'
00181 ));
00182
00183 if ($this->getData('additionalLocales') == null || !is_array($this->getData('additionalLocales'))) {
00184 $this->setData('additionalLocales', array());
00185 }
00186 }
00187
00191 function execute() {
00192 $templateMgr = &TemplateManager::getManager();
00193 $installer = &new Install($this->_data);
00194
00195 if ($installer->execute()) {
00196 if ($this->getData('manualInstall')) {
00197
00198 $templateMgr->assign(array('manualInstall' => true, 'installSql' => $installer->getSQL()));
00199
00200 }
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 error_log($errorMsg);
00247 $this->display();
00248 }
00249
00254 function dbInstallError($errorMsg) {
00255 $templateMgr = &TemplateManager::getManager();
00256 if (empty($errorMsg)) $errorMsg = Locale::translate('common.error.databaseErrorUnknown');
00257 $templateMgr->assign(array('isInstallError' => true, 'dbErrorMsg' => $errorMsg));
00258 error_log($errorMsg);
00259 $this->display();
00260 }
00261
00262 }
00263
00264 ?>