Bumped version
[moodle.git] / install.php
blob33f7b1f91c8ebddff8c2d902b3f22a6adbf658da
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/componentlib.class.php');
135 require_once('./version.php');
137 /// Set version and release
138 $INSTALL['version'] = $version;
139 $INSTALL['release'] = $release;
141 /// Have the $db object ready because we are going to use it often
142 $db = &ADONewConnection($INSTALL['dbtype']);
144 /// guess the www root
145 if ($INSTALL['wwwroot'] == '') {
146 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
147 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
149 // now try to guess the correct dataroot not accessible via web
150 $CFG->wwwroot = $INSTALL['wwwroot'];
151 $i = 0; //safety check - dirname might return some unexpected results
152 while(is_dataroot_insecure()) {
153 $parrent = dirname($CFG->dataroot);
154 $i++;
155 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
156 $CFG->dataroot = ''; //can not find secure location for dataroot
157 break;
159 $CFG->dataroot = dirname($parrent).'/moodledata';
161 $INSTALL['dataroot'] = $CFG->dataroot;
164 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
165 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
166 DIRECTORY => get_string('directorysettingshead', 'install'),
167 DATABASE => get_string('databasesettingshead', 'install'),
168 ADMIN => get_string('admindirsettinghead', 'install'),
169 ENVIRONMENT => get_string('environmenthead', 'install'),
170 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
171 SAVE => get_string('configurationcompletehead', 'install')
174 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
175 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
176 DIRECTORY => get_string('directorysettingssub', 'install'),
177 DATABASE => get_string('databasesettingssub', 'install'),
178 ADMIN => get_string('admindirsettingsub', 'install'),
179 ENVIRONMENT => get_string('environmentsub', 'install'),
180 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
181 SAVE => get_string('configurationcompletesub', 'install')
186 //==========================================================================//
188 /// Are we in help mode?
190 if (isset($_GET['help'])) {
191 $nextstage = -1;
196 //==========================================================================//
198 /// Are we in config download mode?
200 if (isset($_GET['download'])) {
201 header("Content-Type: application/download\n");
202 header("Content-Disposition: attachment; filename=\"config.php\"");
203 echo $INSTALL['config'];
204 exit;
211 //==========================================================================//
213 /// Check the directory settings
215 if ($INSTALL['stage'] == DIRECTORY) {
217 error_reporting(0);
219 /// check wwwroot
220 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
221 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
222 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
223 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
226 if ($fh) fclose($fh);
228 /// check dirroot
229 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
230 $errormsg .= get_string('dirrooterror', 'install').'<br />';
231 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
233 if ($fh) fclose($fh);
235 /// check dataroot
236 $CFG->dataroot = $INSTALL['dataroot'];
237 if (make_upload_directory('sessions', false) === false ) {
238 $errormsg .= get_string('datarooterror', 'install').'<br />';
240 if ($fh) fclose($fh);
242 if (!empty($errormsg)) $nextstage = DIRECTORY;
244 error_reporting(7);
249 //==========================================================================//
251 /// Check database settings if stage 3 data submitted
252 /// Try to connect to the database. If that fails then try to create the database
254 if ($INSTALL['stage'] == DATABASE) {
256 /// First of all, analyze skipdbencodingtest status
257 if (isset($_POST['skipdbencodingtest'])) {
258 $INSTALL['skipdbencodingtest'] = true;
259 } else {
260 $INSTALL['skipdbencodingtest'] = false;
263 /// different format for postgres7 by socket
264 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
265 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
266 $INSTALL['dbuser'] = '';
267 $INSTALL['dbpass'] = '';
268 $INSTALL['dbname'] = '';
270 if ($INSTALL['prefix'] == '') { /// must have a prefix
271 $INSTALL['prefix'] = 'mdl_';
275 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
276 if (!extension_loaded('mysql')) {
277 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
278 $nextstage = DATABASE;
282 if (empty($errormsg)) {
284 error_reporting(0); // Hide errors
286 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
287 /// The following doesn't seem to work but we're working on it
288 /// If you come up with a solution for creating a database in MySQL
289 /// feel free to put it in and let us know
290 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
291 switch ($INSTALL['dbtype']) { /// Try to create a database
292 case 'mysql':
293 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
294 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
295 } else {
296 $errormsg = get_string('dbcreationerror', 'install');
297 $nextstage = DATABASE;
299 break;
302 } else {
303 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
304 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
305 if (empty($INSTALL['skipdbencodingtest'])) {
306 /// We haven't checked the skip test checkbox, so perform the test
307 $encoding = '';
308 switch ($INSTALL['dbtype']) {
309 case 'mysql':
310 ///Get MySQL character_set_database value
311 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
312 if ($rs && $rs->RecordCount() > 0) {
313 $records = $rs->GetAssoc(true);
314 $encoding = $records['character_set_database']['Value'];
315 if (strtoupper($encoding) == 'UTF8') {
316 $INSTALL['dbencodingtestresults'] = true;
317 } else {
318 // Try to set the encoding now!
319 if (! $db->Metatables()) { // We have no tables so go ahead
320 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
321 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
323 $records = $rs->GetAssoc(true);
324 $encoding = $records['character_set_database']['Value'];
326 if (strtoupper($encoding) == 'UTF8') {
327 $INSTALL['dbencodingtestresults'] = true;
328 } else {
329 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
330 $nextstage = DATABASE;
331 $INSTALL['showskipdbencodingtest'] = true;
332 $INSTALL['dbencodingtestresults'] = false;
334 } else {
335 $INSTALL['showskipdbencodingtest'] = true;
336 $INSTALL['dbencodingtestresults'] = false;
340 break;
341 case 'postgres7':
342 ///Get PostgreSQL server_encoding value
343 $rs = $db->Execute("SHOW server_encoding");
344 if ($rs && $rs->RecordCount() > 0) {
345 $encoding = $rs->fields['server_encoding'];
346 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
347 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
348 $nextstage = DATABASE;
349 $INSTALL['showskipdbencodingtest'] = true;
350 $INSTALL['dbencodingtestresults'] = false;
351 } else {
352 $INSTALL['dbencodingtestresults'] = true;
355 break;
361 error_reporting(7);
363 if (($dbconnected === false) and (empty($errormsg)) ) {
364 $errormsg = get_string('dbconnectionerror', 'install');
365 $nextstage = DATABASE;
371 //==========================================================================//
373 /// If the next stage is admin directory settings OR we have just come from there then
374 /// check the admin directory.
375 /// If we can open a file then we know that the admin name is correct.
377 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
378 if (!ini_get('allow_url_fopen') || true) { // MDL-4218 fopen URL is not reliable
379 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
380 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
381 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
382 fclose($fh);
383 } else {
384 if ($nextstage != ADMIN) {
385 $errormsg = get_string('admindirerror', 'install');
386 $nextstage = ADMIN;
391 //==========================================================================//
393 // Check if we can navigate from the environemt page (because it's ok)
395 if ($INSTALL['stage'] == ENVIRONMENT) {
396 error_reporting(0); // Hide errors
397 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
398 error_reporting(7); // Show errors
399 if ($dbconnected) {
400 /// Execute environment check, printing results
401 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
402 $nextstage = ENVIRONMENT;
404 } else {
405 /// We never should reach this because DB has been tested before arriving here
406 $errormsg = get_string('dbconnectionerror', 'install');
407 $nextstage = DATABASE;
413 //==========================================================================//
415 // Try to download the lang pack if it has been selected
417 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
419 $downloadsuccess = false;
420 $downloaderror = '';
422 error_reporting(0); // Hide errors
424 /// Create necessary lang dir
425 if (!make_upload_directory('lang', false)) {
426 $downloaderror = get_string('cannotcreatelangdir', 'error');
429 /// Download and install component
430 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
431 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
432 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
433 switch ($status) {
434 case ERROR:
435 if ($cd->get_error() == 'remotedownloadnotallowed') {
436 $a = new stdClass();
437 $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
438 $a->dest= $CFG->dataroot.'/lang';
439 $downloaderror = get_string($cd->get_error(), 'error', $a);
440 } else {
441 $downloaderror = get_string($cd->get_error(), 'error');
443 break;
444 case UPTODATE:
445 case INSTALLED:
446 $downloadsuccess = true;
447 break;
448 default:
449 //We shouldn't reach this point
451 } else {
452 //We shouldn't reach this point
455 error_reporting(7); // Show errors
457 if ($downloadsuccess) {
458 $INSTALL['downloadlangpack'] = false;
459 $INSTALL['showdownloadlangpack'] = false;
460 $INSTALL['downloadlangpackerror'] = $downloaderror;
461 } else {
462 $INSTALL['downloadlangpack'] = false;
463 $INSTALL['showdownloadlangpack'] = false;
464 $INSTALL['downloadlangpackerror'] = $downloaderror;
470 //==========================================================================//
472 /// Display or print the data
473 /// Put the data into a string
474 /// Try to open config file for writing.
476 if ($nextstage == SAVE) {
478 $str = '<?php /// Moodle Configuration File '."\r\n";
479 $str .= "\r\n";
481 $str .= 'unset($CFG);'."\r\n";
482 $str .= "\r\n";
484 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
485 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
486 if (!empty($INSTALL['dbname'])) {
487 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
488 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
489 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
491 $str .= '$CFG->dbpersist = false;'."\r\n";
492 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
493 $str .= "\r\n";
495 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
496 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
497 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
498 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
499 $str .= "\r\n";
501 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
502 $str .= "\r\n";
504 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
505 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
506 $str .= "\r\n";
509 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
510 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
511 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
512 $str .= '?>';
514 umask(0137);
516 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
517 fwrite($fh, $str);
518 fclose($fh);
522 $INSTALL['config'] = $str;
527 //==========================================================================//
530 <html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
531 <head>
532 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
533 <title>Moodle Install</title>
534 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
535 <?php css_styles() ?>
537 </head>
539 <body>
542 <?php
543 if (isset($_GET['help'])) {
544 print_install_help($_GET['help']);
545 close_window_button();
546 } else {
550 <table class="main" align="center" cellpadding="3" cellspacing="0">
551 <tr>
552 <td class="td_mainlogo">
553 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
554 </td>
555 <td class="td_mainlogo" valign="bottom">
556 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
557 </td>
558 </tr>
560 <tr>
561 <td class="td_mainheading" colspan="2">
562 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
563 <?php if (!empty($substagetext[$nextstage])) { ?>
564 <p class="p_subheading"><?php echo $substagetext[$nextstage] ?></p>
565 <?php } ?>
566 </td>
567 </tr>
569 <tr>
570 <td class="td_main" colspan="2">
572 <?php
574 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
577 if ($nextstage == SAVE) {
578 $INSTALL['stage'] = WELCOME;
579 $options = array();
580 $options['lang'] = $INSTALL['language'];
581 if ($configsuccess) {
582 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
584 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
585 echo "<tr>\n";
586 echo "<td width=\"33.3%\">&nbsp;</td>\n";
587 echo "<td width=\"33.3%\">&nbsp;</td>\n";
588 echo "<td width=\"33.3%\" align=\"right\">\n";
589 print_single_button("index.php", $options, get_string('continue')." &raquo;");
590 echo "</td>\n";
591 echo "</tr>\n";
592 echo "</table>\n";
594 } else {
595 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
597 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
598 echo "<tr>\n";
599 echo "<td width=\"33.3%\">&nbsp;</td>\n";
600 echo "<td width=\"33.3%\" align=\"center\">\n";
601 $installoptions = array();
602 $installoptions['download'] = 1;
603 print_single_button("install.php", $installoptions, get_string('download', 'install'));
604 echo "</td>\n";
605 echo "<td width=\"33.3%\" align=\"right\">\n";
606 print_single_button("index.php", $options, get_string('continue')." &raquo;");
607 echo "</td>\n";
608 echo "</tr>\n";
609 echo "</table>\n";
611 echo "<hr />\n";
612 echo "<div style=\"text-align: left\">\n";
613 print_object(s($str));
614 echo "</div>\n";
616 } else {
617 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
618 form_table($nextstage, $formaction);
623 </td>
624 </tr>
625 </table>
627 <?php
631 </body>
632 </html>
643 <?php
645 //==========================================================================//
648 function print_object($object) {
649 echo "<pre>\n";
650 print_r($object);
651 echo "</pre>\n";
656 //==========================================================================//
658 function form_table($nextstage = WELCOME, $formaction = "install.php") {
659 global $INSTALL, $db;
661 /// Print the standard form if we aren't in the DOWNLOADLANG page
662 /// because it has its own form.
663 if ($nextstage != DOWNLOADLANG) {
664 $needtoopenform = false;
666 <form name="installform" method="post" action="<?php echo $formaction ?>">
667 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
669 <?php
670 } else {
671 $needtoopenform = true;
674 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
676 <?php
677 /// what we do depends on the stage we're at
678 switch ($nextstage) {
679 case WELCOME: /// Welcome and language settings
681 <tr>
682 <td class="td_left"><p><?php print_string('language') ?></p></td>
683 <td class="td_right">
684 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
685 </td>
686 </tr>
688 <?php
689 break;
690 case COMPATIBILITY: /// Compatibilty check
691 $compatsuccess = true;
693 /// Check that PHP is of a sufficient version
694 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
695 /// Check session auto start
696 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
697 /// Check magic quotes
698 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
699 /// Check unsupported PHP configuration
700 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
701 /// Check safe mode
702 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
703 /// Check file uploads
704 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
705 /// Check GD version
706 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
707 /// Check memory limit
708 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
711 break;
712 case DIRECTORY: /// Directory settings
715 <tr>
716 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
717 <td class="td_right">
718 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
719 </td>
720 </tr>
721 <tr>
722 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
723 <td class="td_right">
724 <input type="text" size="40" name="dirrootform" value="<?php p($INSTALL['dirrootform'],true) ?>" />
725 </td>
726 </tr>
727 <tr>
728 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
729 <td class="td_right">
730 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
731 </td>
732 </tr>
734 <?php
735 break;
736 case DATABASE: /// Database settings
739 <tr>
740 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
741 <td class="td_right">
742 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>
743 </td>
744 </tr>
745 <tr>
746 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
747 <td class="td_right">
748 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
749 </td>
750 </tr>
751 <tr>
752 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
753 <td class="td_right">
754 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
755 </td>
756 </tr>
757 <tr>
758 <td class="td_left"><p><?php print_string('user') ?></p></td>
759 <td class="td_right">
760 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
761 </td>
762 </tr>
763 <tr>
764 <td class="td_left"><p><?php print_string('password') ?></p></td>
765 <td class="td_right">
766 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
767 </td>
768 </tr>
769 <tr>
770 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
771 <td class="td_right">
772 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
773 </td>
774 </tr>
775 <?php if ($INSTALL['showskipdbencodingtest']) { ?>
776 <tr>
777 <td class="td_left" colspan="2">
778 <?php print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?>
779 </td>
780 </tr>
781 <?php } ?>
783 <?php
784 break;
785 case ADMIN: /// Administration directory setting
788 <tr>
789 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
790 <td class="td_right">
791 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
792 </td>
793 </tr>
796 <?php
797 break;
798 case ENVIRONMENT: /// Environment checks
801 <tr>
802 <td colspan="2">
803 <?php
804 error_reporting(0); // Hide errors
805 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
806 error_reporting(7); // Show errors
807 if ($dbconnected) {
808 /// Execute environment check, printing results
809 check_moodle_environment($INSTALL['release'], $environment_results, true);
810 } else {
811 /// We never should reach this because DB has been tested before arriving here
812 $errormsg = get_string('dbconnectionerror', 'install');
813 $nextstage = DATABASE;
814 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
817 </td>
818 </tr>
820 <?php
821 break;
822 case DOWNLOADLANG: /// Download language from download.moodle.org
825 <tr>
826 <td colspan="2">
827 <?php
828 /// Get array of languages, we are going to use it
829 $languages=get_installer_list_of_languages();
830 /// Print the download form (button) if necessary
831 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
832 $options = array();
833 $options['downloadlangpack'] = true;
834 $options['stage'] = DOWNLOADLANG;
835 $options['same'] = true;
836 print_simple_box_start('center');
837 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
838 print_simple_box_end();
839 } else {
840 /// Show result info
841 /// English lang packs aren't downloaded
842 if (substr($INSTALL['language'],0,2) == 'en') {
843 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
844 } else {
845 if ($INSTALL['downloadlangpackerror']) {
846 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
847 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
848 } else {
849 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
854 </td>
855 </tr>
857 <?php
858 break;
859 default:
863 <tr>
864 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
866 <?php
867 if ($needtoopenform) {
869 <form name="installform" method="post" action="<?php echo $formaction ?>">
870 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
871 <?php
875 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
876 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
878 <?php
879 if ($needtoopenform) {
881 </form>
882 <?php
887 </td>
889 </tr>
891 </table>
892 <?php
893 if (!$needtoopenform) {
895 </form>
896 <?php
900 <?php
905 //==========================================================================//
907 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
908 echo "<tr>\n";
909 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
910 if ($success) {
911 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
912 echo "<td valign=\"top\">&nbsp;</td>\n";
913 } else {
914 echo "<td valign=\"top\"";
915 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
916 echo "</p></td>\n";
917 echo "<td valign=\"top\">";
918 echo "<p>$errormessage ";
919 install_helpbutton("install.php?help=$helpfield");
920 echo "</p></td>\n";
922 echo "</tr>\n";
923 return $success;
927 //==========================================================================//
929 function install_helpbutton($url, $title='') {
930 if ($title == '') {
931 $title = get_string('help');
933 echo "<a href=\"javascript: void(0)\">";
934 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
935 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
936 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
937 echo "</a>\n";
942 //==========================================================================//
944 function print_install_help($help) {
945 switch ($help) {
946 case 'phpversionhelp':
947 print_string($help, 'install', phpversion());
948 break;
949 case 'memorylimithelp':
950 print_string($help, 'install', get_memory_limit());
951 break;
952 default:
953 print_string($help, 'install');
958 //==========================================================================//
960 function get_memory_limit() {
961 if ($limit = ini_get('memory_limit')) {
962 return $limit;
963 } else {
964 return get_cfg_var('memory_limit');
968 //==========================================================================//
970 function check_memory_limit() {
972 /// if limit is already 16M or more then we don't care if we can change it or not
973 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
974 return true;
977 /// Otherwise, see if we can change it ourselves
978 @ini_set('memory_limit', '16M');
979 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
982 //==========================================================================//
984 function inst_check_php_version() {
985 if (!check_php_version("4.3.0")) {
986 return false;
987 } else if (check_php_version("5.0.0")) {
988 return check_php_version("5.1.0"); // 5.0.x is too buggy
990 return true; // 4.3.x or 4.4.x is fine
992 //==========================================================================//
994 /* This function returns a list of languages and their full names. The
995 * list of available languages is fetched from install/lang/xx/installer.php
996 * and it's used exclusively by the installation process
997 * @return array An associative array with contents in the form of LanguageCode => LanguageName
999 function get_installer_list_of_languages() {
1001 global $CFG;
1003 $languages = array();
1005 /// Get raw list of lang directories
1006 $langdirs = get_list_of_plugins('install/lang');
1007 asort($langdirs);
1008 /// Get some info from each lang
1009 foreach ($langdirs as $lang) {
1010 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1011 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1012 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1013 $shortlang = substr($lang, 0, -5);
1014 } else {
1015 $shortlang = $lang;
1017 if ($lang == 'en') { //Explain this is non-utf8 en
1018 $shortlang = 'non-utf8 en';
1020 if (!empty($string['thislanguage'])) {
1021 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1023 unset($string);
1026 /// Return array
1027 return $languages;
1030 //==========================================================================//
1032 function css_styles() {
1035 <style type="text/css">
1037 body { background-color: #ffeece; }
1038 p, li, td {
1039 font-family: helvetica, arial, sans-serif;
1040 font-size: 10pt;
1042 a { text-decoration: none; color: blue; }
1043 .errormsg {
1044 color: red;
1045 font-weight: bold;
1047 blockquote {
1048 font-family: courier, monospace;
1049 font-size: 10pt;
1051 .install_table {
1052 width: 500px;
1054 .td_left {
1055 text-align: right;
1056 font-weight: bold;
1058 .td_right {
1059 text-align: left;
1061 .main {
1062 width: 500px;
1063 border-width: 1px;
1064 border-style: solid;
1065 border-color: #ffc85f;
1066 -moz-border-radius-bottomleft: 15px;
1067 -moz-border-radius-bottomright: 15px;
1069 .td_mainheading {
1070 background-color: #fee6b9;
1071 padding: 10px;
1073 .td_main {
1074 text-align: center;
1076 .td_mainlogo {
1078 .p_mainlogo {
1080 .p_mainheading {
1081 font-size: 11pt;
1083 .p_subheading {
1084 font-size: 10pt;
1085 padding: 10px;
1087 .p_mainheader{
1088 text-align: right;
1089 font-size: 20pt;
1090 font-weight: bold;
1092 .p_pass {
1093 color: green;
1094 font-weight: bold;
1096 .p_fail {
1097 color: red;
1098 font-weight: bold;
1100 .p_caution {
1101 color: #ff6600;
1102 font-weight: bold;
1104 .p_help {
1105 text-align: center;
1106 font-family: helvetica, arial, sans-serif;
1107 font-size: 14pt;
1108 font-weight: bold;
1109 color: #333333;
1111 .environmenttable {
1112 font-size: 10pt;
1113 border-color: #ffc85f;
1115 table.environmenttable .error {
1116 background-color : red;
1117 color : inherit;
1120 table.environmenttable .warn {
1121 background-color : yellow;
1124 table.environmenttable .ok {
1125 background-color : lightgreen;
1127 .header {
1128 background-color: #fee6b9;
1129 font-size: 10pt;
1131 .cell {
1132 background-color: #ffeece;
1133 font-size: 10pt;
1135 .error {
1136 color: #ff0000;
1138 .errorboxcontent {
1139 text-align: center;
1140 font-weight: bold;
1141 padding: 20px;
1142 color: #ff0000;
1145 </style>
1147 <?php