MDL-10829 Help page for the calculation field and interface
[moodle-pu.git] / install.php
blob0f55a56ad759bf44bdf9582bf542fb71fe943197
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 ///==========================================================================//
27 /// This has to be defined to avoid a notice in current_language()
28 define('SITEID', 0);
30 /// Begin the session as we are holding all information in a session
31 /// variable until the end.
33 session_name('MoodleSession');
34 @session_start();
36 if (! isset($_SESSION['INSTALL'])) {
37 $_SESSION['INSTALL'] = array();
40 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
42 /// detect if install was attempted from diferent directory, if yes reset session to prevent errors,
43 /// dirroot location now fixed in installer
44 if (!empty($INSTALL['dirroot']) and $INSTALL['dirroot'] != dirname(__FILE__)) {
45 $_SESSION['INSTALL'] = array();
48 /// If it's our first time through this script then we need to set some default values
50 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
52 /// set defaults
53 $INSTALL['language'] = 'en_utf8';
55 $INSTALL['dbhost'] = 'localhost';
56 $INSTALL['dbuser'] = '';
57 $INSTALL['dbpass'] = '';
58 $INSTALL['dbtype'] = 'mysql';
59 $INSTALL['dbname'] = 'moodle';
60 $INSTALL['prefix'] = 'mdl_';
62 $INSTALL['downloadlangpack'] = false;
63 $INSTALL['showdownloadlangpack'] = true;
64 $INSTALL['downloadlangpackerror'] = '';
66 /// To be used by the Installer
67 $INSTALL['wwwroot'] = '';
68 $INSTALL['dirroot'] = dirname(__FILE__);
69 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'moodledata';
71 /// To be configured in the Installer
72 $INSTALL['wwwrootform'] = '';
73 $INSTALL['dirrootform'] = dirname(__FILE__);
75 $INSTALL['admindirname'] = 'admin';
77 $INSTALL['stage'] = WELCOME;
80 //==========================================================================//
82 /// Set the page to Unicode always
84 header('Content-Type: text/html; charset=UTF-8');
86 /// Was data submitted?
88 if (isset($_POST['stage'])) {
90 /// Get the stage for which the form was set and the next stage we are going to
92 /// Store any posted data
93 foreach ($_POST as $setting=>$value) {
94 $INSTALL[$setting] = $value;
97 if ( $goforward = (! empty( $_POST['next'] )) ) {
98 $nextstage = $_POST['stage'] + 1;
99 } else if (! empty( $_POST['prev'])) {
100 $nextstage = $_POST['stage'] - 1;
101 $INSTALL['stage'] = $_POST['stage'] - 1;
102 } else if (! empty( $_POST['same'] )) {
103 $nextstage = $_POST['stage'];
107 if ($nextstage < 0) {
108 $nextstage = WELCOME;
112 } else {
114 $goforward = true;
115 $nextstage = WELCOME;
119 //==========================================================================//
121 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
123 $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
124 $CFG->dirroot = $INSTALL['dirroot'];
125 $CFG->libdir = $INSTALL['dirroot'].'/lib';
126 $CFG->dataroot = $INSTALL['dataroot'];
127 $CFG->admin = $INSTALL['admindirname'];
128 $CFG->directorypermissions = 00777;
129 $CFG->running_installer = true;
130 $COURSE->id = 0;
132 /// Include some moodle libraries
134 require_once($CFG->libdir.'/adminlib.php');
135 require_once($CFG->libdir.'/setuplib.php');
136 require_once($CFG->libdir.'/moodlelib.php');
137 require_once($CFG->libdir.'/weblib.php');
138 require_once($CFG->libdir.'/deprecatedlib.php');
139 require_once($CFG->libdir.'/adodb/adodb.inc.php');
140 require_once($CFG->libdir.'/environmentlib.php');
141 require_once($CFG->libdir.'/xmlize.php');
142 require_once($CFG->libdir.'/componentlib.class.php');
143 require_once($CFG->dirroot.'/version.php');
145 /// Set version and release
146 $INSTALL['version'] = $version;
147 $INSTALL['release'] = $release;
149 /// Have the $db object ready because we are going to use it often
150 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
151 $db = &ADONewConnection($INSTALL['dbtype']);
152 $db->SetFetchMode(ADODB_FETCH_ASSOC);
154 /// guess the www root
155 if ($INSTALL['wwwroot'] == '') {
156 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
157 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
159 // now try to guess the correct dataroot not accessible via web
160 $CFG->wwwroot = $INSTALL['wwwroot'];
161 $i = 0; //safety check - dirname might return some unexpected results
162 while(is_dataroot_insecure()) {
163 $parrent = dirname($CFG->dataroot);
164 $i++;
165 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
166 $CFG->dataroot = ''; //can not find secure location for dataroot
167 break;
169 $CFG->dataroot = dirname($parrent).'/moodledata';
171 $INSTALL['dataroot'] = $CFG->dataroot;
174 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
175 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
176 DIRECTORY => get_string('directorysettingshead', 'install'),
177 DATABASE => get_string('databasesettingshead', 'install'),
178 ADMIN => get_string('admindirsettinghead', 'install'),
179 ENVIRONMENT => get_string('environmenthead', 'install'),
180 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
181 SAVE => get_string('configurationcompletehead', 'install')
184 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
185 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
186 DIRECTORY => get_string('directorysettingssub', 'install'),
187 DATABASE => get_string('databasesettingssub', 'install'),
188 ADMIN => get_string('admindirsettingsub', 'install'),
189 ENVIRONMENT => get_string('environmentsub', 'install'),
190 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
191 SAVE => get_string('configurationcompletesub', 'install')
196 //==========================================================================//
198 /// Are we in help mode?
200 if (isset($_GET['help'])) {
201 $nextstage = -1;
206 //==========================================================================//
208 /// Are we in config download mode?
210 if (isset($_GET['download'])) {
211 header("Content-Type: application/x-forcedownload\n");
212 header("Content-Disposition: attachment; filename=\"config.php\"");
213 echo $INSTALL['config'];
214 exit;
221 //==========================================================================//
223 /// Check the directory settings
225 if ($INSTALL['stage'] == DIRECTORY) {
227 error_reporting(0);
229 /// check wwwroot
230 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
231 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
232 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
233 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
236 if ($fh) fclose($fh);
238 /// check dirroot
239 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
240 $errormsg .= get_string('dirrooterror', 'install').'<br />';
241 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
243 if ($fh) fclose($fh);
245 /// check dataroot
246 $CFG->dataroot = $INSTALL['dataroot'];
247 if (make_upload_directory('sessions', false) === false ) {
248 $errormsg .= get_string('datarooterror', 'install').'<br />';
250 if ($fh) fclose($fh);
252 if (!empty($errormsg)) $nextstage = DIRECTORY;
254 error_reporting(7);
259 //==========================================================================//
261 /// Check database settings if stage 3 data submitted
262 /// Try to connect to the database. If that fails then try to create the database
264 if ($INSTALL['stage'] == DATABASE) {
266 /// different format for postgres7 by socket
267 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
268 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
269 $INSTALL['dbuser'] = '';
270 $INSTALL['dbpass'] = '';
271 $INSTALL['dbname'] = '';
273 if ($INSTALL['prefix'] == '') { /// must have a prefix
274 $INSTALL['prefix'] = 'mdl_';
278 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
279 if (!extension_loaded('mysql')) {
280 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
281 $nextstage = DATABASE;
285 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
286 if (!extension_loaded('pgsql')) {
287 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
288 $nextstage = DATABASE;
292 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
293 if (!function_exists('mssql_connect')) {
294 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
295 $nextstage = DATABASE;
299 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
300 if (!function_exists('mssql_connect')) {
301 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
302 $nextstage = DATABASE;
306 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
307 if (!extension_loaded('odbc')) {
308 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
309 $nextstage = DATABASE;
313 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
314 if (!extension_loaded('oci8')) {
315 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
316 $nextstage = DATABASE;
320 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
321 $errormsg = get_string('dbwrongprefix', 'install');
322 $nextstage = DATABASE;
325 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
326 $errormsg = get_string('dbwrongprefix', 'install');
327 $nextstage = DATABASE;
330 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
331 $errormsg = get_string('dbwronghostserver', 'install');
332 $nextstage = DATABASE;
335 if (empty($errormsg)) {
337 error_reporting(0); // Hide errors
339 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
340 /// The following doesn't seem to work but we're working on it
341 /// If you come up with a solution for creating a database in MySQL
342 /// feel free to put it in and let us know
343 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
344 switch ($INSTALL['dbtype']) { /// Try to create a database
345 case 'mysql':
346 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
347 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
348 } else {
349 $errormsg = get_string('dbcreationerror', 'install');
350 $nextstage = DATABASE;
352 break;
355 } else {
356 /// We have been able to connect properly, just test the database encoding now.
357 /// It must be Unicode for 1.8 installations.
358 $encoding = '';
359 switch ($INSTALL['dbtype']) {
360 case 'mysql':
361 /// Get MySQL character_set_database value
362 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
363 if ($rs && $rs->RecordCount() > 0) {
364 $records = $rs->GetAssoc(true);
365 $encoding = $records['character_set_database']['Value'];
366 if (strtoupper($encoding) != 'UTF8') {
367 /// Try to set the encoding now!
368 if (! $db->Metatables()) { // We have no tables so go ahead
369 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
370 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
374 /// If conversion fails, skip, let environment testing do the job
376 break;
377 case 'postgres7':
378 /// Skip, let environment testing do the job
379 break;
380 case 'oci8po':
381 /// Skip, let environment testing do the job
382 break;
387 error_reporting(7);
389 if (($dbconnected === false) and (empty($errormsg)) ) {
390 $errormsg = get_string('dbconnectionerror', 'install');
391 $nextstage = DATABASE;
397 //==========================================================================//
399 /// If the next stage is admin directory settings OR we have just come from there then
400 /// check the admin directory.
401 /// If we can open a file then we know that the admin name is correct.
403 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
404 if (!ini_get('allow_url_fopen')) {
405 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
406 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
407 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
408 fclose($fh);
409 } else {
410 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
411 //if ($nextstage != ADMIN) {
412 // $errormsg = get_string('admindirerror', 'install');
413 // $nextstage = ADMIN;
414 // }
418 //==========================================================================//
420 // Check if we can navigate from the environemt page (because it's ok)
422 if ($INSTALL['stage'] == ENVIRONMENT) {
423 error_reporting(0); // Hide errors
424 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
425 error_reporting(7); // Show errors
426 if ($dbconnected) {
427 /// Execute environment check, printing results
428 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
429 $nextstage = ENVIRONMENT;
431 } else {
432 /// We never should reach this because DB has been tested before arriving here
433 $errormsg = get_string('dbconnectionerror', 'install');
434 $nextstage = DATABASE;
440 //==========================================================================//
442 // Try to download the lang pack if it has been selected
444 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
446 $downloadsuccess = false;
447 $downloaderror = '';
449 error_reporting(0); // Hide errors
451 /// Create necessary lang dir
452 if (!make_upload_directory('lang', false)) {
453 $downloaderror = get_string('cannotcreatelangdir', 'error');
456 /// Download and install component
457 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
458 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
459 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
460 switch ($status) {
461 case ERROR:
462 if ($cd->get_error() == 'remotedownloadnotallowed') {
463 $a = new stdClass();
464 $a->url = 'http://download.moodle.org/lang16/'.$pack.'.zip';
465 $a->dest= $CFG->dataroot.'/lang';
466 $downloaderror = get_string($cd->get_error(), 'error', $a);
467 } else {
468 $downloaderror = get_string($cd->get_error(), 'error');
470 break;
471 case UPTODATE:
472 case INSTALLED:
473 $downloadsuccess = true;
474 break;
475 default:
476 //We shouldn't reach this point
478 } else {
479 //We shouldn't reach this point
482 error_reporting(7); // Show errors
484 if ($downloadsuccess) {
485 $INSTALL['downloadlangpack'] = false;
486 $INSTALL['showdownloadlangpack'] = false;
487 $INSTALL['downloadlangpackerror'] = $downloaderror;
488 } else {
489 $INSTALL['downloadlangpack'] = false;
490 $INSTALL['showdownloadlangpack'] = false;
491 $INSTALL['downloadlangpackerror'] = $downloaderror;
497 //==========================================================================//
499 /// Display or print the data
500 /// Put the data into a string
501 /// Try to open config file for writing.
503 if ($nextstage == SAVE) {
505 $str = '<?php /// Moodle Configuration File '."\r\n";
506 $str .= "\r\n";
508 $str .= 'unset($CFG);'."\r\n";
509 $str .= "\r\n";
511 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
512 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
513 if (!empty($INSTALL['dbname'])) {
514 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
515 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
516 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
518 $str .= '$CFG->dbpersist = false;'."\r\n";
519 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
520 $str .= "\r\n";
522 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
523 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
524 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
525 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
526 $str .= "\r\n";
528 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
529 $str .= "\r\n";
531 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
532 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
533 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
534 $str .= '?>';
536 umask(0137);
538 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
539 fwrite($fh, $str);
540 fclose($fh);
544 $INSTALL['config'] = $str;
549 //==========================================================================//
552 <html dir="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
553 <head>
554 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
555 <title>Moodle Install</title>
556 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
557 <?php css_styles() ?>
558 <?php database_js() ?>
560 </head>
562 <body>
565 <?php
566 if (isset($_GET['help'])) {
567 print_install_help($_GET['help']);
568 close_window_button();
569 } else {
573 <table class="main" align="center" cellpadding="3" cellspacing="0">
574 <tr>
575 <td class="td_mainlogo">
576 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
577 </td>
578 <td class="td_mainlogo" valign="bottom">
579 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
580 </td>
581 </tr>
583 <tr>
584 <td class="td_mainheading" colspan="2">
585 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
586 <?php /// Exceptionaly, depending of the DB selected, we show some different text
587 /// from the standard one to show better instructions for each DB
588 if ($nextstage == DATABASE) {
589 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
590 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
592 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
594 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
595 /// Link to mssql installation page
596 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
597 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
598 echo get_string('moodledocslink', 'install') . '</a></p>';
599 echo '</div>';
601 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
602 /// Link to mssql installation page
603 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
604 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
605 echo get_string('moodledocslink', 'install') . '</a></p>';
606 echo '</div>';
608 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
609 /// Link to mssql installation page
610 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
611 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
612 echo get_string('moodledocslink', 'install') . '</a></p>';
613 echo '</div>';
615 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
616 /// Link to oracle installation page
617 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
618 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
619 echo get_string('moodledocslink', 'install') . '</a></p>';
620 echo '</div>';
621 } else {
622 if (!empty($substagetext[$nextstage])) {
623 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
627 </td>
628 </tr>
630 <tr>
631 <td class="td_main" colspan="2">
633 <?php
635 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
638 if ($nextstage == SAVE) {
639 $INSTALL['stage'] = WELCOME;
640 $options = array();
641 $options['lang'] = $INSTALL['language'];
642 if ($configsuccess) {
643 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
645 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
646 echo "<tr>\n";
647 echo "<td width=\"33.3%\">&nbsp;</td>\n";
648 echo "<td width=\"33.3%\">&nbsp;</td>\n";
649 echo "<td width=\"33.3%\" align=\"right\">\n";
650 print_single_button("index.php", $options, get_string('continue'));
651 echo "</td>\n";
652 echo "</tr>\n";
653 echo "</table>\n";
655 } else {
656 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
658 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
659 echo "<tr>\n";
660 echo "<td width=\"33.3%\">&nbsp;</td>\n";
661 echo "<td width=\"33.3%\" align=\"center\">\n";
662 $installoptions = array();
663 $installoptions['download'] = 1;
664 print_single_button("install.php", $installoptions, get_string('download', 'install'));
665 echo "</td>\n";
666 echo "<td width=\"33.3%\" align=\"right\">\n";
667 print_single_button("index.php", $options, get_string('continue'));
668 echo "</td>\n";
669 echo "</tr>\n";
670 echo "</table>\n";
672 echo "<hr />\n";
673 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
674 echo "<pre>\n";
675 print_r(s($str));
676 echo "</pre>\n";
677 echo "</div>\n";
679 } else {
680 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
681 form_table($nextstage, $formaction);
686 </td>
687 </tr>
688 </table>
690 <?php
694 </body>
695 </html>
706 <?php
709 //==========================================================================//
711 function form_table($nextstage = WELCOME, $formaction = "install.php") {
712 global $INSTALL, $db;
714 /// Print the standard form if we aren't in the DOWNLOADLANG page
715 /// because it has its own form.
716 if ($nextstage != DOWNLOADLANG) {
717 $needtoopenform = false;
719 <form id="installform" method="post" action="<?php echo $formaction ?>">
720 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
722 <?php
723 } else {
724 $needtoopenform = true;
727 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
729 <?php
730 /// what we do depends on the stage we're at
731 switch ($nextstage) {
732 case WELCOME: /// Welcome and language settings
734 <tr>
735 <td class="td_left"><p><?php print_string('language') ?></p></td>
736 <td class="td_right">
737 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
738 </td>
739 </tr>
741 <?php
742 break;
743 case COMPATIBILITY: /// Compatibilty check
744 $compatsuccess = true;
746 /// Check that PHP is of a sufficient version
747 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
748 /// Check session auto start
749 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
750 /// Check magic quotes
751 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
752 /// Check unsupported PHP configuration
753 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
754 /// Check safe mode
755 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
756 /// Check file uploads
757 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
758 /// Check GD version
759 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
760 /// Check memory limit
761 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
764 break;
765 case DIRECTORY: /// Directory settings
768 <tr>
769 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
770 <td class="td_right">
771 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
772 </td>
773 </tr>
774 <tr>
775 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
776 <td class="td_right">
777 <input type="text" size="40" name="dirrootform" disabled="disabled" value="<?php p($INSTALL['dirrootform'],true) ?>" />
778 </td>
779 </tr>
780 <tr>
781 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
782 <td class="td_right">
783 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
784 </td>
785 </tr>
787 <?php
788 break;
789 case DATABASE: /// Database settings
792 <tr>
793 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
794 <td class="td_right">
795 <?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
796 'oci8po' => get_string('oci8po', 'install'),
797 'postgres7' => get_string('postgres7', 'install'),
798 'mssql' => get_string('mssql', 'install'),
799 'mssql_n' => get_string('mssql_n', 'install'),
800 'odbc_mssql' => get_string('odbc_mssql', 'install')),
801 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
802 </td>
803 </tr>
804 <tr>
805 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
806 <td class="td_right">
807 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
808 </td>
809 </tr>
810 <tr>
811 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
812 <td class="td_right">
813 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
814 </td>
815 </tr>
816 <tr>
817 <td class="td_left"><p><?php print_string('user') ?></p></td>
818 <td class="td_right">
819 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
820 </td>
821 </tr>
822 <tr>
823 <td class="td_left"><p><?php print_string('password') ?></p></td>
824 <td class="td_right">
825 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
826 </td>
827 </tr>
828 <tr>
829 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
830 <td class="td_right">
831 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
832 </td>
833 </tr>
835 <?php
836 break;
837 case ADMIN: /// Administration directory setting
840 <tr>
841 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
842 <td class="td_right">
843 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
844 </td>
845 </tr>
848 <?php
849 break;
850 case ENVIRONMENT: /// Environment checks
853 <tr>
854 <td colspan="2">
855 <?php
856 error_reporting(0); // Hide errors
857 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
858 error_reporting(7); // Show errors
859 if ($dbconnected) {
860 /// Execute environment check, printing results
861 check_moodle_environment($INSTALL['release'], $environment_results, true);
862 } else {
863 /// We never should reach this because DB has been tested before arriving here
864 $errormsg = get_string('dbconnectionerror', 'install');
865 $nextstage = DATABASE;
866 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
869 </td>
870 </tr>
872 <?php
873 break;
874 case DOWNLOADLANG: /// Download language from download.moodle.org
877 <tr>
878 <td colspan="2">
879 <?php
880 /// Get array of languages, we are going to use it
881 $languages=get_installer_list_of_languages();
882 /// Print the download form (button) if necessary
883 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
884 $options = array();
885 $options['downloadlangpack'] = true;
886 $options['stage'] = DOWNLOADLANG;
887 $options['same'] = true;
888 print_simple_box_start('center');
889 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
890 print_simple_box_end();
891 } else {
892 /// Show result info
893 /// English lang packs aren't downloaded
894 if (substr($INSTALL['language'],0,2) == 'en') {
895 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
896 } else {
897 if ($INSTALL['downloadlangpackerror']) {
898 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
899 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
900 } else {
901 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
906 </td>
907 </tr>
909 <?php
910 break;
911 default:
915 <tr>
916 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
918 <?php
919 if ($needtoopenform) {
921 <form id="installform" method="post" action="<?php echo $formaction ?>">
922 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
923 <?php
927 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: ".fix_align_rtl("right")."\"/>\n" : "&nbsp;\n" ?>
928 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/>\n" : "&nbsp;\n" ?>
930 <?php
931 if ($needtoopenform) {
933 </form>
934 <?php
939 </td>
941 </tr>
943 </table>
944 <?php
945 if (!$needtoopenform) {
947 </form>
948 <?php
952 <?php
957 //==========================================================================//
959 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
960 echo "<tr>\n";
961 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
962 if ($success) {
963 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
964 echo "<td valign=\"top\">&nbsp;</td>\n";
965 } else {
966 echo "<td valign=\"top\"";
967 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
968 echo "</p></td>\n";
969 echo "<td valign=\"top\">";
970 echo "<p>$errormessage ";
971 install_helpbutton("install.php?help=$helpfield");
972 echo "</p></td>\n";
974 echo "</tr>\n";
975 return $success;
979 //==========================================================================//
981 function install_helpbutton($url, $title='') {
982 if ($title == '') {
983 $title = get_string('help');
985 echo "<a href=\"javascript: void(0)\">";
986 echo "<img src=\"./pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
987 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
988 echo "</a>\n";
993 //==========================================================================//
995 function print_install_help($help) {
996 switch ($help) {
997 case 'phpversionhelp':
998 print_string($help, 'install', phpversion());
999 break;
1000 case 'memorylimithelp':
1001 print_string($help, 'install', get_memory_limit());
1002 break;
1003 default:
1004 print_string($help, 'install');
1009 //==========================================================================//
1011 function get_memory_limit() {
1012 if ($limit = ini_get('memory_limit')) {
1013 return $limit;
1014 } else {
1015 return get_cfg_var('memory_limit');
1019 //==========================================================================//
1021 function check_memory_limit() {
1023 /// if limit is already 40 or more then we don't care if we can change it or not
1024 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1025 return true;
1028 /// Otherwise, see if we can change it ourselves
1029 @ini_set('memory_limit', '40M');
1030 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1033 //==========================================================================//
1035 function inst_check_php_version() {
1036 if (!check_php_version("4.3.0")) {
1037 return false;
1038 } else if (check_php_version("5.0.0")) {
1039 return check_php_version("5.1.0"); // 5.0.x is too buggy
1041 return true; // 4.3.x or 4.4.x is fine
1043 //==========================================================================//
1045 /* This function returns a list of languages and their full names. The
1046 * list of available languages is fetched from install/lang/xx/installer.php
1047 * and it's used exclusively by the installation process
1048 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1050 function get_installer_list_of_languages() {
1052 global $CFG;
1054 $languages = array();
1056 /// Get raw list of lang directories
1057 $langdirs = get_list_of_plugins('install/lang');
1058 asort($langdirs);
1059 /// Get some info from each lang
1060 foreach ($langdirs as $lang) {
1061 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1062 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1063 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1064 $shortlang = substr($lang, 0, -5);
1065 } else {
1066 $shortlang = $lang;
1068 if ($lang == 'en') { //Explain this is non-utf8 en
1069 $shortlang = 'non-utf8 en';
1071 if (!empty($string['thislanguage'])) {
1072 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1074 unset($string);
1077 /// Return array
1078 return $languages;
1081 //==========================================================================//
1083 function css_styles() {
1086 <style type="text/css">
1088 body { background-color: #ffeece; }
1089 p, li, td {
1090 font-family: helvetica, arial, sans-serif;
1091 font-size: 10pt;
1093 a { text-decoration: none; color: blue; }
1094 a img {
1095 border: none;
1097 .errormsg {
1098 color: red;
1099 font-weight: bold;
1101 blockquote {
1102 font-family: courier, monospace;
1103 font-size: 10pt;
1105 .install_table {
1106 width: 500px;
1108 .td_left {
1109 text-align: <?php echo fix_align_rtl("right") ?>;
1110 font-weight: bold;
1112 .td_right {
1113 text-align: <?php echo fix_align_rtl("left") ?>;
1115 .main {
1116 width: 500px;
1117 border-width: 1px;
1118 border-style: solid;
1119 border-color: #ffc85f;
1120 -moz-border-radius-bottomleft: 15px;
1121 -moz-border-radius-bottomright: 15px;
1123 .td_mainheading {
1124 background-color: #fee6b9;
1125 padding: 10px;
1127 .td_main {
1128 text-align: center;
1130 .td_mainlogo {
1132 .p_mainlogo {
1134 .p_mainheading {
1135 font-size: 11pt;
1137 .p_subheading {
1138 font-size: 10pt;
1139 padding: 10px;
1141 .p_mainheader{
1142 text-align: right;
1143 font-size: 20pt;
1144 font-weight: bold;
1146 .p_pass {
1147 color: green;
1148 font-weight: bold;
1150 .p_fail {
1151 color: red;
1152 font-weight: bold;
1154 .p_caution {
1155 color: #ff6600;
1156 font-weight: bold;
1158 .p_help {
1159 text-align: center;
1160 font-family: helvetica, arial, sans-serif;
1161 font-size: 14pt;
1162 font-weight: bold;
1163 color: #333333;
1165 .environmenttable {
1166 font-size: 10pt;
1167 border-color: #ffc85f;
1169 table.environmenttable .error {
1170 background-color : red;
1171 color : inherit;
1174 table.environmenttable .warn {
1175 background-color : yellow;
1178 table.environmenttable .ok {
1179 background-color : lightgreen;
1181 .header {
1182 background-color: #fee6b9;
1183 font-size: 10pt;
1185 .cell {
1186 background-color: #ffeece;
1187 font-size: 10pt;
1189 .error {
1190 color: #ff0000;
1192 .errorboxcontent {
1193 text-align: center;
1194 font-weight: bold;
1195 padding: 20px;
1196 color: #ff0000;
1198 .invisiblefieldset {
1199 display:inline;
1200 border:0px;
1201 padding:0px;
1202 margin:0px;
1204 #mysql, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1205 display: none;
1208 </style>
1210 <?php
1213 //==========================================================================//
1215 function database_js() {
1218 <script type="text/javascript" defer="defer">
1219 function toggledbinfo() {
1220 //Calculate selected value
1221 var showid = 'mysql';
1222 if (document.getElementById('installform').dbtype.value) {
1223 showid = document.getElementById('installform').dbtype.value;
1225 if (document.getElementById) {
1226 //Hide all the divs
1227 document.getElementById('mysql').style.display = '';
1228 document.getElementById('postgres7').style.display = '';
1229 document.getElementById('mssql').style.display = '';
1230 document.getElementById('mssql_n').style.display = '';
1231 document.getElementById('odbc_mssql').style.display = '';
1232 document.getElementById('oci8po').style.display = '';
1233 //Show the selected div
1234 document.getElementById(showid).style.display = 'block';
1235 } else if (document.all) {
1236 //This is the way old msie versions work
1237 //Hide all the divs
1238 document.all['mysql'].style.display = '';
1239 document.all['postgres7'].style.display = '';
1240 document.all['mssql'].style.display = '';
1241 document.all['mssql_n'].style.display = '';
1242 document.all['odbc_mssql'].style.display = '';
1243 document.all['oci8po'].style.display = '';
1244 //Show the selected div
1245 document.all[showid].style.display = 'block';
1246 } else if (document.layers) {
1247 //This is the way nn4 works
1248 //Hide all the divs
1249 document.layers['mysql'].style.display = '';
1250 document.layers['postgres7'].style.display = '';
1251 document.layers['mssql'].style.display = '';
1252 document.layers['mssql_n'].style.display = '';
1253 document.layers['odbc_mssql'].style.display = '';
1254 document.layers['oci8po'].style.display = '';
1255 //Show the selected div
1256 document.layers[showid].style.display = 'block';
1259 </script>
1261 <?php