Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
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
 *
21
 * @package    core
22
 * @subpackage install
23
 * @copyright  2009 Petr Skoda (http://skodak.org)
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
if (isset($_REQUEST['lang'])) {
28
    $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']);
29
} else {
30
    $lang = 'en';
31
}
32
 
33
if (isset($_REQUEST['admin'])) {
34
    $admin = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['admin']);
35
} else {
36
    $admin = 'admin';
37
}
38
 
39
// If config.php exists we just created config.php and need to redirect to continue installation
40
$configfile = './config.php';
41
if (file_exists($configfile)) {
42
    header("Location: $admin/index.php?lang=$lang");
43
    die;
44
}
45
 
46
define('CLI_SCRIPT', false); // prevents some warnings later
47
define('AJAX_SCRIPT', false); // prevents some warnings later
48
define('CACHE_DISABLE_ALL', true); // Disables caching.. just in case.
1441 ariadna 49
define('NO_DEBUG_DISPLAY', false);
1 efrain 50
define('PHPUNIT_TEST', false);
51
define('IGNORE_COMPONENT_CACHE', true);
52
define('MDL_PERF_TEST', false);
53
define('MDL_PERF', false);
54
define('MDL_PERFTOFOOT', false);
55
define('MDL_PERFTOLOG', false);
56
define('MDL_PERFINC', false);
57
 
58
// Servers should define a default timezone in php.ini, but if they don't then make sure something is defined.
59
if (!function_exists('date_default_timezone_set') or !function_exists('date_default_timezone_get')) {
60
    echo("Timezone functions are not available.");
61
    die;
62
}
63
date_default_timezone_set(@date_default_timezone_get());
64
 
65
// make sure PHP errors are displayed - helps with diagnosing of problems
66
@error_reporting(E_ALL);
67
@ini_set('display_errors', '1');
68
 
69
// Check that PHP is of a sufficient version as soon as possible.
70
require_once(__DIR__.'/lib/phpminimumversionlib.php');
71
moodle_require_minimum_php_version();
72
 
73
// make sure iconv is available and actually works
74
if (!function_exists('iconv')) {
75
    // this should not happen, this must be very borked install
76
    echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
77
    die();
78
}
79
 
80
if (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
 
92
/** Used by library scripts to check they are being called by Moodle */
93
define('MOODLE_INTERNAL', true);
94
 
95
require_once(__DIR__.'/lib/classes/component.php');
96
require_once(__DIR__.'/lib/installlib.php');
97
 
98
// TODO: add lang detection here if empty $_REQUEST['lang']
99
 
100
// distro specific customisation
101
$distro = null;
102
if (file_exists('install/distrolib.php')) {
103
    require_once('install/distrolib.php');
104
    if (function_exists('distro_get_config')) {
105
        $distro = distro_get_config();
106
    }
107
}
108
 
109
$config = new stdClass();
110
$config->lang = $lang;
111
 
112
if (!empty($_POST)) {
113
    $config->stage = (int)$_POST['stage'];
114
 
115
    if (isset($_POST['previous'])) {
116
        $config->stage--;
117
        if (INSTALL_DATABASETYPE and !empty($distro->dbtype)) {
118
            $config->stage--;
119
        }
120
        if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_DOWNLOADLANG) {
121
            $config->stage--;
122
        }
123
    } else if (isset($_POST['next'])) {
124
        $config->stage++;
125
    }
126
 
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']);
133
    $config->dbport   = (int)trim($_POST['dbport']);
134
    $config->dbsocket = trim($_POST['dbsocket']);
135
 
136
    if ($config->dbport <= 0) {
137
        $config->dbport = '';
138
    }
139
 
140
    $config->admin    = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']);
141
 
142
    $config->dataroot = trim($_POST['dataroot']);
143
 
144
} else {
145
    $config->stage    = INSTALL_WELCOME;
146
 
147
    $config->dbtype   = empty($distro->dbtype) ? '' : $distro->dbtype; // let distro skip dbtype selection
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
150
    $config->dbpass   = '';
151
    $config->dbname   = 'moodle';
152
    $config->prefix   = 'mdl_';
153
    $config->dbport   = empty($distro->dbport) ? '' : $distro->dbport;
154
    $config->dbsocket = empty($distro->dbsocket) ? '' : $distro->dbsocket;
155
 
156
    $config->admin    = 'admin';
157
 
158
    $config->dataroot = empty($distro->dataroot) ? null  : $distro->dataroot; // initialised later after including libs or by distro
159
}
160
 
