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