Some more strings added to the installer to make it more resposible.
[moodle.git] / install.php
CommitLineData
8b5b1028 1<?php /// $Id$
2 /// install.php - helps admin user to create a config.php file
3
4/// If config.php exists already then we are not needed.
5
51e3e0b9 6if (file_exists('./config.php')) {
8b5b1028 7 header('Location: index.php');
51e3e0b9 8 die;
8b5b1028 9} else {
10 $configfile = './config.php';
11}
12
13///==========================================================================//
14/// We are doing this in stages
3470b39f 15define ('WELCOME', 0); /// 0. Welcome and language settings
16define ('COMPATIBILITY', 1); /// 1. Compatibility
17define ('DIRECTORY', 2); /// 2. Directory settings
18define ('DATABASE', 3); /// 2. Database settings
19define ('ADMIN', 4); /// 4. Administration directory name
3b3b8029 20define ('ENVIRONMENT', 5); /// 5. Administration directory name
68a3f81d 21define ('DOWNLOADLANG', 6); /// 6. Load complete lang from download.moodle.org
22define ('SAVE', 7); /// 7. Save or display the settings
23define ('REDIRECT', 8); /// 8. Redirect to index.php
8b5b1028 24///==========================================================================//
25
26
8d783716 27
8b5b1028 28/// Begin the session as we are holding all information in a session
29/// variable until the end.
30
31session_name('MoodleSession');
32@session_start();
33
34if (! isset($_SESSION['INSTALL'])) {
35 $_SESSION['INSTALL'] = array();
36}
37
38$INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
39
8d783716 40
41/// If it's our first time through this script then we need to set some default values
42
43if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
8b5b1028 44
45 /// set defaults
b9b4e32a 46 $INSTALL['language'] = 'en_utf8';
8b5b1028 47
48 $INSTALL['dbhost'] = 'localhost';
49 $INSTALL['dbuser'] = '';
50 $INSTALL['dbpass'] = '';
51 $INSTALL['dbtype'] = 'mysql';
52 $INSTALL['dbname'] = 'moodle';
53 $INSTALL['prefix'] = 'mdl_';
54
b4dd571d 55 $INSTALL['dbencodingtestresults'] = false;
56 $INSTALL['showskipdbencodingtest'] = false;
57 $INSTALL['skipdbencodingtest'] = false;
58
cdef6d42 59 $INSTALL['downloadlangpack'] = false;
60 $INSTALL['showdownloadlangpack'] = true;
61 $INSTALL['downloadlangpackerror'] = '';
62
63/// To be used by the Installer
8b5b1028 64 $INSTALL['wwwroot'] = '';
65 $INSTALL['dirroot'] = dirname(__FILE__);
66 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
67
cdef6d42 68/// To be configured in the Installer
69 $INSTALL['wwwrootform'] = '';
70 $INSTALL['dirrootform'] = dirname(__FILE__);
71
8b5b1028 72 $INSTALL['admindirname'] = 'admin';
73
3470b39f 74 $INSTALL['stage'] = WELCOME;
8b5b1028 75}
76
3b3b8029 77//==========================================================================//
78
bd507453 79/// Set the page to Unicode always
80
81header('Content-Type: text/html; charset=UTF-8');
82
3b3b8029 83/// Was data submitted?
84
85if (isset($_POST['stage'])) {
86
87 /// Get the stage for which the form was set and the next stage we are going to
88
89
90 if ( $goforward = (! empty( $_POST['next'] )) ) {
91 $nextstage = $_POST['stage'] + 1;
cdef6d42 92 } else if (! empty( $_POST['prev'])) {
3b3b8029 93 $nextstage = $_POST['stage'] - 1;
cdef6d42 94 } else if (! empty( $_POST['same'] )) {
95 $nextstage = $_POST['stage'];
3b3b8029 96 }
97
98
99 if ($nextstage < 0) $nextstage = WELCOME;
100
101
102 /// Store any posted data
103 foreach ($_POST as $setting=>$value) {
104 $INSTALL[$setting] = $value;
105 }
106
107} else {
8b5b1028 108
3b3b8029 109 $goforward = true;
110 $nextstage = WELCOME;
111
112}
8b5b1028 113
114//==========================================================================//
115
116/// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
8d783716 117
8b5b1028 118$SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
119$CFG->dirroot = $INSTALL['dirroot'];
72452dc1 120$CFG->libdir = $INSTALL['dirroot'].'/lib';
8b5b1028 121$CFG->dataroot = $INSTALL['dataroot'];
3b3b8029 122$CFG->admin = $INSTALL['admindirname'];
4b9efec4 123$CFG->directorypermissions = 00777;
b9b4e32a 124$CFG->running_installer = true;
8b5b1028 125
8d783716 126/// Include some moodle libraries
127
add47d44 128require_once('./lib/adminlib.php');
72452dc1 129require_once('./lib/setuplib.php');
8b5b1028 130require_once('./lib/moodlelib.php');
131require_once('./lib/weblib.php');
132require_once('./lib/adodb/adodb.inc.php');
3b3b8029 133require_once('./lib/environmentlib.php');
134require_once('./lib/xmlize.php');
68a3f81d 135require_once('./lib/componentlib.class.php');
3b3b8029 136require_once('./version.php');
8b5b1028 137
3b3b8029 138/// Set version and release
139$INSTALL['version'] = $version;
140$INSTALL['release'] = $release;
141
142/// Have the $db object ready because we are going to use it often
143$db = &ADONewConnection($INSTALL['dbtype']);
8b5b1028 144
bb5a61a1 145/// guess the www root
8b5b1028 146if ($INSTALL['wwwroot'] == '') {
147 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
cdef6d42 148 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
add47d44 149
150 // now try to guess the correct dataroot not accessible via web
151 $CFG->wwwroot = $INSTALL['wwwroot'];
152 $i = 0; //safety check - dirname might return some unexpected results
153 while(is_dataroot_insecure()) {
154 $parrent = dirname($CFG->dataroot);
155 $i++;
b735d140 156 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
add47d44 157 $CFG->dataroot = ''; //can not find secure location for dataroot
158 break;
159 }
160 $CFG->dataroot = dirname($parrent).'/moodledata';
161 }
162 $INSTALL['dataroot'] = $CFG->dataroot;
8b5b1028 163}
164
e6f930f3 165$headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
166 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
167 DIRECTORY => get_string('directorysettingshead', 'install'),
168 DATABASE => get_string('databasesettingshead', 'install'),
169 ADMIN => get_string('admindirsettinghead', 'install'),
3b3b8029 170 ENVIRONMENT => get_string('environmenthead', 'install'),
68a3f81d 171 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
e6f930f3 172 SAVE => get_string('configurationcompletehead', 'install')
173 );
8b5b1028 174
e6f930f3 175$substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
176 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
177 DIRECTORY => get_string('directorysettingssub', 'install'),
178 DATABASE => get_string('databasesettingssub', 'install'),
179 ADMIN => get_string('admindirsettingsub', 'install'),
3b3b8029 180 ENVIRONMENT => get_string('environmentsub', 'install'),
68a3f81d 181 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
e6f930f3 182 SAVE => get_string('configurationcompletesub', 'install')
183 );
8b5b1028 184
8d783716 185
186
187//==========================================================================//
188
189/// Are we in help mode?
190
191if (isset($_GET['help'])) {
192 $nextstage = -1;
193}
194
195
51e3e0b9 196
edd3a5db 197//==========================================================================//
198
51e3e0b9 199/// Are we in config download mode?
edd3a5db 200
51e3e0b9 201if (isset($_GET['download'])) {
202 header("Content-Type: application/download\n");
203 header("Content-Disposition: attachment; filename=\"config.php\"");
204 echo $INSTALL['config'];
205 exit;
edd3a5db 206}
8d783716 207
51e3e0b9 208
209
8b5b1028 210
211
212//==========================================================================//
213
214/// Check the directory settings
8d783716 215
3470b39f 216if ($INSTALL['stage'] == DIRECTORY) {
8b5b1028 217
218 error_reporting(0);
51e3e0b9 219
2df3a721 220 /// check wwwroot
221 if (ini_get('allow_url_fopen')) {
cdef6d42 222 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
2df3a721 223 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
cdef6d42 224 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
8b5b1028 225 }
226 }
2df3a721 227 if ($fh) fclose($fh);
cdef6d42 228
229 /// check dirroot
230 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
231 $errormsg .= get_string('dirrooterror', 'install').'<br />';
232 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
233 }
234 if ($fh) fclose($fh);
2df3a721 235
236 /// check dataroot
237 $CFG->dataroot = $INSTALL['dataroot'];
238 if (make_upload_directory('sessions', false) === false ) {
cdef6d42 239 $errormsg .= get_string('datarooterror', 'install').'<br />';
2df3a721 240 }
241 if ($fh) fclose($fh);
8b5b1028 242
3470b39f 243 if (!empty($errormsg)) $nextstage = DIRECTORY;
8b5b1028 244
245 error_reporting(7);
246}
247
248
249
250//==========================================================================//
251
252/// Check database settings if stage 3 data submitted
253/// Try to connect to the database. If that fails then try to create the database
8d783716 254
3470b39f 255if ($INSTALL['stage'] == DATABASE) {
8b5b1028 256
b4dd571d 257 /// First of all, analyze skipdbencodingtest status
258 if (isset($_POST['skipdbencodingtest'])) {
259 $INSTALL['skipdbencodingtest'] = true;
260 } else {
261 $INSTALL['skipdbencodingtest'] = false;
262 }
51e3e0b9 263
8d783716 264 /// different format for postgres7 by socket
265 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
8b5b1028 266 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
8d783716 267 $INSTALL['dbuser'] = '';
268 $INSTALL['dbpass'] = '';
269 $INSTALL['dbname'] = '';
270
8b5b1028 271 if ($INSTALL['prefix'] == '') { /// must have a prefix
272 $INSTALL['prefix'] = 'mdl_';
273 }
274 }
275
fe515206 276 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
277 if (!extension_loaded('mysql')) {
278 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
3470b39f 279 $nextstage = DATABASE;
fe515206 280 }
281 }
8b5b1028 282
fe515206 283 if (empty($errormsg)) {
284
fe515206 285 error_reporting(0); // Hide errors
286
287 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
288 /// The following doesn't seem to work but we're working on it
289 /// If you come up with a solution for creating a database in MySQL
290 /// feel free to put it in and let us know
291 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
292 switch ($INSTALL['dbtype']) { /// Try to create a database
293 case 'mysql':
294 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
295 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
296 } else {
297 $errormsg = get_string('dbcreationerror', 'install');
3470b39f 298 $nextstage = DATABASE;
fe515206 299 }
300 break;
301 }
8b5b1028 302 }
b4dd571d 303 } else {
304 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
305 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
306 if (empty($INSTALL['skipdbencodingtest'])) {
307 /// We haven't checked the skip test checkbox, so perform the test
308 $encoding = '';
309 switch ($INSTALL['dbtype']) {
310 case 'mysql':
311 ///Get MySQL character_set_database value
312 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
313 if ($rs && $rs->RecordCount() > 0) {
314 $records = $rs->GetAssoc(true);
315 $encoding = $records['character_set_database']['Value'];
b1e64385 316 if (strtoupper($encoding) == 'UTF8') {
b4dd571d 317 $INSTALL['dbencodingtestresults'] = true;
b1e64385 318 } else {
319 // Try to set the encoding now!
320 if (! $db->Metatables()) { // We have no tables so go ahead
321 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
322 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
323
324 $records = $rs->GetAssoc(true);
325 $encoding = $records['character_set_database']['Value'];
326
327 if (strtoupper($encoding) == 'UTF8') {
328 $INSTALL['dbencodingtestresults'] = true;
329 } else {
330 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
331 $nextstage = DATABASE;
332 $INSTALL['showskipdbencodingtest'] = true;
333 $INSTALL['dbencodingtestresults'] = false;
334 }
335 } else {
336 $INSTALL['showskipdbencodingtest'] = true;
337 $INSTALL['dbencodingtestresults'] = false;
338 }
b4dd571d 339 }
340 }
341 break;
342 case 'postgres7':
343 ///Get PostgreSQL server_encoding value
344 $rs = $db->Execute("SHOW server_encoding");
345 if ($rs && $rs->RecordCount() > 0) {
346 $encoding = $rs->fields['server_encoding'];
83e8edb4 347 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
b4dd571d 348 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
349 $nextstage = DATABASE;
350 $INSTALL['showskipdbencodingtest'] = true;
351 $INSTALL['dbencodingtestresults'] = false;
352 } else {
353 $INSTALL['dbencodingtestresults'] = true;
354 }
355 }
356 break;
357 }
358 }
8b5b1028 359 }
360 }
361
362 error_reporting(7);
363
364 if (($dbconnected === false) and (empty($errormsg)) ) {
365 $errormsg = get_string('dbconnectionerror', 'install');
3470b39f 366 $nextstage = DATABASE;
8b5b1028 367 }
368}
369
370
371
372//==========================================================================//
373
374/// If the next stage is admin directory settings OR we have just come from there then
375/// check the admin directory.
376/// If we can open a file then we know that the admin name is correct.
377
3470b39f 378if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
91099e36 379 if (!ini_get('allow_url_fopen')) {
3b3b8029 380 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
78850d9e 381 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
3b3b8029 382 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
8b5b1028 383 fclose($fh);
384 } else {
3470b39f 385 if ($nextstage != ADMIN) {
8b5b1028 386 $errormsg = get_string('admindirerror', 'install');
3470b39f 387 $nextstage = ADMIN;
8b5b1028 388 }
389 }
390}
391
3b3b8029 392//==========================================================================//
393
394// Check if we can navigate from the environemt page (because it's ok)
395
396if ($INSTALL['stage'] == ENVIRONMENT) {
397 error_reporting(0); // Hide errors
398 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
399 error_reporting(7); // Show errors
400 if ($dbconnected) {
401 /// Execute environment check, printing results
402 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
403 $nextstage = ENVIRONMENT;
404 }
405 } else {
406 /// We never should reach this because DB has been tested before arriving here
407 $errormsg = get_string('dbconnectionerror', 'install');
408 $nextstage = DATABASE;
409 }
410}
8b5b1028 411
cdef6d42 412
413
414//==========================================================================//
415
416// Try to download the lang pack if it has been selected
417
418if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
419
420 $downloadsuccess = false;
421 $downloaderror = '';
422
423 error_reporting(0); // Hide errors
424
425/// Create necessary lang dir
426 if (!make_upload_directory('lang', false)) {
427 $downloaderror = get_string('cannotcreatelangdir', 'error');
428 }
429
430/// Download and install component
431 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
432 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
433 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
434 switch ($status) {
435 case ERROR:
436 if ($cd->get_error() == 'remotedownloadnotallowed') {
437 $a = new stdClass();
438 $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
439 $a->dest= $CFG->dataroot.'/lang';
440 $downloaderror = get_string($cd->get_error(), 'error', $a);
441 } else {
442 $downloaderror = get_string($cd->get_error(), 'error');
443 }
444 break;
445 case UPTODATE:
446 case INSTALLED:
447 $downloadsuccess = true;
448 break;
449 default:
450 //We shouldn't reach this point
451 }
452 } else {
453 //We shouldn't reach this point
454 }
455
456 error_reporting(7); // Show errors
457
458 if ($downloadsuccess) {
459 $INSTALL['downloadlangpack'] = false;
460 $INSTALL['showdownloadlangpack'] = false;
461 $INSTALL['downloadlangpackerror'] = $downloaderror;
462 } else {
463 $INSTALL['downloadlangpack'] = false;
464 $INSTALL['showdownloadlangpack'] = false;
465 $INSTALL['downloadlangpackerror'] = $downloaderror;
466 }
467}
468
469
470
8b5b1028 471//==========================================================================//
472
473/// Display or print the data
474/// Put the data into a string
475/// Try to open config file for writing.
8d783716 476
3470b39f 477if ($nextstage == SAVE) {
51e3e0b9 478
479 $str = '<?php /// Moodle Configuration File '."\r\n";
480 $str .= "\r\n";
481
482 $str .= 'unset($CFG);'."\r\n";
483 $str .= "\r\n";
484
485 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
c423badc 486 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
59812bc7 487 if (!empty($INSTALL['dbname'])) {
51e3e0b9 488 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
489 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
490 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
491 }
492 $str .= '$CFG->dbpersist = false;'."\r\n";
493 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
494 $str .= "\r\n";
495
9914f093 496 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
497 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
498 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
499 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
51e3e0b9 500 $str .= "\r\n";
501
6e86ae68 502 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
51e3e0b9 503 $str .= "\r\n";
504
b4dd571d 505 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
506 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
507 $str .= "\r\n";
508 }
509
51e3e0b9 510 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
511 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
512 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
513 $str .= '?>';
514
7c561c7a 515 umask(0137);
516
8b5b1028 517 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
518 fwrite($fh, $str);
519 fclose($fh);
520 }
7c561c7a 521
51e3e0b9 522
523 $INSTALL['config'] = $str;
8b5b1028 524}
525
526
527
528//==========================================================================//
529
530?>
8b5b1028 531<html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
532<head>
f96660f8 533<link rel="shortcut icon" href="theme/standard/favicon.ico" />
8b5b1028 534<title>Moodle Install</title>
bd507453 535<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8b5b1028 536<?php css_styles() ?>
537
538</head>
539
540<body>
541
8d783716 542
543<?php
544if (isset($_GET['help'])) {
545 print_install_help($_GET['help']);
51e3e0b9 546 close_window_button();
8d783716 547} else {
548?>
549
8b5b1028 550
551<table class="main" align="center" cellpadding="3" cellspacing="0">
552 <tr>
8d783716 553 <td class="td_mainlogo">
b6d31b46 554 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
8d783716 555 </td>
556 <td class="td_mainlogo" valign="bottom">
557 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
558 </td>
559 </tr>
560
561 <tr>
562 <td class="td_mainheading" colspan="2">
e6f930f3 563 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
564 <?php if (!empty($substagetext[$nextstage])) { ?>
565 <p class="p_subheading"><?php echo $substagetext[$nextstage] ?></p>
566 <?php } ?>
8d783716 567 </td>
8b5b1028 568 </tr>
569
570 <tr>
8d783716 571 <td class="td_main" colspan="2">
51e3e0b9 572
8b5b1028 573<?php
574
575if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
576
577
3470b39f 578if ($nextstage == SAVE) {
579 $INSTALL['stage'] = WELCOME;
51e3e0b9 580 $options = array();
581 $options['lang'] = $INSTALL['language'];
8b5b1028 582 if ($configsuccess) {
583 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
51e3e0b9 584
585 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
586 echo "<tr>\n";
587 echo "<td width=\"33.3%\">&nbsp;</td>\n";
588 echo "<td width=\"33.3%\">&nbsp;</td>\n";
589 echo "<td width=\"33.3%\" align=\"right\">\n";
590 print_single_button("index.php", $options, get_string('continue')." &raquo;");
591 echo "</td>\n";
592 echo "</tr>\n";
593 echo "</table>\n";
594
8b5b1028 595 } else {
51e3e0b9 596 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
597
598 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
599 echo "<tr>\n";
600 echo "<td width=\"33.3%\">&nbsp;</td>\n";
601 echo "<td width=\"33.3%\" align=\"center\">\n";
602 $installoptions = array();
603 $installoptions['download'] = 1;
604 print_single_button("install.php", $installoptions, get_string('download', 'install'));
605 echo "</td>\n";
606 echo "<td width=\"33.3%\" align=\"right\">\n";
607 print_single_button("index.php", $options, get_string('continue')." &raquo;");
608 echo "</td>\n";
609 echo "</tr>\n";
610 echo "</table>\n";
611
8b5b1028 612 echo "<hr />\n";
51e3e0b9 613 echo "<div style=\"text-align: left\">\n";
3725cc8a 614 print_object(s($str));
51e3e0b9 615 echo "</div>\n";
8b5b1028 616 }
8b5b1028 617} else {
618 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
619 form_table($nextstage, $formaction);
620}
621
622?>
623
624 </td>
625 </tr>
626</table>
627
8d783716 628<?php
629}
630?>
631
8b5b1028 632</body>
633</html>
634
635
636
637
638
639
640
641
642
643
51e3e0b9 644<?php
8b5b1028 645
646//==========================================================================//
647
648
649function print_object($object) {
650 echo "<pre>\n";
651 print_r($object);
652 echo "</pre>\n";
653}
654
655
656
657//==========================================================================//
658
3470b39f 659function form_table($nextstage = WELCOME, $formaction = "install.php") {
3b3b8029 660 global $INSTALL, $db;
8b5b1028 661
cdef6d42 662 /// Print the standard form if we aren't in the DOWNLOADLANG page
663 /// because it has its own form.
664 if ($nextstage != DOWNLOADLANG) {
665 $needtoopenform = false;
8b5b1028 666?>
cdef6d42 667 <form name="installform" method="post" action="<?php echo $formaction ?>">
668 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
8b5b1028 669
cdef6d42 670<?php
671 } else {
672 $needtoopenform = true;
673 }
674?>
8b5b1028 675 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
676
677<?php
678 /// what we do depends on the stage we're at
679 switch ($nextstage) {
3470b39f 680 case WELCOME: /// Welcome and language settings
8b5b1028 681?>
682 <tr>
683 <td class="td_left"><p><?php print_string('language') ?></p></td>
684 <td class="td_right">
b9b4e32a 685 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
8b5b1028 686 </td>
687 </tr>
688
689<?php
8d783716 690 break;
3470b39f 691 case COMPATIBILITY: /// Compatibilty check
8d783716 692 $compatsuccess = true;
51e3e0b9 693
8d783716 694 /// Check that PHP is of a sufficient version
d976b5fe 695 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
8d783716 696 /// Check session auto start
697 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
8d783716 698 /// Check magic quotes
699 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
4d46a3f0 700 /// Check unsupported PHP configuration
701 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
51e3e0b9 702 /// Check safe mode
703 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
8d783716 704 /// Check file uploads
51e3e0b9 705 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
8d783716 706 /// Check GD version
51e3e0b9 707 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
8d783716 708 /// Check memory limit
51e3e0b9 709 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
8d783716 710
711
8b5b1028 712 break;
3470b39f 713 case DIRECTORY: /// Directory settings
8b5b1028 714?>
715
716 <tr>
717 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
718 <td class="td_right">
9914f093 719 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
8b5b1028 720 </td>
721 </tr>
722 <tr>
723 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
724 <td class="td_right">
9914f093 725 <input type="text" size="40" name="dirrootform" value="<?php p($INSTALL['dirrootform'],true) ?>" />
8b5b1028 726 </td>
727 </tr>
728 <tr>
729 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
730 <td class="td_right">
9914f093 731 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
8b5b1028 732 </td>
733 </tr>
734
735<?php
736 break;
3470b39f 737 case DATABASE: /// Database settings
8b5b1028 738?>
739
740 <tr>
741 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
742 <td class="td_right">
dcc6b7c4 743 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7", 'mssql' => 'mssql'), 'dbtype', $INSTALL['dbtype'], '') ?>
8b5b1028 744 </td>
745 </tr>
746 <tr>
747 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
748 <td class="td_right">
749 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
750 </td>
751 </tr>
752 <tr>
753 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
754 <td class="td_right">
755 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
756 </td>
757 </tr>
758 <tr>
759 <td class="td_left"><p><?php print_string('user') ?></p></td>
760 <td class="td_right">
761 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
762 </td>
763 </tr>
764 <tr>
765 <td class="td_left"><p><?php print_string('password') ?></p></td>
766 <td class="td_right">
2df3a721 767 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
8b5b1028 768 </td>
769 </tr>
770 <tr>
771 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
772 <td class="td_right">
773 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
774 </td>
775 </tr>
b4dd571d 776 <?php if ($INSTALL['showskipdbencodingtest']) { ?>
777 <tr>
778 <td class="td_left" colspan="2">
779 <?php print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?>
780 </td>
781 </tr>
782 <?php } ?>
8b5b1028 783
784<?php
785 break;
3470b39f 786 case ADMIN: /// Administration directory setting
8b5b1028 787?>
788
789 <tr>
790 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
791 <td class="td_right">
792 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
793 </td>
794 </tr>
795
796
3b3b8029 797<?php
798 break;
799 case ENVIRONMENT: /// Environment checks
800?>
801
802 <tr>
803 <td colspan="2">
804 <?php
805 error_reporting(0); // Hide errors
806 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
807 error_reporting(7); // Show errors
808 if ($dbconnected) {
809 /// Execute environment check, printing results
810 check_moodle_environment($INSTALL['release'], $environment_results, true);
811 } else {
812 /// We never should reach this because DB has been tested before arriving here
813 $errormsg = get_string('dbconnectionerror', 'install');
814 $nextstage = DATABASE;
815 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
816 }
817 ?>
818 </td>
819 </tr>
820
68a3f81d 821<?php
822 break;
823 case DOWNLOADLANG: /// Download language from download.moodle.org
824?>
825
826 <tr>
827 <td colspan="2">
828 <?php
cdef6d42 829 /// Get array of languages, we are going to use it
830 $languages=get_installer_list_of_languages();
831 /// Print the download form (button) if necessary
832 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
833 $options = array();
834 $options['downloadlangpack'] = true;
835 $options['stage'] = DOWNLOADLANG;
836 $options['same'] = true;
837 print_simple_box_start('center');
838 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
839 print_simple_box_end();
68a3f81d 840 } else {
cdef6d42 841 /// Show result info
842 /// English lang packs aren't downloaded
843 if (substr($INSTALL['language'],0,2) == 'en') {
844 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
845 } else {
846 if ($INSTALL['downloadlangpackerror']) {
847 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
848 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
849 } else {
850 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
851 }
852 }
68a3f81d 853 }
854 ?>
855 </td>
856 </tr>
3b3b8029 857
8b5b1028 858<?php
859 break;
860 default:
861 }
862?>
cd0e958e 863
51e3e0b9 864 <tr>
3470b39f 865 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
51e3e0b9 866
cdef6d42 867<?php
868 if ($needtoopenform) {
869?>
870 <form name="installform" method="post" action="<?php echo $formaction ?>">
871 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
872<?php
873 }
874?>
875
3470b39f 876 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
877 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
cd0e958e 878
cdef6d42 879<?php
880 if ($needtoopenform) {
881?>
882 </form>
883<?php
884 }
885?>
886
7c561c7a 887
51e3e0b9 888 </td>
cd0e958e 889
51e3e0b9 890 </tr>
891
892 </table>
cdef6d42 893<?php
894 if (!$needtoopenform) {
895?>
8b5b1028 896 </form>
cdef6d42 897<?php
898 }
899?>
8b5b1028 900
901<?php
902}
903
904
905
8d783716 906//==========================================================================//
907
51e3e0b9 908function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
8d783716 909 echo "<tr>\n";
51e3e0b9 910 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
8d783716 911 if ($success) {
51e3e0b9 912 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
913 echo "<td valign=\"top\">&nbsp;</td>\n";
8d783716 914 } else {
51e3e0b9 915 echo "<td valign=\"top\"";
916 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
917 echo "</p></td>\n";
918 echo "<td valign=\"top\">";
919 echo "<p>$errormessage ";
920 install_helpbutton("install.php?help=$helpfield");
921 echo "</p></td>\n";
8d783716 922 }
923 echo "</tr>\n";
924 return $success;
925}
926
927
928//==========================================================================//
929
930function install_helpbutton($url, $title='') {
931 if ($title == '') {
932 $title = get_string('help');
933 }
934 echo "<a href=\"javascript: void(0)\">";
1fd3772b 935 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
839f2456 936 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
8d783716 937 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
938 echo "</a>\n";
939}
51e3e0b9 940
8d783716 941
942
943//==========================================================================//
944
945function print_install_help($help) {
8d783716 946 switch ($help) {
947 case 'phpversionhelp':
948 print_string($help, 'install', phpversion());
949 break;
950 case 'memorylimithelp':
94ba66ce 951 print_string($help, 'install', get_memory_limit());
8d783716 952 break;
953 default:
954 print_string($help, 'install');
955 }
8d783716 956}
957
958
959//==========================================================================//
960
961function get_memory_limit() {
962 if ($limit = ini_get('memory_limit')) {
963 return $limit;
964 } else {
965 return get_cfg_var('memory_limit');
966 }
967}
968
969//==========================================================================//
970
971function check_memory_limit() {
972
973 /// if limit is already 16M or more then we don't care if we can change it or not
974 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
975 return true;
976 }
977
978 /// Otherwise, see if we can change it ourselves
979 @ini_set('memory_limit', '16M');
980 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
981}
982
8b5b1028 983//==========================================================================//
b9b4e32a 984
d976b5fe 985function inst_check_php_version() {
986 if (!check_php_version("4.3.0")) {
987 return false;
988 } else if (check_php_version("5.0.0")) {
989 return check_php_version("5.1.0"); // 5.0.x is too buggy
990 }
991 return true; // 4.3.x or 4.4.x is fine
992}
993//==========================================================================//
994
b9b4e32a 995/* This function returns a list of languages and their full names. The
996 * list of available languages is fetched from install/lang/xx/installer.php
997 * and it's used exclusively by the installation process
998 * @return array An associative array with contents in the form of LanguageCode => LanguageName
999 */
1000function get_installer_list_of_languages() {
1001
1002 global $CFG;
1003
1004 $languages = array();
1005
1006/// Get raw list of lang directories
1007 $langdirs = get_list_of_plugins('install/lang');
1008 asort($langdirs);
1009/// Get some info from each lang
1010 foreach ($langdirs as $lang) {
1011 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1012 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1a8bdfc4 1013 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1014 $shortlang = substr($lang, 0, -5);
1015 } else {
1016 $shortlang = $lang;
1017 }
1018 if ($lang == 'en') { //Explain this is non-utf8 en
1019 $shortlang = 'non-utf8 en';
1020 }
b9b4e32a 1021 if (!empty($string['thislanguage'])) {
1a8bdfc4 1022 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
b9b4e32a 1023 }
1024 unset($string);
1025 }
1026 }
1027/// Return array
1028 return $languages;
1029}
1030
1031//==========================================================================//
8b5b1028 1032
1033function css_styles() {
1034?>
1035
1036<style type="text/css">
1037
1038 body { background-color: #ffeece; }
3b3b8029 1039 p, li, td {
8d783716 1040 font-family: helvetica, arial, sans-serif;
1041 font-size: 10pt;
1042 }
8b5b1028 1043 a { text-decoration: none; color: blue; }
1044 .errormsg {
1045 color: red;
1046 font-weight: bold;
1047 }
8d783716 1048 blockquote {
51e3e0b9 1049 font-family: courier, monospace;
8d783716 1050 font-size: 10pt;
1051 }
8b5b1028 1052 .install_table {
1053 width: 500px;
1054 }
1055 .td_left {
1056 text-align: right;
1057 font-weight: bold;
1058 }
1059 .td_right {
1060 text-align: left;
1061 }
1062 .main {
1063 width: 500px;
1064 border-width: 1px;
1065 border-style: solid;
1066 border-color: #ffc85f;
1067 -moz-border-radius-bottomleft: 15px;
1068 -moz-border-radius-bottomright: 15px;
1069 }
1070 .td_mainheading {
1071 background-color: #fee6b9;
8d783716 1072 padding: 10px;
8b5b1028 1073 }
1074 .td_main {
1075 text-align: center;
1076 }
8d783716 1077 .td_mainlogo {
1078 }
1079 .p_mainlogo {
1080 }
8b5b1028 1081 .p_mainheading {
8d783716 1082 font-size: 11pt;
1083 }
182dca14 1084 .p_subheading {
1085 font-size: 10pt;
1086 padding: 10px;
1087 }
8d783716 1088 .p_mainheader{
1089 text-align: right;
1090 font-size: 20pt;
1091 font-weight: bold;
1092 }
1093 .p_pass {
1094 color: green;
1095 font-weight: bold;
1096 }
1097 .p_fail {
1098 color: red;
1099 font-weight: bold;
1100 }
51e3e0b9 1101 .p_caution {
1102 color: #ff6600;
1103 font-weight: bold;
1104 }
8d783716 1105 .p_help {
1106 text-align: center;
1107 font-family: helvetica, arial, sans-serif;
1108 font-size: 14pt;
1109 font-weight: bold;
1110 color: #333333;
8b5b1028 1111 }
3b3b8029 1112 .environmenttable {
1113 font-size: 10pt;
1114 border-color: #ffc85f;
1115 }
1116 .header {
1117 background-color: #fee6b9;
1118 font-size: 10pt;
1119 }
1120 .cell {
1121 background-color: #ffeece;
1122 font-size: 10pt;
1123 }
1124 .error {
1125 color: #ff0000;
1126 }
1127 .errorboxcontent {
1128 text-align: center;
1129 font-weight: bold;
1130 padding: 20px;
1131 color: #ff0000;
1132 }
1133
8b5b1028 1134</style>
1135
1136<?php
1137}
1138?>