161
// Fake some settings so that we can use selected functions from moodlelib.php, weblib.php and filelib.php.
162
global $CFG;
163
$CFG = new stdClass();
164
$CFG->lang                 = $config->lang;
165
$CFG->dirroot              = __DIR__;
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;
169
$CFG->dataroot             = $config->dataroot;
170
$CFG->tempdir              = $CFG->dataroot.'/temp';
171
$CFG->backuptempdir        = $CFG->tempdir.'/backup';
172
$CFG->cachedir             = $CFG->dataroot.'/cache';
173
$CFG->localcachedir        = $CFG->dataroot.'/localcache';
174
$CFG->admin                = $config->admin;
175
$CFG->docroot              = 'https://docs.moodle.org';
176
$CFG->langotherroot        = $CFG->dataroot.'/lang';
177
$CFG->langlocalroot        = $CFG->dataroot.'/lang';
178
$CFG->directorypermissions = isset($distro->directorypermissions) ? $distro->directorypermissions : 00777; // let distros set dir permissions
179
$CFG->filepermissions      = ($CFG->directorypermissions & 0666);
180
$CFG->umaskpermissions     = (($CFG->directorypermissions & 0777) ^ 0777);
181
$CFG->running_installer    = true;
182
$CFG->early_install_lang   = true;
183
$CFG->ostype               = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
1441 ariadna 184
$CFG->debug                = (E_ALL);
1 efrain 185
$CFG->debugdisplay         = true;
186
$CFG->debugdeveloper       = true;
187
 
188
// Require all needed libs
189
require_once($CFG->libdir.'/setuplib.php');
190
 
191
// we need to make sure we have enough memory to load all libraries
192
$memlimit = @ini_get('memory_limit');
193
if (!empty($memlimit) and $memlimit != -1) {
194
    if (get_real_size($memlimit) < get_real_size($minrequiredmemory)) {
195
        // do NOT localise - lang strings would not work here and we CAN not move it to later place
196
        echo "Moodle requires at least {$minrequiredmemory}B of PHP memory.<br />";
197
        echo "Please contact server administrator to fix PHP.ini memory settings.";
198
        die;
199
    }
200
}
201
 
1441 ariadna 202
// Point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
203
// the problem is that we need specific version of quickforms and hacked excel files :-(.
204
ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
205
 
206
// Register our classloader.
207
\core\component::register_autoloader();
208
 
209
// Continue with lib loading.
1 efrain 210
require_once($CFG->libdir.'/classes/text.php');
211
require_once($CFG->libdir.'/classes/string_manager.php');
212
require_once($CFG->libdir.'/classes/string_manager_install.php');
213
require_once($CFG->libdir.'/classes/string_manager_standard.php');
214
require_once($CFG->libdir.'/weblib.php');
215
require_once($CFG->libdir.'/outputlib.php');
216
require_once($CFG->libdir.'/dmllib.php');
217
require_once($CFG->libdir.'/moodlelib.php');
218
require_once($CFG->libdir .'/pagelib.php');
219
require_once($CFG->libdir.'/deprecatedlib.php');
220
require_once($CFG->libdir.'/adminlib.php');
221
require_once($CFG->libdir.'/environmentlib.php');
222
require_once($CFG->libdir.'/componentlib.class.php');
223
 
224
require('version.php');
225
$CFG->target_release = $release;
226
 
227
\core\session\manager::init_empty_session();
228
global $SESSION;
229
global $USER;
230
 
231
global $COURSE;
232
$COURSE = new stdClass();
233
$COURSE->id = 1;
234
 
235
global $SITE;
236
$SITE = $COURSE;
237
define('SITEID', 1);
238
 
239
$hint_dataroot = '';
240
$hint_admindir = '';
241
$hint_database = '';
242
 
243
//first time here? find out suitable dataroot
244
if (is_null($CFG->dataroot)) {
245
    $CFG->dataroot = __DIR__.'/../moodledata';
246
 
247
    $i = 0; //safety check - dirname might return some unexpected results
248
    while(is_dataroot_insecure()) {
249
        $parrent = dirname($CFG->dataroot);
250
        $i++;
251
        if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
252
            $CFG->dataroot = ''; //can not find secure location for dataroot
253
            break;
254
        }
255
        $CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
256
    }
