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