00001 <?php
00002
00022 import('classes.install.Install');
00023 import('lib.pkp.classes.site.VersionCheck');
00024 import('lib.pkp.classes.form.Form');
00025
00026 class InstallForm extends Form {
00027
00029 var $supportedLocales;
00030
00032 var $localesComplete;
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 = AppLocale::getAllLocales();
00054 $this->localesComplete = array();
00055 foreach ($this->supportedLocales as $key => $name) {
00056 $this->localesComplete[$key] = AppLocale::isLocaleComplete($key);
00057 }
00058
00059 $this->supportedClientCharsets = array (
00060 'utf-8' => 'Unicode (UTF-8)',
00061 'iso-8859-1' => 'Western (ISO-8859-1)'
00062 );
00063
00064 $this->supportedConnectionCharsets = array (
00065 '' => __('common.notApplicable'),
00066 'utf8' => 'Unicode (UTF-8)'
00067 );
00068
00069 $this->supportedDatabaseCharsets = array (
00070 '' => __('common.notApplicable'),
00071 'utf8' => 'Unicode (UTF-8)'
00072 );
00073
00074 $this->supportedEncryptionAlgorithms = array (
00075 'md5' => 'MD5'
00076 );
00077 if (function_exists('sha1')) {
00078 $this->supportedEncryptionAlgorithms['sha1'] = 'SHA1';
00079 }
00080
00081 $this->supportedDatabaseDrivers = array (
00082
00083 'mysql' => array('mysql', 'MySQL'),
00084 'postgres' => array('pgsql', 'PostgreSQL'),
00085 'oracle' => array('oci8', 'Oracle'),
00086 'mssql' => array('mssql', 'MS SQL Server'),
00087 'fbsql' => array('fbsql', 'FrontBase'),
00088 'ibase' => array('ibase', 'Interbase'),
00089 'firebird' => array('ibase', 'Firebird'),
00090 'informix' => array('ifx', 'Informix'),
00091 'sybase' => array('sybase', 'Sybase'),
00092 'odbc' => array('odbc', 'ODBC'),
00093 );
00094
00095
00096 $this->addCheck(new FormValidatorInSet($this, 'locale', 'required', 'installer.form.localeRequired', array_keys($this->supportedLocales)));
00097 $this->addCheck(new FormValidatorCustom($this, 'locale', 'required', 'installer.form.localeRequired', array('AppLocale', 'isLocaleValid')));
00098 $this->addCheck(new FormValidatorInSet($this, 'clientCharset', 'required', 'installer.form.clientCharsetRequired', array_keys($this->supportedClientCharsets)));
00099 $this->addCheck(new FormValidator($this, 'filesDir', 'required', 'installer.form.filesDirRequired'));
00100 $this->addCheck(new FormValidatorInSet($this, 'encryption', 'required', 'installer.form.encryptionRequired', array_keys($this->supportedEncryptionAlgorithms)));
00101 $this->addCheck(new FormValidator($this, 'adminUsername', 'required', 'installer.form.usernameRequired'));
00102 $this->addCheck(new FormValidatorAlphaNum($this, 'adminUsername', 'required', 'installer.form.usernameAlphaNumeric'));
00103 $this->addCheck(new FormValidator($this, 'adminPassword', 'required', 'installer.form.passwordRequired'));
00104 $this->addCheck(new FormValidatorCustom($this, 'adminPassword', 'required', 'installer.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'adminPassword2\');'), array(&$this)));
00105 $this->addCheck(new FormValidatorEmail($this, 'adminEmail', 'required', 'installer.form.emailRequired'));
00106 $this->addCheck(new FormValidatorInSet($this, 'databaseDriver', 'required', 'installer.form.databaseDriverRequired', array_keys($this->supportedDatabaseDrivers)));
00107 $this->addCheck(new FormValidator($this, 'databaseName', 'required', 'installer.form.databaseNameRequired'));
00108 $this->addCheck(new FormValidatorPost($this));
00109 }
00110
00114 function display() {
00115 $templateMgr =& TemplateManager::getManager();
00116 $templateMgr->assign('localeOptions', $this->supportedLocales);
00117 $templateMgr->assign('localesComplete', $this->localesComplete);
00118 $templateMgr->assign('clientCharsetOptions', $this->supportedClientCharsets);
00119 $templateMgr->assign('connectionCharsetOptions', $this->supportedConnectionCharsets);
00120 $templateMgr->assign('databaseCharsetOptions', $this->supportedDatabaseCharsets);
00121 $templateMgr->assign('encryptionOptions', $this->supportedEncryptionAlgorithms);
00122 $templateMgr->assign('allowFileUploads', get_cfg_var('file_uploads') ? __('common.yes') : __('common.no'));
00123 $templateMgr->assign('maxFileUploadSize', get_cfg_var('upload_max_filesize'));
00124 $templateMgr->assign('databaseDriverOptions', $this->checkDBDrivers());
00125 $templateMgr->assign('supportsMBString', String::hasMBString() ? __('common.yes') : __('common.no'));
00126 $templateMgr->assign('phpIsSupportedVersion', version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1);
00127 $templateMgr->assign('xslEnabled', $this->checkGeneralPHPModule('xsl'));
00128 $templateMgr->assign('phpRequiredVersion', PHP_REQUIRED_VERSION);
00129 $templateMgr->assign('phpVersion', PHP_VERSION);
00130 $templateMgr->assign('version', VersionCheck::getCurrentCodeVersion());
00131
00132 parent::display();
00133 }
00134
00138 function initData() {
00139 $docRoot = dirname($_SERVER['DOCUMENT_ROOT']);
00140 if (Core::isWindows()) {
00141
00142 $docRoot = str_replace('\\', '/', $docRoot);
00143 }
00144
00145
00146 if ($docRoot !== '/') $docRoot .= '/';
00147
00148 $this->_data = array(
00149 'locale' => AppLocale::getLocale(),
00150 'additionalLocales' => array(),
00151 'clientCharset' => 'utf-8',
00152 'connectionCharset' => '',
00153 'databaseCharset' => '',
00154 'encryption' => 'md5',
00155 'filesDir' => $docRoot . 'files',
00156 'databaseDriver' => 'mysql',
00157 'databaseHost' => 'localhost',
00158 'databaseUsername' => 'omp',
00159 'databasePassword' => '',
00160 'databaseName' => 'omp',
00161 'createDatabase' => 1,
00162 'oaiRepositoryId' => 'omp.' . Request::getServerHost(),
00163 );
00164 }
00165
00169 function readInputData() {
00170 $this->readUserVars(array(
00171 'locale',
00172 'additionalLocales',
00173 'clientCharset',
00174 'connectionCharset',
00175 'databaseCharset',
00176 'filesDir',
00177 'encryption',
00178 'adminUsername',
00179 'adminPassword',
00180 'adminPassword2',
00181 'adminEmail',
00182 'databaseDriver',
00183 'databaseHost',
00184 'databaseUsername',
00185 'databasePassword',
00186 'databaseName',
00187 'createDatabase',
00188 'oaiRepositoryId'
00189 ));
00190
00191 if ($this->getData('additionalLocales') == null || !is_array($this->getData('additionalLocales'))) {
00192 $this->setData('additionalLocales', array());
00193 }
00194 }
00195
00199 function execute() {
00200 $templateMgr =& TemplateManager::getManager();
00201 $installer = new Install($this->_data);
00202
00203 if ($installer->execute()) {
00204 if (!$installer->wroteConfig()) {
00205
00206 $templateMgr->assign(array('writeConfigFailed' => true, 'configFileContents' => $installer->getConfigContents()));
00207 }
00208
00209 $templateMgr->display('install/installComplete.tpl');
00210
00211 } else {
00212 switch ($installer->getErrorType()) {
00213 case INSTALLER_ERROR_DB:
00214 $this->dbInstallError($installer->getErrorMsg());
00215 break;
00216 default:
00217 $this->installError($installer->getErrorMsg());
00218 break;
00219 }
00220 }
00221
00222 $installer->destroy();
00223 }
00224
00230 function checkDBDrivers() {
00231 $dbDrivers = array();
00232 foreach ($this->supportedDatabaseDrivers as $driver => $info) {
00233 list($module, $name) = $info;
00234 if (!extension_loaded($module)) {
00235 $name = '[ ' . $name . ' ]';
00236 }
00237 $dbDrivers[$driver] = $name;
00238 }
00239 return $dbDrivers;
00240 }
00241
00247 function checkGeneralPHPModule($moduleName) {
00248 if (extension_loaded($moduleName)) {
00249 return true;
00250 }
00251 return false;
00252 }
00253
00258 function installError($errorMsg) {
00259 $templateMgr =& TemplateManager::getManager();
00260 $templateMgr->assign(array('isInstallError' => true, 'errorMsg' => $errorMsg));
00261 error_log($errorMsg);
00262 $this->display();
00263 }
00264
00269 function dbInstallError($errorMsg) {
00270 $templateMgr =& TemplateManager::getManager();
00271 if (empty($errorMsg)) $errorMsg = __('common.error.databaseErrorUnknown');
00272 $templateMgr->assign(array('isInstallError' => true, 'dbErrorMsg' => $errorMsg));
00273 error_log($errorMsg);
00274 $this->display();
00275 }
00276
00277 }
00278
00279 ?>