Automatic installer.php lang files by installer_builder (20080621)
[moodle.git] / install.php
blobe8ae2a99375821004fba4f70af00d20fe07d573f
1 <?php /// $Id$
2 /// install.php - helps admin user to create a config.php file
4 /// If config.php exists already then we are not needed.
6 if (file_exists('./config.php')) {
7 header('Location: index.php');
8 die;
9 } else {
10 $configfile = './config.php';
13 ///==========================================================================//
14 /// We are doing this in stages
15 define ('WELCOME', 0); /// 0. Welcome and language settings
16 define ('COMPATIBILITY', 1); /// 1. Compatibility
17 define ('DIRECTORY', 2); /// 2. Directory settings
18 define ('DATABASE', 3); /// 2. Database settings
19 define ('ADMIN', 4); /// 4. Administration directory name
20 define ('ENVIRONMENT', 5); /// 5. Administration directory name
21 define ('DOWNLOADLANG', 6); /// 6. Load complete lang from download.moodle.org
22 define ('SAVE', 7); /// 7. Save or display the settings
23 define ('REDIRECT', 8); /// 8. Redirect to index.php
24 ///==========================================================================//
28 /// Begin the session as we are holding all information in a session
29 /// variable until the end.
31 session_name('MoodleSession');
32 @session_start();
34 if (! isset($_SESSION['INSTALL'])) {
35 $_SESSION['INSTALL'] = array();
38 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
41 /// If it's our first time through this script then we need to set some default values
43 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
45 /// set defaults
46 $INSTALL['language'] = 'en_utf8';
48 $INSTALL['dbhost'] = 'localhost';
49 $INSTALL['dbuser'] = '';
50 $INSTALL['dbpass'] = '';
51 $INSTALL['dbtype'] = 'mysql';
52 $INSTALL['dbname'] = 'moodle';
53 $INSTALL['prefix'] = 'mdl_';
55 $INSTALL['dbencodingtestresults'] = false;
56 $INSTALL['showskipdbencodingtest'] = false;
57 $INSTALL['skipdbencodingtest'] = false;
59 $INSTALL['downloadlangpack'] = false;
60 $INSTALL['showdownloadlangpack'] = true;
61 $INSTALL['downloadlangpackerror'] = '';
63 /// To be used by the Installer
64 $INSTALL['wwwroot'] = '';
65 $INSTALL['dirroot'] = dirname(__FILE__);
66 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
68 /// To be configured in the Installer
69 $INSTALL['wwwrootform'] = '';
70 $INSTALL['dirrootform'] = dirname(__FILE__);
72 $INSTALL['admindirname'] = 'admin';
74 $INSTALL['stage'] = WELCOME;
77 //==========================================================================//
79 /// Set the page to Unicode always
81 header('Content-Type: text/html; charset=UTF-8');
83 /// Was data submitted?
85 if (isset($_POST['stage'])) {
87 /// Get the stage for which the form was set and the next stage we are going to
90 if ( $goforward = (! empty( $_POST['next'] )) ) {
91 $nextstage = $_POST['stage'] + 1;
92 } else if (! empty( $_POST['prev'])) {
93 $nextstage = $_POST['stage'] - 1;
94 } else if (! empty( $_POST['same'] )) {
95 $nextstage = $_POST['stage'];
99 if ($nextstage < 0) $nextstage = WELCOME;
102 /// Store any posted data
103 foreach ($_POST as $setting=>$value) {
104 $INSTALL[$setting] = $value;
107 } else {
109 $goforward = true;
110 $nextstage = WELCOME;
114 //==========================================================================//
116 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
118 $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
119 $CFG->dirroot = $INSTALL['dirroot'];
120 $CFG->libdir = $INSTALL['dirroot'].'/lib';
121 $CFG->dataroot = $INSTALL['dataroot'];
122 $CFG->admin = $INSTALL['admindirname'];
123 $CFG->directorypermissions = 00777;
124 $CFG->running_installer = true;
126 /// Include some moodle libraries
128 require_once('./lib/adminlib.php');
129 require_once('./lib/setuplib.php');
130 require_once('./lib/moodlelib.php');
131 require_once('./lib/deprecatedlib.php');
132 require_once('./lib/weblib.php');
133 require_once('./lib/adodb/adodb.inc.php');
134 require_once('./lib/environmentlib.php');
135 require_once('./lib/xmlize.php');
136 require_once('./lib/componentlib.class.php');
137 require_once('./version.php');
139 /// Set version and release
140 $INSTALL['version'] = $version;
141 $INSTALL['release'] = $release;
143 /// Have the $db object ready because we are going to use it often
144 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
145 $db = &ADONewConnection($INSTALL['dbtype']);
146 $db->SetFetchMode(ADODB_FETCH_ASSOC);
148 /// guess the www root
149 if ($INSTALL['wwwroot'] == '') {
150 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
151 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
153 // now try to guess the correct dataroot not accessible via web
154 $CFG->wwwroot = $INSTALL['wwwroot'];
155 $i = 0; //safety check - dirname might return some unexpected results
156 while(is_dataroot_insecure()) {
157 $parrent = dirname($CFG->dataroot);
158 $i++;
159 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
160 $CFG->dataroot = ''; //can not find secure location for dataroot
161 break;
163 $CFG->dataroot = dirname($parrent).'/moodledata';
165 $INSTALL['dataroot'] = $CFG->dataroot;
168 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
169 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
170 DIRECTORY => get_string('directorysettingshead', 'install'),
171 DATABASE => get_string('databasesettingshead', 'install'),
172 ADMIN => get_string('admindirsettinghead', 'install'),
173 ENVIRONMENT => get_string('environmenthead', 'install'),
174 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
175 SAVE => get_string('configurationcompletehead', 'install')
178 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
179 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
180 DIRECTORY => get_string('directorysettingssub', 'install'),
181 DATABASE => get_string('databasesettingssub', 'install'),
182 ADMIN => get_string('admindirsettingsub', 'install'),
183 ENVIRONMENT => get_string('environmentsub', 'install'),
184 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
185 SAVE => get_string('configurationcompletesub', 'install')
190 //==========================================================================//
192 /// Are we in help mode?
194 if (isset($_GET['help'])) {
195 $nextstage = -1;
200 //==========================================================================//
202 /// Are we in config download mode?
204 if (isset($_GET['download'])) {
205 header("Content-Type: application/download\n");
206 header("Content-Disposition: attachment; filename=\"config.php\"");
207 echo $INSTALL['config'];
208 exit;
215 //==========================================================================//
217 /// Check the directory settings
219 if ($INSTALL['stage'] == DIRECTORY) {
221 error_reporting(0);
223 /// check wwwroot
224 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
225 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
226 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
227 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
230 if ($fh) fclose($fh);
232 /// check dirroot
233 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
234 $errormsg .= get_string('dirrooterror', 'install').'<br />';
235 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
237 if ($fh) fclose($fh);
239 /// check dataroot
240 $CFG->dataroot = $INSTALL['dataroot'];
241 if (make_upload_directory('sessions', false) === false ) {
242 $errormsg .= get_string('datarooterror', 'install').'<br />';
244 if ($fh) fclose($fh);
246 if (!empty($errormsg)) $nextstage = DIRECTORY;
248 error_reporting(7);
253 //==========================================================================//
255 /// Check database settings if stage 3 data submitted
256 /// Try to connect to the database. If that fails then try to create the database
258 if ($INSTALL['stage'] == DATABASE) {
260 /// First of all, analyze skipdbencodingtest status
261 if (isset($_POST['skipdbencodingtest'])) {
262 $INSTALL['skipdbencodingtest'] = true;
263 } else {
264 $INSTALL['skipdbencodingtest'] = false;
267 /// different format for postgres7 by socket
268 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
269 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
270 $INSTALL['dbuser'] = '';
271 $INSTALL['dbpass'] = '';
272 $INSTALL['dbname'] = '';
274 if ($INSTALL['prefix'] == '') { /// must have a prefix
275 $INSTALL['prefix'] = 'mdl_';
279 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
280 if (!extension_loaded('mysql')) {
281 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
282 $nextstage = DATABASE;
286 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
287 if (!extension_loaded('pgsql')) {
288 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
289 $nextstage = DATABASE;
293 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
294 if (!function_exists('mssql_connect')) {
295 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
296 $nextstage = DATABASE;
300 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
301 if (!function_exists('mssql_connect')) {
302 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
303 $nextstage = DATABASE;
307 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
308 if (!extension_loaded('odbc')) {
309 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
310 $nextstage = DATABASE;
314 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
315 if (!extension_loaded('oci8')) {
316 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
317 $nextstage = DATABASE;
321 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
322 $errormsg = get_string('dbwrongprefix', 'install');
323 $nextstage = DATABASE;
326 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
327 $errormsg = get_string('dbwrongprefix', 'install');
328 $nextstage = DATABASE;
331 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
332 $errormsg = get_string('dbwronghostserver', 'install');
333 $nextstage = DATABASE;
337 if (empty($errormsg)) {
339 error_reporting(0); // Hide errors
341 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
342 /// The following doesn't seem to work but we're working on it
343 /// If you come up with a solution for creating a database in MySQL
344 /// feel free to put it in and let us know
345 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
346 switch ($INSTALL['dbtype']) { /// Try to create a database
347 case 'mysql':
348 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
349 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
350 } else {
351 $errormsg = get_string('dbcreationerror', 'install');
352 $nextstage = DATABASE;
354 break;
357 } else {
358 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
359 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
360 if (empty($INSTALL['skipdbencodingtest'])) {
361 /// We haven't checked the skip test checkbox, so perform the test
362 $encoding = '';
363 switch ($INSTALL['dbtype']) {
364 case 'mysql':
365 ///Get MySQL character_set_database value
366 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
367 if ($rs && $rs->RecordCount() > 0) {
368 $records = $rs->GetAssoc(true);
369 $encoding = $records['character_set_database']['Value'];
370 if (strtoupper($encoding) == 'UTF8') {
371 $INSTALL['dbencodingtestresults'] = true;
372 } else {
373 // Try to set the encoding now!
374 if (! $db->Metatables()) { // We have no tables so go ahead
375 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
376 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
378 $records = $rs->GetAssoc(true);
379 $encoding = $records['character_set_database']['Value'];
381 if (strtoupper($encoding) == 'UTF8') {
382 $INSTALL['dbencodingtestresults'] = true;
383 } else {
384 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
385 $nextstage = DATABASE;
386 $INSTALL['showskipdbencodingtest'] = true;
387 $INSTALL['dbencodingtestresults'] = false;
389 } else {
390 $INSTALL['showskipdbencodingtest'] = true;
391 $INSTALL['dbencodingtestresults'] = false;
395 break;
396 case 'postgres7':
397 ///Get PostgreSQL server_encoding value
398 $rs = $db->Execute("SHOW server_encoding");
399 if ($rs && $rs->RecordCount() > 0) {
400 $encoding = $rs->fields['server_encoding'];
401 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
402 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
403 $nextstage = DATABASE;
404 $INSTALL['showskipdbencodingtest'] = true;
405 $INSTALL['dbencodingtestresults'] = false;
406 } else {
407 $INSTALL['dbencodingtestresults'] = true;
410 break;
411 case 'oci8po':
412 ///Get Oracle NLS_CHARACTERSET value
413 $rs = $db->Execute("SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET'");
414 if ($rs && $rs->RecordCount() > 0) {
415 $encoding = $rs->fields['value'];
416 if (strtoupper($encoding) != 'AL32UTF8') {
417 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
418 $nextstage = DATABASE;
419 $INSTALL['dbencodingtestresults'] = false;
420 } else {
421 $INSTALL['dbencodingtestresults'] = true;
424 /// Get client NLS_LANG environment variable
425 if (strpos(getenv('NLS_LANG'), 'AL32UTF8') === false) { // Oracle client must be correct UTF8
426 $errormsg = get_string('dbwrongnlslang', 'install', $encoding);
427 $nextstage = DATABASE;
428 $INSTALL['dbencodingtestresults'] = false;
430 break;
436 error_reporting(7);
438 if (($dbconnected === false) and (empty($errormsg)) ) {
439 $errormsg = get_string('dbconnectionerror', 'install');
440 $nextstage = DATABASE;
446 //==========================================================================//
448 /// If the next stage is admin directory settings OR we have just come from there then
449 /// check the admin directory.
450 /// If we can open a file then we know that the admin name is correct.
452 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
453 if (!ini_get('allow_url_fopen') || true) { // MDL-4218 fopen URL is not reliable
454 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
455 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
456 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
457 fclose($fh);
458 } else {
459 if ($nextstage != ADMIN) {
460 $errormsg = get_string('admindirerror', 'install');
461 $nextstage = ADMIN;
466 //==========================================================================//
468 // Check if we can navigate from the environemt page (because it's ok)
470 if ($INSTALL['stage'] == ENVIRONMENT) {
471 error_reporting(0); // Hide errors
472 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
473 error_reporting(7); // Show errors
474 if ($dbconnected) {
475 /// Execute environment check, printing results
476 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
477 $nextstage = ENVIRONMENT;
479 } else {
480 /// We never should reach this because DB has been tested before arriving here
481 $errormsg = get_string('dbconnectionerror', 'install');
482 $nextstage = DATABASE;
488 //==========================================================================//
490 // Try to download the lang pack if it has been selected
492 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
494 $downloadsuccess = false;
495 $downloaderror = '';
497 error_reporting(0); // Hide errors
499 /// Create necessary lang dir
500 if (!make_upload_directory('lang', false)) {
501 $downloaderror = get_string('cannotcreatelangdir', 'error');
504 /// Download and install component
505 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
506 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
507 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
508 switch ($status) {
509 case ERROR:
510 if ($cd->get_error() == 'remotedownloadnotallowed') {
511 $a = new stdClass();
512 $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip';
513 $a->dest= $CFG->dataroot.'/lang';
514 $downloaderror = get_string($cd->get_error(), 'error', $a);
515 } else {
516 $downloaderror = get_string($cd->get_error(), 'error');
518 break;
519 case UPTODATE:
520 case INSTALLED:
521 $downloadsuccess = true;
522 break;
523 default:
524 //We shouldn't reach this point
526 } else {
527 //We shouldn't reach this point
530 error_reporting(7); // Show errors
532 if ($downloadsuccess) {
533 $INSTALL['downloadlangpack'] = false;
534 $INSTALL['showdownloadlangpack'] = false;
535 $INSTALL['downloadlangpackerror'] = $downloaderror;
536 } else {
537 $INSTALL['downloadlangpack'] = false;
538 $INSTALL['showdownloadlangpack'] = false;
539 $INSTALL['downloadlangpackerror'] = $downloaderror;
545 //==========================================================================//
547 /// Display or print the data
548 /// Put the data into a string
549 /// Try to open config file for writing.
551 if ($nextstage == SAVE) {
553 $str = '<?php /// Moodle Configuration File '."\r\n";
554 $str .= "\r\n";
556 $str .= 'unset($CFG);'."\r\n";
557 $str .= "\r\n";
559 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
560 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
561 if (!empty($INSTALL['dbname'])) {
562 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
563 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
564 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
566 $str .= '$CFG->dbpersist = false;'."\r\n";
567 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
568 $str .= "\r\n";
570 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
571 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
572 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
573 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
574 $str .= "\r\n";
576 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
577 $str .= "\r\n";
579 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
580 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
581 $str .= "\r\n";
584 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
585 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
586 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
587 $str .= '?>';
589 umask(0137);
591 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
592 fwrite($fh, $str);
593 fclose($fh);
597 $INSTALL['config'] = $str;
602 //==========================================================================//
605 <html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
606 <head>
607 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
608 <title>Moodle Install</title>
609 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
610 <?php css_styles() ?>
611 <?php database_js() ?>
613 </head>
615 <body>
618 <?php
619 if (isset($_GET['help'])) {
620 print_install_help($_GET['help']);
621 close_window_button();
622 } else {
626 <table class="main" align="center" cellpadding="3" cellspacing="0">
627 <tr>
628 <td class="td_mainlogo">
629 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"></p>
630 </td>
631 <td class="td_mainlogo" valign="bottom">
632 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
633 </td>
634 </tr>
636 <tr>
637 <td class="td_mainheading" colspan="2">
638 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
639 <?php /// Exceptionaly, depending of the DB selected, we show some different text
640 /// from the standard one to show better instructions for each DB
641 if ($nextstage == DATABASE) {
642 echo '<script language="JavaScript" type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
643 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
645 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
647 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
648 /// Link to mssql installation page
649 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
650 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
651 echo get_string('moodledocslink', 'install') . '</a></p>';
652 echo '</div>';
654 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
655 /// Link to mssql installation page
656 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
657 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
658 echo get_string('moodledocslink', 'install') . '</a></p>';
659 echo '</div>';
661 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
662 /// Link to mssql installation page
663 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
664 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
665 echo get_string('moodledocslink', 'install') . '</a></p>';
666 echo '</div>';
668 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
669 /// Link to oracle installation page
670 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
671 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
672 echo get_string('moodledocslink', 'install') . '</a></p>';
673 echo '</div>';
674 } else {
675 if (!empty($substagetext[$nextstage])) {
676 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
680 </td>
681 </tr>
683 <tr>
684 <td class="td_main" colspan="2">
686 <?php
688 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
691 if ($nextstage == SAVE) {
692 $INSTALL['stage'] = WELCOME;
693 $options = array();
694 $options['lang'] = $INSTALL['language'];
695 if ($configsuccess) {
696 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
698 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
699 echo "<tr>\n";
700 echo "<td width=\"33.3%\">&nbsp;</td>\n";
701 echo "<td width=\"33.3%\">&nbsp;</td>\n";
702 echo "<td width=\"33.3%\" align=\"right\">\n";
703 print_single_button("index.php", $options, get_string('continue'));
704 echo "</td>\n";
705 echo "</tr>\n";
706 echo "</table>\n";
708 } else {
709 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
711 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
712 echo "<tr>\n";
713 echo "<td width=\"33.3%\">&nbsp;</td>\n";
714 echo "<td width=\"33.3%\" align=\"center\">\n";
715 $installoptions = array();
716 $installoptions['download'] = 1;
717 print_single_button("install.php", $installoptions, get_string('download', 'install'));
718 echo "</td>\n";
719 echo "<td width=\"33.3%\" align=\"right\">\n";
720 print_single_button("index.php", $options, get_string('continue'));
721 echo "</td>\n";
722 echo "</tr>\n";
723 echo "</table>\n";
725 echo "<hr />\n";
726 echo "<div style=\"text-align: left\">\n";
727 print_object(s($str));
728 echo "</div>\n";
730 } else {
731 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
732 form_table($nextstage, $formaction);
737 </td>
738 </tr>
739 </table>
741 <?php
745 </body>
746 </html>
757 <?php
759 //==========================================================================//
762 function print_object($object) {
763 echo "<pre>\n";
764 print_r($object);
765 echo "</pre>\n";
770 //==========================================================================//
772 function form_table($nextstage = WELCOME, $formaction = "install.php") {
773 global $INSTALL, $db;
775 /// Print the standard form if we aren't in the DOWNLOADLANG page
776 /// because it has its own form.
777 if ($nextstage != DOWNLOADLANG) {
778 $needtoopenform = false;
780 <form name="installform" method="post" action="<?php echo $formaction ?>">
781 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
783 <?php
784 } else {
785 $needtoopenform = true;
788 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
790 <?php
791 /// what we do depends on the stage we're at
792 switch ($nextstage) {
793 case WELCOME: /// Welcome and language settings
795 <tr>
796 <td class="td_left"><p><?php print_string('language') ?></p></td>
797 <td class="td_right">
798 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
799 </td>
800 </tr>
802 <?php
803 break;
804 case COMPATIBILITY: /// Compatibilty check
805 $compatsuccess = true;
807 /// Check that PHP is of a sufficient version
808 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
809 /// Check session auto start
810 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
811 /// Check magic quotes
812 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
813 /// Check unsupported PHP configuration
814 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
815 /// Check safe mode
816 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
817 /// Check file uploads
818 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
819 /// Check GD version
820 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
821 /// Check memory limit
822 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
825 break;
826 case DIRECTORY: /// Directory settings
829 <tr>
830 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
831 <td class="td_right">
832 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
833 </td>
834 </tr>
835 <tr>
836 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
837 <td class="td_right">
838 <input type="text" size="40" name="dirrootform" value="<?php p($INSTALL['dirrootform'],true) ?>" />
839 </td>
840 </tr>
841 <tr>
842 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
843 <td class="td_right">
844 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
845 </td>
846 </tr>
848 <?php
849 break;
850 case DATABASE: /// Database settings
853 <tr>
854 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
855 <td class="td_right">
856 <?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
857 'oci8po' => get_string('oci8po', 'install'),
858 'postgres7' => get_string('postgres7', 'install'),
859 'mssql' => get_string('mssql', 'install'),
860 'mssql_n' => get_string('mssql_n', 'install'),
861 'odbc_mssql' => get_string('odbc_mssql', 'install')),
862 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
863 </td>
864 </tr>
865 <tr>
866 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
867 <td class="td_right">
868 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
869 </td>
870 </tr>
871 <tr>
872 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
873 <td class="td_right">
874 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
875 </td>
876 </tr>
877 <tr>
878 <td class="td_left"><p><?php print_string('user') ?></p></td>
879 <td class="td_right">
880 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
881 </td>
882 </tr>
883 <tr>
884 <td class="td_left"><p><?php print_string('password') ?></p></td>
885 <td class="td_right">
886 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
887 </td>
888 </tr>
889 <tr>
890 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
891 <td class="td_right">
892 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
893 </td>
894 </tr>
895 <?php if ($INSTALL['showskipdbencodingtest']) { ?>
896 <tr>
897 <td class="td_left" colspan="2">
898 <?php print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?>
899 </td>
900 </tr>
901 <?php } ?>
903 <?php
904 break;
905 case ADMIN: /// Administration directory setting
908 <tr>
909 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
910 <td class="td_right">
911 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
912 </td>
913 </tr>
916 <?php
917 break;
918 case ENVIRONMENT: /// Environment checks
921 <tr>
922 <td colspan="2">
923 <?php
924 error_reporting(0); // Hide errors
925 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
926 error_reporting(7); // Show errors
927 if ($dbconnected) {
928 /// Execute environment check, printing results
929 check_moodle_environment($INSTALL['release'], $environment_results, true);
930 } else {
931 /// We never should reach this because DB has been tested before arriving here
932 $errormsg = get_string('dbconnectionerror', 'install');
933 $nextstage = DATABASE;
934 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
937 </td>
938 </tr>
940 <?php
941 break;
942 case DOWNLOADLANG: /// Download language from download.moodle.org
945 <tr>
946 <td colspan="2">
947 <?php
948 /// Get array of languages, we are going to use it
949 $languages=get_installer_list_of_languages();
950 /// Print the download form (button) if necessary
951 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
952 $options = array();
953 $options['downloadlangpack'] = true;
954 $options['stage'] = DOWNLOADLANG;
955 $options['same'] = true;
956 print_simple_box_start('center');
957 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
958 print_simple_box_end();
959 } else {
960 /// Show result info
961 /// English lang packs aren't downloaded
962 if (substr($INSTALL['language'],0,2) == 'en') {
963 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
964 } else {
965 if ($INSTALL['downloadlangpackerror']) {
966 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
967 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
968 } else {
969 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
974 </td>
975 </tr>
977 <?php
978 break;
979 default:
983 <tr>
984 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
986 <?php
987 if ($needtoopenform) {
989 <form name="installform" method="post" action="<?php echo $formaction ?>">
990 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
991 <?php
995 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
996 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
998 <?php
999 if ($needtoopenform) {
1001 </form>
1002 <?php
1007 </td>
1009 </tr>
1011 </table>
1012 <?php
1013 if (!$needtoopenform) {
1015 </form>
1016 <?php
1020 <?php
1025 //==========================================================================//
1027 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
1028 echo "<tr>\n";
1029 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
1030 if ($success) {
1031 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1032 echo "<td valign=\"top\">&nbsp;</td>\n";
1033 } else {
1034 echo "<td valign=\"top\"";
1035 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1036 echo "</p></td>\n";
1037 echo "<td valign=\"top\">";
1038 echo "<p>$errormessage ";
1039 install_helpbutton("install.php?help=$helpfield");
1040 echo "</p></td>\n";
1042 echo "</tr>\n";
1043 return $success;
1047 //==========================================================================//
1049 function install_helpbutton($url, $title='') {
1050 if ($title == '') {
1051 $title = get_string('help');
1053 echo "<a href=\"javascript: void(0)\">";
1054 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
1055 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
1056 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1057 echo "</a>\n";
1062 //==========================================================================//
1064 function print_install_help($help) {
1065 switch ($help) {
1066 case 'phpversionhelp':
1067 print_string($help, 'install', phpversion());
1068 break;
1069 case 'memorylimithelp':
1070 print_string($help, 'install', get_memory_limit());
1071 break;
1072 default:
1073 print_string($help, 'install');
1078 //==========================================================================//
1080 function get_memory_limit() {
1081 if ($limit = ini_get('memory_limit')) {
1082 return $limit;
1083 } else {
1084 return get_cfg_var('memory_limit');
1088 //==========================================================================//
1090 function check_memory_limit() {
1092 /// if limit is already 16M or more then we don't care if we can change it or not
1093 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
1094 return true;
1097 /// Otherwise, see if we can change it ourselves
1098 @ini_set('memory_limit', '16M');
1099 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
1102 //==========================================================================//
1104 function inst_check_php_version() {
1105 if (!check_php_version("4.3.0")) {
1106 return false;
1107 } else if (check_php_version("5.0.0")) {
1108 return check_php_version("5.1.0"); // 5.0.x is too buggy
1110 return true; // 4.3.x or 4.4.x is fine
1112 //==========================================================================//
1114 /* This function returns a list of languages and their full names. The
1115 * list of available languages is fetched from install/lang/xx/installer.php
1116 * and it's used exclusively by the installation process
1117 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1119 function get_installer_list_of_languages() {
1121 global $CFG;
1123 $languages = array();
1125 /// Get raw list of lang directories
1126 $langdirs = get_list_of_plugins('install/lang');
1127 asort($langdirs);
1128 /// Get some info from each lang
1129 foreach ($langdirs as $lang) {
1130 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1131 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1132 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1133 $shortlang = substr($lang, 0, -5);
1134 } else {
1135 $shortlang = $lang;
1137 if ($lang == 'en') { //Explain this is non-utf8 en
1138 $shortlang = 'non-utf8 en';
1140 if (!empty($string['thislanguage'])) {
1141 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1143 unset($string);
1146 /// Return array
1147 return $languages;
1150 //==========================================================================//
1152 function css_styles() {
1155 <style type="text/css">
1157 body { background-color: #ffeece; }
1158 p, li, td {
1159 font-family: helvetica, arial, sans-serif;
1160 font-size: 10pt;
1162 a { text-decoration: none; color: blue; }
1163 .errormsg {
1164 color: red;
1165 font-weight: bold;
1167 blockquote {
1168 font-family: courier, monospace;
1169 font-size: 10pt;
1171 .install_table {
1172 width: 500px;
1174 .td_left {
1175 text-align: right;
1176 font-weight: bold;
1178 .td_right {
1179 text-align: left;
1181 .main {
1182 width: 500px;
1183 border-width: 1px;
1184 border-style: solid;
1185 border-color: #ffc85f;
1186 -moz-border-radius-bottomleft: 15px;
1187 -moz-border-radius-bottomright: 15px;
1189 .td_mainheading {
1190 background-color: #fee6b9;
1191 padding: 10px;
1193 .td_main {
1194 text-align: center;
1196 .td_mainlogo {
1198 .p_mainlogo {
1200 .p_mainheading {
1201 font-size: 11pt;
1203 .p_subheading {
1204 font-size: 10pt;
1205 padding: 10px;
1207 .p_mainheader{
1208 text-align: right;
1209 font-size: 20pt;
1210 font-weight: bold;
1212 .p_pass {
1213 color: green;
1214 font-weight: bold;
1216 .p_fail {
1217 color: red;
1218 font-weight: bold;
1220 .p_caution {
1221 color: #ff6600;
1222 font-weight: bold;
1224 .p_help {
1225 text-align: center;
1226 font-family: helvetica, arial, sans-serif;
1227 font-size: 14pt;
1228 font-weight: bold;
1229 color: #333333;
1231 .environmenttable {
1232 font-size: 10pt;
1233 border-color: #ffc85f;
1235 table.environmenttable .error {
1236 background-color : red;
1237 color : inherit;
1240 table.environmenttable .warn {
1241 background-color : yellow;
1244 table.environmenttable .ok {
1245 background-color : lightgreen;
1247 .header {
1248 background-color: #fee6b9;
1249 font-size: 10pt;
1251 .cell {
1252 background-color: #ffeece;
1253 font-size: 10pt;
1255 .error {
1256 color: #ff0000;
1258 .errorboxcontent {
1259 text-align: center;
1260 font-weight: bold;
1261 padding: 20px;
1262 color: #ff0000;
1264 #mysql, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1265 display: none;
1268 </style>
1270 <?php
1273 //==========================================================================//
1275 function database_js() {
1278 <script language="JavaScript" type="text/javascript" defer="defer">
1279 function toggledbinfo() {
1280 //Calculate selected value
1281 var showid = 'mysql';
1282 if (document.installform.dbtype.value) {
1283 showid = document.installform.dbtype.value;
1285 if (document.getElementById) {
1286 //Hide all the divs
1287 document.getElementById('mysql').style.display = '';
1288 document.getElementById('postgres7').style.display = '';
1289 document.getElementById('mssql').style.display = '';
1290 document.getElementById('mssql_n').style.display = '';
1291 document.getElementById('odbc_mssql').style.display = '';
1292 document.getElementById('oci8po').style.display = '';
1293 //Show the selected div
1294 document.getElementById(showid).style.display = 'block';
1295 } else if (document.all) {
1296 //This is the way old msie versions work
1297 //Hide all the divs
1298 document.all['mysql'].style.display = '';
1299 document.all['postgres7'].style.display = '';
1300 document.all['mssql'].style.display = '';
1301 document.all['mssql_n'].style.display = '';
1302 document.all['odbc_mssql'].style.display = '';
1303 document.all['oci8po'].style.display = '';
1304 //Show the selected div
1305 document.all[showid].style.display = 'block';
1306 } else if (document.layers) {
1307 //This is the way nn4 works
1308 //Hide all the divs
1309 document.layers['mysql'].style.display = '';
1310 document.layers['postgres7'].style.display = '';
1311 document.layers['mssql'].style.display = '';
1312 document.layers['mssql_n'].style.display = '';
1313 document.layers['odbc_mssql'].style.display = '';
1314 document.layers['oci8po'].style.display = '';
1315 //Show the selected div
1316 document.layers[showid].style.display = 'block';
1319 </script>
1321 <?php