257
    $config->dataroot = $CFG->dataroot;
258
    $config->stage    = INSTALL_WELCOME;
259
}
260
 
261
// now let's do the stage work
262
if ($config->stage < INSTALL_WELCOME) {
263
    $config->stage = INSTALL_WELCOME;
264
}
265
if ($config->stage > INSTALL_SAVE) {
266
    $config->stage = INSTALL_SAVE;
267
}
268
 
269
 
270
 
271
if ($config->stage == INSTALL_SAVE) {
272
    $CFG->early_install_lang = false;
273
 
274
    $database = moodle_database::get_driver_instance($config->dbtype, 'native');
275
    if (!$database->driver_installed()) {
276
        $config->stage = INSTALL_DATABASETYPE;
277
    } else {
278
        if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
279
            $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);
280
        }
281
        $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));
282
 
283
        if ($hint_database === '') {
284
            $configphp = install_generate_configphp($database, $CFG);
285
 
286
            umask(0137);
287
            if (($fh = @fopen($configfile, 'w')) !== false) {
288
                fwrite($fh, $configphp);
289
                fclose($fh);
290
            }
291
 
292
            if (file_exists($configfile)) {
293
                // config created, let's continue!
294
                redirect("$CFG->wwwroot/$config->admin/index.php?lang=$config->lang");
295
            }
296
 
297
            install_print_header($config, 'config.php',
298
                                          get_string('configurationcompletehead', 'install'),
299
                                          get_string('configurationcompletesub', 'install').get_string('configfilenotwritten', 'install'), 'alert-error');
300
            echo '<div class="configphp"><pre>';
301
            echo p($configphp);
302
            echo '</pre></div>';
303
 
304
            install_print_footer($config);
305
            die;
306
 
307
        } else {
308
            $config->stage = INSTALL_DATABASE;
309
        }
310
    }
311
}
312
 
313
 
314
 
315
if ($config->stage == INSTALL_DOWNLOADLANG) {
316
    if (empty($CFG->dataroot)) {
317
        $config->stage = INSTALL_PATHS;
318
 
319
    } else if (is_dataroot_insecure()) {
320
        $hint_dataroot = get_string('pathsunsecuredataroot', 'install');
321
        $config->stage = INSTALL_PATHS;
322
 
323
    } else if (!file_exists($CFG->dataroot)) {
324
        $a = new stdClass();
325
        $a->parent = dirname($CFG->dataroot);
326
        $a->dataroot = $CFG->dataroot;
327
        if (!is_writable($a->parent)) {
328
            $hint_dataroot = get_string('pathsroparentdataroot', 'install', $a);
329
            $config->stage = INSTALL_PATHS;
330
        } else {
331
            if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
332
                $hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
333
                $config->stage = INSTALL_PATHS;
334
            }
335
        }
336
 
337
    } else if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
338
        $hint_dataroot = get_string('pathserrcreatedataroot', 'install', array('dataroot' => $CFG->dataroot));
339
        $config->stage = INSTALL_PATHS;
340
    }
341
 
342
    if (empty($hint_dataroot) and !is_writable($CFG->dataroot)) {
343
        $hint_dataroot = get_string('pathsrodataroot', 'install');
344
        $config->stage = INSTALL_PATHS;
345
    }
346
 
347
    if ($config->admin === '' or !file_exists($CFG->dirroot.'/'.$config->admin.'/environment.xml')) {
348
        $hint_admindir = get_string('pathswrongadmindir', 'install');
349
        $config->stage = INSTALL_PATHS;
350
    }
351
}
352
 
353
 
354
 
355
if ($config->stage == INSTALL_DOWNLOADLANG) {
356
    // no need to download anything if en lang selected
357
    if ($CFG->lang == 'en') {
358
        $config->stage = INSTALL_DATABASETYPE;
359
    }
360
}
361
 
362
 
363
 
364
if ($config->stage == INSTALL_DATABASETYPE) {
365
    // skip db selection if distro package supports only one db
366
    if (!empty($distro->dbtype)) {
367
        $config->stage = INSTALL_DATABASE;
368
    }
369
}
370
 
