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