Automatic installer.php lang files by installer_builder (20070323)
[moodle.git] / install.php
blob67dbab713119612177f3aa187a1cb754ee86331e
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/setuplib.php');
129 require_once('./lib/moodlelib.php');
130 require_once('./lib/weblib.php');
131 require_once('./lib/adodb/adodb.inc.php');
132 require_once('./lib/environmentlib.php');
133 require_once('./lib/xmlize.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'];
150 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
151 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
152 DIRECTORY => get_string('directorysettingshead', 'install'),
153 DATABASE => get_string('databasesettingshead', 'install'),
154 ADMIN => get_string('admindirsettinghead', 'install'),
155 ENVIRONMENT => get_string('environmenthead', 'install'),
156 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
157 SAVE => get_string('configurationcompletehead', 'install')
160 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
161 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
162 DIRECTORY => get_string('directorysettingssub', 'install'),
163 DATABASE => get_string('databasesettingssub', 'install'),
164 ADMIN => get_string('admindirsettingsub', 'install'),
165 ENVIRONMENT => get_string('environmentsub', 'install'),
166 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
167 SAVE => get_string('configurationcompletesub', 'install')
172 //==========================================================================//
174 /// Are we in help mode?
176 if (isset($_GET['help'])) {
177 $nextstage = -1;
182 //==========================================================================//
184 /// Are we in config download mode?
186 if (isset($_GET['download'])) {
187 header("Content-Type: application/download\n");
188 header("Content-Disposition: attachment; filename=\"config.php\"");
189 echo $INSTALL['config'];
190 exit;
197 //==========================================================================//
199 /// Check the directory settings
201 if ($INSTALL['stage'] == DIRECTORY) {
203 error_reporting(0);
205 /// check wwwroot
206 if (ini_get('allow_url_fopen')) {
207 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
208 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
209 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
212 if ($fh) fclose($fh);
214 /// check dirroot
215 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
216 $errormsg .= get_string('dirrooterror', 'install').'<br />';
217 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
219 if ($fh) fclose($fh);
221 /// check dataroot
222 $CFG->dataroot = $INSTALL['dataroot'];
223 if (make_upload_directory('sessions', false) === false ) {
224 $errormsg .= get_string('datarooterror', 'install').'<br />';
226 if ($fh) fclose($fh);
228 if (!empty($errormsg)) $nextstage = DIRECTORY;
230 error_reporting(7);
235 //==========================================================================//
237 /// Check database settings if stage 3 data submitted
238 /// Try to connect to the database. If that fails then try to create the database
240 if ($INSTALL['stage'] == DATABASE) {
242 /// First of all, analyze skipdbencodingtest status
243 if (isset($_POST['skipdbencodingtest'])) {
244 $INSTALL['skipdbencodingtest'] = true;
245 } else {
246 $INSTALL['skipdbencodingtest'] = false;
249 /// different format for postgres7 by socket
250 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
251 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
252 $INSTALL['dbuser'] = '';
253 $INSTALL['dbpass'] = '';
254 $INSTALL['dbname'] = '';
256 if ($INSTALL['prefix'] == '') { /// must have a prefix
257 $INSTALL['prefix'] = 'mdl_';
261 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
262 if (!extension_loaded('mysql')) {
263 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
264 $nextstage = DATABASE;
268 if (empty($errormsg)) {
270 error_reporting(0); // Hide errors
272 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
273 /// The following doesn't seem to work but we're working on it
274 /// If you come up with a solution for creating a database in MySQL
275 /// feel free to put it in and let us know
276 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
277 switch ($INSTALL['dbtype']) { /// Try to create a database
278 case 'mysql':
279 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
280 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
281 } else {
282 $errormsg = get_string('dbcreationerror', 'install');
283 $nextstage = DATABASE;
285 break;
288 } else {
289 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
290 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
291 if (empty($INSTALL['skipdbencodingtest'])) {
292 /// We haven't checked the skip test checkbox, so perform the test
293 $encoding = '';
294 switch ($INSTALL['dbtype']) {
295 case 'mysql':
296 ///Get MySQL character_set_database value
297 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
298 if ($rs && $rs->RecordCount() > 0) {
299 $records = $rs->GetAssoc(true);
300 $encoding = $records['character_set_database']['Value'];
301 if (strtoupper($encoding) == 'UTF8') {
302 $INSTALL['dbencodingtestresults'] = true;
303 } else {
304 // Try to set the encoding now!
305 if (! $db->Metatables()) { // We have no tables so go ahead
306 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
307 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
309 $records = $rs->GetAssoc(true);
310 $encoding = $records['character_set_database']['Value'];
312 if (strtoupper($encoding) == 'UTF8') {
313 $INSTALL['dbencodingtestresults'] = true;
314 } else {
315 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
316 $nextstage = DATABASE;
317 $INSTALL['showskipdbencodingtest'] = true;
318 $INSTALL['dbencodingtestresults'] = false;
320 } else {
321 $INSTALL['showskipdbencodingtest'] = true;
322 $INSTALL['dbencodingtestresults'] = false;
326 break;
327 case 'postgres7':
328 ///Get PostgreSQL server_encoding value
329 $rs = $db->Execute("SHOW server_encoding");
330 if ($rs && $rs->RecordCount() > 0) {
331 $encoding = $rs->fields['server_encoding'];
332 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
333 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
334 $nextstage = DATABASE;
335 $INSTALL['showskipdbencodingtest'] = true;
336 $INSTALL['dbencodingtestresults'] = false;
337 } else {
338 $INSTALL['dbencodingtestresults'] = true;
341 break;
347 error_reporting(7);
349 if (($dbconnected === false) and (empty($errormsg)) ) {
350 $errormsg = get_string('dbconnectionerror', 'install');
351 $nextstage = DATABASE;
357 //==========================================================================//
359 /// If the next stage is admin directory settings OR we have just come from there then
360 /// check the admin directory.
361 /// If we can open a file then we know that the admin name is correct.
363 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
364 if (!ini_get('allow_url_fopen')) {
365 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
366 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
367 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
368 fclose($fh);
369 } else {
370 if ($nextstage != ADMIN) {
371 $errormsg = get_string('admindirerror', 'install');
372 $nextstage = ADMIN;
377 //==========================================================================//
379 // Check if we can navigate from the environemt page (because it's ok)
381 if ($INSTALL['stage'] == ENVIRONMENT) {
382 error_reporting(0); // Hide errors
383 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
384 error_reporting(7); // Show errors
385 if ($dbconnected) {
386 /// Execute environment check, printing results
387 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
388 $nextstage = ENVIRONMENT;
390 } else {
391 /// We never should reach this because DB has been tested before arriving here
392 $errormsg = get_string('dbconnectionerror', 'install');
393 $nextstage = DATABASE;
399 //==========================================================================//
401 // Try to download the lang pack if it has been selected
403 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
405 $downloadsuccess = false;
406 $downloaderror = '';
408 error_reporting(0); // Hide errors
410 /// Create necessary lang dir
411 if (!make_upload_directory('lang', false)) {
412 $downloaderror = get_string('cannotcreatelangdir', 'error');
415 /// Download and install component
416 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
417 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
418 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
419 switch ($status) {
420 case ERROR:
421 if ($cd->get_error() == 'remotedownloadnotallowed') {
422 $a = new stdClass();
423 $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
424 $a->dest= $CFG->dataroot.'/lang';
425 $downloaderror = get_string($cd->get_error(), 'error', $a);
426 } else {
427 $downloaderror = get_string($cd->get_error(), 'error');
429 break;
430 case UPTODATE:
431 case INSTALLED:
432 $downloadsuccess = true;
433 break;
434 default:
435 //We shouldn't reach this point
437 } else {
438 //We shouldn't reach this point
441 error_reporting(7); // Show errors
443 if ($downloadsuccess) {
444 $INSTALL['downloadlangpack'] = false;
445 $INSTALL['showdownloadlangpack'] = false;
446 $INSTALL['downloadlangpackerror'] = $downloaderror;
447 } else {
448 $INSTALL['downloadlangpack'] = false;
449 $INSTALL['showdownloadlangpack'] = false;
450 $INSTALL['downloadlangpackerror'] = $downloaderror;
456 //==========================================================================//
458 /// Display or print the data
459 /// Put the data into a string
460 /// Try to open config file for writing.
462 if ($nextstage == SAVE) {
464 $str = '<?php /// Moodle Configuration File '."\r\n";
465 $str .= "\r\n";
467 $str .= 'unset($CFG);'."\r\n";
468 $str .= "\r\n";
470 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
471 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
472 if (!empty($INSTALL['dbname'])) {
473 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
474 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
475 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
477 $str .= '$CFG->dbpersist = false;'."\r\n";
478 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
479 $str .= "\r\n";
481 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
482 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
483 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
484 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
485 $str .= "\r\n";
487 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
488 $str .= "\r\n";
490 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
491 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
492 $str .= "\r\n";
495 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
496 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
497 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
498 $str .= '?>';
500 umask(0137);
502 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
503 fwrite($fh, $str);
504 fclose($fh);
508 $INSTALL['config'] = $str;
513 //==========================================================================//
516 <html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
517 <head>
518 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
519 <title>Moodle Install</title>
520 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
521 <?php css_styles() ?>
523 </head>
525 <body>
528 <?php
529 if (isset($_GET['help'])) {
530 print_install_help($_GET['help']);
531 close_window_button();
532 } else {
536 <table class="main" align="center" cellpadding="3" cellspacing="0">
537 <tr>
538 <td class="td_mainlogo">
539 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
540 </td>
541 <td class="td_mainlogo" valign="bottom">
542 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
543 </td>
544 </tr>
546 <tr>
547 <td class="td_mainheading" colspan="2">
548 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
549 <?php if (!empty($substagetext[$nextstage])) { ?>
550 <p class="p_subheading"><?php echo $substagetext[$nextstage] ?></p>
551 <?php } ?>
552 </td>
553 </tr>
555 <tr>
556 <td class="td_main" colspan="2">
558 <?php
560 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
563 if ($nextstage == SAVE) {
564 $INSTALL['stage'] = WELCOME;
565 $options = array();
566 $options['lang'] = $INSTALL['language'];
567 if ($configsuccess) {
568 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
570 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
571 echo "<tr>\n";
572 echo "<td width=\"33.3%\">&nbsp;</td>\n";
573 echo "<td width=\"33.3%\">&nbsp;</td>\n";
574 echo "<td width=\"33.3%\" align=\"right\">\n";
575 print_single_button("index.php", $options, get_string('continue')." &raquo;");
576 echo "</td>\n";
577 echo "</tr>\n";
578 echo "</table>\n";
580 } else {
581 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
583 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
584 echo "<tr>\n";
585 echo "<td width=\"33.3%\">&nbsp;</td>\n";
586 echo "<td width=\"33.3%\" align=\"center\">\n";
587 $installoptions = array();
588 $installoptions['download'] = 1;
589 print_single_button("install.php", $installoptions, get_string('download', 'install'));
590 echo "</td>\n";
591 echo "<td width=\"33.3%\" align=\"right\">\n";
592 print_single_button("index.php", $options, get_string('continue')." &raquo;");
593 echo "</td>\n";
594 echo "</tr>\n";
595 echo "</table>\n";
597 echo "<hr />\n";
598 echo "<div style=\"text-align: left\">\n";
599 print_object(s($str));
600 echo "</div>\n";
602 } else {
603 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
604 form_table($nextstage, $formaction);
609 </td>
610 </tr>
611 </table>
613 <?php
617 </body>
618 </html>
629 <?php
631 //==========================================================================//
634 function print_object($object) {
635 echo "<pre>\n";
636 print_r($object);
637 echo "</pre>\n";
642 //==========================================================================//
644 function form_table($nextstage = WELCOME, $formaction = "install.php") {
645 global $INSTALL, $db;
647 /// Print the standard form if we aren't in the DOWNLOADLANG page
648 /// because it has its own form.
649 if ($nextstage != DOWNLOADLANG) {
650 $needtoopenform = false;
652 <form name="installform" method="post" action="<?php echo $formaction ?>">
653 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
655 <?php
656 } else {
657 $needtoopenform = true;
660 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
662 <?php
663 /// what we do depends on the stage we're at
664 switch ($nextstage) {
665 case WELCOME: /// Welcome and language settings
667 <tr>
668 <td class="td_left"><p><?php print_string('language') ?></p></td>
669 <td class="td_right">
670 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
671 </td>
672 </tr>
674 <?php
675 break;
676 case COMPATIBILITY: /// Compatibilty check
677 $compatsuccess = true;
679 /// Check that PHP is of a sufficient version
680 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
681 /// Check session auto start
682 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
683 /// Check magic quotes
684 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
685 /// Check unsupported PHP configuration
686 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
687 /// Check safe mode
688 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
689 /// Check file uploads
690 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
691 /// Check GD version
692 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
693 /// Check memory limit
694 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
697 break;
698 case DIRECTORY: /// Directory settings
701 <tr>
702 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
703 <td class="td_right">
704 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
705 </td>
706 </tr>
707 <tr>
708 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
709 <td class="td_right">
710 <input type="text" size="40" name="dirrootform" value="<?php p($INSTALL['dirrootform'],true) ?>" />
711 </td>
712 </tr>
713 <tr>
714 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
715 <td class="td_right">
716 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
717 </td>
718 </tr>
720 <?php
721 break;
722 case DATABASE: /// Database settings
725 <tr>
726 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
727 <td class="td_right">
728 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>
729 </td>
730 </tr>
731 <tr>
732 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
733 <td class="td_right">
734 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
735 </td>
736 </tr>
737 <tr>
738 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
739 <td class="td_right">
740 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
741 </td>
742 </tr>
743 <tr>
744 <td class="td_left"><p><?php print_string('user') ?></p></td>
745 <td class="td_right">
746 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
747 </td>
748 </tr>
749 <tr>
750 <td class="td_left"><p><?php print_string('password') ?></p></td>
751 <td class="td_right">
752 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
753 </td>
754 </tr>
755 <tr>
756 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
757 <td class="td_right">
758 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
759 </td>
760 </tr>
761 <?php if ($INSTALL['showskipdbencodingtest']) { ?>
762 <tr>
763 <td class="td_left" colspan="2">
764 <?php print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?>
765 </td>
766 </tr>
767 <?php } ?>
769 <?php
770 break;
771 case ADMIN: /// Administration directory setting
774 <tr>
775 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
776 <td class="td_right">
777 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
778 </td>
779 </tr>
782 <?php
783 break;
784 case ENVIRONMENT: /// Environment checks
787 <tr>
788 <td colspan="2">
789 <?php
790 error_reporting(0); // Hide errors
791 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
792 error_reporting(7); // Show errors
793 if ($dbconnected) {
794 /// Execute environment check, printing results
795 check_moodle_environment($INSTALL['release'], $environment_results, true);
796 } else {
797 /// We never should reach this because DB has been tested before arriving here
798 $errormsg = get_string('dbconnectionerror', 'install');
799 $nextstage = DATABASE;
800 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
803 </td>
804 </tr>
806 <?php
807 break;
808 case DOWNLOADLANG: /// Download language from download.moodle.org
811 <tr>
812 <td colspan="2">
813 <?php
814 /// Get array of languages, we are going to use it
815 $languages=get_installer_list_of_languages();
816 /// Print the download form (button) if necessary
817 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
818 $options = array();
819 $options['downloadlangpack'] = true;
820 $options['stage'] = DOWNLOADLANG;
821 $options['same'] = true;
822 print_simple_box_start('center');
823 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
824 print_simple_box_end();
825 } else {
826 /// Show result info
827 /// English lang packs aren't downloaded
828 if (substr($INSTALL['language'],0,2) == 'en') {
829 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
830 } else {
831 if ($INSTALL['downloadlangpackerror']) {
832 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
833 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
834 } else {
835 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
840 </td>
841 </tr>
843 <?php
844 break;
845 default:
849 <tr>
850 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
852 <?php
853 if ($needtoopenform) {
855 <form name="installform" method="post" action="<?php echo $formaction ?>">
856 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
857 <?php
861 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
862 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
864 <?php
865 if ($needtoopenform) {
867 </form>
868 <?php
873 </td>
875 </tr>
877 </table>
878 <?php
879 if (!$needtoopenform) {
881 </form>
882 <?php
886 <?php
891 //==========================================================================//
893 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
894 echo "<tr>\n";
895 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
896 if ($success) {
897 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
898 echo "<td valign=\"top\">&nbsp;</td>\n";
899 } else {
900 echo "<td valign=\"top\"";
901 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
902 echo "</p></td>\n";
903 echo "<td valign=\"top\">";
904 echo "<p>$errormessage ";
905 install_helpbutton("install.php?help=$helpfield");
906 echo "</p></td>\n";
908 echo "</tr>\n";
909 return $success;
913 //==========================================================================//
915 function install_helpbutton($url, $title='') {
916 if ($title == '') {
917 $title = get_string('help');
919 echo "<a href=\"javascript: void(0)\">";
920 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
921 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
922 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
923 echo "</a>\n";
928 //==========================================================================//
930 function print_install_help($help) {
931 switch ($help) {
932 case 'phpversionhelp':
933 print_string($help, 'install', phpversion());
934 break;
935 case 'memorylimithelp':
936 print_string($help, 'install', get_memory_limit());
937 break;
938 default:
939 print_string($help, 'install');
944 //==========================================================================//
946 function get_memory_limit() {
947 if ($limit = ini_get('memory_limit')) {
948 return $limit;
949 } else {
950 return get_cfg_var('memory_limit');
954 //==========================================================================//
956 function check_memory_limit() {
958 /// if limit is already 16M or more then we don't care if we can change it or not
959 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
960 return true;
963 /// Otherwise, see if we can change it ourselves
964 @ini_set('memory_limit', '16M');
965 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
968 //==========================================================================//
970 function inst_check_php_version() {
971 if (!check_php_version("4.3.0")) {
972 return false;
973 } else if (check_php_version("5.0.0")) {
974 return check_php_version("5.1.0"); // 5.0.x is too buggy
976 return true; // 4.3.x or 4.4.x is fine
978 //==========================================================================//
980 /* This function returns a list of languages and their full names. The
981 * list of available languages is fetched from install/lang/xx/installer.php
982 * and it's used exclusively by the installation process
983 * @return array An associative array with contents in the form of LanguageCode => LanguageName
985 function get_installer_list_of_languages() {
987 global $CFG;
989 $languages = array();
991 /// Get raw list of lang directories
992 $langdirs = get_list_of_plugins('install/lang');
993 asort($langdirs);
994 /// Get some info from each lang
995 foreach ($langdirs as $lang) {
996 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
997 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
998 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
999 $shortlang = substr($lang, 0, -5);
1000 } else {
1001 $shortlang = $lang;
1003 if ($lang == 'en') { //Explain this is non-utf8 en
1004 $shortlang = 'non-utf8 en';
1006 if (!empty($string['thislanguage'])) {
1007 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1009 unset($string);
1012 /// Return array
1013 return $languages;
1016 //==========================================================================//
1018 function css_styles() {
1021 <style type="text/css">
1023 body { background-color: #ffeece; }
1024 p, li, td {
1025 font-family: helvetica, arial, sans-serif;
1026 font-size: 10pt;
1028 a { text-decoration: none; color: blue; }
1029 .errormsg {
1030 color: red;
1031 font-weight: bold;
1033 blockquote {
1034 font-family: courier, monospace;
1035 font-size: 10pt;
1037 .install_table {
1038 width: 500px;
1040 .td_left {
1041 text-align: right;
1042 font-weight: bold;
1044 .td_right {
1045 text-align: left;
1047 .main {
1048 width: 500px;
1049 border-width: 1px;
1050 border-style: solid;
1051 border-color: #ffc85f;
1052 -moz-border-radius-bottomleft: 15px;
1053 -moz-border-radius-bottomright: 15px;
1055 .td_mainheading {
1056 background-color: #fee6b9;
1057 padding: 10px;
1059 .td_main {
1060 text-align: center;
1062 .td_mainlogo {
1064 .p_mainlogo {
1066 .p_mainheading {
1067 font-size: 11pt;
1069 .p_subheading {
1070 font-size: 10pt;
1071 padding: 10px;
1073 .p_mainheader{
1074 text-align: right;
1075 font-size: 20pt;
1076 font-weight: bold;
1078 .p_pass {
1079 color: green;
1080 font-weight: bold;
1082 .p_fail {
1083 color: red;
1084 font-weight: bold;
1086 .p_caution {
1087 color: #ff6600;
1088 font-weight: bold;
1090 .p_help {
1091 text-align: center;
1092 font-family: helvetica, arial, sans-serif;
1093 font-size: 14pt;
1094 font-weight: bold;
1095 color: #333333;
1097 .environmenttable {
1098 font-size: 10pt;
1099 border-color: #ffc85f;
1101 .header {
1102 background-color: #fee6b9;
1103 font-size: 10pt;
1105 .cell {
1106 background-color: #ffeece;
1107 font-size: 10pt;
1109 .error {
1110 color: #ff0000;
1112 .errorboxcontent {
1113 text-align: center;
1114 font-weight: bold;
1115 padding: 20px;
1116 color: #ff0000;
1119 </style>
1121 <?php