Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
InstallForm.inc.php
1 <?php
2 
21 import('classes.install.Install');
22 import('lib.pkp.classes.site.VersionCheck');
23 import('lib.pkp.classes.form.Form');
24 
25 class InstallForm extends Form {
26 
29 
32 
35 
38 
41 
44 
46  var $_request;
47 
51  function InstallForm($request) {
52  parent::Form('install/install.tpl');
53 
54  // FIXME Move the below options to an external configuration file?
55  $this->supportedLocales = AppLocale::getAllLocales();
56  $this->localesComplete = array();
57  foreach ($this->supportedLocales as $key => $name) {
58  $this->localesComplete[$key] = AppLocale::isLocaleComplete($key);
59  }
60 
61  $this->supportedClientCharsets = array (
62  'utf-8' => 'Unicode (UTF-8)',
63  'iso-8859-1' => 'Western (ISO-8859-1)'
64  );
65 
66  $this->supportedConnectionCharsets = array (
67  '' => __('common.notApplicable'),
68  'utf8' => 'Unicode (UTF-8)'
69  );
70 
71  $this->supportedDatabaseCharsets = array (
72  '' => __('common.notApplicable'),
73  'utf8' => 'Unicode (UTF-8)'
74  );
75 
76  $this->supportedEncryptionAlgorithms = array (
77  'md5' => 'MD5'
78  );
79  if (function_exists('sha1')) {
80  $this->supportedEncryptionAlgorithms['sha1'] = 'SHA1';
81  }
82 
83  $this->supportedDatabaseDrivers = array (
84  // <adodb-driver> => array(<php-module>, <name>)
85  'mysql' => array('mysql', 'MySQL'),
86  'postgres' => array('pgsql', 'PostgreSQL'),
87  'oracle' => array('oci8', 'Oracle'),
88  'mssql' => array('mssql', 'MS SQL Server'),
89  'fbsql' => array('fbsql', 'FrontBase'),
90  'ibase' => array('ibase', 'Interbase'),
91  'firebird' => array('ibase', 'Firebird'),
92  'informix' => array('ifx', 'Informix'),
93  'sybase' => array('sybase', 'Sybase'),
94  'odbc' => array('odbc', 'ODBC'),
95  );
96 
97  // Validation checks for this form
98  $this->addCheck(new FormValidatorInSet($this, 'locale', 'required', 'installer.form.localeRequired', array_keys($this->supportedLocales)));
99  $this->addCheck(new FormValidatorCustom($this, 'locale', 'required', 'installer.form.localeRequired', array('AppLocale', 'isLocaleValid')));
100  $this->addCheck(new FormValidatorInSet($this, 'clientCharset', 'required', 'installer.form.clientCharsetRequired', array_keys($this->supportedClientCharsets)));
101  $this->addCheck(new FormValidator($this, 'filesDir', 'required', 'installer.form.filesDirRequired'));
102  $this->addCheck(new FormValidatorInSet($this, 'encryption', 'required', 'installer.form.encryptionRequired', array_keys($this->supportedEncryptionAlgorithms)));
103  $this->addCheck(new FormValidator($this, 'adminUsername', 'required', 'installer.form.usernameRequired'));
104  $this->addCheck(new FormValidatorAlphaNum($this, 'adminUsername', 'required', 'installer.form.usernameAlphaNumeric'));
105  $this->addCheck(new FormValidator($this, 'adminPassword', 'required', 'installer.form.passwordRequired'));
106  $this->addCheck(new FormValidatorCustom($this, 'adminPassword', 'required', 'installer.form.passwordsDoNotMatch', create_function('$password,$form', 'return $password == $form->getData(\'adminPassword2\');'), array(&$this)));
107  $this->addCheck(new FormValidatorEmail($this, 'adminEmail', 'required', 'installer.form.emailRequired'));
108  $this->addCheck(new FormValidatorInSet($this, 'databaseDriver', 'required', 'installer.form.databaseDriverRequired', array_keys($this->supportedDatabaseDrivers)));
109  $this->addCheck(new FormValidator($this, 'databaseName', 'required', 'installer.form.databaseNameRequired'));
110  $this->addCheck(new FormValidatorPost($this));
111 
112  $this->_request = $request;
113  }
114 
118  function display() {
119  $templateMgr = TemplateManager::getManager($this->_request);
120  $templateMgr->assign('localeOptions', $this->supportedLocales);
121  $templateMgr->assign('localesComplete', $this->localesComplete);
122  $templateMgr->assign('clientCharsetOptions', $this->supportedClientCharsets);
123  $templateMgr->assign('connectionCharsetOptions', $this->supportedConnectionCharsets);
124  $templateMgr->assign('databaseCharsetOptions', $this->supportedDatabaseCharsets);
125  $templateMgr->assign('encryptionOptions', $this->supportedEncryptionAlgorithms);
126  $templateMgr->assign('allowFileUploads', get_cfg_var('file_uploads') ? __('common.yes') : __('common.no'));
127  $templateMgr->assign('maxFileUploadSize', get_cfg_var('upload_max_filesize'));
128  $templateMgr->assign('databaseDriverOptions', $this->checkDBDrivers());
129  $templateMgr->assign('supportsMBString', String::hasMBString() ? __('common.yes') : __('common.no'));
130  $templateMgr->assign('phpIsSupportedVersion', version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1);
131  $templateMgr->assign('xslEnabled', Core::checkGeneralPHPModule('xsl'));
132  $templateMgr->assign('xslRequired', true);
133  $templateMgr->assign('phpRequiredVersion', PHP_REQUIRED_VERSION);
134  $templateMgr->assign('phpVersion', PHP_VERSION);
135  $templateMgr->assign('version', VersionCheck::getCurrentCodeVersion());
136 
137  parent::display();
138  }
143  function initData() {
144  $docRoot = dirname($_SERVER['DOCUMENT_ROOT']);
145  if (Core::isWindows()) {
146  // Replace backslashes with slashes for the default files directory.
147  $docRoot = str_replace('\\', '/', $docRoot);
148  }
149 
150  // Add a trailing slash for paths that aren't filesystem root
151  if ($docRoot !== '/') $docRoot .= '/';
152 
153  $this->_data = array(
154  'locale' => AppLocale::getLocale(),
155  'additionalLocales' => array(),
156  'clientCharset' => 'utf-8',
157  'connectionCharset' => '',
158  'databaseCharset' => '',
159  'encryption' => function_exists('sha1')?'sha1':'md5',
160  'filesDir' => $docRoot . 'files',
161  'databaseDriver' => 'mysql',
162  'databaseHost' => 'localhost',
163  'databaseUsername' => 'omp',
164  'databasePassword' => '',
165  'databaseName' => 'omp',
166  'createDatabase' => 1,
167  'oaiRepositoryId' => 'omp.' . $this->_request->getServerHost(),
168  );
169  }
170 
174  function readInputData() {
175  $this->readUserVars(array(
176  'locale',
177  'additionalLocales',
178  'clientCharset',
179  'connectionCharset',
180  'databaseCharset',
181  'filesDir',
182  'encryption',
183  'adminUsername',
184  'adminPassword',
185  'adminPassword2',
186  'adminEmail',
187  'databaseDriver',
188  'databaseHost',
189  'databaseUsername',
190  'databasePassword',
191  'databaseName',
192  'createDatabase',
193  'oaiRepositoryId'
194  ));
196  if ($this->getData('additionalLocales') == null || !is_array($this->getData('additionalLocales'))) {
197  $this->setData('additionalLocales', array());
198  }
199  }
200 
204  function execute() {
205  $templateMgr = TemplateManager::getManager();
206  $installer = new Install($this->_data);
207 
208  if ($installer->execute()) {
209  if (!$installer->wroteConfig()) {
210  // Display config file contents for manual replacement
211  $templateMgr->assign(array('writeConfigFailed' => true, 'configFileContents' => $installer->getConfigContents()));
212  }
213 
214  $templateMgr->display('install/installComplete.tpl');
215 
216  } else {
217  switch ($installer->getErrorType()) {
218  case INSTALLER_ERROR_DB:
219  $this->dbInstallError($installer->getErrorMsg());
220  break;
221  default:
222  $this->installError($installer->getErrorMsg());
223  break;
224  }
225  }
226 
227  $installer->destroy();
228  }
229 
235  function checkDBDrivers() {
236  $dbDrivers = array();
237  foreach ($this->supportedDatabaseDrivers as $driver => $info) {
238  list($module, $name) = $info;
239  if (!extension_loaded($module)) {
240  $name = '[ ' . $name . ' ]';
241  }
242  $dbDrivers[$driver] = $name;
243  }
244  return $dbDrivers;
245  }
246 
251  function installError($errorMsg) {
252  $templateMgr = TemplateManager::getManager();
253  $templateMgr->assign(array('isInstallError' => true, 'errorMsg' => $errorMsg));
254  error_log($errorMsg);
255  $this->display();
256  }
257 
262  function dbInstallError($errorMsg) {
263  $templateMgr = TemplateManager::getManager();
264  if (empty($errorMsg)) $errorMsg = __('common.error.databaseErrorUnknown');
265  $templateMgr->assign(array('isInstallError' => true, 'dbErrorMsg' => $errorMsg));
266  error_log($errorMsg);
267  $this->display();
268  }
269 
270 }
271 
272 ?>
InstallForm($request)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
Form validation check with a custom user function performing the validation check.
Form validation check to make sure the form is POSTed.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
installError($errorMsg)
static isWindows()
Definition: Core.inc.php:128
Perform system installation.
Definition: Install.inc.php:28
Form validation check for email addresses.
Form for system installation.
getData($key)
Definition: Form.inc.php:210
static & getAllLocales()
static getLocale()
static hasMBString()
Definition: String.inc.php:88
static isLocaleComplete($locale)
dbInstallError($errorMsg)
Form validation check for alphanumeric (plus interior dash/underscore) characters only...
static checkGeneralPHPModule($moduleName)
Definition: Core.inc.php:137
Form validation check that checks if value is within a certain set.
Class to represent a form validation check.