MDL-41254 backup Raise time and memory limit in precheck.
[moodle.git] / install.php
CommitLineData
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 *
b7315f35 21 * @package core
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 27if (isset($_REQUEST['lang'])) {
6dbcacee 28 $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']);
8b5b1028 29} else {
3a915b06 30 $lang = 'en';
8b5b1028 31}
32
3b093310 33if (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';
41if (file_exists($configfile)) {
42 header("Location: $admin/index.php?lang=$lang");
43 die;
d36afd6d 44}
8d783716 45
e2253187
PS
46define('CLI_SCRIPT', false); // prevents some warnings later
47define('AJAX_SCRIPT', false); // prevents some warnings later
94ef67cf 48define('CACHE_DISABLE_ALL', true); // Disables caching.. just in case.
1abf2f6a 49define('PHPUNIT_TEST', false);
d7245e34 50define('IGNORE_COMPONENT_CACHE', true);
e2253187 51
4ede587e
PS
52// Servers should define a default timezone in php.ini, but if they don't then make sure something is defined.
53// This is a quick hack. Ideally we should ask the admin for a value. See MDL-22625 for more on this.
54if (function_exists('date_default_timezone_set') and function_exists('date_default_timezone_get')) {
55 @date_default_timezone_set(@date_default_timezone_get());
56}
57
082157a8 58// make sure PHP errors are displayed - helps with diagnosing of problems
3b093310 59@error_reporting(E_ALL);
60@ini_set('display_errors', '1');
3b093310 61
68cd60b7 62// Check that PHP is of a sufficient version.
0fd23b76 63if (version_compare(phpversion(), '5.3.3') < 0) {
3b093310 64 $phpversion = phpversion();
65 // do NOT localise - lang strings would not work here and we CAN not move it after installib
0fd23b76 66 echo "Moodle 2.5 or later requires at least PHP 5.3.3 (currently using version $phpversion).<br />";
eab044a0 67 echo "Please upgrade your server software or install older Moodle version.";
3b093310 68 die;
8b5b1028 69}
70
695940df
PS
71// make sure iconv is available and actually works
72if (!function_exists('iconv')) {
73 // this should not happen, this must be very borked install
7d85a4e2 74 echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
695940df
PS
75 die();
76}
695940df 77
86449d22
PS
78if (PHP_INT_SIZE > 4) {
79 // most probably 64bit PHP - we need a lot more memory
80 $minrequiredmemory = '70M';
81} else {
82 // 32bit PHP
83 $minrequiredmemory = '40M';
84}
85// increase or decrease available memory - we need to make sure moodle
86// installs even with low memory, otherwise developers would overlook
87// sudden increases of memory needs ;-)
88@ini_set('memory_limit', $minrequiredmemory);
89
460ebd6c
PS
90/** Used by library scripts to check they are being called by Moodle */
91define('MOODLE_INTERNAL', true);
92
1abf2f6a
PS
93require_once(__DIR__.'/lib/classes/component.php');
94require_once(__DIR__.'/lib/installlib.php');
bd507453 95
3b093310 96// TODO: add lang detection here if empty $_REQUEST['lang']
3b3b8029 97
5c1fb7d4 98// distro specific customisation
99$distro = null;
768408e8 100if (file_exists('install/distrolib.php')) {
101 require_once('install/distrolib.php');
102 if (function_exists('distro_get_config')) {
103 $distro = distro_get_config();
104 }
5c1fb7d4 105}
106
3b093310 107$config = new stdClass();
108$config->lang = $lang;
3b3b8029 109
3b093310 110if (!empty($_POST)) {
111 if (install_ini_get_bool('magic_quotes_gpc')) {
fa53493e 112 $_POST = array_map('stripslashes', $_POST);
3b093310 113 }
3b3b8029 114
3b093310 115 $config->stage = (int)$_POST['stage'];
56ca1c60 116
3b093310 117 if (isset($_POST['previous'])) {
118 $config->stage--;
5167827b 119 if (INSTALL_DATABASETYPE and !empty($distro->dbtype)) {
120 $config->stage--;
121 }
3b093310 122 if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_DOWNLOADLANG) {
123 $config->stage--;
56ca1c60 124 }
3b093310 125 } else if (isset($_POST['next'])) {
126 $config->stage++;
d36afd6d 127 }
3b3b8029 128
3b093310 129 $config->dbtype = trim($_POST['dbtype']);
130 $config->dbhost = trim($_POST['dbhost']);
131 $config->dbuser = trim($_POST['dbuser']);
132 $config->dbpass = trim($_POST['dbpass']);
133 $config->dbname = trim($_POST['dbname']);
134 $config->prefix = trim($_POST['prefix']);
b29ca9b5
PS
135 $config->dbport = (int)trim($_POST['dbport']);
136 $config->dbsocket = trim($_POST['dbsocket']);
137
138 if ($config->dbport <= 0) {
139 $config->dbport = '';
140 }
3b3b8029 141
3b093310 142 $config->admin = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']);
53a0367d 143
3b093310 144 $config->dataroot = trim($_POST['dataroot']);
d36afd6d 145
3b3b8029 146} else {
3b093310 147 $config->stage = INSTALL_WELCOME;
8b5b1028 148
4f9dba35 149 $config->dbtype = empty($distro->dbtype) ? '' : $distro->dbtype; // let distro skip dbtype selection
6724b059 150 $config->dbhost = empty($distro->dbhost) ? 'localhost' : $distro->dbhost; // let distros set dbhost
151 $config->dbuser = empty($distro->dbuser) ? '' : $distro->dbuser; // let distros set dbuser
3b093310 152 $config->dbpass = '';
153 $config->dbname = 'moodle';
154 $config->prefix = 'mdl_';
b29ca9b5
PS
155 $config->dbport = empty($distro->dbport) ? '' : $distro->dbport;
156 $config->dbsocket = empty($distro->dbsocket) ? '' : $distro->dbsocket;
53a0367d 157
3b093310 158 $config->admin = 'admin';
8b5b1028 159
4f9dba35 160 $config->dataroot = empty($distro->dataroot) ? null : $distro->dataroot; // initialised later after including libs or by distro
3b093310 161}
8b5b1028 162
cf4cef7d 163// Fake some settings so that we can use selected functions from moodlelib.php, weblib.php and filelib.php.
3b093310 164$CFG = new stdClass();
165$CFG->lang = $config->lang;
3b5ff37f 166$CFG->dirroot = dirname(__FILE__);
3b093310 167$CFG->libdir = "$CFG->dirroot/lib";
168$CFG->wwwroot = install_guess_wwwroot(); // can not be changed - ppl must use the real address when installing
169$CFG->httpswwwroot = $CFG->wwwroot;
3b093310 170$CFG->dataroot = $config->dataroot;
f848c0f6 171$CFG->tempdir = $CFG->dataroot.'/temp';
12812ad5 172$CFG->cachedir = $CFG->dataroot.'/cache';
85b38061 173$CFG->localcachedir = $CFG->dataroot.'/localcache';
3b093310 174$CFG->admin = $config->admin;
175$CFG->docroot = 'http://docs.moodle.org';
d8fa5a13
PS
176$CFG->langotherroot = $CFG->dataroot.'/lang';
177$CFG->langlocalroot = $CFG->dataroot.'/lang';
70801baf 178$CFG->directorypermissions = isset($distro->directorypermissions) ? $distro->directorypermissions : 00777; // let distros set dir permissions
7f0ffc54
PS
179$CFG->filepermissions = ($CFG->directorypermissions & 0666);
180$CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777);
3b093310 181$CFG->running_installer = true;
3a915b06 182$CFG->early_install_lang = true;
cf4cef7d 183$CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
96f81ea3
PS
184$CFG->debug = (E_ALL | E_STRICT);
185$CFG->debugdisplay = true;
186$CFG->debugdeveloper = true;
8d783716 187
082157a8 188// Require all needed libs
d36afd6d 189require_once($CFG->libdir.'/setuplib.php');
86449d22
PS
190
191// we need to make sure we have enough memory to load all libraries
192$memlimit = @ini_get('memory_limit');
193if (!empty($memlimit) and $memlimit != -1) {
194 if (get_real_size($memlimit) < get_real_size($minrequiredmemory)) {
195 // do NOT localise - lang strings would not work here and we CAN not move it to later place
eab044a0 196 echo "Moodle requires at least {$minrequiredmemory}B of PHP memory.<br />";
86449d22
PS
197 echo "Please contact server administrator to fix PHP.ini memory settings.";
198 die;
199 }
200}
201
202// Continue with lib loading
d534708f 203require_once($CFG->libdir.'/classes/text.php');
99a9d8d9
PS
204require_once($CFG->libdir.'/classes/string_manager.php');
205require_once($CFG->libdir.'/classes/string_manager_install.php');
206require_once($CFG->libdir.'/classes/string_manager_standard.php');
d36afd6d 207require_once($CFG->libdir.'/weblib.php');
318f0519 208require_once($CFG->libdir.'/outputlib.php');
3b093310 209require_once($CFG->libdir.'/dmllib.php');
251387d0 210require_once($CFG->libdir.'/moodlelib.php');
d4a03c00 211require_once($CFG->libdir .'/pagelib.php');
3b093310 212require_once($CFG->libdir.'/deprecatedlib.php');
251387d0 213require_once($CFG->libdir.'/adminlib.php');
d36afd6d 214require_once($CFG->libdir.'/environmentlib.php');
d36afd6d 215require_once($CFG->libdir.'/componentlib.class.php');
067200e2 216require_once($CFG->dirroot.'/cache/lib.php');
3b093310 217
e8da62a9
PS
218//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
219//the problem is that we need specific version of quickforms and hacked excel files :-(
220ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
221//point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else
222ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
6f5e0852 223
3b093310 224require('version.php');
9ace5094 225$CFG->target_release = $release;
3b093310 226
a226a972 227$SESSION = new stdClass();
3b093310 228$SESSION->lang = $CFG->lang;
229
a226a972 230$USER = new stdClass();
3b093310 231$USER->id = 0;
232
a226a972 233$COURSE = new stdClass();
3b093310 234$COURSE->id = 0;
235
236$SITE = $COURSE;
237define('SITEID', 0);
238
239$hint_dataroot = '';
3b093310 240$hint_admindir = '';
241$hint_database = '';
242
082157a8 243// Are we in help mode?
3b093310 244if (isset($_GET['help'])) {
245 install_print_help_page($_GET['help']);
246}
247
082157a8 248//first time here? find out suitable dataroot
3b093310 249if (is_null($CFG->dataroot)) {
3b5ff37f 250 $CFG->dataroot = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'moodledata';
add47d44 251
add47d44 252 $i = 0; //safety check - dirname might return some unexpected results
253 while(is_dataroot_insecure()) {
254 $parrent = dirname($CFG->dataroot);
255 $i++;
b735d140 256 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
add47d44 257 $CFG->dataroot = ''; //can not find secure location for dataroot
258 break;
259 }
3b5ff37f 260 $CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
add47d44 261 }
3b093310 262 $config->dataroot = $CFG->dataroot;
263 $config->stage = INSTALL_WELCOME;
8b5b1028 264}
265
3b093310 266// now let's do the stage work
267if ($config->stage < INSTALL_WELCOME) {
268 $config->stage = INSTALL_WELCOME;
269}
270if ($config->stage > INSTALL_SAVE) {
271 $config->stage = INSTALL_SAVE;
8d783716 272}
273
274
51e3e0b9 275
3b093310 276if ($config->stage == INSTALL_SAVE) {
3a915b06
PS
277 $CFG->early_install_lang = false;
278
3b093310 279 $database = moodle_database::get_driver_instance($config->dbtype, 'native');
280 if (!$database->driver_installed()) {
281 $config->stage = INSTALL_DATABASETYPE;
282 } else {
082157a8 283 if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
b29ca9b5 284 $distro = distro_pre_create_db($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbport'=>$config->dbport, 'dbsocket'=>$config->dbsocket), $distro);
768408e8 285 }
b29ca9b5 286 $hint_database = install_db_validate($database, $config->dbhost, $config->dbuser, $config->dbpass, $config->dbname, $config->prefix, array('dbpersist'=>0, 'dbport'=>$config->dbport, 'dbsocket'=>$config->dbsocket));
edd3a5db 287
3b093310 288 if ($hint_database === '') {
3b5ff37f 289 $configphp = install_generate_configphp($database, $CFG);
53a0367d 290
3b093310 291 umask(0137);
3b093310 292 if (($fh = @fopen($configfile, 'w')) !== false) {
293 fwrite($fh, $configphp);
294 fclose($fh);
295 }
082157a8 296
3b093310 297 if (file_exists($configfile)) {
298 // config created, let's continue!
299 redirect("$CFG->wwwroot/$config->admin/index.php?lang=$config->lang");
300 }
2df3a721 301
3b093310 302 install_print_header($config, 'config.php',
303 get_string('configurationcompletehead', 'install'),
304 get_string('configurationcompletesub', 'install').get_string('configfilenotwritten', 'install'));
305 echo '<div class="configphp"><pre>';
306 echo p($configphp);
307 echo '</pre></div>';
bba0beae 308
3b093310 309 install_print_footer($config);
310 die;
8b5b1028 311
3b093310 312 } else {
313 $config->stage = INSTALL_DATABASE;
314 }
6d5a22b2 315 }
8b5b1028 316}
317
318
319
5167827b 320if ($config->stage == INSTALL_DOWNLOADLANG) {
321 if (empty($CFG->dataroot)) {
322 $config->stage = INSTALL_PATHS;
323
324 } else if (is_dataroot_insecure()) {
325 $hint_dataroot = get_string('pathsunsecuredataroot', 'install');
326 $config->stage = INSTALL_PATHS;
327
cf89052a 328 } else if (!file_exists($CFG->dataroot)) {
329 $a = new stdClass();
330 $a->parent = dirname($CFG->dataroot);
331 $a->dataroot = $CFG->dataroot;
e92977d3 332 if (!is_writable($a->parent)) {
cf89052a 333 $hint_dataroot = get_string('pathsroparentdataroot', 'install', $a);
334 $config->stage = INSTALL_PATHS;
335 } else {
0bda7031 336 if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
cf89052a 337 $hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
338 $config->stage = INSTALL_PATHS;
339 }
340 }
16564524
DM
341
342 } else if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
e92977d3 343 $hint_dataroot = get_string('pathserrcreatedataroot', 'install', array('dataroot' => $CFG->dataroot));
16564524 344 $config->stage = INSTALL_PATHS;
cf89052a 345 }
346
347 if (empty($hint_dataroot) and !is_writable($CFG->dataroot)) {
5167827b 348 $hint_dataroot = get_string('pathsrodataroot', 'install');
349 $config->stage = INSTALL_PATHS;
350 }
351
3b5ff37f 352 if ($config->admin === '' or !file_exists($CFG->dirroot.'/'.$config->admin.'/environment.xml')) {
5167827b 353 $hint_admindir = get_string('pathswrongadmindir', 'install');
354 $config->stage = INSTALL_PATHS;
355 }
356}
357
358
359
360if ($config->stage == INSTALL_DOWNLOADLANG) {
361 // no need to download anything if en lang selected
3a915b06 362 if ($CFG->lang == 'en') {
5167827b 363 $config->stage = INSTALL_DATABASETYPE;
364 }
365}
366
367
368
369if ($config->stage == INSTALL_DATABASETYPE) {
370 // skip db selection if distro package supports only one db
371 if (!empty($distro->dbtype)) {
372 $config->stage = INSTALL_DATABASE;
373 }
374}
375
376
08261d3a 377if ($config->stage == INSTALL_DOWNLOADLANG) {
378 $downloaderror = '';
379
74a4c9a9
DM
380 // download and install required lang packs, the lang dir has already been created in install_init_dataroot
381 $installer = new lang_installer($CFG->lang);
382 $results = $installer->run();
383 foreach ($results as $langcode => $langstatus) {
384 if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
385 $a = new stdClass();
386 $a->url = $installer->lang_pack_url($langcode);
387 $a->dest = $CFG->dataroot.'/lang';
388 $downloaderror = get_string('remotedownloaderror', 'error', $a);
08261d3a 389 }
390 }
391
392 if ($downloaderror !== '') {
393 install_print_header($config, get_string('language'), get_string('langdownloaderror', 'install', $CFG->lang), $downloaderror);
394 install_print_footer($config);
395 die;
396 } else {
397 if (empty($distro->dbtype)) {
398 $config->stage = INSTALL_DATABASETYPE;
399 } else {
400 $config->stage = INSTALL_DATABASE;
401 }
402 }
807ee8bc
DM
403
404 // switch the string_manager instance to stop using install/lang/
405 $CFG->early_install_lang = false;
406 $CFG->langotherroot = $CFG->dataroot.'/lang';
407 $CFG->langlocalroot = $CFG->dataroot.'/lang';
408 get_string_manager(true);
08261d3a 409}
410
5167827b 411
3b093310 412if ($config->stage == INSTALL_DATABASE) {
3a915b06
PS
413 $CFG->early_install_lang = false;
414
3b093310 415 $database = moodle_database::get_driver_instance($config->dbtype, 'native');
8b5b1028 416
3b093310 417 $sub = '<h3>'.$database->get_name().'</h3>'.$database->get_configuration_help();
8d783716 418
3b093310 419 install_print_header($config, get_string('database', 'install'), get_string('databasehead', 'install'), $sub);
53a0367d 420
3b093310 421 $strdbhost = get_string('databasehost', 'install');
422 $strdbname = get_string('databasename', 'install');
423 $strdbuser = get_string('databaseuser', 'install');
424 $strdbpass = get_string('databasepass', 'install');
425 $strprefix = get_string('dbprefix', 'install');
b29ca9b5 426 $strdbport = get_string('databaseport', 'install');
3b093310 427 $strdbsocket = get_string('databasesocket', 'install');
8d783716 428
3b093310 429 echo '<div class="userinput">';
6724b059 430
431 $disabled = empty($distro->dbhost) ? '' : 'disabled="disabled';
3b093310 432 echo '<div class="formrow"><label for="id_dbhost" class="formlabel">'.$strdbhost.'</label>';
8231a0ca 433 echo '<input id="id_dbhost" name="dbhost" '.$disabled.' type="text" value="'.s($config->dbhost).'" size="50" class="forminput" />';
3b093310 434 echo '</div>';
8b5b1028 435
3b093310 436 echo '<div class="formrow"><label for="id_dbname" class="formlabel">'.$strdbname.'</label>';
8231a0ca 437 echo '<input id="id_dbname" name="dbname" type="text" value="'.s($config->dbname).'" size="50" class="forminput" />';
3b093310 438 echo '</div>';
86453d8b 439
6724b059 440 $disabled = empty($distro->dbuser) ? '' : 'disabled="disabled';
3b093310 441 echo '<div class="formrow"><label for="id_dbuser" class="formlabel">'.$strdbuser.'</label>';
8231a0ca 442 echo '<input id="id_dbuser" name="dbuser" '.$disabled.' type="text" value="'.s($config->dbuser).'" size="50" class="forminput" />';
3b093310 443 echo '</div>';
86453d8b 444
3b093310 445 echo '<div class="formrow"><label for="id_dbpass" class="formlabel">'.$strdbpass.'</label>';
446 // no password field here, the password may be visible in config.php if we can not write it to disk
8231a0ca 447 echo '<input id="id_dbpass" name="dbpass" type="text" value="'.s($config->dbpass).'" size="50" class="forminput" />';
3b093310 448 echo '</div>';
86453d8b 449
3b093310 450 echo '<div class="formrow"><label for="id_prefix" class="formlabel">'.$strprefix.'</label>';
451 echo '<input id="id_prefix" name="prefix" type="text" value="'.s($config->prefix).'" size="10" class="forminput" />';
452 echo '</div>';
fe515206 453
b29ca9b5
PS
454 echo '<div class="formrow"><label for="id_prefix" class="formlabel">'.$strdbport.'</label>';
455 echo '<input id="id_dbport" name="dbport" type="text" value="'.s($config->dbport).'" size="10" class="forminput" />';
456 echo '</div>';
457
3b093310 458 if (!(stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin'))) {
3b093310 459 echo '<div class="formrow"><label for="id_dbsocket" class="formlabel">'.$strdbsocket.'</label>';
b29ca9b5 460 echo '<input id="id_dbsocket" name="dbsocket" type="text" value="'.s($config->dbsocket).'" size="50" class="forminput" />';
3b093310 461 echo '</div>';
8b5b1028 462 }
463
3b093310 464 echo '<div class="hint">'.$hint_database.'</div>';
465 echo '</div>';
466 install_print_footer($config);
467 die;
8b5b1028 468}
469
470
3b093310 471if ($config->stage == INSTALL_DATABASETYPE) {
3a915b06
PS
472 $CFG->early_install_lang = false;
473
082157a8 474 // Finally ask for DB type
3b093310 475 install_print_header($config, get_string('database', 'install'),
476 get_string('databasetypehead', 'install'),
477 get_string('databasetypesub', 'install'));
51e3e0b9 478
3b093310 479 $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
17601a7e 480 'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
3b093310 481 'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'),
482 'oci' => moodle_database::get_driver_instance('oci', 'native'),
7e60d0d6 483 'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
a2b9bca5 484 'mssql' => moodle_database::get_driver_instance('mssql', 'native'), // FreeTDS driver
3b093310 485 );
51e3e0b9 486
3b093310 487 echo '<div class="userinput">';
488 echo '<div class="formrow"><label class="formlabel" for="dbtype">'.get_string('dbtype', 'install').'</label>';
489 echo '<select id="dbtype" name="dbtype" class="forminput">';
490 $disabled = array();
491 $options = array();
492 foreach ($databases as $type=>$database) {
493 if ($database->driver_installed() !== true) {
494 $disabled[$type] = $database;
495 continue;
496 }
497 echo '<option value="'.s($type).'">'.$database->get_name().'</option>';
51e3e0b9 498 }
3b093310 499 if ($disabled) {
500 echo '<optgroup label="'.s(get_string('notavailable')).'">';
501 foreach ($disabled as $type=>$database) {
502 echo '<option value="'.s($type).'" class="notavailable">'.$database->get_name().'</option>';
503 }
504 echo '</optgroup>';
8b5b1028 505 }
3b093310 506 echo '</select></div>';
507 echo '</div>';
53a0367d 508
3b093310 509 install_print_footer($config);
510 die;
8b5b1028 511}
512
513
514
3b093310 515if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) {
0fd23b76 516 $version_fail = (version_compare(phpversion(), "5.3.3") < 0);
3a915b06
PS
517 $curl_fail = ($lang !== 'en' and !extension_loaded('curl')); // needed for lang pack download
518 $zip_fail = ($lang !== 'en' and !extension_loaded('zip')); // needed for lang pack download
8b5b1028 519
3b093310 520 if ($version_fail or $curl_fail or $zip_fail) {
521 $config->stage = INSTALL_ENVIRONMENT;
8b5b1028 522
85ed076b 523 install_print_header($config, get_string('environmenthead', 'install'),
3b093310 524 get_string('errorsinenvironment', 'install'),
525 get_string('environmentsub2', 'install'));
8b5b1028 526
3b093310 527 echo '<div id="envresult"><dl>';
528 if ($version_fail) {
0fd23b76 529 $a = (object)array('needed'=>'5.3.3', 'current'=>phpversion());
3b093310 530 echo '<dt>'.get_string('phpversion', 'install').'</dt><dd>'.get_string('environmentrequireversion', 'admin', $a).'</dd>';
531 }
532 if ($curl_fail) {
533 echo '<dt>'.get_string('phpextension', 'install', 'cURL').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>';
534 }
535 if ($zip_fail) {
536 echo '<dt>'.get_string('phpextension', 'install', 'Zip').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>';
537 }
538 echo '</dl></div>';
8d783716 539
3b093310 540 install_print_footer($config, true);
541 die;
51e3e0b9 542
8b5b1028 543 } else {
3b093310 544 $config->stage = INSTALL_PATHS;
8b5b1028 545 }
8b5b1028 546}
547
8b5b1028 548
8b5b1028 549
3b093310 550if ($config->stage == INSTALL_PATHS) {
551 $paths = array('wwwroot' => get_string('wwwroot', 'install'),
552 'dirroot' => get_string('dirroot', 'install'),
3b5ff37f 553 'dataroot' => get_string('dataroot', 'install'));
627d326a 554
3b093310 555 $sub = '<dl>';
556 foreach ($paths as $path=>$name) {
557 $sub .= '<dt>'.$name.'</dt><dd>'.get_string('pathssub'.$path, 'install').'</dd>';
8b5b1028 558 }
3b5ff37f
PS
559 if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
560 $sub .= '<dt>'.get_string('admindirname', 'install').'</dt><dd>'.get_string('pathssubadmindir', 'install').'</dd>';
561 }
3b093310 562 $sub .= '</dl>';
cd0e958e 563
3b093310 564 install_print_header($config, get_string('paths', 'install'), get_string('pathshead', 'install'), $sub);
627d326a 565
3b093310 566 $strwwwroot = get_string('wwwroot', 'install');
567 $strdirroot = get_string('dirroot', 'install');
568 $strdataroot = get_string('dataroot', 'install');
569 $stradmindirname = get_string('admindirname', 'install');
cdef6d42 570
3b093310 571 echo '<div class="userinput">';
572 echo '<div class="formrow"><label for="id_wwwroot" class="formlabel">'.$paths['wwwroot'].'</label>';
ae3a7947 573 echo '<input id="id_wwwroot" name="wwwroot" type="text" value="'.s($CFG->wwwroot).'" disabled="disabled" size="70" class="forminput" />';
3b093310 574 echo '</div>';
cd0e958e 575
3b093310 576 echo '<div class="formrow"><label for="id_dirroot" class="formlabel">'.$paths['dirroot'].'</label>';
ae3a7947 577 echo '<input id="id_dirroot" name="dirroot" type="text" value="'.s($CFG->dirroot).'" disabled="disabled" size="70"class="forminput" />';
3b093310 578 echo '</div>';
53a0367d 579
3b093310 580 echo '<div class="formrow"><label for="id_dataroot" class="formlabel">'.$paths['dataroot'].'</label>';
ae3a7947 581 echo '<input id="id_dataroot" name="dataroot" type="text" value="'.s($config->dataroot).'" size="70" class="forminput" />';
3b093310 582 if ($hint_dataroot !== '') {
583 echo '<div class="hint">'.$hint_dataroot.'</div>';
cdef6d42 584 }
3b093310 585 echo '</div>';
8b5b1028 586
8d783716 587
3b5ff37f
PS
588 if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
589 echo '<div class="formrow"><label for="id_admin" class="formlabel">'.$paths['admindir'].'</label>';
590 echo '<input id="id_admin" name="admin" type="text" value="'.s($config->admin).'" size="10" class="forminput" />';
591 if ($hint_admindir !== '') {
592 echo '<div class="hint">'.$hint_admindir.'</div>';
593 }
594 echo '</div>';
8d783716 595 }
8d783716 596
3b093310 597 echo '</div>';
8d783716 598
3b093310 599 install_print_footer($config);
600 die;
8d783716 601}
602
86453d8b 603
86453d8b 604
3b093310 605$config->stage = INSTALL_WELCOME;
64c368e3 606
607if ($distro) {
608 ob_start();
609 include('install/distribution.html');
610 $sub = ob_get_clean();
611
612 install_print_header($config, get_string('language'),
613 get_string('chooselanguagehead', 'install'),
614 $sub);
082157a8 615
64c368e3 616} else {
617 install_print_header($config, get_string('language'),
618 get_string('chooselanguagehead', 'install'),
619 get_string('chooselanguagesub', 'install'));
620}
86453d8b 621
1f96e907 622$languages = get_string_manager()->get_list_of_translations();
3b093310 623echo '<div class="userinput">';
624echo '<div class="formrow"><label class="formlabel" for="langselect">'.get_string('language').'</label>';
4d928665 625echo '<select id="langselect" name="lang" class="forminput" onchange="this.form.submit()">';
3b093310 626foreach ($languages as $name=>$value) {
627 $selected = ($name == $CFG->lang) ? 'selected="selected"' : '';
628 echo '<option value="'.s($name).'" '.$selected.'>'.$value.'</option>';
86453d8b 629}
3b093310 630echo '</select></div>';
631echo '</div>';
86453d8b 632
3b093310 633install_print_footer($config);
634die;
2961367e 635