Commit | Line | Data |
---|---|---|
d764d4ca | 1 | <?php |
8b5b1028 | 2 | |
d764d4ca | 3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This script creates config.php file during installation. | |
20 | * | |
21 | * @package moodlecore | |
95feaf96 | 22 | * @subpackage install |
d764d4ca | 23 | * @copyright 2009 Petr Skoda (http://skodak.org) |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
25 | */ | |
8b5b1028 | 26 | |
3b093310 | 27 | if (isset($_REQUEST['lang'])) { |
6dbcacee | 28 | $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']); |
8b5b1028 | 29 | } else { |
3b093310 | 30 | $lang = 'en_utf8'; |
8b5b1028 | 31 | } |
32 | ||
3b093310 | 33 | if (isset($_REQUEST['admin'])) { |
6dbcacee | 34 | $admin = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['admin']); |
3b093310 | 35 | } else { |
36 | $admin = 'admin'; | |
8b5b1028 | 37 | } |
38 | ||
082157a8 | 39 | // If config.php exists we just created config.php and need to redirect to continue installation |
3b093310 | 40 | $configfile = './config.php'; |
41 | if (file_exists($configfile)) { | |
42 | header("Location: $admin/index.php?lang=$lang"); | |
43 | die; | |
d36afd6d | 44 | } |
8d783716 | 45 | |
e2253187 PS |
46 | define('CLI_SCRIPT', false); // prevents some warnings later |
47 | define('AJAX_SCRIPT', false); // prevents some warnings later | |
48 | ||
082157a8 | 49 | // make sure PHP errors are displayed - helps with diagnosing of problems |
3b093310 | 50 | @error_reporting(E_ALL); |
51 | @ini_set('display_errors', '1'); | |
3b093310 | 52 | |
082157a8 | 53 | // Check that PHP is of a sufficient version |
3b093310 | 54 | if (version_compare(phpversion(), "5.2.0") < 0) { |
55 | $phpversion = phpversion(); | |
56 | // do NOT localise - lang strings would not work here and we CAN not move it after installib | |
86449d22 | 57 | echo "Sorry, Moodle 2.0 requires PHP 5.2.8 or later (currently using version $phpversion).<br />"; |
3b093310 | 58 | echo "Please upgrade your server software or install latest Moodle 1.9.x instead."; |
59 | die; | |
8b5b1028 | 60 | } |
61 | ||
86449d22 PS |
62 | if (PHP_INT_SIZE > 4) { |
63 | // most probably 64bit PHP - we need a lot more memory | |
64 | $minrequiredmemory = '70M'; | |
65 | } else { | |
66 | // 32bit PHP | |
67 | $minrequiredmemory = '40M'; | |
68 | } | |
69 | // increase or decrease available memory - we need to make sure moodle | |
70 | // installs even with low memory, otherwise developers would overlook | |
71 | // sudden increases of memory needs ;-) | |
72 | @ini_set('memory_limit', $minrequiredmemory); | |
73 | ||
3b093310 | 74 | require dirname(__FILE__).'/lib/installlib.php'; |
bd507453 | 75 | |
3b093310 | 76 | // TODO: add lang detection here if empty $_REQUEST['lang'] |
3b3b8029 | 77 | |
5c1fb7d4 | 78 | // distro specific customisation |
79 | $distro = null; | |
768408e8 | 80 | if (file_exists('install/distrolib.php')) { |
81 | require_once('install/distrolib.php'); | |
82 | if (function_exists('distro_get_config')) { | |
83 | $distro = distro_get_config(); | |
84 | } | |
5c1fb7d4 | 85 | } |
86 | ||
3b093310 | 87 | $config = new stdClass(); |
88 | $config->lang = $lang; | |
3b3b8029 | 89 | |
3b093310 | 90 | if (!empty($_POST)) { |
91 | if (install_ini_get_bool('magic_quotes_gpc')) { | |
fa53493e | 92 | $_POST = array_map('stripslashes', $_POST); |
3b093310 | 93 | } |
3b3b8029 | 94 | |
3b093310 | 95 | $config->stage = (int)$_POST['stage']; |
56ca1c60 | 96 | |
3b093310 | 97 | if (isset($_POST['previous'])) { |
98 | $config->stage--; | |
5167827b | 99 | if (INSTALL_DATABASETYPE and !empty($distro->dbtype)) { |
100 | $config->stage--; | |
101 | } | |
3b093310 | 102 | if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_DOWNLOADLANG) { |
103 | $config->stage--; | |
56ca1c60 | 104 | } |
3b093310 | 105 | } else if (isset($_POST['next'])) { |
106 | $config->stage++; | |
d36afd6d | 107 | } |
3b3b8029 | 108 | |
3b093310 | 109 | $config->dbtype = trim($_POST['dbtype']); |
110 | $config->dbhost = trim($_POST['dbhost']); | |
111 | $config->dbuser = trim($_POST['dbuser']); | |
112 | $config->dbpass = trim($_POST['dbpass']); | |
113 | $config->dbname = trim($_POST['dbname']); | |
114 | $config->prefix = trim($_POST['prefix']); | |
115 | $config->dbsocket = (int)(!empty($_POST['dbsocket'])); | |
3b3b8029 | 116 | |
3b093310 | 117 | $config->dirroot = trim($_POST['dirroot']); |
118 | $config->admin = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']); | |
53a0367d | 119 | |
3b093310 | 120 | $config->dataroot = trim($_POST['dataroot']); |
d36afd6d | 121 | |
3b3b8029 | 122 | } else { |
3b093310 | 123 | $config->stage = INSTALL_WELCOME; |
8b5b1028 | 124 | |
4f9dba35 | 125 | $config->dbtype = empty($distro->dbtype) ? '' : $distro->dbtype; // let distro skip dbtype selection |
6724b059 | 126 | $config->dbhost = empty($distro->dbhost) ? 'localhost' : $distro->dbhost; // let distros set dbhost |
127 | $config->dbuser = empty($distro->dbuser) ? '' : $distro->dbuser; // let distros set dbuser | |
3b093310 | 128 | $config->dbpass = ''; |
129 | $config->dbname = 'moodle'; | |
130 | $config->prefix = 'mdl_'; | |
131 | $config->dbsocket = 0; | |
53a0367d | 132 | |
f571f5f5 | 133 | $config->dirroot = str_replace('\\', '/', dirname(__FILE__)); // Fix for win32 |
3b093310 | 134 | $config->admin = 'admin'; |
8b5b1028 | 135 | |
4f9dba35 | 136 | $config->dataroot = empty($distro->dataroot) ? null : $distro->dataroot; // initialised later after including libs or by distro |
3b093310 | 137 | } |
8b5b1028 | 138 | |
082157a8 | 139 | // Fake some settings so that we can use selected functions from moodlelib.php and weblib.php |
3b093310 | 140 | $CFG = new stdClass(); |
141 | $CFG->lang = $config->lang; | |
f571f5f5 | 142 | $CFG->dirroot = str_replace('\\', '/', dirname(__FILE__)); // Fix for win32 |
3b093310 | 143 | $CFG->libdir = "$CFG->dirroot/lib"; |
144 | $CFG->wwwroot = install_guess_wwwroot(); // can not be changed - ppl must use the real address when installing | |
145 | $CFG->httpswwwroot = $CFG->wwwroot; | |
3b093310 | 146 | $CFG->dataroot = $config->dataroot; |
147 | $CFG->admin = $config->admin; | |
148 | $CFG->docroot = 'http://docs.moodle.org'; | |
4b9efec4 | 149 | $CFG->directorypermissions = 00777; |
3b093310 | 150 | $CFG->running_installer = true; |
8d783716 | 151 | |
082157a8 | 152 | // Require all needed libs |
d36afd6d | 153 | require_once($CFG->libdir.'/setuplib.php'); |
86449d22 PS |
154 | |
155 | // we need to make sure we have enough memory to load all libraries | |
156 | $memlimit = @ini_get('memory_limit'); | |
157 | if (!empty($memlimit) and $memlimit != -1) { | |
158 | if (get_real_size($memlimit) < get_real_size($minrequiredmemory)) { | |
159 | // do NOT localise - lang strings would not work here and we CAN not move it to later place | |
160 | echo "Sorry, Moodle 2.0 requires at least {$minrequiredmemory}B of PHP memory.<br />"; | |
161 | echo "Please contact server administrator to fix PHP.ini memory settings."; | |
162 | die; | |
163 | } | |
164 | } | |
165 | ||
166 | // Continue with lib loading | |
3b093310 | 167 | require_once($CFG->libdir.'/textlib.class.php'); |
d36afd6d | 168 | require_once($CFG->libdir.'/weblib.php'); |
318f0519 | 169 | require_once($CFG->libdir.'/outputlib.php'); |
3b093310 | 170 | require_once($CFG->libdir.'/dmllib.php'); |
251387d0 | 171 | require_once($CFG->libdir.'/moodlelib.php'); |
d4a03c00 | 172 | require_once($CFG->libdir .'/pagelib.php'); |
3b093310 | 173 | require_once($CFG->libdir.'/deprecatedlib.php'); |
251387d0 | 174 | require_once($CFG->libdir.'/adminlib.php'); |
d36afd6d | 175 | require_once($CFG->libdir.'/environmentlib.php'); |
176 | require_once($CFG->libdir.'/xmlize.php'); | |
177 | require_once($CFG->libdir.'/componentlib.class.php'); | |
3b093310 | 178 | |
318f0519 | 179 | //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else |
180 | //the problem is that we need specific version of quickforms and hacked excel files :-( | |
181 | ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path')); | |
182 | //point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else | |
183 | ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path')); | |
6f5e0852 | 184 | |
3b093310 | 185 | require('version.php'); |
9ace5094 | 186 | $CFG->target_release = $release; |
3b093310 | 187 | |
188 | $SESSION = new object(); | |
189 | $SESSION->lang = $CFG->lang; | |
190 | ||
191 | $USER = new object(); | |
192 | $USER->id = 0; | |
193 | ||
194 | $COURSE = new object(); | |
195 | $COURSE->id = 0; | |
196 | ||
197 | $SITE = $COURSE; | |
198 | define('SITEID', 0); | |
199 | ||
200 | $hint_dataroot = ''; | |
201 | $hint_dirroot = ''; | |
202 | $hint_admindir = ''; | |
203 | $hint_database = ''; | |
204 | ||
082157a8 | 205 | // Are we in help mode? |
3b093310 | 206 | if (isset($_GET['help'])) { |
207 | install_print_help_page($_GET['help']); | |
208 | } | |
209 | ||
082157a8 | 210 | // send css? |
3b093310 | 211 | if (isset($_GET['css'])) { |
212 | install_css_styles(); | |
6d5a22b2 | 213 | } |
8b5b1028 | 214 | |
082157a8 | 215 | //first time here? find out suitable dataroot |
3b093310 | 216 | if (is_null($CFG->dataroot)) { |
217 | $CFG->dataroot = str_replace('\\', '/', dirname(dirname(__FILE__)).'/moodledata'); | |
add47d44 | 218 | |
add47d44 | 219 | $i = 0; //safety check - dirname might return some unexpected results |
220 | while(is_dataroot_insecure()) { | |
221 | $parrent = dirname($CFG->dataroot); | |
222 | $i++; | |
b735d140 | 223 | if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) { |
add47d44 | 224 | $CFG->dataroot = ''; //can not find secure location for dataroot |
225 | break; | |
226 | } | |
227 | $CFG->dataroot = dirname($parrent).'/moodledata'; | |
228 | } | |
3b093310 | 229 | $config->dataroot = $CFG->dataroot; |
230 | $config->stage = INSTALL_WELCOME; | |
8b5b1028 | 231 | } |
232 | ||
3b093310 | 233 | // now let's do the stage work |
234 | if ($config->stage < INSTALL_WELCOME) { | |
235 | $config->stage = INSTALL_WELCOME; | |
236 | } | |
237 | if ($config->stage > INSTALL_SAVE) { | |
238 | $config->stage = INSTALL_SAVE; | |
8d783716 | 239 | } |
240 | ||
241 | ||
51e3e0b9 | 242 | |
3b093310 | 243 | if ($config->stage == INSTALL_SAVE) { |
244 | $database = moodle_database::get_driver_instance($config->dbtype, 'native'); | |
245 | if (!$database->driver_installed()) { | |
246 | $config->stage = INSTALL_DATABASETYPE; | |
247 | } else { | |
082157a8 | 248 | if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation |
a0b7200d | 249 | $distro = distro_pre_create_db($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbsocket'=>$config->dbsocket), $distro); |
768408e8 | 250 | } |
a0b7200d | 251 | $hint_database = install_db_validate($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbsocket'=>$config->dbsocket)); |
edd3a5db | 252 | |
3b093310 | 253 | if ($hint_database === '') { |
082157a8 | 254 | // extra hackery needed for symbolic link support |
255 | if ($CFG->dirroot !== $config->dirroot) { | |
256 | $CFG->dirroot = $config->dirroot; | |
257 | $userealpath = true; | |
3b093310 | 258 | } else { |
082157a8 | 259 | $userealpath = false; |
3b093310 | 260 | } |
082157a8 | 261 | $configphp = install_generate_configphp($database, $CFG, $userealpath); |
53a0367d | 262 | |
3b093310 | 263 | umask(0137); |
3b093310 | 264 | if (($fh = @fopen($configfile, 'w')) !== false) { |
265 | fwrite($fh, $configphp); | |
266 | fclose($fh); | |
267 | } | |
082157a8 | 268 | |
3b093310 | 269 | if (file_exists($configfile)) { |
270 | // config created, let's continue! | |
271 | redirect("$CFG->wwwroot/$config->admin/index.php?lang=$config->lang"); | |
272 | } | |
2df3a721 | 273 | |
3b093310 | 274 | install_print_header($config, 'config.php', |
275 | get_string('configurationcompletehead', 'install'), | |
276 | get_string('configurationcompletesub', 'install').get_string('configfilenotwritten', 'install')); | |
277 | echo '<div class="configphp"><pre>'; | |
278 | echo p($configphp); | |
279 | echo '</pre></div>'; | |
bba0beae | 280 | |
3b093310 | 281 | install_print_footer($config); |
282 | die; | |
8b5b1028 | 283 | |
3b093310 | 284 | } else { |
285 | $config->stage = INSTALL_DATABASE; | |
286 | } | |
6d5a22b2 | 287 | } |
8b5b1028 | 288 | } |
289 | ||
290 | ||
291 | ||
5167827b | 292 | if ($config->stage == INSTALL_DOWNLOADLANG) { |
293 | if (empty($CFG->dataroot)) { | |
294 | $config->stage = INSTALL_PATHS; | |
295 | ||
296 | } else if (is_dataroot_insecure()) { | |
297 | $hint_dataroot = get_string('pathsunsecuredataroot', 'install'); | |
298 | $config->stage = INSTALL_PATHS; | |
299 | ||
cf89052a | 300 | } else if (!file_exists($CFG->dataroot)) { |
301 | $a = new stdClass(); | |
302 | $a->parent = dirname($CFG->dataroot); | |
303 | $a->dataroot = $CFG->dataroot; | |
304 | if (!is_writable(dirname($CFG->dataroot))) { | |
305 | $hint_dataroot = get_string('pathsroparentdataroot', 'install', $a); | |
306 | $config->stage = INSTALL_PATHS; | |
307 | } else { | |
082157a8 | 308 | if (!make_upload_directory('lang', false)) { |
cf89052a | 309 | $hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a); |
310 | $config->stage = INSTALL_PATHS; | |
311 | } | |
312 | } | |
313 | } | |
314 | ||
315 | if (empty($hint_dataroot) and !is_writable($CFG->dataroot)) { | |
5167827b | 316 | $hint_dataroot = get_string('pathsrodataroot', 'install'); |
317 | $config->stage = INSTALL_PATHS; | |
318 | } | |
319 | ||
320 | if ($config->dirroot === '' or !file_exists($config->dirroot)) { | |
321 | $hint_dirroot = get_string('pathswrongdirroot', 'install'); | |
322 | $config->stage = INSTALL_PATHS; | |
323 | } | |
324 | ||
325 | if ($config->admin === '' or !file_exists($config->dirroot.'/'.$config->admin.'/environment.xml')) { | |
326 | $hint_admindir = get_string('pathswrongadmindir', 'install'); | |
327 | $config->stage = INSTALL_PATHS; | |
328 | } | |
329 | } | |
330 | ||
331 | ||
332 | ||
333 | if ($config->stage == INSTALL_DOWNLOADLANG) { | |
334 | // no need to download anything if en lang selected | |
335 | if ($CFG->lang == 'en_utf8') { | |
336 | $config->stage = INSTALL_DATABASETYPE; | |
337 | } | |
338 | } | |
339 | ||
340 | ||
341 | ||
342 | if ($config->stage == INSTALL_DATABASETYPE) { | |
343 | // skip db selection if distro package supports only one db | |
344 | if (!empty($distro->dbtype)) { | |
345 | $config->stage = INSTALL_DATABASE; | |
346 | } | |
347 | } | |
348 | ||
349 | ||
08261d3a | 350 | if ($config->stage == INSTALL_DOWNLOADLANG) { |
351 | $downloaderror = ''; | |
352 | ||
082157a8 | 353 | // Create necessary lang dir |
08261d3a | 354 | if (!make_upload_directory('lang', false)) { |
355 | $downloaderror = get_string('cannotcreatelangdir', 'error'); | |
356 | ||
082157a8 | 357 | // Download and install lang component |
08261d3a | 358 | } else if ($cd = new component_installer('http://download.moodle.org', 'lang16', $CFG->lang.'.zip', 'languages.md5', 'lang')) { |
359 | if ($cd->install() == COMPONENT_ERROR) { | |
360 | if ($cd->get_error() == 'remotedownloaderror') { | |
361 | $a = new stdClass(); | |
362 | $a->url = 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip'; | |
363 | $a->dest = $CFG->dataroot.'/lang'; | |
364 | $downloaderror = get_string($cd->get_error(), 'error', $a); | |
365 | } else { | |
366 | $downloaderror = get_string($cd->get_error(), 'error'); | |
367 | } | |
368 | } else { | |
369 | // install parent lang if defined | |
370 | if ($parentlang = get_parent_language()) { | |
371 | if ($cd = new component_installer('http://download.moodle.org', 'lang16', $parentlang.'.zip', 'languages.md5', 'lang')) { | |
372 | $cd->install(); | |
373 | } | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
378 | if ($downloaderror !== '') { | |
379 | install_print_header($config, get_string('language'), get_string('langdownloaderror', 'install', $CFG->lang), $downloaderror); | |
380 | install_print_footer($config); | |
381 | die; | |
382 | } else { | |
383 | if (empty($distro->dbtype)) { | |
384 | $config->stage = INSTALL_DATABASETYPE; | |
385 | } else { | |
386 | $config->stage = INSTALL_DATABASE; | |
387 | } | |
388 | } | |
389 | } | |
390 | ||
5167827b | 391 | |
3b093310 | 392 | if ($config->stage == INSTALL_DATABASE) { |
393 | $database = moodle_database::get_driver_instance($config->dbtype, 'native'); | |
8b5b1028 | 394 | |
3b093310 | 395 | $sub = '<h3>'.$database->get_name().'</h3>'.$database->get_configuration_help(); |
8d783716 | 396 | |
3b093310 | 397 | install_print_header($config, get_string('database', 'install'), get_string('databasehead', 'install'), $sub); |
53a0367d | 398 | |
3b093310 | 399 | $strdbhost = get_string('databasehost', 'install'); |
400 | $strdbname = get_string('databasename', 'install'); | |
401 | $strdbuser = get_string('databaseuser', 'install'); | |
402 | $strdbpass = get_string('databasepass', 'install'); | |
403 | $strprefix = get_string('dbprefix', 'install'); | |
404 | $strdbsocket = get_string('databasesocket', 'install'); | |
8d783716 | 405 | |
3b093310 | 406 | echo '<div class="userinput">'; |
6724b059 | 407 | |
408 | $disabled = empty($distro->dbhost) ? '' : 'disabled="disabled'; | |
3b093310 | 409 | echo '<div class="formrow"><label for="id_dbhost" class="formlabel">'.$strdbhost.'</label>'; |
6724b059 | 410 | echo '<input id="id_dbhost" name="dbhost" '.$disabled.' type="text" value="'.s($config->dbhost).'" size="30" class="forminput" />'; |
3b093310 | 411 | echo '</div>'; |
8b5b1028 | 412 | |
3b093310 | 413 | echo '<div class="formrow"><label for="id_dbname" class="formlabel">'.$strdbname.'</label>'; |
414 | echo '<input id="id_dbname" name="dbname" type="text" value="'.s($config->dbname).'" size="30" class="forminput" />'; | |
415 | echo '</div>'; | |
86453d8b | 416 | |
6724b059 | 417 | $disabled = empty($distro->dbuser) ? '' : 'disabled="disabled'; |
3b093310 | 418 | echo '<div class="formrow"><label for="id_dbuser" class="formlabel">'.$strdbuser.'</label>'; |
6724b059 | 419 | echo '<input id="id_dbuser" name="dbuser" '.$disabled.' type="text" value="'.s($config->dbuser).'" size="30" class="forminput" />'; |
3b093310 | 420 | echo '</div>'; |
86453d8b | 421 | |
3b093310 | 422 | echo '<div class="formrow"><label for="id_dbpass" class="formlabel">'.$strdbpass.'</label>'; |
423 | // no password field here, the password may be visible in config.php if we can not write it to disk | |
424 | echo '<input id="id_dbpass" name="dbpass" type="text" value="'.s($config->dbpass).'" size="30" class="forminput" />'; | |
425 | echo '</div>'; | |
86453d8b | 426 | |
3b093310 | 427 | echo '<div class="formrow"><label for="id_prefix" class="formlabel">'.$strprefix.'</label>'; |
428 | echo '<input id="id_prefix" name="prefix" type="text" value="'.s($config->prefix).'" size="10" class="forminput" />'; | |
429 | echo '</div>'; | |
fe515206 | 430 | |
3b093310 | 431 | if (!(stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin'))) { |
432 | $checked = $config->dbsocket ? 'checked="checked' : ''; | |
433 | echo '<div class="formrow"><label for="id_dbsocket" class="formlabel">'.$strdbsocket.'</label>'; | |
434 | echo '<input type="hidden" value="0" name="dbsocket" />'; | |
435 | echo '<input type="checkbox" id="id_dbsocket" value="1" name="dbsocket" '.$checked.' class="forminput" />'; | |
436 | echo '</div>'; | |
8b5b1028 | 437 | } |
438 | ||
3b093310 | 439 | echo '<div class="hint">'.$hint_database.'</div>'; |
440 | echo '</div>'; | |
441 | install_print_footer($config); | |
442 | die; | |
8b5b1028 | 443 | } |
444 | ||
445 | ||
3b093310 | 446 | if ($config->stage == INSTALL_DATABASETYPE) { |
082157a8 | 447 | // Finally ask for DB type |
3b093310 | 448 | install_print_header($config, get_string('database', 'install'), |
449 | get_string('databasetypehead', 'install'), | |
450 | get_string('databasetypesub', 'install')); | |
51e3e0b9 | 451 | |
3b093310 | 452 | // TODO: move this PHP5 code to lib/installib.php so that this file parses in PHP4 |
453 | $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'), | |
454 | 'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'), | |
455 | 'oci' => moodle_database::get_driver_instance('oci', 'native'), | |
456 | //'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // new MS sql driver - win32 only | |
457 | //'mssql' => moodle_database::get_driver_instance('mssql', 'native'), // FreeTDS driver | |
458 | ); | |
51e3e0b9 | 459 | |
3b093310 | 460 | echo '<div class="userinput">'; |
461 | echo '<div class="formrow"><label class="formlabel" for="dbtype">'.get_string('dbtype', 'install').'</label>'; | |
462 | echo '<select id="dbtype" name="dbtype" class="forminput">'; | |
463 | $disabled = array(); | |
464 | $options = array(); | |
465 | foreach ($databases as $type=>$database) { | |
466 | if ($database->driver_installed() !== true) { | |
467 | $disabled[$type] = $database; | |
468 | continue; | |
469 | } | |
470 | echo '<option value="'.s($type).'">'.$database->get_name().'</option>'; | |
51e3e0b9 | 471 | } |
3b093310 | 472 | if ($disabled) { |
473 | echo '<optgroup label="'.s(get_string('notavailable')).'">'; | |
474 | foreach ($disabled as $type=>$database) { | |
475 | echo '<option value="'.s($type).'" class="notavailable">'.$database->get_name().'</option>'; | |
476 | } | |
477 | echo '</optgroup>'; | |
8b5b1028 | 478 | } |
3b093310 | 479 | echo '</select></div>'; |
480 | echo '</div>'; | |
53a0367d | 481 | |
3b093310 | 482 | install_print_footer($config); |
483 | die; | |
8b5b1028 | 484 | } |
485 | ||
486 | ||
487 | ||
3b093310 | 488 | if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) { |
489 | $version_fail = (version_compare(phpversion(), "5.2.8") < 0); | |
490 | $curl_fail = ($lang !== 'en_utf8' and !extension_loaded('curl')); // needed for lang pack download | |
491 | $zip_fail = ($lang !== 'en_utf8' and !extension_loaded('zip')); // needed for lang pack download | |
8b5b1028 | 492 | |
3b093310 | 493 | if ($version_fail or $curl_fail or $zip_fail) { |
494 | $config->stage = INSTALL_ENVIRONMENT; | |
8b5b1028 | 495 | |
3b093310 | 496 | install_print_header($config, get_string('environment', 'install'), |
497 | get_string('errorsinenvironment', 'install'), | |
498 | get_string('environmentsub2', 'install')); | |
8b5b1028 | 499 | |
3b093310 | 500 | echo '<div id="envresult"><dl>'; |
501 | if ($version_fail) { | |
502 | $a = (object)array('needed'=>'5.2.8', 'current'=>phpversion()); | |
503 | echo '<dt>'.get_string('phpversion', 'install').'</dt><dd>'.get_string('environmentrequireversion', 'admin', $a).'</dd>'; | |
504 | } | |
505 | if ($curl_fail) { | |
506 | echo '<dt>'.get_string('phpextension', 'install', 'cURL').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>'; | |
507 | } | |
508 | if ($zip_fail) { | |
509 | echo '<dt>'.get_string('phpextension', 'install', 'Zip').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>'; | |
510 | } | |
511 | echo '</dl></div>'; | |
8d783716 | 512 | |
3b093310 | 513 | install_print_footer($config, true); |
514 | die; | |
51e3e0b9 | 515 | |
8b5b1028 | 516 | } else { |
3b093310 | 517 | $config->stage = INSTALL_PATHS; |
8b5b1028 | 518 | } |
8b5b1028 | 519 | } |
520 | ||
8b5b1028 | 521 | |
8b5b1028 | 522 | |
3b093310 | 523 | if ($config->stage == INSTALL_PATHS) { |
524 | $paths = array('wwwroot' => get_string('wwwroot', 'install'), | |
525 | 'dirroot' => get_string('dirroot', 'install'), | |
526 | 'dataroot' => get_string('dataroot', 'install'), | |
527 | 'admindir' => get_string('admindirname', 'install')); | |
627d326a | 528 | |
3b093310 | 529 | $sub = '<dl>'; |
530 | foreach ($paths as $path=>$name) { | |
531 | $sub .= '<dt>'.$name.'</dt><dd>'.get_string('pathssub'.$path, 'install').'</dd>'; | |
8b5b1028 | 532 | } |
3b093310 | 533 | $sub .= '</dl>'; |
cd0e958e | 534 | |
3b093310 | 535 | install_print_header($config, get_string('paths', 'install'), get_string('pathshead', 'install'), $sub); |
627d326a | 536 | |
3b093310 | 537 | $strwwwroot = get_string('wwwroot', 'install'); |
538 | $strdirroot = get_string('dirroot', 'install'); | |
539 | $strdataroot = get_string('dataroot', 'install'); | |
540 | $stradmindirname = get_string('admindirname', 'install'); | |
cdef6d42 | 541 | |
3b093310 | 542 | echo '<div class="userinput">'; |
543 | echo '<div class="formrow"><label for="id_wwwroot" class="formlabel">'.$paths['wwwroot'].'</label>'; | |
544 | echo '<input id="id_wwwroot" name="wwwroot" type="text" value="'.s($CFG->wwwroot).'" disabled="disabled" size="45" class="forminput" />'; | |
545 | echo '</div>'; | |
cd0e958e | 546 | |
3b093310 | 547 | echo '<div class="formrow"><label for="id_dirroot" class="formlabel">'.$paths['dirroot'].'</label>'; |
548 | echo '<input id="id_dirroot" name="dirroot" type="text" value="'.s($config->dirroot).'" size="45"class="forminput" />'; | |
549 | if ($hint_dirroot !== '') { | |
550 | echo '<div class="hint">'.$hint_dirroot.'</div>'; | |
cdef6d42 | 551 | } |
3b093310 | 552 | echo '</div>'; |
53a0367d | 553 | |
3b093310 | 554 | echo '<div class="formrow"><label for="id_dataroot" class="formlabel">'.$paths['dataroot'].'</label>'; |
555 | echo '<input id="id_dataroot" name="dataroot" type="text" value="'.s($config->dataroot).'" size="45" class="forminput" />'; | |
556 | if ($hint_dataroot !== '') { | |
557 | echo '<div class="hint">'.$hint_dataroot.'</div>'; | |
cdef6d42 | 558 | } |
3b093310 | 559 | echo '</div>'; |
8b5b1028 | 560 | |
8d783716 | 561 | |
3b093310 | 562 | if (file_exists("$CFG->dirroot/admin/environment.xml")) { |
563 | $disabled = 'disabled="disabled"'; | |
8d783716 | 564 | } else { |
3b093310 | 565 | $disabled = ''; |
8d783716 | 566 | } |
3b093310 | 567 | echo '<div class="formrow"><label for="id_admin" class="formlabel">'.$paths['admindir'].'</label>'; |
568 | echo '<input id="id_admin" name="admin" type="text" value="'.s($config->admin).'" '.$disabled.' size="10" class="forminput" />'; | |
569 | if ($hint_admindir !== '') { | |
570 | echo '<div class="hint">'.$hint_admindir.'</div>'; | |
8d783716 | 571 | } |
3b093310 | 572 | echo '</div>'; |
8d783716 | 573 | |
3b093310 | 574 | echo '</div>'; |
8d783716 | 575 | |
3b093310 | 576 | install_print_footer($config); |
577 | die; | |
8d783716 | 578 | } |
579 | ||
86453d8b | 580 | |
86453d8b | 581 | |
3b093310 | 582 | $config->stage = INSTALL_WELCOME; |
64c368e3 | 583 | |
584 | if ($distro) { | |
585 | ob_start(); | |
586 | include('install/distribution.html'); | |
587 | $sub = ob_get_clean(); | |
588 | ||
589 | install_print_header($config, get_string('language'), | |
590 | get_string('chooselanguagehead', 'install'), | |
591 | $sub); | |
082157a8 | 592 | |
64c368e3 | 593 | } else { |
594 | install_print_header($config, get_string('language'), | |
595 | get_string('chooselanguagehead', 'install'), | |
596 | get_string('chooselanguagesub', 'install')); | |
597 | } | |
86453d8b | 598 | |
3b093310 | 599 | $languages = install_get_list_of_languages(); |
600 | echo '<div class="userinput">'; | |
601 | echo '<div class="formrow"><label class="formlabel" for="langselect">'.get_string('language').'</label>'; | |
4d928665 | 602 | echo '<select id="langselect" name="lang" class="forminput" onchange="this.form.submit()">'; |
3b093310 | 603 | foreach ($languages as $name=>$value) { |
604 | $selected = ($name == $CFG->lang) ? 'selected="selected"' : ''; | |
605 | echo '<option value="'.s($name).'" '.$selected.'>'.$value.'</option>'; | |
86453d8b | 606 | } |
3b093310 | 607 | echo '</select></div>'; |
608 | echo '</div>'; | |
86453d8b | 609 | |
3b093310 | 610 | install_print_footer($config); |
611 | die; | |
2961367e | 612 |