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