Updated the 19 build version to 20081221
[moodle.git] / install.php
blobd71ea3baa443b1068e95f4465abe40b1214a81ad
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 /// make sure PHP errors are displayed to help diagnose problems
37 @error_reporting(1023); //E_ALL not used because we do not want strict notices in PHP5 yet
38 @ini_set('display_errors', '1');
40 if (! isset($_SESSION['INSTALL'])) {
41 $_SESSION['INSTALL'] = array();
44 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
46 /// detect if install was attempted from diferent directory, if yes reset session to prevent errors,
47 /// dirroot location now fixed in installer
48 if (!empty($INSTALL['dirroot']) and $INSTALL['dirroot'] != dirname(__FILE__)) {
49 $_SESSION['INSTALL'] = array();
52 /// If it's our first time through this script then we need to set some default values
54 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
56 /// set defaults
57 $INSTALL['language'] = 'en_utf8';
59 $INSTALL['dbhost'] = 'localhost';
60 $INSTALL['dbuser'] = '';
61 $INSTALL['dbpass'] = '';
62 $INSTALL['dbtype'] = 'mysql';
63 $INSTALL['dbname'] = 'moodle';
64 $INSTALL['prefix'] = 'mdl_';
66 $INSTALL['downloadlangpack'] = false;
67 $INSTALL['showdownloadlangpack'] = true;
68 $INSTALL['downloadlangpackerror'] = '';
70 /// To be used by the Installer
71 $INSTALL['wwwroot'] = '';
72 $INSTALL['dirroot'] = dirname(__FILE__);
73 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'moodledata';
75 /// To be configured in the Installer
76 $INSTALL['wwwrootform'] = '';
77 $INSTALL['dirrootform'] = dirname(__FILE__);
79 $INSTALL['admindirname'] = 'admin';
81 $INSTALL['stage'] = WELCOME;
84 //==========================================================================//
86 /// Set the page to Unicode always
88 header('Content-Type: text/html; charset=UTF-8');
90 /// Was data submitted?
92 if (isset($_POST['stage'])) {
94 /// Get the stage for which the form was set and the next stage we are going to
96 $gpc = ini_get('magic_quotes_gpc');
97 $gpc = ($gpc == '1' or strtolower($gpc) == 'on');
99 /// Store any posted data
100 foreach ($_POST as $setting=>$value) {
101 if ($gpc) {
102 $value = stripslashes($value);
105 $INSTALL[$setting] = $value;
108 if ( $goforward = (! empty( $_POST['next'] )) ) {
109 $nextstage = $_POST['stage'] + 1;
110 } else if (! empty( $_POST['prev'])) {
111 $nextstage = $_POST['stage'] - 1;
112 $INSTALL['stage'] = $_POST['stage'] - 1;
113 } else if (! empty( $_POST['same'] )) {
114 $nextstage = $_POST['stage'];
117 $nextstage = (int)$nextstage;
119 if ($nextstage < 0) {
120 $nextstage = WELCOME;
124 } else {
126 $goforward = true;
127 $nextstage = WELCOME;
131 //==========================================================================//
133 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
135 $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
136 $CFG->dirroot = $INSTALL['dirroot'];
137 $CFG->libdir = $INSTALL['dirroot'].'/lib';
138 $CFG->dataroot = $INSTALL['dataroot'];
139 $CFG->admin = $INSTALL['admindirname'];
140 $CFG->directorypermissions = 00777;
141 $CFG->running_installer = true;
142 $CFG->docroot = 'http://docs.moodle.org';
143 $CFG->httpswwwroot = $INSTALL['wwwrootform']; // Needed by doc_link() in Server Checks page.
144 $COURSE->id = 0;
146 /// Include some moodle libraries
148 require_once($CFG->libdir.'/adminlib.php');
149 require_once($CFG->libdir.'/setuplib.php');
150 require_once($CFG->libdir.'/moodlelib.php');
151 require_once($CFG->libdir.'/weblib.php');
152 require_once($CFG->libdir.'/deprecatedlib.php');
153 require_once($CFG->libdir.'/adodb/adodb.inc.php');
154 require_once($CFG->libdir.'/environmentlib.php');
155 require_once($CFG->libdir.'/xmlize.php');
156 require_once($CFG->libdir.'/componentlib.class.php');
157 require_once($CFG->dirroot.'/version.php');
159 /// Set version and release
160 $INSTALL['version'] = $version;
161 $INSTALL['release'] = $release;
163 /// Have the $db object ready because we are going to use it often
164 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
165 $db = &ADONewConnection($INSTALL['dbtype']);
166 $db->SetFetchMode(ADODB_FETCH_ASSOC);
168 /// guess the www root
169 if ($INSTALL['wwwroot'] == '') {
170 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
171 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
173 // now try to guess the correct dataroot not accessible via web
174 $CFG->wwwroot = $INSTALL['wwwroot'];
175 $i = 0; //safety check - dirname might return some unexpected results
176 while(is_dataroot_insecure()) {
177 $parrent = dirname($CFG->dataroot);
178 $i++;
179 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
180 $CFG->dataroot = ''; //can not find secure location for dataroot
181 break;
183 $CFG->dataroot = dirname($parrent).'/moodledata';
185 $INSTALL['dataroot'] = $CFG->dataroot;
188 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
189 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
190 DIRECTORY => get_string('directorysettingshead', 'install'),
191 DATABASE => get_string('databasesettingshead', 'install'),
192 ADMIN => get_string('admindirsettinghead', 'install'),
193 ENVIRONMENT => get_string('environmenthead', 'install'),
194 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
195 SAVE => get_string('configurationcompletehead', 'install')
198 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
199 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
200 DIRECTORY => get_string('directorysettingssub', 'install'),
201 DATABASE => get_string('databasesettingssub', 'install'),
202 ADMIN => get_string('admindirsettingsub', 'install'),
203 ENVIRONMENT => get_string('environmentsub', 'install'),
204 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
205 SAVE => get_string('configurationcompletesub', 'install')
210 //==========================================================================//
212 /// Are we in help mode?
214 if (isset($_GET['help'])) {
215 $nextstage = -1;
220 //==========================================================================//
222 /// Are we in config download mode?
224 if (isset($_GET['download'])) {
225 header("Content-Type: application/x-forcedownload\n");
226 header("Content-Disposition: attachment; filename=\"config.php\"");
227 echo $INSTALL['config'];
228 exit;
235 //==========================================================================//
237 /// Check the directory settings
239 if ($INSTALL['stage'] == DIRECTORY) {
241 error_reporting(0);
243 /// check wwwroot
244 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
245 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
246 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
247 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
250 if ($fh) fclose($fh);
252 /// check dirroot
253 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
254 $errormsg .= get_string('dirrooterror', 'install').'<br />';
255 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
257 if ($fh) fclose($fh);
259 /// check dataroot
260 $CFG->dataroot = $INSTALL['dataroot'];
261 $CFG->wwwroot = $INSTALL['wwwroot'];
262 if (make_upload_directory('sessions', false) === false ) {
263 $errormsg .= get_string('datarooterror', 'install').'<br />';
265 } else if (is_dataroot_insecure(true) == INSECURE_DATAROOT_ERROR) {
266 $errormsg .= get_string('datarootpublicerror', 'install').'<br />';
269 if (!empty($errormsg)) $nextstage = DIRECTORY;
271 error_reporting(7);
276 //==========================================================================//
278 /// Check database settings if stage 3 data submitted
279 /// Try to connect to the database. If that fails then try to create the database
281 if ($INSTALL['stage'] == DATABASE) {
283 /// different format for postgres7 by socket
284 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
285 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
286 $INSTALL['dbuser'] = '';
287 $INSTALL['dbpass'] = '';
288 $INSTALL['dbname'] = '';
290 if ($INSTALL['prefix'] == '') { /// must have a prefix
291 $INSTALL['prefix'] = 'mdl_';
295 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
296 if (!extension_loaded('mysql')) {
297 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
298 $nextstage = DATABASE;
302 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
303 if (!extension_loaded('mysqli')) {
304 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
305 $nextstage = DATABASE;
309 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
310 if (!extension_loaded('pgsql')) {
311 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
312 $nextstage = DATABASE;
316 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
317 if (!function_exists('mssql_connect')) {
318 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
319 $nextstage = DATABASE;
323 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
324 if (!function_exists('mssql_connect')) {
325 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
326 $nextstage = DATABASE;
330 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
331 if (!extension_loaded('odbc')) {
332 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
333 $nextstage = DATABASE;
337 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
338 if (!extension_loaded('oci8')) {
339 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
340 $nextstage = DATABASE;
344 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
345 $errormsg = get_string('dbwrongprefix', 'install');
346 $nextstage = DATABASE;
349 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
350 $errormsg = get_string('dbwrongprefix', 'install');
351 $nextstage = DATABASE;
354 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
355 $errormsg = get_string('dbwronghostserver', 'install');
356 $nextstage = DATABASE;
359 if (empty($errormsg)) {
361 error_reporting(0); // Hide errors
363 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
364 $db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
365 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
366 switch ($INSTALL['dbtype']) { /// Try to create a database
367 case 'mysql':
368 case 'mysqli':
369 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
370 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
371 } else {
372 $errormsg = get_string('dbcreationerror', 'install');
373 $nextstage = DATABASE;
375 break;
378 } else {
379 /// We have been able to connect properly, just test the database encoding now.
380 /// It must be Unicode for 1.8 installations.
381 $encoding = '';
382 switch ($INSTALL['dbtype']) {
383 case 'mysql':
384 case 'mysqli':
385 /// Get MySQL character_set_database value
386 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
387 if ($rs && !$rs->EOF) {
388 $records = $rs->GetAssoc(true);
389 $encoding = $records['character_set_database']['Value'];
390 if (strtoupper($encoding) != 'UTF8') {
391 /// Try to set the encoding now!
392 if (! $db->Metatables()) { // We have no tables so go ahead
393 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
394 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
398 /// If conversion fails, skip, let environment testing do the job
400 break;
401 case 'postgres7':
402 /// Skip, let environment testing do the job
403 break;
404 case 'oci8po':
405 /// Skip, let environment testing do the job
406 break;
411 error_reporting(7);
413 if (($dbconnected === false) and (empty($errormsg)) ) {
414 $errormsg = get_string('dbconnectionerror', 'install');
415 $nextstage = DATABASE;
421 //==========================================================================//
423 /// If the next stage is admin directory settings OR we have just come from there then
424 /// check the admin directory.
425 /// If we can open a file then we know that the admin name is correct.
427 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
428 if (!ini_get('allow_url_fopen')) {
429 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
430 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
431 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
432 fclose($fh);
433 } else {
434 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
435 //if ($nextstage != ADMIN) {
436 // $errormsg = get_string('admindirerror', 'install');
437 // $nextstage = ADMIN;
438 // }
442 //==========================================================================//
444 // Check if we can navigate from the environemt page (because it's ok)
446 if ($INSTALL['stage'] == ENVIRONMENT) {
447 error_reporting(0); // Hide errors
448 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
449 error_reporting(7); // Show errors
450 if ($dbconnected) {
451 /// Execute environment check, printing results
452 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
453 $nextstage = ENVIRONMENT;
455 } else {
456 /// We never should reach this because DB has been tested before arriving here
457 $errormsg = get_string('dbconnectionerror', 'install');
458 $nextstage = DATABASE;
464 //==========================================================================//
466 // Try to download the lang pack if it has been selected
468 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
470 $downloadsuccess = false;
471 $downloaderror = '';
473 error_reporting(0); // Hide errors
475 /// Create necessary lang dir
476 if (!make_upload_directory('lang', false)) {
477 $downloaderror = get_string('cannotcreatelangdir', 'error');
480 /// Download and install component
481 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
482 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
483 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
484 switch ($status) {
485 case COMPONENT_ERROR:
486 if ($cd->get_error() == 'remotedownloaderror') {
487 $a = new stdClass();
488 $a->url = 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip';
489 $a->dest= $CFG->dataroot.'/lang';
490 $downloaderror = get_string($cd->get_error(), 'error', $a);
491 } else {
492 $downloaderror = get_string($cd->get_error(), 'error');
494 break;
495 case COMPONENT_UPTODATE:
496 case COMPONENT_INSTALLED:
497 $downloadsuccess = true;
498 break;
499 default:
500 //We shouldn't reach this point
502 } else {
503 //We shouldn't reach this point
506 error_reporting(7); // Show errors
508 if ($downloadsuccess) {
509 $INSTALL['downloadlangpack'] = false;
510 $INSTALL['showdownloadlangpack'] = false;
511 $INSTALL['downloadlangpackerror'] = $downloaderror;
512 } else {
513 $INSTALL['downloadlangpack'] = false;
514 $INSTALL['showdownloadlangpack'] = false;
515 $INSTALL['downloadlangpackerror'] = $downloaderror;
521 //==========================================================================//
523 /// Display or print the data
524 /// Put the data into a string
525 /// Try to open config file for writing.
527 if ($nextstage == SAVE) {
529 $str = '<?php /// Moodle Configuration File '."\r\n";
530 $str .= "\r\n";
532 $str .= 'unset($CFG);'."\r\n";
533 $str .= "\r\n";
535 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
536 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
537 if (!empty($INSTALL['dbname'])) {
538 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
539 // support single quotes in db user/passwords
540 $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
541 $str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
543 $str .= '$CFG->dbpersist = false;'."\r\n";
544 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
545 $str .= "\r\n";
547 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
548 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
549 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
550 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
551 $str .= "\r\n";
553 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
554 $str .= "\r\n";
556 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
557 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
558 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
559 $str .= '?>';
561 umask(0137);
563 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
564 fwrite($fh, $str);
565 fclose($fh);
569 $INSTALL['config'] = $str;
574 //==========================================================================//
577 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
578 <html dir="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
579 <head>
580 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
581 <title>Moodle Install</title>
582 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
583 <?php css_styles() ?>
584 <?php database_js() ?>
586 </head>
588 <body>
591 <?php
592 if (isset($_GET['help'])) {
593 print_install_help($_GET['help']);
594 close_window_button();
595 } else {
599 <table class="main" cellpadding="3" cellspacing="0">
600 <tr>
601 <td class="td_mainlogo">
602 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"/></p>
603 </td>
604 <td class="td_mainlogo" valign="bottom">
605 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
606 </td>
607 </tr>
609 <tr>
610 <td class="td_mainheading" colspan="2">
611 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
612 <?php /// Exceptionaly, depending of the DB selected, we show some different text
613 /// from the standard one to show better instructions for each DB
614 if ($nextstage == DATABASE) {
615 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
616 echo '<div id="mysql">' . get_string('databasesettingssub_mysql', 'install');
617 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
618 echo '</div>';
620 echo '<div id="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
621 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
622 echo '</div>';
624 echo '<div id="postgres7">' . get_string('databasesettingssub_postgres7', 'install');
625 echo '<p style="text-align: left">' . get_string('postgresqlwarning', 'install') . '</p>';
626 echo '</div>';
628 echo '<div id="mssql">' . get_string('databasesettingssub_mssql', 'install');
629 /// Link to mssql installation page
630 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
631 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
632 echo ">";
633 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
634 echo get_string('moodledocslink', 'install') . '</a></p>';
635 echo '</div>';
637 echo '<div id="mssql_n">' . get_string('databasesettingssub_mssql_n', 'install');
638 /// Link to mssql installation page
639 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
640 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
641 echo ">";
642 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
643 echo get_string('moodledocslink', 'install') . '</a></p>';
644 echo '</div>';
646 echo '<div id="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
647 /// Link to mssql installation page
648 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
649 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
650 echo ">";
651 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
652 echo get_string('moodledocslink', 'install') . '</a></p>';
653 echo '</div>';
655 echo '<div id="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
656 /// Link to oracle installation page
657 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
658 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_Oracle_for_PHP')\"";
659 echo ">";
660 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
661 echo get_string('moodledocslink', 'install') . '</a></p>';
662 echo '</div>';
663 } else {
664 if (!empty($substagetext[$nextstage])) {
665 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
669 </td>
670 </tr>
672 <tr>
673 <td class="td_main" colspan="2">
675 <?php
677 if (!empty($errormsg)) echo "<p class=\"errormsg\" style=\"text-align:center\">$errormsg</p>\n";
680 if ($nextstage == SAVE) {
681 $INSTALL['stage'] = WELCOME;
682 $options = array();
683 $options['lang'] = $INSTALL['language'];
684 if ($configsuccess) {
685 echo "<p class=\"p_install\">".get_string('configfilewritten', 'install')."</p>\n";
687 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
688 echo "<tr>\n";
689 echo "<td>&nbsp;</td>\n";
690 echo "<td>&nbsp;</td>\n";
691 echo "<td align=\"right\">\n";
692 print_single_button("index.php", $options, get_string('continue'));
693 echo "</td>\n";
694 echo "</tr>\n";
695 echo "</table>\n";
697 } else {
698 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
700 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
701 echo "<tr>\n";
702 echo "<td>&nbsp;</td>\n";
703 echo "<td align=\"center\">\n";
704 $installoptions = array();
705 $installoptions['download'] = 1;
706 print_single_button("install.php", $installoptions, get_string('download', 'install'));
707 echo "</td>\n";
708 echo "<td align=\"right\">\n";
709 print_single_button("index.php", $options, get_string('continue'));
710 echo "</td>\n";
711 echo "</tr>\n";
712 echo "</table>\n";
714 echo "<hr />\n";
715 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
716 echo "<pre>\n";
717 print_r(s($str));
718 echo "</pre>\n";
719 echo "</div>\n";
721 } else {
722 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
723 form_table($nextstage, $formaction);
728 </td>
729 </tr>
730 </table>
732 <?php
736 </body>
737 </html>
748 <?php
751 //==========================================================================//
753 function form_table($nextstage = WELCOME, $formaction = "install.php") {
754 global $INSTALL, $db;
756 $enablenext = true;
758 /// Print the standard form if we aren't in the DOWNLOADLANG page
759 /// because it has its own form.
760 if ($nextstage != DOWNLOADLANG) {
761 $needtoopenform = false;
763 <form id="installform" method="post" action="<?php echo $formaction ?>">
764 <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
766 <?php
767 } else {
768 $needtoopenform = true;
771 <table class="install_table" cellspacing="3" cellpadding="3">
773 <?php
774 /// what we do depends on the stage we're at
775 switch ($nextstage) {
776 case WELCOME: /// Welcome and language settings
778 <tr>
779 <td class="td_left"><p class="p_install"><?php print_string('language') ?></p></td>
780 <td class="td_right">
781 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
782 </td>
783 </tr>
785 <?php
786 break;
787 case COMPATIBILITY: /// Compatibilty check
788 $compatsuccess = true;
790 /// Check that PHP is of a sufficient version
791 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
792 $enablenext = $enablenext && inst_check_php_version();
793 /// Check session auto start
794 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
795 $enablenext = $enablenext && !ini_get_bool('session.auto_start');
796 /// Check magic quotes
797 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
798 $enablenext = $enablenext && !ini_get_bool('magic_quotes_runtime');
799 /// Check unsupported PHP configuration
800 print_compatibility_row(!ini_get_bool('register_globals'), get_string('globalsquotes', 'install'), get_string('globalswarning', 'install'));
801 $enablenext = $enablenext && !ini_get_bool('register_globals');
802 /// Check safe mode
803 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
804 /// Check file uploads
805 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
806 /// Check GD version
807 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
808 /// Check memory limit
809 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
812 break;
813 case DIRECTORY: /// Directory settings
816 <tr>
817 <td class="td_left"><p class="p_install"><?php print_string('wwwroot', 'install') ?></p></td>
818 <td class="td_right">
819 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
820 </td>
821 </tr>
822 <tr>
823 <td class="td_left"><p class="p_install"><?php print_string('dirroot', 'install') ?></p></td>
824 <td class="td_right">
825 <input type="text" size="40" name="dirrootform" disabled="disabled" value="<?php p($INSTALL['dirrootform'],true) ?>" />
826 </td>
827 </tr>
828 <tr>
829 <td class="td_left"><p class="p_install"><?php print_string('dataroot', 'install') ?></p></td>
830 <td class="td_right">
831 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
832 </td>
833 </tr>
835 <?php
836 break;
837 case DATABASE: /// Database settings
840 <tr>
841 <td class="td_left"><p class="p_install"><?php print_string('dbtype', 'install') ?></p></td>
842 <td class="td_right">
843 <?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
844 'mysqli' => get_string('mysqli', 'install'),
845 'oci8po' => get_string('oci8po', 'install'),
846 'postgres7' => get_string('postgres7', 'install'),
847 'mssql' => get_string('mssql', 'install'),
848 'mssql_n' => get_string('mssql_n', 'install'),
849 'odbc_mssql' => get_string('odbc_mssql', 'install')),
850 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
851 </td>
852 </tr>
853 <tr>
854 <td class="td_left"><p class="p_install"><?php print_string('dbhost', 'install') ?></p></td>
855 <td class="td_right">
856 <input type="text" class="input_database" name="dbhost" value="<?php p($INSTALL['dbhost']) ?>" />
857 </td>
858 </tr>
859 <tr>
860 <td class="td_left"><p class="p_install"><?php print_string('database', 'install') ?></p></td>
861 <td class="td_right">
862 <input type="text" class="input_database" name="dbname" value="<?php p($INSTALL['dbname']) ?>" />
863 </td>
864 </tr>
865 <tr>
866 <td class="td_left"><p class="p_install"><?php print_string('user') ?></p></td>
867 <td class="td_right">
868 <input type="text" class="input_database" name="dbuser" value="<?php p($INSTALL['dbuser']) ?>" />
869 </td>
870 </tr>
871 <tr>
872 <td class="td_left"><p class="p_install"><?php print_string('password') ?></p></td>
873 <td class="td_right">
874 <input type="password" class="input_database" name="dbpass" value="<?php p($INSTALL['dbpass']) ?>" />
875 </td>
876 </tr>
877 <tr>
878 <td class="td_left"><p class="p_install"><?php print_string('dbprefix', 'install') ?></p></td>
879 <td class="td_right">
880 <input type="text" class="input_database" name="prefix" value="<?php p($INSTALL['prefix']) ?>" />
881 </td>
882 </tr>
884 <?php
885 break;
886 case ADMIN: /// Administration directory setting
889 <tr>
890 <td class="td_left"><p class="p_install"><?php print_string('admindirname', 'install') ?></p></td>
891 <td class="td_right">
892 <input type="text" size="40" name="admindirname" value="<?php p($INSTALL['admindirname']) ?>" />
893 </td>
894 </tr>
897 <?php
898 break;
899 case ENVIRONMENT: /// Environment checks
902 <tr>
903 <td colspan="2">
904 <?php
905 error_reporting(0); // Hide errors
906 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
907 error_reporting(7); // Show errors
908 if ($dbconnected) {
909 /// Execute environment check, printing results
910 check_moodle_environment($INSTALL['release'], $environment_results, true);
911 } else {
912 /// We never should reach this because DB has been tested before arriving here
913 $errormsg = get_string('dbconnectionerror', 'install');
914 $nextstage = DATABASE;
915 echo '<p class="errormsg" style="text-align:center">'.get_string('dbconnectionerror', 'install').'</p>';
918 </td>
919 </tr>
921 <?php
922 break;
923 case DOWNLOADLANG: /// Download language from download.moodle.org
926 <tr>
927 <td colspan="2">
928 <?php
929 /// Get array of languages, we are going to use it
930 $languages=get_installer_list_of_languages();
931 /// Print the download form (button) if necessary
932 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
933 $options = array();
934 $options['downloadlangpack'] = true;
935 $options['stage'] = DOWNLOADLANG;
936 $options['same'] = true;
937 print_simple_box_start('center');
938 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'post');
939 print_simple_box_end();
940 } else {
941 /// Show result info
942 /// English lang packs aren't downloaded
943 if (substr($INSTALL['language'],0,2) == 'en') {
944 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
945 } else {
946 if ($INSTALL['downloadlangpackerror']) {
947 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
948 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
949 } else {
950 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
955 </td>
956 </tr>
958 <?php
959 break;
960 default:
964 <tr>
965 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
967 <?php
968 if ($needtoopenform) {
970 <form id="installform" method="post" action="<?php echo $formaction ?>">
971 <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
972 <?php
975 $disabled = $enablenext ? '' : 'disabled="disabled"';
978 <?php echo ($nextstage < SAVE) ? "<div><input $disabled type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: ".fix_align_rtl("right")."\"/></div>\n" : "&nbsp;\n" ?>
979 <?php echo ($nextstage > WELCOME) ? "<div><input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/></div>\n" : "&nbsp;\n" ?>
981 <?php
982 if ($needtoopenform) {
984 </form>
985 <?php
990 </td>
992 </tr>
994 </table>
995 <?php
996 if (!$needtoopenform) {
998 </form>
999 <?php
1003 <?php
1008 //==========================================================================//
1010 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
1011 echo "<tr>\n";
1012 echo "<td class=\"td_left_nowrap\" valign=\"top\"><p class=\"p_install\">$testtext</p></td>\n";
1013 if ($success) {
1014 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1015 echo "<td valign=\"top\">&nbsp;</td>\n";
1016 } else {
1017 echo "<td valign=\"top\">";
1018 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1019 echo "</p></td>\n";
1020 echo "<td valign=\"top\">";
1021 echo "<p class=\"p_install\">$errormessage ";
1022 if ($helpfield !== '') {
1023 install_helpbutton("install.php?help=$helpfield");
1025 echo "</p></td>\n";
1027 echo "</tr>\n";
1028 return $success;
1032 //==========================================================================//
1034 function install_helpbutton($url, $title='') {
1035 if ($title == '') {
1036 $title = get_string('help');
1038 echo "<a href=\"javascript:void(0)\" ";
1039 echo "onclick=\"return window.open('$url','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400')\"";
1040 echo ">";
1041 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\"/>";
1042 echo "</a>\n";
1047 //==========================================================================//
1049 function print_install_help($help) {
1050 switch ($help) {
1051 case 'phpversionhelp':
1052 print_string($help, 'install', phpversion());
1053 break;
1054 case 'memorylimithelp':
1055 print_string($help, 'install', get_memory_limit());
1056 break;
1057 default:
1058 print_string($help, 'install');
1063 //==========================================================================//
1065 function get_memory_limit() {
1066 if ($limit = ini_get('memory_limit')) {
1067 return $limit;
1068 } else {
1069 return get_cfg_var('memory_limit');
1073 //==========================================================================//
1075 function check_memory_limit() {
1077 /// if limit is already 40 or more then we don't care if we can change it or not
1078 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1079 return true;
1082 /// Otherwise, see if we can change it ourselves
1083 @ini_set('memory_limit', '40M');
1084 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1087 //==========================================================================//
1089 function inst_check_php_version() {
1090 if (!check_php_version("4.3.0")) {
1091 return false;
1092 } else if (check_php_version("5.0.0")) {
1093 return check_php_version("5.1.0"); // 5.0.x is too buggy
1095 return true; // 4.3.x or 4.4.x is fine
1097 //==========================================================================//
1099 /* This function returns a list of languages and their full names. The
1100 * list of available languages is fetched from install/lang/xx/installer.php
1101 * and it's used exclusively by the installation process
1102 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1104 function get_installer_list_of_languages() {
1106 global $CFG;
1108 $languages = array();
1110 /// Get raw list of lang directories
1111 $langdirs = get_list_of_plugins('install/lang');
1112 asort($langdirs);
1113 /// Get some info from each lang
1114 foreach ($langdirs as $lang) {
1115 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1116 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1117 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1118 $shortlang = substr($lang, 0, -5);
1119 } else {
1120 $shortlang = $lang;
1122 if ($lang == 'en') { //Explain this is non-utf8 en
1123 $shortlang = 'non-utf8 en';
1125 if (!empty($string['thislanguage'])) {
1126 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1128 unset($string);
1131 /// Return array
1132 return $languages;
1135 //==========================================================================//
1137 function css_styles() {
1140 <style type="text/css">
1142 body { background-color: #ffeece; }
1143 p, li, td {
1144 font-family: helvetica, arial, sans-serif;
1145 font-size: 10pt;
1147 a { text-decoration: none; color: blue; }
1148 a img {
1149 border: none;
1151 .errormsg {
1152 color: red;
1153 font-weight: bold;
1155 blockquote {
1156 font-family: courier, monospace;
1157 font-size: 10pt;
1159 .input_database {
1160 width: 270px;
1162 .install_table {
1163 width: 500px;
1164 margin-left:auto;
1165 margin-right:auto;
1167 .td_left {
1168 text-align: <?php echo fix_align_rtl("right") ?>;
1169 font-weight: bold;
1171 .td_left_nowrap{
1172 text-align: <?php echo fix_align_rtl("right") ?>;
1173 font-weight: bold;
1174 white-space: nowrap;
1175 width: 160px;
1176 padding-left: 10px;
1178 .td_right {
1179 text-align: <?php echo fix_align_rtl("left") ?>;
1181 .main {
1182 width: 80%;
1183 border-width: 1px;
1184 border-style: solid;
1185 border-color: #ffc85f;
1186 margin-left:auto;
1187 margin-right:auto;
1188 -moz-border-radius-bottomleft: 15px;
1189 -moz-border-radius-bottomright: 15px;
1191 .td_mainheading {
1192 background-color: #fee6b9;
1193 padding-left: 10px;
1195 .td_main {
1196 text-align: center;
1198 .td_mainlogo {
1199 vertical-align: middle;
1201 .p_mainlogo {
1202 margin-top: 0px;
1203 margin-bottom: 0px;
1205 .p_mainheading {
1206 font-size: 11pt;
1207 margin-top: 16px;
1208 margin-bottom: 16px;
1210 .p_subheading {
1211 font-size: 10pt;
1212 padding-left: 10px;
1213 margin-top: 16px;
1214 margin-bottom: 16px;
1216 .p_mainheader{
1217 text-align: right;
1218 font-size: 20pt;
1219 font-weight: bold;
1220 margin-top: 0px;
1221 margin-bottom: 0px;
1223 .p_pass {
1224 color: green;
1225 font-weight: bold;
1226 margin-top: 0px;
1227 margin-bottom: 0px;
1229 .p_fail {
1230 color: red;
1231 font-weight: bold;
1232 margin-top: 0px;
1233 margin-bottom: 0px;
1235 .p_caution {
1236 color: #ff6600;
1237 font-weight: bold;
1238 margin-top: 0px;
1239 margin-bottom: 0px;
1241 .p_help {
1242 text-align: center;
1243 font-family: helvetica, arial, sans-serif;
1244 font-size: 14pt;
1245 font-weight: bold;
1246 color: #333333;
1247 margin-top: 0px;
1248 margin-bottom: 0px;
1250 /* This override the p tag for every p tag in this installation script,
1251 but not in lang\xxx\installer.php
1253 .p_install {
1254 margin-top: 0px;
1255 margin-bottom: 0px;
1257 .environmenttable {
1258 font-size: 10pt;
1259 border-color: #ffc85f;
1261 table.environmenttable .error {
1262 background-color : red;
1263 color : inherit;
1266 table.environmenttable .warn {
1267 background-color : yellow;
1270 table.environmenttable .ok {
1271 background-color : lightgreen;
1273 .header {
1274 background-color: #fee6b9;
1275 font-size: 10pt;
1277 .cell {
1278 background-color: #ffeece;
1279 font-size: 10pt;
1281 .error {
1282 color: #ff0000;
1284 .errorboxcontent {
1285 text-align: center;
1286 font-weight: bold;
1287 padding-left: 20px;
1288 color: #ff0000;
1290 .invisiblefieldset {
1291 display:inline;
1292 border:0px;
1293 padding:0px;
1294 margin:0px;
1296 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1297 display: none;
1300 </style>
1302 <?php
1305 //==========================================================================//
1307 function database_js() {
1310 <script type="text/javascript" defer="defer">
1311 function toggledbinfo() {
1312 //Calculate selected value
1313 var showid = 'mysql';
1314 if (document.getElementById('installform').dbtype.value) {
1315 showid = document.getElementById('installform').dbtype.value;
1317 if (document.getElementById) {
1318 //Hide all the divs
1319 document.getElementById('mysql').style.display = '';
1320 document.getElementById('mysqli').style.display = '';
1321 document.getElementById('postgres7').style.display = '';
1322 document.getElementById('mssql').style.display = '';
1323 document.getElementById('mssql_n').style.display = '';
1324 document.getElementById('odbc_mssql').style.display = '';
1325 document.getElementById('oci8po').style.display = '';
1326 //Show the selected div
1327 document.getElementById(showid).style.display = 'block';
1328 } else if (document.all) {
1329 //This is the way old msie versions work
1330 //Hide all the divs
1331 document.all['mysql'].style.display = '';
1332 document.all['mysqli'].style.display = '';
1333 document.all['postgres7'].style.display = '';
1334 document.all['mssql'].style.display = '';
1335 document.all['mssql_n'].style.display = '';
1336 document.all['odbc_mssql'].style.display = '';
1337 document.all['oci8po'].style.display = '';
1338 //Show the selected div
1339 document.all[showid].style.display = 'block';
1340 } else if (document.layers) {
1341 //This is the way nn4 works
1342 //Hide all the divs
1343 document.layers['mysql'].style.display = '';
1344 document.layers['mysqli'].style.display = '';
1345 document.layers['postgres7'].style.display = '';
1346 document.layers['mssql'].style.display = '';
1347 document.layers['mssql_n'].style.display = '';
1348 document.layers['odbc_mssql'].style.display = '';
1349 document.layers['oci8po'].style.display = '';
1350 //Show the selected div
1351 document.layers[showid].style.display = 'block';
1354 </script>
1356 <?php
1360 * Add slashes for single quotes and backslashes
1361 * so they can be included in single quoted string
1362 * (for config.php)
1364 function addsingleslashes($input){
1365 return preg_replace("/(['\\\])/", "\\\\$1", $input);