PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/install.php

https://bitbucket.org/moodle/moodle
PHP | 655 lines | 479 code | 121 blank | 55 comment | 96 complexity | c3ff6cfdfb1c07775fb693aeb31eac3f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This script creates config.php file during installation.
  18. *
  19. * @package core
  20. * @subpackage install
  21. * @copyright 2009 Petr Skoda (http://skodak.org)
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. if (isset($_REQUEST['lang'])) {
  25. $lang = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['lang']);
  26. } else {
  27. $lang = 'en';
  28. }
  29. if (isset($_REQUEST['admin'])) {
  30. $admin = preg_replace('/[^A-Za-z0-9_-]/i', '', $_REQUEST['admin']);
  31. } else {
  32. $admin = 'admin';
  33. }
  34. // If config.php exists we just created config.php and need to redirect to continue installation
  35. $configfile = './config.php';
  36. if (file_exists($configfile)) {
  37. header("Location: $admin/index.php?lang=$lang");
  38. die;
  39. }
  40. define('CLI_SCRIPT', false); // prevents some warnings later
  41. define('AJAX_SCRIPT', false); // prevents some warnings later
  42. define('CACHE_DISABLE_ALL', true); // Disables caching.. just in case.
  43. define('PHPUNIT_TEST', false);
  44. define('IGNORE_COMPONENT_CACHE', true);
  45. define('MDL_PERF_TEST', false);
  46. // Servers should define a default timezone in php.ini, but if they don't then make sure something is defined.
  47. if (!function_exists('date_default_timezone_set') or !function_exists('date_default_timezone_get')) {
  48. echo("Timezone functions are not available.");
  49. die;
  50. }
  51. date_default_timezone_set(@date_default_timezone_get());
  52. // make sure PHP errors are displayed - helps with diagnosing of problems
  53. @error_reporting(E_ALL);
  54. @ini_set('display_errors', '1');
  55. // Check that PHP is of a sufficient version as soon as possible.
  56. require_once(__DIR__.'/lib/phpminimumversionlib.php');
  57. moodle_require_minimum_php_version();
  58. // make sure iconv is available and actually works
  59. if (!function_exists('iconv')) {
  60. // this should not happen, this must be very borked install
  61. echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
  62. die();
  63. }
  64. if (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. /** Used by library scripts to check they are being called by Moodle */
  76. define('MOODLE_INTERNAL', true);
  77. require_once(__DIR__.'/lib/classes/component.php');
  78. require_once(__DIR__.'/lib/installlib.php');
  79. // TODO: add lang detection here if empty $_REQUEST['lang']
  80. // distro specific customisation
  81. $distro = null;
  82. if (file_exists('install/distrolib.php')) {
  83. require_once('install/distrolib.php');
  84. if (function_exists('distro_get_config')) {
  85. $distro = distro_get_config();
  86. }
  87. }
  88. $config = new stdClass();
  89. $config->lang = $lang;
  90. if (!empty($_POST)) {
  91. $config->stage = (int)$_POST['stage'];
  92. if (isset($_POST['previous'])) {
  93. $config->stage--;
  94. if (INSTALL_DATABASETYPE and !empty($distro->dbtype)) {
  95. $config->stage--;
  96. }
  97. if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_DOWNLOADLANG) {
  98. $config->stage--;
  99. }
  100. } else if (isset($_POST['next'])) {
  101. $config->stage++;
  102. }
  103. $config->dbtype = trim($_POST['dbtype']);
  104. $config->dbhost = trim($_POST['dbhost']);
  105. $config->dbuser = trim($_POST['dbuser']);
  106. $config->dbpass = trim($_POST['dbpass']);
  107. $config->dbname = trim($_POST['dbname']);
  108. $config->prefix = trim($_POST['prefix']);
  109. $config->dbport = (int)trim($_POST['dbport']);
  110. $config->dbsocket = trim($_POST['dbsocket']);
  111. if ($config->dbport <= 0) {
  112. $config->dbport = '';
  113. }
  114. $config->admin = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']);
  115. $config->dataroot = trim($_POST['dataroot']);
  116. } else {
  117. $config->stage = INSTALL_WELCOME;
  118. $config->dbtype = empty($distro->dbtype) ? '' : $distro->dbtype; // let distro skip dbtype selection
  119. $config->dbhost = empty($distro->dbhost) ? 'localhost' : $distro->dbhost; // let distros set dbhost
  120. $config->dbuser = empty($distro->dbuser) ? '' : $distro->dbuser; // let distros set dbuser
  121. $config->dbpass = '';
  122. $config->dbname = 'moodle';
  123. $config->prefix = 'mdl_';
  124. $config->dbport = empty($distro->dbport) ? '' : $distro->dbport;
  125. $config->dbsocket = empty($distro->dbsocket) ? '' : $distro->dbsocket;
  126. $config->admin = 'admin';
  127. $config->dataroot = empty($distro->dataroot) ? null : $distro->dataroot; // initialised later after including libs or by distro
  128. }
  129. // Fake some settings so that we can use selected functions from moodlelib.php, weblib.php and filelib.php.
  130. global $CFG;
  131. $CFG = new stdClass();
  132. $CFG->lang = $config->lang;
  133. $CFG->dirroot = __DIR__;
  134. $CFG->libdir = "$CFG->dirroot/lib";
  135. $CFG->wwwroot = install_guess_wwwroot(); // can not be changed - ppl must use the real address when installing
  136. $CFG->httpswwwroot = $CFG->wwwroot;
  137. $CFG->dataroot = $config->dataroot;
  138. $CFG->tempdir = $CFG->dataroot.'/temp';
  139. $CFG->backuptempdir = $CFG->tempdir.'/backup';
  140. $CFG->cachedir = $CFG->dataroot.'/cache';
  141. $CFG->localcachedir = $CFG->dataroot.'/localcache';
  142. $CFG->admin = $config->admin;
  143. $CFG->docroot = 'https://docs.moodle.org';
  144. $CFG->langotherroot = $CFG->dataroot.'/lang';
  145. $CFG->langlocalroot = $CFG->dataroot.'/lang';
  146. $CFG->directorypermissions = isset($distro->directorypermissions) ? $distro->directorypermissions : 00777; // let distros set dir permissions
  147. $CFG->filepermissions = ($CFG->directorypermissions & 0666);
  148. $CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777);
  149. $CFG->running_installer = true;
  150. $CFG->early_install_lang = true;
  151. $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
  152. $CFG->debug = (E_ALL | E_STRICT);
  153. $CFG->debugdisplay = true;
  154. $CFG->debugdeveloper = true;
  155. // Require all needed libs
  156. require_once($CFG->libdir.'/setuplib.php');
  157. // we need to make sure we have enough memory to load all libraries
  158. $memlimit = @ini_get('memory_limit');
  159. if (!empty($memlimit) and $memlimit != -1) {
  160. if (get_real_size($memlimit) < get_real_size($minrequiredmemory)) {
  161. // do NOT localise - lang strings would not work here and we CAN not move it to later place
  162. echo "Moodle requires at least {$minrequiredmemory}B of PHP memory.<br />";
  163. echo "Please contact server administrator to fix PHP.ini memory settings.";
  164. die;
  165. }
  166. }
  167. // Continue with lib loading
  168. require_once($CFG->libdir.'/classes/text.php');
  169. require_once($CFG->libdir.'/classes/string_manager.php');
  170. require_once($CFG->libdir.'/classes/string_manager_install.php');
  171. require_once($CFG->libdir.'/classes/string_manager_standard.php');
  172. require_once($CFG->libdir.'/weblib.php');
  173. require_once($CFG->libdir.'/outputlib.php');
  174. require_once($CFG->libdir.'/dmllib.php');
  175. require_once($CFG->libdir.'/moodlelib.php');
  176. require_once($CFG->libdir .'/pagelib.php');
  177. require_once($CFG->libdir.'/deprecatedlib.php');
  178. require_once($CFG->libdir.'/adminlib.php');
  179. require_once($CFG->libdir.'/environmentlib.php');
  180. require_once($CFG->libdir.'/componentlib.class.php');
  181. require_once($CFG->dirroot.'/cache/lib.php');
  182. //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
  183. //the problem is that we need specific version of quickforms and hacked excel files :-(
  184. ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
  185. // Register our classloader, in theory somebody might want to replace it to load other hacked core classes.
  186. // Required because the database checks below lead to session interaction which is going to lead us to requiring autoloaded classes.
  187. if (defined('COMPONENT_CLASSLOADER')) {
  188. spl_autoload_register(COMPONENT_CLASSLOADER);
  189. } else {
  190. spl_autoload_register('core_component::classloader');
  191. }
  192. require('version.php');
  193. $CFG->target_release = $release;
  194. \core\session\manager::init_empty_session();
  195. global $SESSION;
  196. global $USER;
  197. global $COURSE;
  198. $COURSE = new stdClass();
  199. $COURSE->id = 1;
  200. global $SITE;
  201. $SITE = $COURSE;
  202. define('SITEID', 1);
  203. $hint_dataroot = '';
  204. $hint_admindir = '';
  205. $hint_database = '';
  206. // Are we in help mode?
  207. if (isset($_GET['help'])) {
  208. install_print_help_page($_GET['help']);
  209. }
  210. //first time here? find out suitable dataroot
  211. if (is_null($CFG->dataroot)) {
  212. $CFG->dataroot = __DIR__.'/../moodledata';
  213. $i = 0; //safety check - dirname might return some unexpected results
  214. while(is_dataroot_insecure()) {
  215. $parrent = dirname($CFG->dataroot);
  216. $i++;
  217. if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
  218. $CFG->dataroot = ''; //can not find secure location for dataroot
  219. break;
  220. }
  221. $CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
  222. }
  223. $config->dataroot = $CFG->dataroot;
  224. $config->stage = INSTALL_WELCOME;
  225. }
  226. // now let's do the stage work
  227. if ($config->stage < INSTALL_WELCOME) {
  228. $config->stage = INSTALL_WELCOME;
  229. }
  230. if ($config->stage > INSTALL_SAVE) {
  231. $config->stage = INSTALL_SAVE;
  232. }
  233. if ($config->stage == INSTALL_SAVE) {
  234. $CFG->early_install_lang = false;
  235. $database = moodle_database::get_driver_instance($config->dbtype, 'native');
  236. if (!$database->driver_installed()) {
  237. $config->stage = INSTALL_DATABASETYPE;
  238. } else {
  239. if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
  240. $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);
  241. }
  242. $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));
  243. if ($hint_database === '') {
  244. $configphp = install_generate_configphp($database, $CFG);
  245. umask(0137);
  246. if (($fh = @fopen($configfile, 'w')) !== false) {
  247. fwrite($fh, $configphp);
  248. fclose($fh);
  249. }
  250. if (file_exists($configfile)) {
  251. // config created, let's continue!
  252. redirect("$CFG->wwwroot/$config->admin/index.php?lang=$config->lang");
  253. }
  254. install_print_header($config, 'config.php',
  255. get_string('configurationcompletehead', 'install'),
  256. get_string('configurationcompletesub', 'install').get_string('configfilenotwritten', 'install'), 'alert-error');
  257. echo '<div class="configphp"><pre>';
  258. echo p($configphp);
  259. echo '</pre></div>';
  260. install_print_footer($config);
  261. die;
  262. } else {
  263. $config->stage = INSTALL_DATABASE;
  264. }
  265. }
  266. }
  267. if ($config->stage == INSTALL_DOWNLOADLANG) {
  268. if (empty($CFG->dataroot)) {
  269. $config->stage = INSTALL_PATHS;
  270. } else if (is_dataroot_insecure()) {
  271. $hint_dataroot = get_string('pathsunsecuredataroot', 'install');
  272. $config->stage = INSTALL_PATHS;
  273. } else if (!file_exists($CFG->dataroot)) {
  274. $a = new stdClass();
  275. $a->parent = dirname($CFG->dataroot);
  276. $a->dataroot = $CFG->dataroot;
  277. if (!is_writable($a->parent)) {
  278. $hint_dataroot = get_string('pathsroparentdataroot', 'install', $a);
  279. $config->stage = INSTALL_PATHS;
  280. } else {
  281. if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
  282. $hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
  283. $config->stage = INSTALL_PATHS;
  284. }
  285. }
  286. } else if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
  287. $hint_dataroot = get_string('pathserrcreatedataroot', 'install', array('dataroot' => $CFG->dataroot));
  288. $config->stage = INSTALL_PATHS;
  289. }
  290. if (empty($hint_dataroot) and !is_writable($CFG->dataroot)) {
  291. $hint_dataroot = get_string('pathsrodataroot', 'install');
  292. $config->stage = INSTALL_PATHS;
  293. }
  294. if ($config->admin === '' or !file_exists($CFG->dirroot.'/'.$config->admin.'/environment.xml')) {
  295. $hint_admindir = get_string('pathswrongadmindir', 'install');
  296. $config->stage = INSTALL_PATHS;
  297. }
  298. }
  299. if ($config->stage == INSTALL_DOWNLOADLANG) {
  300. // no need to download anything if en lang selected
  301. if ($CFG->lang == 'en') {
  302. $config->stage = INSTALL_DATABASETYPE;
  303. }
  304. }
  305. if ($config->stage == INSTALL_DATABASETYPE) {
  306. // skip db selection if distro package supports only one db
  307. if (!empty($distro->dbtype)) {
  308. $config->stage = INSTALL_DATABASE;
  309. }
  310. }
  311. if ($config->stage == INSTALL_DOWNLOADLANG) {
  312. $downloaderror = '';
  313. // download and install required lang packs, the lang dir has already been created in install_init_dataroot
  314. $installer = new lang_installer($CFG->lang);
  315. $results = $installer->run();
  316. foreach ($results as $langcode => $langstatus) {
  317. if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
  318. $a = new stdClass();
  319. $a->url = $installer->lang_pack_url($langcode);
  320. $a->dest = $CFG->dataroot.'/lang';
  321. $downloaderror = get_string('remotedownloaderror', 'error', $a);
  322. }
  323. }
  324. if ($downloaderror !== '') {
  325. install_print_header($config, get_string('language'), get_string('langdownloaderror', 'install', $CFG->lang), $downloaderror);
  326. install_print_footer($config);
  327. die;
  328. } else {
  329. if (empty($distro->dbtype)) {
  330. $config->stage = INSTALL_DATABASETYPE;
  331. } else {
  332. $config->stage = INSTALL_DATABASE;
  333. }
  334. }
  335. // switch the string_manager instance to stop using install/lang/
  336. $CFG->early_install_lang = false;
  337. $CFG->langotherroot = $CFG->dataroot.'/lang';
  338. $CFG->langlocalroot = $CFG->dataroot.'/lang';
  339. get_string_manager(true);
  340. }
  341. if ($config->stage == INSTALL_DATABASE) {
  342. $CFG->early_install_lang = false;
  343. $database = moodle_database::get_driver_instance($config->dbtype, 'native');
  344. $sub = '<h3>'.$database->get_name().'</h3>'.$database->get_configuration_help();
  345. install_print_header($config, get_string('database', 'install'), get_string('databasehead', 'install'), $sub);
  346. $strdbhost = get_string('databasehost', 'install');
  347. $strdbname = get_string('databasename', 'install');
  348. $strdbuser = get_string('databaseuser', 'install');
  349. $strdbpass = get_string('databasepass', 'install');
  350. $strprefix = get_string('dbprefix', 'install');
  351. $strdbport = get_string('databaseport', 'install');
  352. $strdbsocket = get_string('databasesocket', 'install');
  353. echo '<div class="row mb-4">';
  354. $disabled = empty($distro->dbhost) ? '' : 'disabled="disabled';
  355. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dbhost">'.$strdbhost.'</label></div>';
  356. echo '<div class="col-md-9" data-fieldtype="text">';
  357. echo '<input id="id_dbhost" name="dbhost" '.$disabled.' type="text" class="form-control text-ltr" value="'.s($config->dbhost).'" size="50" /></div>';
  358. echo '</div>';
  359. echo '<div class="row mb-4">';
  360. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dbname">'.$strdbname.'</label></div>';
  361. echo '<div class="col-md-9" data-fieldtype="text">';
  362. echo '<input id="id_dbname" name="dbname" type="text" class="form-control text-ltr" value="'.s($config->dbname).'" size="50" /></div>';
  363. echo '</div>';
  364. $disabled = empty($distro->dbuser) ? '' : 'disabled="disabled';
  365. echo '<div class="row mb-4">';
  366. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dbuser">'.$strdbuser.'</label></div>';
  367. echo '<div class="col-md-9" data-fieldtype="text">';
  368. echo '<input id="id_dbuser" name="dbuser" '.$disabled.' type="text" class="form-control text-ltr" value="'.s($config->dbuser).'" size="50" /></div>';
  369. echo '</div>';
  370. echo '<div class="row mb-4">';
  371. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dbpass">'.$strdbpass.'</label></div>';
  372. // no password field here, the password may be visible in config.php if we can not write it to disk
  373. echo '<div class="col-md-9" data-fieldtype="text">';
  374. echo '<input id="id_dbpass" name="dbpass" type="text" class="form-control text-ltr" value="'.s($config->dbpass).'" size="50" /></div>';
  375. echo '</div>';
  376. echo '<div class="row mb-4">';
  377. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_prefix">'.$strprefix.'</label></div>';
  378. echo '<div class="col-md-9" data-fieldtype="text">';
  379. echo '<input id="id_prefix" name="prefix" type="text" class="form-control text-ltr" value="'.s($config->prefix).'" size="10" /></div>';
  380. echo '</div>';
  381. echo '<div class="row mb-4">';
  382. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_prefix">'.$strdbport.'</label></div>';
  383. echo '<div class="col-md-9" data-fieldtype="text">';
  384. echo '<input id="id_dbport" name="dbport" type="text" class="form-control text-ltr" value="'.s($config->dbport).'" size="10" /></div>';
  385. echo '</div>';
  386. if (!(stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin'))) {
  387. echo '<div class="row mb-4">';
  388. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dbsocket">'.$strdbsocket.'</label></div>';
  389. echo '<div class="col-md-9" data-fieldtype="text">';
  390. echo '<input id="id_dbsocket" name="dbsocket" type="text" class="form-control text-ltr" value="'.s($config->dbsocket).'" size="50" /></div>';
  391. echo '</div>';
  392. }
  393. if ($hint_database !== '') {
  394. echo '<div class="alert alert-danger">'.$hint_database.'</div>';
  395. }
  396. echo '</div>';
  397. install_print_footer($config);
  398. die;
  399. }
  400. if ($config->stage == INSTALL_DATABASETYPE) {
  401. $CFG->early_install_lang = false;
  402. // Finally ask for DB type
  403. install_print_header($config, get_string('database', 'install'),
  404. get_string('databasetypehead', 'install'),
  405. get_string('databasetypesub', 'install'));
  406. $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
  407. 'auroramysql' => moodle_database::get_driver_instance('auroramysql', 'native'),
  408. 'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
  409. 'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'),
  410. 'oci' => moodle_database::get_driver_instance('oci', 'native'),
  411. 'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
  412. );
  413. echo '<div class="row mb-4">';
  414. echo '<div class="col-md-3 text-md-right pt-1"><label for="dbtype">'.get_string('dbtype', 'install').'</label></div>';
  415. echo '<div class="col-md-9" data-fieldtype="select">';
  416. echo '<select class="form-control" id="dbtype" name="dbtype">';
  417. $disabled = array();
  418. $options = array();
  419. foreach ($databases as $type=>$database) {
  420. if ($database->driver_installed() !== true) {
  421. $disabled[$type] = $database;
  422. continue;
  423. }
  424. echo '<option value="'.s($type).'">'.$database->get_name().'</option>';
  425. }
  426. if ($disabled) {
  427. echo '<optgroup label="'.s(get_string('notavailable')).'">';
  428. foreach ($disabled as $type=>$database) {
  429. echo '<option value="'.s($type).'" class="notavailable">'.$database->get_name().'</option>';
  430. }
  431. echo '</optgroup>';
  432. }
  433. echo '</select></div></div>';
  434. install_print_footer($config);
  435. die;
  436. }
  437. if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) {
  438. $curl_fail = ($lang !== 'en' and !extension_loaded('curl')); // needed for lang pack download
  439. $zip_fail = ($lang !== 'en' and !extension_loaded('zip')); // needed for lang pack download
  440. if ($curl_fail or $zip_fail) {
  441. $config->stage = INSTALL_ENVIRONMENT;
  442. install_print_header($config, get_string('environmenthead', 'install'),
  443. get_string('errorsinenvironment', 'install'),
  444. get_string('environmentsub2', 'install'));
  445. echo '<div id="envresult"><dl>';
  446. if ($curl_fail) {
  447. echo '<dt>'.get_string('phpextension', 'install', 'cURL').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>';
  448. }
  449. if ($zip_fail) {
  450. echo '<dt>'.get_string('phpextension', 'install', 'Zip').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>';
  451. }
  452. echo '</dl></div>';
  453. install_print_footer($config, true);
  454. die;
  455. } else {
  456. $config->stage = INSTALL_PATHS;
  457. }
  458. }
  459. if ($config->stage == INSTALL_PATHS) {
  460. $paths = array('wwwroot' => get_string('wwwroot', 'install'),
  461. 'dirroot' => get_string('dirroot', 'install'),
  462. 'dataroot' => get_string('dataroot', 'install'));
  463. $sub = '<dl>';
  464. foreach ($paths as $path=>$name) {
  465. $sub .= '<dt>'.$name.'</dt><dd>'.get_string('pathssub'.$path, 'install').'</dd>';
  466. }
  467. if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
  468. $sub .= '<dt>'.get_string('admindirname', 'install').'</dt><dd>'.get_string('pathssubadmindir', 'install').'</dd>';
  469. }
  470. $sub .= '</dl>';
  471. install_print_header($config, get_string('paths', 'install'), get_string('pathshead', 'install'), $sub);
  472. $strwwwroot = get_string('wwwroot', 'install');
  473. $strdirroot = get_string('dirroot', 'install');
  474. $strdataroot = get_string('dataroot', 'install');
  475. $stradmindirname = get_string('admindirname', 'install');
  476. echo '<div class="row mb-4">';
  477. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_wwwroot">'.$paths['wwwroot'].'</label></div>';
  478. echo '<div class="col-md-9" data-fieldtype="text">';
  479. echo '<input id="id_wwwroot" name="wwwroot" type="text" class="form-control text-ltr" value="'.s($CFG->wwwroot).'" disabled="disabled" size="70" /></div>';
  480. echo '</div>';
  481. echo '<div class="row mb-4">';
  482. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dirroot">'.$paths['dirroot'].'</label></div>';
  483. echo '<div class="col-md-9" data-fieldtype="text">';
  484. echo '<input id="id_dirroot" name="dirroot" type="text" class="form-control text-ltr" value="'.s($CFG->dirroot).'" disabled="disabled" size="70" /></div>';
  485. echo '</div>';
  486. echo '<div class="row mb-4">';
  487. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_dataroot">'.$paths['dataroot'].'</label></div>';
  488. echo '<div class="col-md-9" data-fieldtype="text">';
  489. echo '<input id="id_dataroot" name="dataroot" type="text" class="form-control text-ltr" value="'.s($config->dataroot).'" size="70" /></div>';
  490. echo '</div>';
  491. if ($hint_dataroot !== '') {
  492. echo '<div class="alert alert-danger">'.$hint_dataroot.'</div>';
  493. }
  494. if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
  495. echo '<div class="row mb-4">';
  496. echo '<div class="col-md-3 text-md-right pt-1"><label for="id_admin">'.$paths['admindir'].'</label></div>';
  497. echo '<div class="col-md-9" data-fieldtype="text">';
  498. echo '<input id="id_admin" name="admin" type="text" class="form-control text-ltr" value="'.s($config->admin).'" size="10" /></div>';
  499. echo '</div>';
  500. if ($hint_admindir !== '') {
  501. echo '<div class="alert alert-danger">'.$hint_admindir.'</div>';
  502. }
  503. echo '</div>';
  504. }
  505. echo '</div>';
  506. install_print_footer($config);
  507. die;
  508. }
  509. $config->stage = INSTALL_WELCOME;
  510. if ($distro) {
  511. ob_start();
  512. include('install/distribution.html');
  513. $sub = ob_get_clean();
  514. install_print_header($config, get_string('language'),
  515. get_string('chooselanguagehead', 'install'),
  516. $sub, 'alert-success');
  517. } else {
  518. install_print_header($config, get_string('language'),
  519. get_string('chooselanguagehead', 'install'),
  520. get_string('chooselanguagesub', 'install'));
  521. }
  522. $languages = get_string_manager()->get_list_of_translations();
  523. echo '<div class="row mb-4">';
  524. echo '<div class="col-md-3 text-md-right pt-1"><label for="langselect">'.get_string('language').'</label></div>';
  525. echo '<div class="col-md-9" data-fieldtype="select">';
  526. echo '<select id="langselect" class="form-control" name="lang" onchange="this.form.submit()">';
  527. foreach ($languages as $name=>$value) {
  528. $selected = ($name == $CFG->lang) ? 'selected="selected"' : '';
  529. echo '<option value="'.s($name).'" '.$selected.'>'.$value.'</option>';
  530. }
  531. echo '</select></div>';
  532. echo '</div>';
  533. install_print_footer($config);
  534. die;