371
 
372
if ($config->stage == INSTALL_DOWNLOADLANG) {
373
    $downloaderror = '';
374
 
375
    // download and install required lang packs, the lang dir has already been created in install_init_dataroot
376
    $installer = new lang_installer($CFG->lang);
377
    $results = $installer->run();
378
    foreach ($results as $langcode => $langstatus) {
379
        if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
380
            $a       = new stdClass();
381
            $a->url  = $installer->lang_pack_url($langcode);
382
            $a->dest = $CFG->dataroot.'/lang';
383
            $downloaderror = get_string('remotedownloaderror', 'error', $a);
384
        }
385
    }
386
 
387
    if ($downloaderror !== '') {
388
        install_print_header($config, get_string('language'), get_string('langdownloaderror', 'install', $CFG->lang), $downloaderror);
389
        install_print_footer($config);
390
        die;
391
    } else {
392
        if (empty($distro->dbtype)) {
393
            $config->stage = INSTALL_DATABASETYPE;
394
        } else {
395
            $config->stage = INSTALL_DATABASE;
396
        }
397
    }
398
 
399
    // switch the string_manager instance to stop using install/lang/
400
    $CFG->early_install_lang = false;
401
    $CFG->langotherroot      = $CFG->dataroot.'/lang';
402
    $CFG->langlocalroot      = $CFG->dataroot.'/lang';
403
    get_string_manager(true);
404
}
405
 
406
 
