Fixes bug MDL-8234, "New groups code & AS keyword"
[moodle-pu.git] / install.php
bloba84b71d1848bfbb0973c4534d4068bddaa3909f9
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
40 /// detect if install was attempted from diferent directory, if yes reset session to prevent errors,
41 /// dirroot location now fixed in installer
42 if (!empty($INSTALL['dirroot']) and $INSTALL['dirroot'] != dirname(__FILE__)) {
43 $_SESSION['INSTALL'] = array();
46 /// If it's our first time through this script then we need to set some default values
48 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
50 /// set defaults
51 $INSTALL['language'] = 'en_utf8';
53 $INSTALL['dbhost'] = 'localhost';
54 $INSTALL['dbuser'] = '';
55 $INSTALL['dbpass'] = '';
56 $INSTALL['dbtype'] = 'mysql';
57 $INSTALL['dbname'] = 'moodle';
58 $INSTALL['prefix'] = 'mdl_';
60 $INSTALL['downloadlangpack'] = false;
61 $INSTALL['showdownloadlangpack'] = true;
62 $INSTALL['downloadlangpackerror'] = '';
64 /// To be used by the Installer
65 $INSTALL['wwwroot'] = '';
66 $INSTALL['dirroot'] = dirname(__FILE__);
67 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
69 /// To be configured in the Installer
70 $INSTALL['wwwrootform'] = '';
71 $INSTALL['dirrootform'] = dirname(__FILE__);
73 $INSTALL['admindirname'] = 'admin';
75 $INSTALL['stage'] = WELCOME;
78 //==========================================================================//
80 /// Set the page to Unicode always
82 header('Content-Type: text/html; charset=UTF-8');
84 /// Was data submitted?
86 if (isset($_POST['stage'])) {
88 /// Get the stage for which the form was set and the next stage we are going to
90 /// Store any posted data
91 foreach ($_POST as $setting=>$value) {
92 $INSTALL[$setting] = $value;
95 if ( $goforward = (! empty( $_POST['next'] )) ) {
96 $nextstage = $_POST['stage'] + 1;
97 } else if (! empty( $_POST['prev'])) {
98 $nextstage = $_POST['stage'] - 1;
99 $INSTALL['stage'] = $_POST['stage'] - 1;
100 } else if (! empty( $_POST['same'] )) {
101 $nextstage = $_POST['stage'];
105 if ($nextstage < 0) {
106 $nextstage = WELCOME;
110 } else {
112 $goforward = true;
113 $nextstage = WELCOME;
117 //==========================================================================//
119 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
121 $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
122 $CFG->dirroot = $INSTALL['dirroot'];
123 $CFG->libdir = $INSTALL['dirroot'].'/lib';
124 $CFG->dataroot = $INSTALL['dataroot'];
125 $CFG->admin = $INSTALL['admindirname'];
126 $CFG->directorypermissions = 00777;
127 $CFG->running_installer = true;
129 /// Include some moodle libraries
131 require_once($CFG->libdir.'/adminlib.php');
132 require_once($CFG->libdir.'/setuplib.php');
133 require_once($CFG->libdir.'/moodlelib.php');
134 require_once($CFG->libdir.'/weblib.php');
135 require_once($CFG->libdir.'/deprecatedlib.php');
136 require_once($CFG->libdir.'/adodb/adodb.inc.php');
137 require_once($CFG->libdir.'/environmentlib.php');
138 require_once($CFG->libdir.'/xmlize.php');
139 require_once($CFG->libdir.'/componentlib.class.php');
140 require_once($CFG->dirroot.'/version.php');
142 /// Set version and release
143 $INSTALL['version'] = $version;
144 $INSTALL['release'] = $release;
146 /// Have the $db object ready because we are going to use it often
147 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
148 $db = &ADONewConnection($INSTALL['dbtype']);
149 $db->SetFetchMode(ADODB_FETCH_ASSOC);
151 /// guess the www root
152 if ($INSTALL['wwwroot'] == '') {
153 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
154 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
156 // now try to guess the correct dataroot not accessible via web
157 $CFG->wwwroot = $INSTALL['wwwroot'];
158 $i = 0; //safety check - dirname might return some unexpected results
159 while(is_dataroot_insecure()) {
160 $parrent = dirname($CFG->dataroot);
161 $i++;
162 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
163 $CFG->dataroot = ''; //can not find secure location for dataroot
164 break;
166 $CFG->dataroot = dirname($parrent).'/moodledata';
168 $INSTALL['dataroot'] = $CFG->dataroot;
171 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
172 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
173 DIRECTORY => get_string('directorysettingshead', 'install'),
174 DATABASE => get_string('databasesettingshead', 'install'),
175 ADMIN => get_string('admindirsettinghead', 'install'),
176 ENVIRONMENT => get_string('environmenthead', 'install'),
177 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
178 SAVE => get_string('configurationcompletehead', 'install')
181 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
182 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
183 DIRECTORY => get_string('directorysettingssub', 'install'),
184 DATABASE => get_string('databasesettingssub', 'install'),
185 ADMIN => get_string('admindirsettingsub', 'install'),
186 ENVIRONMENT => get_string('environmentsub', 'install'),
187 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
188 SAVE => get_string('configurationcompletesub', 'install')
193 //==========================================================================//
195 /// Are we in help mode?
197 if (isset($_GET['help'])) {
198 $nextstage = -1;
203 //==========================================================================//
205 /// Are we in config download mode?
207 if (isset($_GET['download'])) {
208 header("Content-Type: application/x-forcedownload\n");
209 header("Content-Disposition: attachment; filename=\"config.php\"");
210 echo $INSTALL['config'];
211 exit;
218 //==========================================================================//
220 /// Check the directory settings
222 if ($INSTALL['stage'] == DIRECTORY) {
224 error_reporting(0);
226 /// check wwwroot
227 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
228 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
229 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
230 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
233 if ($fh) fclose($fh);
235 /// check dirroot
236 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
237 $errormsg .= get_string('dirrooterror', 'install').'<br />';
238 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
240 if ($fh) fclose($fh);
242 /// check dataroot
243 $CFG->dataroot = $INSTALL['dataroot'];
244 if (make_upload_directory('sessions', false) === false ) {
245 $errormsg .= get_string('datarooterror', 'install').'<br />';
247 if ($fh) fclose($fh);
249 if (!empty($errormsg)) $nextstage = DIRECTORY;
251 error_reporting(7);
256 //==========================================================================//
258 /// Check database settings if stage 3 data submitted
259 /// Try to connect to the database. If that fails then try to create the database
261 if ($INSTALL['stage'] == DATABASE) {
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 ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
283 if (!extension_loaded('pgsql')) {
284 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
285 $nextstage = DATABASE;
289 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
290 if (!function_exists('mssql_connect')) {
291 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
292 $nextstage = DATABASE;
296 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
297 if (!function_exists('mssql_connect')) {
298 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
299 $nextstage = DATABASE;
303 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
304 if (!extension_loaded('odbc')) {
305 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
306 $nextstage = DATABASE;
310 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
311 if (!extension_loaded('oci8')) {
312 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
313 $nextstage = DATABASE;
317 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
318 $errormsg = get_string('dbwrongprefix', 'install');
319 $nextstage = DATABASE;
322 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
323 $errormsg = get_string('dbwrongprefix', 'install');
324 $nextstage = DATABASE;
327 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
328 $errormsg = get_string('dbwronghostserver', 'install');
329 $nextstage = DATABASE;
332 if (empty($errormsg)) {
334 error_reporting(0); // Hide errors
336 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
337 /// The following doesn't seem to work but we're working on it
338 /// If you come up with a solution for creating a database in MySQL
339 /// feel free to put it in and let us know
340 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
341 switch ($INSTALL['dbtype']) { /// Try to create a database
342 case 'mysql':
343 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
344 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
345 } else {
346 $errormsg = get_string('dbcreationerror', 'install');
347 $nextstage = DATABASE;
349 break;
352 } else {
353 /// We have been able to connect properly, just test the database encoding now.
354 /// It must be Unicode for 1.8 installations.
355 $encoding = '';
356 switch ($INSTALL['dbtype']) {
357 case 'mysql':
358 /// Get MySQL character_set_database value
359 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
360 if ($rs && $rs->RecordCount() > 0) {
361 $records = $rs->GetAssoc(true);
362 $encoding = $records['character_set_database']['Value'];
363 if (strtoupper($encoding) != 'UTF8') {
364 /// Try to set the encoding now!
365 if (! $db->Metatables()) { // We have no tables so go ahead
366 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
367 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
371 /// If conversion fails, skip, let environment testing do the job
373 break;
374 case 'postgres7':
375 /// Skip, let environment testing do the job
376 break;
377 case 'oci8po':
378 /// Skip, let environment testing do the job
379 break;
384 error_reporting(7);
386 if (($dbconnected === false) and (empty($errormsg)) ) {
387 $errormsg = get_string('dbconnectionerror', 'install');
388 $nextstage = DATABASE;
394 //==========================================================================//
396 /// If the next stage is admin directory settings OR we have just come from there then
397 /// check the admin directory.
398 /// If we can open a file then we know that the admin name is correct.
400 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
401 if (!ini_get('allow_url_fopen')) {
402 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
403 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
404 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
405 fclose($fh);
406 } else {
407 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
408 //if ($nextstage != ADMIN) {
409 // $errormsg = get_string('admindirerror', 'install');
410 // $nextstage = ADMIN;
411 // }
415 //==========================================================================//
417 // Check if we can navigate from the environemt page (because it's ok)
419 if ($INSTALL['stage'] == ENVIRONMENT) {
420 error_reporting(0); // Hide errors
421 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
422 error_reporting(7); // Show errors
423 if ($dbconnected) {
424 /// Execute environment check, printing results
425 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
426 $nextstage = ENVIRONMENT;
428 } else {
429 /// We never should reach this because DB has been tested before arriving here
430 $errormsg = get_string('dbconnectionerror', 'install');
431 $nextstage = DATABASE;
437 //==========================================================================//
439 // Try to download the lang pack if it has been selected
441 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
443 $downloadsuccess = false;
444 $downloaderror = '';
446 error_reporting(0); // Hide errors
448 /// Create necessary lang dir
449 if (!make_upload_directory('lang', false)) {
450 $downloaderror = get_string('cannotcreatelangdir', 'error');
453 /// Download and install component
454 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
455 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
456 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
457 switch ($status) {
458 case ERROR:
459 if ($cd->get_error() == 'remotedownloadnotallowed') {
460 $a = new stdClass();
461 $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
462 $a->dest= $CFG->dataroot.'/lang';
463 $downloaderror = get_string($cd->get_error(), 'error', $a);
464 } else {
465 $downloaderror = get_string($cd->get_error(), 'error');
467 break;
468 case UPTODATE:
469 case INSTALLED:
470 $downloadsuccess = true;
471 break;
472 default:
473 //We shouldn't reach this point
475 } else {
476 //We shouldn't reach this point
479 error_reporting(7); // Show errors
481 if ($downloadsuccess) {
482 $INSTALL['downloadlangpack'] = false;
483 $INSTALL['showdownloadlangpack'] = false;
484 $INSTALL['downloadlangpackerror'] = $downloaderror;
485 } else {
486 $INSTALL['downloadlangpack'] = false;
487 $INSTALL['showdownloadlangpack'] = false;
488 $INSTALL['downloadlangpackerror'] = $downloaderror;
494 //==========================================================================//
496 /// Display or print the data
497 /// Put the data into a string
498 /// Try to open config file for writing.
500 if ($nextstage == SAVE) {
502 $str = '<?php /// Moodle Configuration File '."\r\n";
503 $str .= "\r\n";
505 $str .= 'unset($CFG);'."\r\n";
506 $str .= "\r\n";
508 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
509 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
510 if (!empty($INSTALL['dbname'])) {
511 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
512 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
513 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
515 $str .= '$CFG->dbpersist = false;'."\r\n";
516 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
517 $str .= "\r\n";
519 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
520 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
521 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
522 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
523 $str .= "\r\n";
525 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
526 $str .= "\r\n";
528 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
529 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
530 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
531 $str .= '?>';
533 umask(0137);
535 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
536 fwrite($fh, $str);
537 fclose($fh);
541 $INSTALL['config'] = $str;
546 //==========================================================================//
549 <html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
550 <head>
551 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
552 <title>Moodle Install</title>
553 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
554 <?php css_styles() ?>
555 <?php database_js() ?>
557 </head>
559 <body>
562 <?php
563 if (isset($_GET['help'])) {
564 print_install_help($_GET['help']);
565 close_window_button();
566 } else {
570 <table class="main" align="center" cellpadding="3" cellspacing="0">
571 <tr>
572 <td class="td_mainlogo">
573 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
574 </td>
575 <td class="td_mainlogo" valign="bottom">
576 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
577 </td>
578 </tr>
580 <tr>
581 <td class="td_mainheading" colspan="2">
582 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
583 <?php /// Exceptionaly, depending of the DB selected, we show some different text
584 /// from the standard one to show better instructions for each DB
585 if ($nextstage == DATABASE) {
586 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
587 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
589 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
591 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
592 /// Link to mssql installation page
593 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
594 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
595 echo get_string('moodledocslink', 'install') . '</a></p>';
596 echo '</div>';
598 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
599 /// Link to mssql installation page
600 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
601 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
602 echo get_string('moodledocslink', 'install') . '</a></p>';
603 echo '</div>';
605 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
606 /// Link to mssql installation page
607 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
608 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
609 echo get_string('moodledocslink', 'install') . '</a></p>';
610 echo '</div>';
612 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
613 /// Link to oracle installation page
614 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
615 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
616 echo get_string('moodledocslink', 'install') . '</a></p>';
617 echo '</div>';
618 } else {
619 if (!empty($substagetext[$nextstage])) {
620 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
624 </td>
625 </tr>
627 <tr>
628 <td class="td_main" colspan="2">
630 <?php
632 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
635 if ($nextstage == SAVE) {
636 $INSTALL['stage'] = WELCOME;
637 $options = array();
638 $options['lang'] = $INSTALL['language'];
639 if ($configsuccess) {
640 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
642 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
643 echo "<tr>\n";
644 echo "<td width=\"33.3%\">&nbsp;</td>\n";
645 echo "<td width=\"33.3%\">&nbsp;</td>\n";
646 echo "<td width=\"33.3%\" align=\"right\">\n";
647 print_single_button("index.php", $options, get_string('continue')." &raquo;");
648 echo "</td>\n";
649 echo "</tr>\n";
650 echo "</table>\n";
652 } else {
653 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
655 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
656 echo "<tr>\n";
657 echo "<td width=\"33.3%\">&nbsp;</td>\n";
658 echo "<td width=\"33.3%\" align=\"center\">\n";
659 $installoptions = array();
660 $installoptions['download'] = 1;
661 print_single_button("install.php", $installoptions, get_string('download', 'install'));
662 echo "</td>\n";
663 echo "<td width=\"33.3%\" align=\"right\">\n";
664 print_single_button("index.php", $options, get_string('continue')." &raquo;");
665 echo "</td>\n";
666 echo "</tr>\n";
667 echo "</table>\n";
669 echo "<hr />\n";
670 echo "<div style=\"text-align: left\">\n";
671 echo "<pre>\n";
672 print_r(s($str));
673 echo "</pre>\n";
674 echo "</div>\n";
676 } else {
677 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
678 form_table($nextstage, $formaction);
683 </td>
684 </tr>
685 </table>
687 <?php
691 </body>
692 </html>
703 <?php
706 //==========================================================================//
708 function form_table($nextstage = WELCOME, $formaction = "install.php") {
709 global $INSTALL, $db;
711 /// Print the standard form if we aren't in the DOWNLOADLANG page
712 /// because it has its own form.
713 if ($nextstage != DOWNLOADLANG) {
714 $needtoopenform = false;
716 <form id="installform" method="post" action="<?php echo $formaction ?>">
717 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
719 <?php
720 } else {
721 $needtoopenform = true;
724 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
726 <?php
727 /// what we do depends on the stage we're at
728 switch ($nextstage) {
729 case WELCOME: /// Welcome and language settings
731 <tr>
732 <td class="td_left"><p><?php print_string('language') ?></p></td>
733 <td class="td_right">
734 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
735 </td>
736 </tr>
738 <?php
739 break;
740 case COMPATIBILITY: /// Compatibilty check
741 $compatsuccess = true;
743 /// Check that PHP is of a sufficient version
744 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
745 /// Check session auto start
746 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
747 /// Check magic quotes
748 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
749 /// Check unsupported PHP configuration
750 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
751 /// Check safe mode
752 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
753 /// Check file uploads
754 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
755 /// Check GD version
756 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
757 /// Check memory limit
758 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
761 break;
762 case DIRECTORY: /// Directory settings
765 <tr>
766 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
767 <td class="td_right">
768 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
769 </td>
770 </tr>
771 <tr>
772 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
773 <td class="td_right">
774 <input type="text" size="40" name="dirrootform" disabled="disabled" value="<?php p($INSTALL['dirrootform'],true) ?>" />
775 </td>
776 </tr>
777 <tr>
778 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
779 <td class="td_right">
780 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
781 </td>
782 </tr>
784 <?php
785 break;
786 case DATABASE: /// Database settings
789 <tr>
790 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
791 <td class="td_right">
792 <?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
793 'oci8po' => get_string('oci8po', 'install'),
794 'postgres7' => get_string('postgres7', 'install'),
795 'mssql' => get_string('mssql', 'install'),
796 'mssql_n' => get_string('mssql_n', 'install'),
797 'odbc_mssql' => get_string('odbc_mssql', 'install')),
798 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
799 </td>
800 </tr>
801 <tr>
802 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
803 <td class="td_right">
804 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
805 </td>
806 </tr>
807 <tr>
808 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
809 <td class="td_right">
810 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
811 </td>
812 </tr>
813 <tr>
814 <td class="td_left"><p><?php print_string('user') ?></p></td>
815 <td class="td_right">
816 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
817 </td>
818 </tr>
819 <tr>
820 <td class="td_left"><p><?php print_string('password') ?></p></td>
821 <td class="td_right">
822 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
823 </td>
824 </tr>
825 <tr>
826 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
827 <td class="td_right">
828 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
829 </td>
830 </tr>
832 <?php
833 break;
834 case ADMIN: /// Administration directory setting
837 <tr>
838 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
839 <td class="td_right">
840 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
841 </td>
842 </tr>
845 <?php
846 break;
847 case ENVIRONMENT: /// Environment checks
850 <tr>
851 <td colspan="2">
852 <?php
853 error_reporting(0); // Hide errors
854 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
855 error_reporting(7); // Show errors
856 if ($dbconnected) {
857 /// Execute environment check, printing results
858 check_moodle_environment($INSTALL['release'], $environment_results, true);
859 } else {
860 /// We never should reach this because DB has been tested before arriving here
861 $errormsg = get_string('dbconnectionerror', 'install');
862 $nextstage = DATABASE;
863 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
866 </td>
867 </tr>
869 <?php
870 break;
871 case DOWNLOADLANG: /// Download language from download.moodle.org
874 <tr>
875 <td colspan="2">
876 <?php
877 /// Get array of languages, we are going to use it
878 $languages=get_installer_list_of_languages();
879 /// Print the download form (button) if necessary
880 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
881 $options = array();
882 $options['downloadlangpack'] = true;
883 $options['stage'] = DOWNLOADLANG;
884 $options['same'] = true;
885 print_simple_box_start('center');
886 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
887 print_simple_box_end();
888 } else {
889 /// Show result info
890 /// English lang packs aren't downloaded
891 if (substr($INSTALL['language'],0,2) == 'en') {
892 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
893 } else {
894 if ($INSTALL['downloadlangpackerror']) {
895 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
896 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
897 } else {
898 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
903 </td>
904 </tr>
906 <?php
907 break;
908 default:
912 <tr>
913 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
915 <?php
916 if ($needtoopenform) {
918 <form id="installform" method="post" action="<?php echo $formaction ?>">
919 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
920 <?php
924 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
925 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
927 <?php
928 if ($needtoopenform) {
930 </form>
931 <?php
936 </td>
938 </tr>
940 </table>
941 <?php
942 if (!$needtoopenform) {
944 </form>
945 <?php
949 <?php
954 //==========================================================================//
956 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
957 echo "<tr>\n";
958 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
959 if ($success) {
960 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
961 echo "<td valign=\"top\">&nbsp;</td>\n";
962 } else {
963 echo "<td valign=\"top\"";
964 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
965 echo "</p></td>\n";
966 echo "<td valign=\"top\">";
967 echo "<p>$errormessage ";
968 install_helpbutton("install.php?help=$helpfield");
969 echo "</p></td>\n";
971 echo "</tr>\n";
972 return $success;
976 //==========================================================================//
978 function install_helpbutton($url, $title='') {
979 if ($title == '') {
980 $title = get_string('help');
982 echo "<a href=\"javascript: void(0)\">";
983 echo "<img src=\"./pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
984 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
985 echo "</a>\n";
990 //==========================================================================//
992 function print_install_help($help) {
993 switch ($help) {
994 case 'phpversionhelp':
995 print_string($help, 'install', phpversion());
996 break;
997 case 'memorylimithelp':
998 print_string($help, 'install', get_memory_limit());
999 break;
1000 default:
1001 print_string($help, 'install');
1006 //==========================================================================//
1008 function get_memory_limit() {
1009 if ($limit = ini_get('memory_limit')) {
1010 return $limit;
1011 } else {
1012 return get_cfg_var('memory_limit');
1016 //==========================================================================//
1018 function check_memory_limit() {
1020 /// if limit is already 16M or more then we don't care if we can change it or not
1021 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
1022 return true;
1025 /// Otherwise, see if we can change it ourselves
1026 @ini_set('memory_limit', '16M');
1027 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
1030 //==========================================================================//
1032 function inst_check_php_version() {
1033 if (!check_php_version("4.3.0")) {
1034 return false;
1035 } else if (check_php_version("5.0.0")) {
1036 return check_php_version("5.1.0"); // 5.0.x is too buggy
1038 return true; // 4.3.x or 4.4.x is fine
1040 //==========================================================================//
1042 /* This function returns a list of languages and their full names. The
1043 * list of available languages is fetched from install/lang/xx/installer.php
1044 * and it's used exclusively by the installation process
1045 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1047 function get_installer_list_of_languages() {
1049 global $CFG;
1051 $languages = array();
1053 /// Get raw list of lang directories
1054 $langdirs = get_list_of_plugins('install/lang');
1055 asort($langdirs);
1056 /// Get some info from each lang
1057 foreach ($langdirs as $lang) {
1058 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1059 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1060 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1061 $shortlang = substr($lang, 0, -5);
1062 } else {
1063 $shortlang = $lang;
1065 if ($lang == 'en') { //Explain this is non-utf8 en
1066 $shortlang = 'non-utf8 en';
1068 if (!empty($string['thislanguage'])) {
1069 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1071 unset($string);
1074 /// Return array
1075 return $languages;
1078 //==========================================================================//
1080 function css_styles() {
1083 <style type="text/css">
1085 body { background-color: #ffeece; }
1086 p, li, td {
1087 font-family: helvetica, arial, sans-serif;
1088 font-size: 10pt;
1090 a { text-decoration: none; color: blue; }
1091 .errormsg {
1092 color: red;
1093 font-weight: bold;
1095 blockquote {
1096 font-family: courier, monospace;
1097 font-size: 10pt;
1099 .install_table {
1100 width: 500px;
1102 .td_left {
1103 text-align: right;
1104 font-weight: bold;
1106 .td_right {
1107 text-align: left;
1109 .main {
1110 width: 500px;
1111 border-width: 1px;
1112 border-style: solid;
1113 border-color: #ffc85f;
1114 -moz-border-radius-bottomleft: 15px;
1115 -moz-border-radius-bottomright: 15px;
1117 .td_mainheading {
1118 background-color: #fee6b9;
1119 padding: 10px;
1121 .td_main {
1122 text-align: center;
1124 .td_mainlogo {
1126 .p_mainlogo {
1128 .p_mainheading {
1129 font-size: 11pt;
1131 .p_subheading {
1132 font-size: 10pt;
1133 padding: 10px;
1135 .p_mainheader{
1136 text-align: right;
1137 font-size: 20pt;
1138 font-weight: bold;
1140 .p_pass {
1141 color: green;
1142 font-weight: bold;
1144 .p_fail {
1145 color: red;
1146 font-weight: bold;
1148 .p_caution {
1149 color: #ff6600;
1150 font-weight: bold;
1152 .p_help {
1153 text-align: center;
1154 font-family: helvetica, arial, sans-serif;
1155 font-size: 14pt;
1156 font-weight: bold;
1157 color: #333333;
1159 .environmenttable {
1160 font-size: 10pt;
1161 border-color: #ffc85f;
1163 .header {
1164 background-color: #fee6b9;
1165 font-size: 10pt;
1167 .cell {
1168 background-color: #ffeece;
1169 font-size: 10pt;
1171 .error {
1172 color: #ff0000;
1174 .errorboxcontent {
1175 text-align: center;
1176 font-weight: bold;
1177 padding: 20px;
1178 color: #ff0000;
1180 .invisiblefieldset {
1181 display:inline;
1182 border:0px;
1183 padding:0px;
1184 margin:0px;
1186 #mysql, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1187 display: none;
1190 </style>
1192 <?php
1195 //==========================================================================//
1197 function database_js() {
1200 <script type="text/javascript" defer="defer">
1201 function toggledbinfo() {
1202 //Calculate selected value
1203 var showid = 'mysql';
1204 if (document.getElementById('installform').dbtype.value) {
1205 showid = document.getElementById('installform').dbtype.value;
1207 if (document.getElementById) {
1208 //Hide all the divs
1209 document.getElementById('mysql').style.display = '';
1210 document.getElementById('postgres7').style.display = '';
1211 document.getElementById('mssql').style.display = '';
1212 document.getElementById('mssql_n').style.display = '';
1213 document.getElementById('odbc_mssql').style.display = '';
1214 document.getElementById('oci8po').style.display = '';
1215 //Show the selected div
1216 document.getElementById(showid).style.display = 'block';
1217 } else if (document.all) {
1218 //This is the way old msie versions work
1219 //Hide all the divs
1220 document.all['mysql'].style.display = '';
1221 document.all['postgres7'].style.display = '';
1222 document.all['mssql'].style.display = '';
1223 document.all['mssql_n'].style.display = '';
1224 document.all['odbc_mssql'].style.display = '';
1225 document.all['oci8po'].style.display = '';
1226 //Show the selected div
1227 document.all[showid].style.display = 'block';
1228 } else if (document.layers) {
1229 //This is the way nn4 works
1230 //Hide all the divs
1231 document.layers['mysql'].style.display = '';
1232 document.layers['postgres7'].style.display = '';
1233 document.layers['mssql'].style.display = '';
1234 document.layers['mssql_n'].style.display = '';
1235 document.layers['odbc_mssql'].style.display = '';
1236 document.layers['oci8po'].style.display = '';
1237 //Show the selected div
1238 document.layers[showid].style.display = 'block';
1241 </script>
1243 <?php