Recent changes
[moodle.git] / install.php
blob8f47eefb7a82c6763e2ffb449c802f82c9c500a2
1 <?php /// $Id$
2 /// install.php - helps admin user to create a config.php file
4 /// If config.php exists already then we are not needed.
6 if (file_exists('./config.php')) {
7 header('Location: index.php');
8 die;
9 } else {
10 $configfile = './config.php';
13 ///==========================================================================//
14 /// We are doing this in stages
15 define ('WELCOME', 0); /// 0. Welcome and language settings
16 define ('COMPATIBILITY', 1); /// 1. Compatibility
17 define ('DIRECTORY', 2); /// 2. Directory settings
18 define ('DATABASE', 3); /// 2. Database settings
19 define ('ADMIN', 4); /// 4. Administration directory name
20 define ('ENVIRONMENT', 5); /// 5. Administration directory name
21 define ('DOWNLOADLANG', 6); /// 6. Load complete lang from download.moodle.org
22 define ('SAVE', 7); /// 7. Save or display the settings
23 define ('REDIRECT', 8); /// 8. Redirect to index.php
24 ///==========================================================================//
28 /// Begin the session as we are holding all information in a session
29 /// variable until the end.
31 session_name('MoodleSession');
32 @session_start();
34 if (! isset($_SESSION['INSTALL'])) {
35 $_SESSION['INSTALL'] = array();
38 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
41 /// If it's our first time through this script then we need to set some default values
43 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
45 /// set defaults
46 $INSTALL['language'] = 'en_utf8';
48 $INSTALL['dbhost'] = 'localhost';
49 $INSTALL['dbuser'] = '';
50 $INSTALL['dbpass'] = '';
51 $INSTALL['dbtype'] = 'mysql';
52 $INSTALL['dbname'] = 'moodle';
53 $INSTALL['prefix'] = 'mdl_';
55 $INSTALL['dbencodingtestresults'] = false;
56 $INSTALL['showskipdbencodingtest'] = false;
57 $INSTALL['skipdbencodingtest'] = false;
59 $INSTALL['downloadlangpack'] = false;
60 $INSTALL['showdownloadlangpack'] = true;
61 $INSTALL['downloadlangpackerror'] = '';
63 /// To be used by the Installer
64 $INSTALL['wwwroot'] = '';
65 $INSTALL['dirroot'] = dirname(__FILE__);
66 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
68 /// To be configured in the Installer
69 $INSTALL['wwwrootform'] = '';
70 $INSTALL['dirrootform'] = dirname(__FILE__);
72 $INSTALL['admindirname'] = 'admin';
74 $INSTALL['stage'] = WELCOME;
77 //==========================================================================//
79 /// Set the page to Unicode always
81 header('Content-Type: text/html; charset=UTF-8');
83 /// Was data submitted?
85 if (isset($_POST['stage'])) {
87 /// Get the stage for which the form was set and the next stage we are going to
90 if ( $goforward = (! empty( $_POST['next'] )) ) {
91 $nextstage = $_POST['stage'] + 1;
92 } else if (! empty( $_POST['prev'])) {
93 $nextstage = $_POST['stage'] - 1;
94 } else if (! empty( $_POST['same'] )) {
95 $nextstage = $_POST['stage'];
99 if ($nextstage < 0) $nextstage = WELCOME;
102 /// Store any posted data
103 foreach ($_POST as $setting=>$value) {
104 $INSTALL[$setting] = $value;
107 } else {
109 $goforward = true;
110 $nextstage = WELCOME;
114 //==========================================================================//
116 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
118 $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
119 $CFG->dirroot = $INSTALL['dirroot'];
120 $CFG->libdir = $INSTALL['dirroot'].'/lib';
121 $CFG->dataroot = $INSTALL['dataroot'];
122 $CFG->admin = $INSTALL['admindirname'];
123 $CFG->directorypermissions = 00777;
124 $CFG->running_installer = true;
126 /// Include some moodle libraries
128 require_once('./lib/adminlib.php');
129 require_once('./lib/setuplib.php');
130 require_once('./lib/moodlelib.php');
131 require_once('./lib/weblib.php');
132 require_once('./lib/adodb/adodb.inc.php');
133 require_once('./lib/environmentlib.php');
134 require_once('./lib/xmlize.php');
135 require_once('./lib/componentlib.class.php');
136 require_once('./version.php');
138 /// Set version and release
139 $INSTALL['version'] = $version;
140 $INSTALL['release'] = $release;
142 /// Have the $db object ready because we are going to use it often
143 $db = &ADONewConnection($INSTALL['dbtype']);
145 /// guess the www root
146 if ($INSTALL['wwwroot'] == '') {
147 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
148 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
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++;
156 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
157 $CFG->dataroot = ''; //can not find secure location for dataroot
158 break;
160 $CFG->dataroot = dirname($parrent).'/moodledata';
162 $INSTALL['dataroot'] = $CFG->dataroot;
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'),
170 ENVIRONMENT => get_string('environmenthead', 'install'),
171 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
172 SAVE => get_string('configurationcompletehead', 'install')
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'),
180 ENVIRONMENT => get_string('environmentsub', 'install'),
181 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
182 SAVE => get_string('configurationcompletesub', 'install')
187 //==========================================================================//
189 /// Are we in help mode?
191 if (isset($_GET['help'])) {
192 $nextstage = -1;
197 //==========================================================================//
199 /// Are we in config download mode?
201 if (isset($_GET['download'])) {
202 header("Content-Type: application/download\n");
203 header("Content-Disposition: attachment; filename=\"config.php\"");
204 echo $INSTALL['config'];
205 exit;
212 //==========================================================================//
214 /// Check the directory settings
216 if ($INSTALL['stage'] == DIRECTORY) {
218 error_reporting(0);
220 /// check wwwroot
221 if (ini_get('allow_url_fopen')) {
222 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
223 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
224 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
227 if ($fh) fclose($fh);
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'];
234 if ($fh) fclose($fh);
236 /// check dataroot
237 $CFG->dataroot = $INSTALL['dataroot'];
238 if (make_upload_directory('sessions', false) === false ) {
239 $errormsg .= get_string('datarooterror', 'install').'<br />';
241 if ($fh) fclose($fh);
243 if (!empty($errormsg)) $nextstage = DIRECTORY;
245 error_reporting(7);
250 //==========================================================================//
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
255 if ($INSTALL['stage'] == DATABASE) {
257 /// First of all, analyze skipdbencodingtest status
258 if (isset($_POST['skipdbencodingtest'])) {
259 $INSTALL['skipdbencodingtest'] = true;
260 } else {
261 $INSTALL['skipdbencodingtest'] = false;
264 /// different format for postgres7 by socket
265 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
266 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
267 $INSTALL['dbuser'] = '';
268 $INSTALL['dbpass'] = '';
269 $INSTALL['dbname'] = '';
271 if ($INSTALL['prefix'] == '') { /// must have a prefix
272 $INSTALL['prefix'] = 'mdl_';
276 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
277 if (!extension_loaded('mysql')) {
278 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
279 $nextstage = DATABASE;
283 if (empty($errormsg)) {
285 error_reporting(0); // Hide errors
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');
298 $nextstage = DATABASE;
300 break;
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'];
316 if (strtoupper($encoding) == 'UTF8') {
317 $INSTALL['dbencodingtestresults'] = true;
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
324 $records = $rs->GetAssoc(true);
325 $encoding = $records['character_set_database']['Value'];
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;
335 } else {
336 $INSTALL['showskipdbencodingtest'] = true;
337 $INSTALL['dbencodingtestresults'] = false;
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'];
347 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
348 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
349 $nextstage = DATABASE;
350 $INSTALL['showskipdbencodingtest'] = true;
351 $INSTALL['dbencodingtestresults'] = false;
352 } else {
353 $INSTALL['dbencodingtestresults'] = true;
356 break;
362 error_reporting(7);
364 if (($dbconnected === false) and (empty($errormsg)) ) {
365 $errormsg = get_string('dbconnectionerror', 'install');
366 $nextstage = DATABASE;
372 //==========================================================================//
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.
378 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
379 if (!ini_get('allow_url_fopen')) {
380 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
381 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
382 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
383 fclose($fh);
384 } else {
385 if ($nextstage != ADMIN) {
386 $errormsg = get_string('admindirerror', 'install');
387 $nextstage = ADMIN;
392 //==========================================================================//
394 // Check if we can navigate from the environemt page (because it's ok)
396 if ($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;
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;
414 //==========================================================================//
416 // Try to download the lang pack if it has been selected
418 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
420 $downloadsuccess = false;
421 $downloaderror = '';
423 error_reporting(0); // Hide errors
425 /// Create necessary lang dir
426 if (!make_upload_directory('lang', false)) {
427 $downloaderror = get_string('cannotcreatelangdir', 'error');
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');
444 break;
445 case UPTODATE:
446 case INSTALLED:
447 $downloadsuccess = true;
448 break;
449 default:
450 //We shouldn't reach this point
452 } else {
453 //We shouldn't reach this point
456 error_reporting(7); // Show errors
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;
471 //==========================================================================//
473 /// Display or print the data
474 /// Put the data into a string
475 /// Try to open config file for writing.
477 if ($nextstage == SAVE) {
479 $str = '<?php /// Moodle Configuration File '."\r\n";
480 $str .= "\r\n";
482 $str .= 'unset($CFG);'."\r\n";
483 $str .= "\r\n";
485 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
486 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
487 if (!empty($INSTALL['dbname'])) {
488 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
489 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
490 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
492 $str .= '$CFG->dbpersist = false;'."\r\n";
493 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
494 $str .= "\r\n";
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";
500 $str .= "\r\n";
502 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
503 $str .= "\r\n";
505 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
506 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
507 $str .= "\r\n";
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 .= '?>';
515 umask(0137);
517 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
518 fwrite($fh, $str);
519 fclose($fh);
523 $INSTALL['config'] = $str;
528 //==========================================================================//
531 <html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
532 <head>
533 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
534 <title>Moodle Install</title>
535 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
536 <?php css_styles() ?>
538 </head>
540 <body>
543 <?php
544 if (isset($_GET['help'])) {
545 print_install_help($_GET['help']);
546 close_window_button();
547 } else {
551 <table class="main" align="center" cellpadding="3" cellspacing="0">
552 <tr>
553 <td class="td_mainlogo">
554 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
555 </td>
556 <td class="td_mainlogo" valign="bottom">
557 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
558 </td>
559 </tr>
561 <tr>
562 <td class="td_mainheading" colspan="2">
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 } ?>
567 </td>
568 </tr>
570 <tr>
571 <td class="td_main" colspan="2">
573 <?php
575 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
578 if ($nextstage == SAVE) {
579 $INSTALL['stage'] = WELCOME;
580 $options = array();
581 $options['lang'] = $INSTALL['language'];
582 if ($configsuccess) {
583 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
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";
595 } else {
596 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
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";
612 echo "<hr />\n";
613 echo "<div style=\"text-align: left\">\n";
614 print_object(s($str));
615 echo "</div>\n";
617 } else {
618 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
619 form_table($nextstage, $formaction);
624 </td>
625 </tr>
626 </table>
628 <?php
632 </body>
633 </html>
644 <?php
646 //==========================================================================//
649 function print_object($object) {
650 echo "<pre>\n";
651 print_r($object);
652 echo "</pre>\n";
657 //==========================================================================//
659 function form_table($nextstage = WELCOME, $formaction = "install.php") {
660 global $INSTALL, $db;
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;
667 <form name="installform" method="post" action="<?php echo $formaction ?>">
668 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
670 <?php
671 } else {
672 $needtoopenform = true;
675 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
677 <?php
678 /// what we do depends on the stage we're at
679 switch ($nextstage) {
680 case WELCOME: /// Welcome and language settings
682 <tr>
683 <td class="td_left"><p><?php print_string('language') ?></p></td>
684 <td class="td_right">
685 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
686 </td>
687 </tr>
689 <?php
690 break;
691 case COMPATIBILITY: /// Compatibilty check
692 $compatsuccess = true;
694 /// Check that PHP is of a sufficient version
695 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
696 /// Check session auto start
697 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
698 /// Check magic quotes
699 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
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');
702 /// Check safe mode
703 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
704 /// Check file uploads
705 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
706 /// Check GD version
707 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
708 /// Check memory limit
709 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
712 break;
713 case DIRECTORY: /// Directory settings
716 <tr>
717 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
718 <td class="td_right">
719 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
720 </td>
721 </tr>
722 <tr>
723 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
724 <td class="td_right">
725 <input type="text" size="40" name="dirrootform" value="<?php p($INSTALL['dirrootform'],true) ?>" />
726 </td>
727 </tr>
728 <tr>
729 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
730 <td class="td_right">
731 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
732 </td>
733 </tr>
735 <?php
736 break;
737 case DATABASE: /// Database settings
740 <tr>
741 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
742 <td class="td_right">
743 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>
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">
767 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
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>
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 } ?>
784 <?php
785 break;
786 case ADMIN: /// Administration directory setting
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>
797 <?php
798 break;
799 case ENVIRONMENT: /// Environment checks
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>';
818 </td>
819 </tr>
821 <?php
822 break;
823 case DOWNLOADLANG: /// Download language from download.moodle.org
826 <tr>
827 <td colspan="2">
828 <?php
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();
840 } else {
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%');
855 </td>
856 </tr>
858 <?php
859 break;
860 default:
864 <tr>
865 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
867 <?php
868 if ($needtoopenform) {
870 <form name="installform" method="post" action="<?php echo $formaction ?>">
871 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
872 <?php
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" ?>
879 <?php
880 if ($needtoopenform) {
882 </form>
883 <?php
888 </td>
890 </tr>
892 </table>
893 <?php
894 if (!$needtoopenform) {
896 </form>
897 <?php
901 <?php
906 //==========================================================================//
908 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
909 echo "<tr>\n";
910 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
911 if ($success) {
912 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
913 echo "<td valign=\"top\">&nbsp;</td>\n";
914 } else {
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";
923 echo "</tr>\n";
924 return $success;
928 //==========================================================================//
930 function install_helpbutton($url, $title='') {
931 if ($title == '') {
932 $title = get_string('help');
934 echo "<a href=\"javascript: void(0)\">";
935 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
936 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
937 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
938 echo "</a>\n";
943 //==========================================================================//
945 function print_install_help($help) {
946 switch ($help) {
947 case 'phpversionhelp':
948 print_string($help, 'install', phpversion());
949 break;
950 case 'memorylimithelp':
951 print_string($help, 'install', get_memory_limit());
952 break;
953 default:
954 print_string($help, 'install');
959 //==========================================================================//
961 function get_memory_limit() {
962 if ($limit = ini_get('memory_limit')) {
963 return $limit;
964 } else {
965 return get_cfg_var('memory_limit');
969 //==========================================================================//
971 function check_memory_limit() {
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;
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);
983 //==========================================================================//
985 function 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
991 return true; // 4.3.x or 4.4.x is fine
993 //==========================================================================//
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
1000 function get_installer_list_of_languages() {
1002 global $CFG;
1004 $languages = array();
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');
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;
1018 if ($lang == 'en') { //Explain this is non-utf8 en
1019 $shortlang = 'non-utf8 en';
1021 if (!empty($string['thislanguage'])) {
1022 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1024 unset($string);
1027 /// Return array
1028 return $languages;
1031 //==========================================================================//
1033 function css_styles() {
1036 <style type="text/css">
1038 body { background-color: #ffeece; }
1039 p, li, td {
1040 font-family: helvetica, arial, sans-serif;
1041 font-size: 10pt;
1043 a { text-decoration: none; color: blue; }
1044 .errormsg {
1045 color: red;
1046 font-weight: bold;
1048 blockquote {
1049 font-family: courier, monospace;
1050 font-size: 10pt;
1052 .install_table {
1053 width: 500px;
1055 .td_left {
1056 text-align: right;
1057 font-weight: bold;
1059 .td_right {
1060 text-align: left;
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;
1070 .td_mainheading {
1071 background-color: #fee6b9;
1072 padding: 10px;
1074 .td_main {
1075 text-align: center;
1077 .td_mainlogo {
1079 .p_mainlogo {
1081 .p_mainheading {
1082 font-size: 11pt;
1084 .p_subheading {
1085 font-size: 10pt;
1086 padding: 10px;
1088 .p_mainheader{
1089 text-align: right;
1090 font-size: 20pt;
1091 font-weight: bold;
1093 .p_pass {
1094 color: green;
1095 font-weight: bold;
1097 .p_fail {
1098 color: red;
1099 font-weight: bold;
1101 .p_caution {
1102 color: #ff6600;
1103 font-weight: bold;
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;
1112 .environmenttable {
1113 font-size: 10pt;
1114 border-color: #ffc85f;
1116 .header {
1117 background-color: #fee6b9;
1118 font-size: 10pt;
1120 .cell {
1121 background-color: #ffeece;
1122 font-size: 10pt;
1124 .error {
1125 color: #ff0000;
1127 .errorboxcontent {
1128 text-align: center;
1129 font-weight: bold;
1130 padding: 20px;
1131 color: #ff0000;
1134 </style>
1136 <?php