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