install.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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.
  56. if (version_compare(phpversion(), '5.6.5') < 0) {
  57. $phpversion = phpversion();
  58. // do NOT localise - lang strings would not work here and we CAN not move it after installib
  59. echo "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).<br />";
  60. echo "Please upgrade your server software or install older Moodle version.";
  61. die;
  62. }
  63. // make sure iconv is available and actually works
  64. if (!function_exists('iconv')) {
  65. // this should not happen, this must be very borked install
  66. echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
  67. die();
  68. }
  69. if (PHP_INT_SIZE > 4) {
  70. // most probably 64bit PHP - we need a lot more memory
  71. $minrequiredmemory = '70M';
  72. } else {
  73. // 32bit PHP
  74. $minrequiredmemory = '40M';
  75. }
  76. // increase or decrease available memory - we need to make sure moodle
  77. // installs even with low memory, otherwise developers would overlook
  78. // sudden increases of memory needs ;-)
  79. @ini_set('memory_limit', $minrequiredmemory);
  80. /** Used by library scripts to check they are being called by Moodle */
  81. define('MOODLE_INTERNAL', true);
  82. require_once(__DIR__.'/lib/classes/component.php');
  83. require_once(__DIR__.'/lib/installlib.php');
  84. // TODO: add lang detection here if empty $_REQUEST['lang']
  85. // distro specific customisation
  86. $distro = null;
  87. if (file_exists('install/distrolib.php')) {
  88. require_once('install/distrolib.php');
  89. if (function_exists('distro_get_config')) {
  90. $distro = distro_get_config();
  91. }
  92. }
  93. $config = new stdClass();
  94. $config->lang = $lang;
  95. if (!empty($_POST)) {
  96. $config->stage = (int)$_POST['stage'];
  97. if (isset($_POST['previous'])) {
  98. $config->stage--;
  99. if (INSTALL_DATABASETYPE and !empty($distro->dbtype)) {
  100. $config->stage--;
  101. }
  102. if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_DOWNLOADLANG) {
  103. $config->stage--;
  104. }
  105. } else if (isset($_POST['next'])) {
  106. $config->stage++;
  107. }
  108. $config->dbtype = trim($_POST['dbtype']);
  109. $config->dbhost = trim($_POST['dbhost']);
  110. $config->dbuser = trim($_POST['dbuser']);
  111. $config->dbpass = trim($_POST['dbpass']);
  112. $config->dbname = trim($_POST['dbname']);
  113. $config->prefix = trim($_POST['prefix']);
  114. $config->dbport = (int)trim($_POST['dbport']);
  115. $config->dbsocket = trim($_POST['dbsocket']);
  116. if ($config->dbport <= 0) {
  117. $config->dbport = '';
  118. }
  119. $config->admin = empty($_POST['admin']) ? 'admin' : trim($_POST['admin']);
  120. $config->dataroot = trim($_POST['dataroot']);
  121. } else {
  122. $config->stage = INSTALL_WELCOME;
  123. $config->dbtype = empty($distro->dbtype) ? '' : $distro->dbtype; // let distro skip dbtype selection
  124. $config->dbhost = empty($distro->dbhost) ? 'localhost' : $distro->dbhost; // let distros set dbhost
  125. $config->dbuser = empty($distro->dbuser) ? '' : $distro->dbuser; // let distros set dbuser
  126. $config->dbpass = '';
  127. $config->dbname = 'moodle';
  128. $config->prefix = 'mdl_';
  129. $config->dbport = empty($distro->dbport) ? '' : $distro->dbport;
  130. $config->dbsocket = empty($distro->dbsocket) ? '' : $distro->dbsocket;
  131. $config->admin = 'admin';
  132. $config->dataroot = empty($distro->dataroot) ? null : $distro->dataroot; // initialised later after including libs or by distro
  133. }
  134. // Fake some settings so that we can use selected functions from moodlelib.php, weblib.php and filelib.php.
  135. global $CFG;
  136. $CFG = new stdClass();
  137. $CFG->lang = $config->lang;
  138. $CFG->dirroot = __DIR__;
  139. $CFG->libdir = "$CFG->dirroot/lib";
  140. $CFG->wwwroot = install_guess_wwwroot(); // can not be changed - ppl must use the real address when installing
  141. $CFG->httpswwwroot = $CFG->wwwroot;
  142. $CFG->dataroot = $config->dataroot;
  143. $CFG->tempdir = $CFG->dataroot.'/temp';
  144. $CFG->cachedir = $CFG->dataroot.'/cache';
  145. $CFG->localcachedir = $CFG->dataroot.'/localcache';
  146. $CFG->admin = $config->admin;
  147. $CFG->docroot = 'http://docs.moodle.org';
  148. $CFG->langotherroot = $CFG->dataroot.'/lang';
  149. $CFG->langlocalroot = $CFG->dataroot.'/lang';
  150. $CFG->directorypermissions = isset($distro->directorypermissions) ? $distro->directorypermissions : 00777; // let distros set dir permissions
  151. $CFG->filepermissions = ($CFG->directorypermissions & 0666);
  152. $CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777);
  153. $CFG->running_installer = true;
  154. $CFG->early_install_lang = true;
  155. $CFG->ostype = (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) ? 'WINDOWS' : 'UNIX';
  156. $CFG->debug = (E_ALL | E_STRICT);
  157. $CFG->debugdisplay = true;
  158. $CFG->debugdeveloper = true;
  159. // Require all needed libs
  160. require_once($CFG->libdir.'/setuplib.php');
  161. // we need to make sure we have enough memory to load all libraries
  162. $memlimit = @ini_get('memory_limit');
  163. if (!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 "Moodle 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. // Continue with lib loading
  172. require_once($CFG->libdir.'/classes/text.php');
  173. require_once($CFG->libdir.'/classes/string_manager.php');
  174. require_once($CFG->libdir.'/classes/string_manager_install.php');
  175. require_once($CFG->libdir.'/classes/string_manager_standard.php');
  176. require_once($CFG->libdir.'/weblib.php');
  177. require_once($CFG->libdir.'/outputlib.php');
  178. require_once($CFG->libdir.'/dmllib.php');
  179. require_once($CFG->libdir.'/moodlelib.php');
  180. require_once($CFG->libdir .'/pagelib.php');
  181. require_once($CFG->libdir.'/deprecatedlib.php');
  182. require_once($CFG->libdir.'/adminlib.php');
  183. require_once($CFG->libdir.'/environmentlib.php');
  184. require_once($CFG->libdir.'/componentlib.class.php');
  185. require_once($CFG->dirroot.'/cache/lib.php');
  186. //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
  187. //the problem is that we need specific version of quickforms and hacked excel files :-(
  188. ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
  189. // Register our classloader, in theory somebody might want to replace it to load other hacked core classes.
  190. // Required because the database checks below lead to session interaction which is going to lead us to requiring autoloaded classes.
  191. if (defined('COMPONENT_CLASSLOADER')) {
  192. spl_autoload_register(COMPONENT_CLASSLOADER);
  193. } else {
  194. spl_autoload_register('core_component::classloader');
  195. }
  196. require('version.php');
  197. $CFG->target_release = $release;
  198. \core\session\manager::init_empty_session();
  199. global $SESSION;
  200. global $USER;
  201. global $COURSE;
  202. $COURSE = new stdClass();
  203. $COURSE->id = 1;
  204. global $SITE;
  205. $SITE = $COURSE;
  206. define('SITEID', 1);
  207. $hint_dataroot = '';
  208. $hint_admindir = '';
  209. $hint_database = '';
  210. // Are we in help mode?
  211. if (isset($_GET['help'])) {
  212. install_print_help_page($_GET['help']);
  213. }
  214. //first time here? find out suitable dataroot
  215. if (is_null($CFG->dataroot)) {
  216. $CFG->dataroot = __DIR__.'/../moodledata';
  217. $i = 0; //safety check - dirname might return some unexpected results
  218. while(is_dataroot_insecure()) {
  219. $parrent = dirname($CFG->dataroot);
  220. $i++;
  221. if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
  222. $CFG->dataroot = ''; //can not find secure location for dataroot
  223. break;
  224. }
  225. $CFG->dataroot = dirname($parrent).DIRECTORY_SEPARATOR.'moodledata';
  226. }
  227. $config->dataroot = $CFG->dataroot;
  228. $config->stage = INSTALL_WELCOME;
  229. }
  230. // now let's do the stage work
  231. if ($config->stage < INSTALL_WELCOME) {
  232. $config->stage = INSTALL_WELCOME;
  233. }
  234. if ($config->stage > INSTALL_SAVE) {
  235. $config->stage = INSTALL_SAVE;
  236. }
  237. if ($config->stage == INSTALL_SAVE) {
  238. $CFG->early_install_lang = false;
  239. $database = moodle_database::get_driver_instance($config->dbtype, 'native');
  240. if (!$database->driver_installed()) {
  241. $config->stage = INSTALL_DATABASETYPE;
  242. } else {
  243. if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
  244. $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);
  245. }
  246. $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));
  247. if ($hint_database === '') {
  248. $configphp = install_generate_configphp($database, $CFG);
  249. umask(0137);
  250. if (($fh = @fopen($configfile, 'w')) !== false) {
  251. fwrite($fh, $configphp);
  252. fclose($fh);
  253. }
  254. if (file_exists($configfile)) {
  255. // config created, let's continue!
  256. redirect("$CFG->wwwroot/$config->admin/index.php?lang=$config->lang");
  257. }
  258. install_print_header($config, 'config.php',
  259. get_string('configurationcompletehead', 'install'),
  260. get_string('configurationcompletesub', 'install').get_string('configfilenotwritten', 'install'), 'alert-error');
  261. echo '<div class="configphp"><pre>';
  262. echo p($configphp);
  263. echo '</pre></div>';
  264. install_print_footer($config);
  265. die;
  266. } else {
  267. $config->stage = INSTALL_DATABASE;
  268. }
  269. }
  270. }
  271. if ($config->stage == INSTALL_DOWNLOADLANG) {
  272. if (empty($CFG->dataroot)) {
  273. $config->stage = INSTALL_PATHS;
  274. } else if (is_dataroot_insecure()) {
  275. $hint_dataroot = get_string('pathsunsecuredataroot', 'install');
  276. $config->stage = INSTALL_PATHS;
  277. } else if (!file_exists($CFG->dataroot)) {
  278. $a = new stdClass();
  279. $a->parent = dirname($CFG->dataroot);
  280. $a->dataroot = $CFG->dataroot;
  281. if (!is_writable($a->parent)) {
  282. $hint_dataroot = get_string('pathsroparentdataroot', 'install', $a);
  283. $config->stage = INSTALL_PATHS;
  284. } else {
  285. if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
  286. $hint_dataroot = get_string('pathserrcreatedataroot', 'install', $a);
  287. $config->stage = INSTALL_PATHS;
  288. }
  289. }
  290. } else if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
  291. $hint_dataroot = get_string('pathserrcreatedataroot', 'install', array('dataroot' => $CFG->dataroot));
  292. $config->stage = INSTALL_PATHS;
  293. }
  294. if (empty($hint_dataroot) and !is_writable($CFG->dataroot)) {
  295. $hint_dataroot = get_string('pathsrodataroot', 'install');
  296. $config->stage = INSTALL_PATHS;
  297. }
  298. if ($config->admin === '' or !file_exists($CFG->dirroot.'/'.$config->admin.'/environment.xml')) {
  299. $hint_admindir = get_string('pathswrongadmindir', 'install');
  300. $config->stage = INSTALL_PATHS;
  301. }
  302. }
  303. if ($config->stage == INSTALL_DOWNLOADLANG) {
  304. // no need to download anything if en lang selected
  305. if ($CFG->lang == 'en') {
  306. $config->stage = INSTALL_DATABASETYPE;
  307. }
  308. }
  309. if ($config->stage == INSTALL_DATABASETYPE) {
  310. // skip db selection if distro package supports only one db
  311. if (!empty($distro->dbtype)) {
  312. $config->stage = INSTALL_DATABASE;
  313. }
  314. }
  315. if ($config->stage == INSTALL_DOWNLOADLANG) {
  316. $downloaderror = '';
  317. // download and install required lang packs, the lang dir has already been created in install_init_dataroot
  318. $installer = new lang_installer($CFG->lang);
  319. $results = $installer->run();
  320. foreach ($results as $langcode => $langstatus) {
  321. if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
  322. $a = new stdClass();
  323. $a->url = $installer->lang_pack_url($langcode);
  324. $a->dest = $CFG->dataroot.'/lang';
  325. $downloaderror = get_string('remotedownloaderror', 'error', $a);
  326. }
  327. }
  328. if ($downloaderror !== '') {
  329. install_print_header($config, get_string('language'), get_string('langdownloaderror', 'install', $CFG->lang), $downloaderror);
  330. install_print_footer($config);
  331. die;
  332. } else {
  333. if (empty($distro->dbtype)) {
  334. $config->stage = INSTALL_DATABASETYPE;
  335. } else {
  336. $config->stage = INSTALL_DATABASE;
  337. }
  338. }
  339. // switch the string_manager instance to stop using install/lang/
  340. $CFG->early_install_lang = false;
  341. $CFG->langotherroot = $CFG->dataroot.'/lang';
  342. $CFG->langlocalroot = $CFG->dataroot.'/lang';
  343. get_string_manager(true);
  344. }
  345. if ($config->stage == INSTALL_DATABASE) {
  346. $CFG->early_install_lang = false;
  347. $database = moodle_database::get_driver_instance($config->dbtype, 'native');
  348. $sub = '<h3>'.$database->get_name().'</h3>'.$database->get_configuration_help();
  349. install_print_header($config, get_string('database', 'install'), get_string('databasehead', 'install'), $sub);
  350. $strdbhost = get_string('databasehost', 'install');
  351. $strdbname = get_string('databasename', 'install');
  352. $strdbuser = get_string('databaseuser', 'install');
  353. $strdbpass = get_string('databasepass', 'install');
  354. $strprefix = get_string('dbprefix', 'install');
  355. $strdbport = get_string('databaseport', 'install');
  356. $strdbsocket = get_string('databasesocket', 'install');
  357. echo '<div class="userinput">';
  358. $disabled = empty($distro->dbhost) ? '' : 'disabled="disabled';
  359. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dbhost">'.$strdbhost.'</label></div>';
  360. echo '<div class="fitemelement"><input id="id_dbhost" name="dbhost" '.$disabled.' type="text" value="'.s($config->dbhost).'" size="50" /></div>';
  361. echo '</div>';
  362. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dbname">'.$strdbname.'</label></div>';
  363. echo '<div class="fitemelement"><input id="id_dbname" name="dbname" type="text" value="'.s($config->dbname).'" size="50" /></div>';
  364. echo '</div>';
  365. $disabled = empty($distro->dbuser) ? '' : 'disabled="disabled';
  366. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dbuser">'.$strdbuser.'</label></div>';
  367. echo '<div class="fitemelement"><input id="id_dbuser" name="dbuser" '.$disabled.' type="text" value="'.s($config->dbuser).'" size="50" /></div>';
  368. echo '</div>';
  369. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dbpass">'.$strdbpass.'</label></div>';
  370. // no password field here, the password may be visible in config.php if we can not write it to disk
  371. echo '<div class="fitemelement"><input id="id_dbpass" name="dbpass" type="text" value="'.s($config->dbpass).'" size="50" /></div>';
  372. echo '</div>';
  373. echo '<div class="fitem"><div class="fitemtitle"><label for="id_prefix">'.$strprefix.'</label></div>';
  374. echo '<div class="fitemelement"><input id="id_prefix" name="prefix" type="text" value="'.s($config->prefix).'" size="10" /></div>';
  375. echo '</div>';
  376. echo '<div class="fitem"><div class="fitemtitle"><label for="id_prefix">'.$strdbport.'</label></div>';
  377. echo '<div class="fitemelement"><input id="id_dbport" name="dbport" type="text" value="'.s($config->dbport).'" size="10" /></div>';
  378. echo '</div>';
  379. if (!(stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin'))) {
  380. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dbsocket">'.$strdbsocket.'</label></div>';
  381. echo '<div class="fitemelement"><input id="id_dbsocket" name="dbsocket" type="text" value="'.s($config->dbsocket).'" size="50" /></div>';
  382. echo '</div>';
  383. }
  384. if ($hint_database !== '') {
  385. echo '<div class="alert alert-error">'.$hint_database.'</div>';
  386. }
  387. echo '</div>';
  388. install_print_footer($config);
  389. die;
  390. }
  391. if ($config->stage == INSTALL_DATABASETYPE) {
  392. $CFG->early_install_lang = false;
  393. // Finally ask for DB type
  394. install_print_header($config, get_string('database', 'install'),
  395. get_string('databasetypehead', 'install'),
  396. get_string('databasetypesub', 'install'));
  397. $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
  398. 'mariadb'=> moodle_database::get_driver_instance('mariadb', 'native'),
  399. 'pgsql' => moodle_database::get_driver_instance('pgsql', 'native'),
  400. 'oci' => moodle_database::get_driver_instance('oci', 'native'),
  401. 'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
  402. 'mssql' => moodle_database::get_driver_instance('mssql', 'native'), // FreeTDS driver
  403. );
  404. echo '<div class="userinput">';
  405. echo '<div class="fitem"><div class="fitemtitle"><label for="dbtype">'.get_string('dbtype', 'install').'</label></div>';
  406. echo '<div class="fitemelement"><select id="dbtype" name="dbtype">';
  407. $disabled = array();
  408. $options = array();
  409. foreach ($databases as $type=>$database) {
  410. if ($database->driver_installed() !== true) {
  411. $disabled[$type] = $database;
  412. continue;
  413. }
  414. echo '<option value="'.s($type).'">'.$database->get_name().'</option>';
  415. }
  416. if ($disabled) {
  417. echo '<optgroup label="'.s(get_string('notavailable')).'">';
  418. foreach ($disabled as $type=>$database) {
  419. echo '<option value="'.s($type).'" class="notavailable">'.$database->get_name().'</option>';
  420. }
  421. echo '</optgroup>';
  422. }
  423. echo '</select></div></div>';
  424. echo '</div>';
  425. install_print_footer($config);
  426. die;
  427. }
  428. if ($config->stage == INSTALL_ENVIRONMENT or $config->stage == INSTALL_PATHS) {
  429. $curl_fail = ($lang !== 'en' and !extension_loaded('curl')); // needed for lang pack download
  430. $zip_fail = ($lang !== 'en' and !extension_loaded('zip')); // needed for lang pack download
  431. if ($curl_fail or $zip_fail) {
  432. $config->stage = INSTALL_ENVIRONMENT;
  433. install_print_header($config, get_string('environmenthead', 'install'),
  434. get_string('errorsinenvironment', 'install'),
  435. get_string('environmentsub2', 'install'));
  436. echo '<div id="envresult"><dl>';
  437. if ($curl_fail) {
  438. echo '<dt>'.get_string('phpextension', 'install', 'cURL').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>';
  439. }
  440. if ($zip_fail) {
  441. echo '<dt>'.get_string('phpextension', 'install', 'Zip').'</dt><dd>'.get_string('environmentrequireinstall', 'admin').'</dd>';
  442. }
  443. echo '</dl></div>';
  444. install_print_footer($config, true);
  445. die;
  446. } else {
  447. $config->stage = INSTALL_PATHS;
  448. }
  449. }
  450. if ($config->stage == INSTALL_PATHS) {
  451. $paths = array('wwwroot' => get_string('wwwroot', 'install'),
  452. 'dirroot' => get_string('dirroot', 'install'),
  453. 'dataroot' => get_string('dataroot', 'install'));
  454. $sub = '<dl>';
  455. foreach ($paths as $path=>$name) {
  456. $sub .= '<dt>'.$name.'</dt><dd>'.get_string('pathssub'.$path, 'install').'</dd>';
  457. }
  458. if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
  459. $sub .= '<dt>'.get_string('admindirname', 'install').'</dt><dd>'.get_string('pathssubadmindir', 'install').'</dd>';
  460. }
  461. $sub .= '</dl>';
  462. install_print_header($config, get_string('paths', 'install'), get_string('pathshead', 'install'), $sub);
  463. $strwwwroot = get_string('wwwroot', 'install');
  464. $strdirroot = get_string('dirroot', 'install');
  465. $strdataroot = get_string('dataroot', 'install');
  466. $stradmindirname = get_string('admindirname', 'install');
  467. echo '<div class="userinput">';
  468. echo '<div class="fitem"><div class="fitemtitle"><label for="id_wwwroot">'.$paths['wwwroot'].'</label></div>';
  469. echo '<div class="fitemelement"><input id="id_wwwroot" name="wwwroot" type="text" value="'.s($CFG->wwwroot).'" disabled="disabled" size="70" /></div>';
  470. echo '</div>';
  471. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dirroot">'.$paths['dirroot'].'</label></div>';
  472. echo '<div class="fitemelement"><input id="id_dirroot" name="dirroot" type="text" value="'.s($CFG->dirroot).'" disabled="disabled" size="70" /></div>';
  473. echo '</div>';
  474. echo '<div class="fitem"><div class="fitemtitle"><label for="id_dataroot">'.$paths['dataroot'].'</label></div>';
  475. echo '<div class="fitemelement"><input id="id_dataroot" name="dataroot" type="text" value="'.s($config->dataroot).'" size="70" /></div>';
  476. if ($hint_dataroot !== '') {
  477. echo '<div class="alert alert-error">'.$hint_dataroot.'</div>';
  478. }
  479. echo '</div>';
  480. if (!file_exists("$CFG->dirroot/admin/environment.xml")) {
  481. echo '<div class="fitem"><div class="fitemtitle"><label for="id_admin">'.$paths['admindir'].'</label></div>';
  482. echo '<div class="fitemelement"><input id="id_admin" name="admin" type="text" value="'.s($config->admin).'" size="10" /></div>';
  483. if ($hint_admindir !== '') {
  484. echo '<div class="alert alert-error">'.$hint_admindir.'</div>';
  485. }
  486. echo '</div>';
  487. }
  488. echo '</div>';
  489. install_print_footer($config);
  490. die;
  491. }
  492. $config->stage = INSTALL_WELCOME;
  493. if ($distro) {
  494. ob_start();
  495. include('install/distribution.html');
  496. $sub = ob_get_clean();
  497. install_print_header($config, get_string('language'),
  498. get_string('chooselanguagehead', 'install'),
  499. $sub, 'alert-success');
  500. } else {
  501. install_print_header($config, get_string('language'),
  502. get_string('chooselanguagehead', 'install'),
  503. get_string('chooselanguagesub', 'install'));
  504. }
  505. $languages = get_string_manager()->get_list_of_translations();
  506. echo '<div class="userinput">';
  507. echo '<div class="fitem"><div class="fitemtitle"><label for="langselect">'.get_string('language').'</label></div>';
  508. echo '<div class="fitemelement"><select id="langselect" name="lang" onchange="this.form.submit()">';
  509. foreach ($languages as $name=>$value) {
  510. $selected = ($name == $CFG->lang) ? 'selected="selected"' : '';
  511. echo '<option value="'.s($name).'" '.$selected.'>'.$value.'</option>';
  512. }
  513. echo '</select></div></div>';
  514. echo '</div>';
  515. install_print_footer($config);
  516. die;