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