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