Automatic installer.php lang files by installer_builder (20090122)
[moodle.git] / install.php
blob5b9d7f1a139385114120f846f857bcfe78e464d1
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 $enablenext = true;
663 /// Print the standard form if we aren't in the DOWNLOADLANG page
664 /// because it has its own form.
665 if ($nextstage != DOWNLOADLANG) {
666 $needtoopenform = false;
668 <form name="installform" method="post" action="<?php echo $formaction ?>">
669 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
671 <?php
672 } else {
673 $needtoopenform = true;
676 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
678 <?php
679 /// what we do depends on the stage we're at
680 switch ($nextstage) {
681 case WELCOME: /// Welcome and language settings
683 <tr>
684 <td class="td_left"><p><?php print_string('language') ?></p></td>
685 <td class="td_right">
686 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
687 </td>
688 </tr>
690 <?php
691 break;
692 case COMPATIBILITY: /// Compatibilty check
693 $compatsuccess = true;
695 /// Check that PHP is of a sufficient version
696 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
697 $enablenext = $enablenext && inst_check_php_version();
698 /// Check session auto start
699 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
700 $enablenext = $enablenext && !ini_get_bool('session.auto_start');
701 /// Check magic quotes
702 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
703 $enablenext = $enablenext && !ini_get_bool('magic_quotes_runtime');
704 /// Check unsupported PHP configuration
705 print_compatibility_row(!ini_get_bool('register_globals'), get_string('globalsquotes', 'install'), get_string('globalswarning', 'install'));
706 $enablenext = $enablenext && !ini_get_bool('register_globals');
707 /// Check safe mode
708 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
709 /// Check file uploads
710 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
711 /// Check GD version
712 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
713 /// Check memory limit
714 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
717 break;
718 case DIRECTORY: /// Directory settings
721 <tr>
722 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
723 <td class="td_right">
724 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
725 </td>
726 </tr>
727 <tr>
728 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
729 <td class="td_right">
730 <input type="text" size="40" name="dirrootform" value="<?php p($INSTALL['dirrootform'],true) ?>" />
731 </td>
732 </tr>
733 <tr>
734 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
735 <td class="td_right">
736 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
737 </td>
738 </tr>
740 <?php
741 break;
742 case DATABASE: /// Database settings
745 <tr>
746 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
747 <td class="td_right">
748 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>
749 </td>
750 </tr>
751 <tr>
752 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
753 <td class="td_right">
754 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
755 </td>
756 </tr>
757 <tr>
758 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
759 <td class="td_right">
760 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
761 </td>
762 </tr>
763 <tr>
764 <td class="td_left"><p><?php print_string('user') ?></p></td>
765 <td class="td_right">
766 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
767 </td>
768 </tr>
769 <tr>
770 <td class="td_left"><p><?php print_string('password') ?></p></td>
771 <td class="td_right">
772 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
773 </td>
774 </tr>
775 <tr>
776 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
777 <td class="td_right">
778 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
779 </td>
780 </tr>
781 <?php if ($INSTALL['showskipdbencodingtest']) { ?>
782 <tr>
783 <td class="td_left" colspan="2">
784 <?php print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?>
785 </td>
786 </tr>
787 <?php } ?>
789 <?php
790 break;
791 case ADMIN: /// Administration directory setting
794 <tr>
795 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
796 <td class="td_right">
797 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
798 </td>
799 </tr>
802 <?php
803 break;
804 case ENVIRONMENT: /// Environment checks
807 <tr>
808 <td colspan="2">
809 <?php
810 error_reporting(0); // Hide errors
811 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
812 error_reporting(7); // Show errors
813 if ($dbconnected) {
814 /// Execute environment check, printing results
815 check_moodle_environment($INSTALL['release'], $environment_results, true);
816 } else {
817 /// We never should reach this because DB has been tested before arriving here
818 $errormsg = get_string('dbconnectionerror', 'install');
819 $nextstage = DATABASE;
820 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
823 </td>
824 </tr>
826 <?php
827 break;
828 case DOWNLOADLANG: /// Download language from download.moodle.org
831 <tr>
832 <td colspan="2">
833 <?php
834 /// Get array of languages, we are going to use it
835 $languages=get_installer_list_of_languages();
836 /// Print the download form (button) if necessary
837 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
838 $options = array();
839 $options['downloadlangpack'] = true;
840 $options['stage'] = DOWNLOADLANG;
841 $options['same'] = true;
842 print_simple_box_start('center');
843 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
844 print_simple_box_end();
845 } else {
846 /// Show result info
847 /// English lang packs aren't downloaded
848 if (substr($INSTALL['language'],0,2) == 'en') {
849 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
850 } else {
851 if ($INSTALL['downloadlangpackerror']) {
852 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
853 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
854 } else {
855 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
860 </td>
861 </tr>
863 <?php
864 break;
865 default:
869 <tr>
870 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
872 <?php
873 if ($needtoopenform) {
875 <form name="installform" method="post" action="<?php echo $formaction ?>">
876 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
877 <?php
880 $disabled = $enablenext ? '' : 'disabled="disabled"';
883 <?php echo ($nextstage < SAVE) ? "<input $disabled type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
884 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
886 <?php
887 if ($needtoopenform) {
889 </form>
890 <?php
895 </td>
897 </tr>
899 </table>
900 <?php
901 if (!$needtoopenform) {
903 </form>
904 <?php
908 <?php
913 //==========================================================================//
915 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
916 echo "<tr>\n";
917 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
918 if ($success) {
919 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
920 echo "<td valign=\"top\">&nbsp;</td>\n";
921 } else {
922 echo "<td valign=\"top\"";
923 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
924 echo "</p></td>\n";
925 echo "<td valign=\"top\">";
926 echo "<p>$errormessage ";
927 if ($helpfield !== '') {
928 install_helpbutton("install.php?help=$helpfield");
930 echo "</p></td>\n";
932 echo "</tr>\n";
933 return $success;
937 //==========================================================================//
939 function install_helpbutton($url, $title='') {
940 if ($title == '') {
941 $title = get_string('help');
943 echo "<a href=\"javascript: void(0)\">";
944 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
945 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
946 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
947 echo "</a>\n";
952 //==========================================================================//
954 function print_install_help($help) {
955 switch ($help) {
956 case 'phpversionhelp':
957 print_string($help, 'install', phpversion());
958 break;
959 case 'memorylimithelp':
960 print_string($help, 'install', get_memory_limit());
961 break;
962 default:
963 print_string($help, 'install');
968 //==========================================================================//
970 function get_memory_limit() {
971 if ($limit = ini_get('memory_limit')) {
972 return $limit;
973 } else {
974 return get_cfg_var('memory_limit');
978 //==========================================================================//
980 function check_memory_limit() {
982 /// if limit is already 16M or more then we don't care if we can change it or not
983 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
984 return true;
987 /// Otherwise, see if we can change it ourselves
988 @ini_set('memory_limit', '16M');
989 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
992 //==========================================================================//
994 function inst_check_php_version() {
995 if (!check_php_version("4.3.0")) {
996 return false;
997 } else if (check_php_version("5.0.0")) {
998 return check_php_version("5.1.0"); // 5.0.x is too buggy
1000 return true; // 4.3.x or 4.4.x is fine
1002 //==========================================================================//
1004 /* This function returns a list of languages and their full names. The
1005 * list of available languages is fetched from install/lang/xx/installer.php
1006 * and it's used exclusively by the installation process
1007 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1009 function get_installer_list_of_languages() {
1011 global $CFG;
1013 $languages = array();
1015 /// Get raw list of lang directories
1016 $langdirs = get_list_of_plugins('install/lang');
1017 asort($langdirs);
1018 /// Get some info from each lang
1019 foreach ($langdirs as $lang) {
1020 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1021 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1022 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1023 $shortlang = substr($lang, 0, -5);
1024 } else {
1025 $shortlang = $lang;
1027 if ($lang == 'en') { //Explain this is non-utf8 en
1028 $shortlang = 'non-utf8 en';
1030 if (!empty($string['thislanguage'])) {
1031 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1033 unset($string);
1036 /// Return array
1037 return $languages;
1040 //==========================================================================//
1042 function css_styles() {
1045 <style type="text/css">
1047 body { background-color: #ffeece; }
1048 p, li, td {
1049 font-family: helvetica, arial, sans-serif;
1050 font-size: 10pt;
1052 a { text-decoration: none; color: blue; }
1053 .errormsg {
1054 color: red;
1055 font-weight: bold;
1057 blockquote {
1058 font-family: courier, monospace;
1059 font-size: 10pt;
1061 .install_table {
1062 width: 500px;
1064 .td_left {
1065 text-align: right;
1066 font-weight: bold;
1068 .td_right {
1069 text-align: left;
1071 .main {
1072 width: 500px;
1073 border-width: 1px;
1074 border-style: solid;
1075 border-color: #ffc85f;
1076 -moz-border-radius-bottomleft: 15px;
1077 -moz-border-radius-bottomright: 15px;
1079 .td_mainheading {
1080 background-color: #fee6b9;
1081 padding: 10px;
1083 .td_main {
1084 text-align: center;
1086 .td_mainlogo {
1088 .p_mainlogo {
1090 .p_mainheading {
1091 font-size: 11pt;
1093 .p_subheading {
1094 font-size: 10pt;
1095 padding: 10px;
1097 .p_mainheader{
1098 text-align: right;
1099 font-size: 20pt;
1100 font-weight: bold;
1102 .p_pass {
1103 color: green;
1104 font-weight: bold;
1106 .p_fail {
1107 color: red;
1108 font-weight: bold;
1110 .p_caution {
1111 color: #ff6600;
1112 font-weight: bold;
1114 .p_help {
1115 text-align: center;
1116 font-family: helvetica, arial, sans-serif;
1117 font-size: 14pt;
1118 font-weight: bold;
1119 color: #333333;
1121 .environmenttable {
1122 font-size: 10pt;
1123 border-color: #ffc85f;
1125 table.environmenttable .error {
1126 background-color : red;
1127 color : inherit;
1130 table.environmenttable .warn {
1131 background-color : yellow;
1134 table.environmenttable .ok {
1135 background-color : lightgreen;
1137 .header {
1138 background-color: #fee6b9;
1139 font-size: 10pt;
1141 .cell {
1142 background-color: #ffeece;
1143 font-size: 10pt;
1145 .error {
1146 color: #ff0000;
1148 .errorboxcontent {
1149 text-align: center;
1150 font-weight: bold;
1151 padding: 20px;
1152 color: #ff0000;
1155 </style>
1157 <?php