407
if ($config->stage == INSTALL_DATABASE) {
408
    $CFG->early_install_lang = false;
409
 
410
    $database = moodle_database::get_driver_instance($config->dbtype, 'native');
411
 
412
    $sub = '<h3>'.$database->get_name().'</h3>'.$database->get_configuration_help();
413
 
414
    install_print_header($config, get_string('database', 'install'), get_string('databasehead', 'install'), $sub);
415
 
416
    $strdbhost   = get_string('databasehost', 'install');
417
    $strdbname   = get_string('databasename', 'install');
418
    $strdbuser   = get_string('databaseuser', 'install');
419
    $strdbpass   = get_string('databasepass', 'install');
420
    $strprefix   = get_string('dbprefix', 'install');
421
    $strdbport   = get_string('databaseport', 'install');
422
    $strdbsocket = get_string('databasesocket', 'install');
423
 
424
    echo '<div class="row mb-4">';
425
 
426
    $disabled = empty($distro->dbhost) ? '' : 'disabled="disabled';
1441 ariadna 427
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dbhost">'.$strdbhost.'</label></div>';
1 efrain 428
    echo '<div class="col-md-9" data-fieldtype="text">';
429
    echo '<input id="id_dbhost" name="dbhost" '.$disabled.' type="text" class="form-control text-ltr" value="'.s($config->dbhost).'" size="50" /></div>';
430
    echo '</div>';
431
 
432
    echo '<div class="row mb-4">';
1441 ariadna 433
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dbname">'.$strdbname.'</label></div>';
1 efrain 434
    echo '<div class="col-md-9" data-fieldtype="text">';
435
    echo '<input id="id_dbname" name="dbname" type="text" class="form-control text-ltr" value="'.s($config->dbname).'" size="50" /></div>';
436
    echo '</div>';
437
 
438
    $disabled = empty($distro->dbuser) ? '' : 'disabled="disabled';
439
    echo '<div class="row mb-4">';
1441 ariadna 440
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dbuser">'.$strdbuser.'</label></div>';
1 efrain 441
    echo '<div class="col-md-9" data-fieldtype="text">';
442
    echo '<input id="id_dbuser" name="dbuser" '.$disabled.' type="text" class="form-control text-ltr" value="'.s($config->dbuser).'" size="50" /></div>';
443
    echo '</div>';
444
 
445
    echo '<div class="row mb-4">';
1441 ariadna 446
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dbpass">'.$strdbpass.'</label></div>';
1 efrain 447
    // no password field here, the password may be visible in config.php if we can not write it to disk
448
    echo '<div class="col-md-9" data-fieldtype="text">';
449
    echo '<input id="id_dbpass" name="dbpass" type="text" class="form-control text-ltr" value="'.s($config->dbpass).'" size="50" /></div>';
450
    echo '</div>';
451
 
452
    echo '<div class="row mb-4">';
1441 ariadna 453
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_prefix">'.$strprefix.'</label></div>';
1 efrain 454
    echo '<div class="col-md-9" data-fieldtype="text">';
455
    echo '<input id="id_prefix" name="prefix" type="text" class="form-control text-ltr" value="'.s($config->prefix).'" size="10" /></div>';
456
    echo '</div>';
457
 
458
    echo '<div class="row mb-4">';
1441 ariadna 459
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_prefix">'.$strdbport.'</label></div>';
1 efrain 460
    echo '<div class="col-md-9" data-fieldtype="text">';
461
    echo '<input id="id_dbport" name="dbport" type="text" class="form-control text-ltr" value="'.s($config->dbport).'" size="10" /></div>';
462
    echo '</div>';
463
 
464
    if (!(stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin'))) {
465
        echo '<div class="row mb-4">';
1441 ariadna 466
        echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dbsocket">'.$strdbsocket.'</label></div>';
1 efrain 467
        echo '<div class="col-md-9" data-fieldtype="text">';
468
        echo '<input id="id_dbsocket" name="dbsocket" type="text" class="form-control text-ltr" value="'.s($config->dbsocket).'" size="50" /></div>';
469
        echo '</div>';
470
    }
471
 
472
    if ($hint_database !== '') {
473
        echo '<div class="alert alert-danger">'.$hint_database.'</div>';
474
    }
475
 
476
    install_print_footer($config);
477
    die;
478
}
479
 
480
 
481
if ($config->stage == INSTALL_DATABASETYPE) {
482
    $CFG->early_install_lang = false;
483
 
484
    // Finally ask for DB type
485
    install_print_header($config, get_string('database', 'install'),
486
                                  get_string('databasetypehead', 'install'),
487
                                  get_string('databasetypesub', 'install'));
488
 
489
    $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
490
                       'auroramysql' => moodle_database::get_driver_instance('auroramysql', 'native'),
491
                       'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
492
                       'pgsql'  => moodle_database::get_driver_instance('pgsql',  'native'),
493
                       'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
494
                      );
495
 
496
    echo '<div class="row mb-4">';
1441 ariadna 497
    echo '<div class="col-md-3 text-md-end pt-1"><label for="dbtype">'.get_string('dbtype', 'install').'</label></div>';
1 efrain 498
    echo '<div class="col-md-9" data-fieldtype="select">';
499
    echo '<select class="form-control" id="dbtype" name="dbtype">';
500
    $disabled = array();
501
    $options = array();
502
    foreach ($databases as $type=>$database) {
503
        if ($database->driver_installed() !== true) {
504
            $disabled[$type] = $database;
505
            continue;
506
        }
507
        echo '<option value="'.s($type).'">'.$database->get_name().'</option>';
508
    }
509
    if ($disabled) {
510
        echo '<optgroup label="'.s(get_string('notavailable')).'">';
511
        foreach ($disabled as $type=>$database) {
512
            echo '<option value="'.s($type).'" class="notavailable">'.$database->get_name().'</option>';
513
        }
514
        echo '</optgroup>';
515
    }
516
    echo '</select></div></div>';
517
 
518
    install_print_footer($config);
519
    die;
520
}
521
 
522
 
523
 
524
if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) {
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
527
 
528
    if ($curl_fail or $zip_fail) {
529
        $config->stage = INSTALL_ENVIRONMENT;
530
 
531
        install_print_header($config, get_string('environmenthead', 'install'),
532
                                      get_string('errorsinenvironment', 'install'),
533
                                      get_string('environmentsub2', 'install'));
534
 
535
        echo '<div id="envresult"><dl>';
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>';
543
 
544
        install_print_footer($config, true);
545
        die;
546
 
547
    } else {
548
        $config->stage = INSTALL_PATHS;
549
    }
550
}
551
 
552
 
553
 
554
if ($config->stage == INSTALL_PATHS) {
555
    $paths = array('wwwroot'  => get_string('wwwroot', 'install'),
556
                   'dirroot'  => get_string('dirroot', 'install'),
557
                   'dataroot' => get_string('dataroot', 'install'));
558
 
559
    $sub = '<dl>';
560
    foreach ($paths as $path=>$name) {
561
        $sub .= '<dt>'.$name.'</dt><dd>'.get_string('pathssub'.$path, 'install').'</dd>';
562
    }
563
    if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
564
        $sub .= '<dt>'.get_string('admindirname', 'install').'</dt><dd>'.get_string('pathssubadmindir', 'install').'</dd>';
565
    }
566
    $sub .= '</dl>';
567
 
568
    install_print_header($config, get_string('paths', 'install'), get_string('pathshead', 'install'), $sub);
569
 
570
    $strwwwroot      = get_string('wwwroot', 'install');
571
    $strdirroot      = get_string('dirroot', 'install');
572
    $strdataroot     = get_string('dataroot', 'install');
573
    $stradmindirname = get_string('admindirname', 'install');
574
 
575
    echo '<div class="row mb-4">';
1441 ariadna 576
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_wwwroot">'.$paths['wwwroot'].'</label></div>';
1 efrain 577
    echo '<div class="col-md-9" data-fieldtype="text">';
578
    echo '<input id="id_wwwroot" name="wwwroot" type="text" class="form-control text-ltr" value="'.s($CFG->wwwroot).'" disabled="disabled" size="70" /></div>';
579
    echo '</div>';
580
 
581
    echo '<div class="row mb-4">';
1441 ariadna 582
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dirroot">'.$paths['dirroot'].'</label></div>';
1 efrain 583
    echo '<div class="col-md-9" data-fieldtype="text">';
584
    echo '<input id="id_dirroot" name="dirroot" type="text" class="form-control text-ltr" value="'.s($CFG->dirroot).'" disabled="disabled" size="70" /></div>';
585
    echo '</div>';
586
 
587
    echo '<div class="row mb-4">';
1441 ariadna 588
    echo '<div class="col-md-3 text-md-end pt-1"><label for="id_dataroot">'.$paths['dataroot'].'</label></div>';
1 efrain 589
    echo '<div class="col-md-9" data-fieldtype="text">';
590
    echo '<input id="id_dataroot" name="dataroot" type="text" class="form-control text-ltr" value="'.s($config->dataroot).'" size="70" /></div>';
591
    echo '</div>';
592
    if ($hint_dataroot !== '') {
593
        echo '<div class="alert alert-danger">'.$hint_dataroot.'</div>';
594
    }
595
 
596
 
597
    if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
598
        echo '<div class="row mb-4">';
1441 ariadna 599
        echo '<div class="col-md-3 text-md-end pt-1"><label for="id_admin">'.$paths['admindir'].'</label></div>';
1 efrain 600
        echo '<div class="col-md-9" data-fieldtype="text">';
601
        echo '<input id="id_admin" name="admin" type="text" class="form-control text-ltr" value="'.s($config->admin).'" size="10" /></div>';
602
        echo '</div>';
603
        if ($hint_admindir !== '') {
604
            echo '<div class="alert alert-danger">'.$hint_admindir.'</div>';
605
        }
606
    }
607
 
608
    install_print_footer($config);
609
    die;
610
}
611
 
612
 
613
 
614
$config->stage = INSTALL_WELCOME;
615
 
616
if ($distro) {
617
    ob_start();
618
    include('install/distribution.html');
619
    $sub = ob_get_clean();
620
 
621
    install_print_header($config, get_string('language'),
622
                                  get_string('chooselanguagehead', 'install'),
623
                                  $sub, 'alert-success');
624
 
625
} else {
626
    install_print_header($config, get_string('language'),
627
                                  get_string('chooselanguagehead', 'install'),
628
                                  get_string('chooselanguagesub', 'install'));
629
}
630
 
631
$languages = get_string_manager()->get_list_of_translations();
632
echo '<div class="row mb-4">';
1441 ariadna 633
echo '<div class="col-md-3 text-md-end pt-1"><label for="langselect">'.get_string('language').'</label></div>';
1 efrain 634
echo '<div class="col-md-9" data-fieldtype="select">';
635
echo '<select id="langselect" class="form-control" name="lang" onchange="this.form.submit()">';
636
foreach ($languages as $name=>$value) {
637
    $selected = ($name == $CFG->lang) ? 'selected="selected"' : '';
638
    echo '<option value="'.s($name).'" '.$selected.'>'.$value.'</option>';
639
}
640
echo '</select></div>';
641
echo '</div>';
642
 
643
install_print_footer($config);
644
die;