Whoops. missed a string.
[moodle-linuxchix.git] / install.php
blob1f955dffe7ff4fd203e5341a57e264b215e05e64
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 if (make_upload_directory('sessions', false) === false ) {
262 $errormsg .= get_string('datarooterror', 'install').'<br />';
264 if ($fh) fclose($fh);
266 if (!empty($errormsg)) $nextstage = DIRECTORY;
268 error_reporting(7);
273 //==========================================================================//
275 /// Check database settings if stage 3 data submitted
276 /// Try to connect to the database. If that fails then try to create the database
278 if ($INSTALL['stage'] == DATABASE) {
280 /// different format for postgres7 by socket
281 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
282 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
283 $INSTALL['dbuser'] = '';
284 $INSTALL['dbpass'] = '';
285 $INSTALL['dbname'] = '';
287 if ($INSTALL['prefix'] == '') { /// must have a prefix
288 $INSTALL['prefix'] = 'mdl_';
292 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
293 if (!extension_loaded('mysql')) {
294 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
295 $nextstage = DATABASE;
299 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
300 if (!extension_loaded('mysqli')) {
301 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
302 $nextstage = DATABASE;
306 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
307 if (!extension_loaded('pgsql')) {
308 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
309 $nextstage = DATABASE;
313 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
314 if (!function_exists('mssql_connect')) {
315 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
316 $nextstage = DATABASE;
320 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
321 if (!function_exists('mssql_connect')) {
322 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
323 $nextstage = DATABASE;
327 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
328 if (!extension_loaded('odbc')) {
329 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
330 $nextstage = DATABASE;
334 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
335 if (!extension_loaded('oci8')) {
336 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
337 $nextstage = DATABASE;
341 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
342 $errormsg = get_string('dbwrongprefix', 'install');
343 $nextstage = DATABASE;
346 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
347 $errormsg = get_string('dbwrongprefix', 'install');
348 $nextstage = DATABASE;
351 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
352 $errormsg = get_string('dbwronghostserver', 'install');
353 $nextstage = DATABASE;
356 if (empty($errormsg)) {
358 error_reporting(0); // Hide errors
360 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
361 $db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
362 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
363 switch ($INSTALL['dbtype']) { /// Try to create a database
364 case 'mysql':
365 case 'mysqli':
366 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
367 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
368 } else {
369 $errormsg = get_string('dbcreationerror', 'install');
370 $nextstage = DATABASE;
372 break;
375 } else {
376 /// We have been able to connect properly, just test the database encoding now.
377 /// It must be Unicode for 1.8 installations.
378 $encoding = '';
379 switch ($INSTALL['dbtype']) {
380 case 'mysql':
381 case 'mysqli':
382 /// Get MySQL character_set_database value
383 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
384 if ($rs && !$rs->EOF) {
385 $records = $rs->GetAssoc(true);
386 $encoding = $records['character_set_database']['Value'];
387 if (strtoupper($encoding) != 'UTF8') {
388 /// Try to set the encoding now!
389 if (! $db->Metatables()) { // We have no tables so go ahead
390 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
391 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
395 /// If conversion fails, skip, let environment testing do the job
397 break;
398 case 'postgres7':
399 /// Skip, let environment testing do the job
400 break;
401 case 'oci8po':
402 /// Skip, let environment testing do the job
403 break;
408 error_reporting(7);
410 if (($dbconnected === false) and (empty($errormsg)) ) {
411 $errormsg = get_string('dbconnectionerror', 'install');
412 $nextstage = DATABASE;
418 //==========================================================================//
420 /// If the next stage is admin directory settings OR we have just come from there then
421 /// check the admin directory.
422 /// If we can open a file then we know that the admin name is correct.
424 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
425 if (!ini_get('allow_url_fopen')) {
426 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
427 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
428 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
429 fclose($fh);
430 } else {
431 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
432 //if ($nextstage != ADMIN) {
433 // $errormsg = get_string('admindirerror', 'install');
434 // $nextstage = ADMIN;
435 // }
439 //==========================================================================//
441 // Check if we can navigate from the environemt page (because it's ok)
443 if ($INSTALL['stage'] == ENVIRONMENT) {
444 error_reporting(0); // Hide errors
445 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
446 error_reporting(7); // Show errors
447 if ($dbconnected) {
448 /// Execute environment check, printing results
449 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
450 $nextstage = ENVIRONMENT;
452 } else {
453 /// We never should reach this because DB has been tested before arriving here
454 $errormsg = get_string('dbconnectionerror', 'install');
455 $nextstage = DATABASE;
461 //==========================================================================//
463 // Try to download the lang pack if it has been selected
465 if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
467 $downloadsuccess = false;
468 $downloaderror = '';
470 error_reporting(0); // Hide errors
472 /// Create necessary lang dir
473 if (!make_upload_directory('lang', false)) {
474 $downloaderror = get_string('cannotcreatelangdir', 'error');
477 /// Download and install component
478 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
479 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
480 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
481 switch ($status) {
482 case COMPONENT_ERROR:
483 if ($cd->get_error() == 'remotedownloaderror') {
484 $a = new stdClass();
485 $a->url = 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip';
486 $a->dest= $CFG->dataroot.'/lang';
487 $downloaderror = get_string($cd->get_error(), 'error', $a);
488 } else {
489 $downloaderror = get_string($cd->get_error(), 'error');
491 break;
492 case COMPONENT_UPTODATE:
493 case COMPONENT_INSTALLED:
494 $downloadsuccess = true;
495 break;
496 default:
497 //We shouldn't reach this point
499 } else {
500 //We shouldn't reach this point
503 error_reporting(7); // Show errors
505 if ($downloadsuccess) {
506 $INSTALL['downloadlangpack'] = false;
507 $INSTALL['showdownloadlangpack'] = false;
508 $INSTALL['downloadlangpackerror'] = $downloaderror;
509 } else {
510 $INSTALL['downloadlangpack'] = false;
511 $INSTALL['showdownloadlangpack'] = false;
512 $INSTALL['downloadlangpackerror'] = $downloaderror;
518 //==========================================================================//
520 /// Display or print the data
521 /// Put the data into a string
522 /// Try to open config file for writing.
524 if ($nextstage == SAVE) {
526 $str = '<?php /// Moodle Configuration File '."\r\n";
527 $str .= "\r\n";
529 $str .= 'unset($CFG);'."\r\n";
530 $str .= "\r\n";
532 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
533 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
534 if (!empty($INSTALL['dbname'])) {
535 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
536 // support single quotes in db user/passwords
537 $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
538 $str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
540 $str .= '$CFG->dbpersist = false;'."\r\n";
541 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
542 $str .= "\r\n";
544 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
545 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
546 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
547 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
548 $str .= "\r\n";
550 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
551 $str .= "\r\n";
553 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
554 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
555 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
556 $str .= '?>';
558 umask(0137);
560 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
561 fwrite($fh, $str);
562 fclose($fh);
566 $INSTALL['config'] = $str;
571 //==========================================================================//
574 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
575 <html dir="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
576 <head>
577 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
578 <title>Moodle Install</title>
579 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
580 <?php css_styles() ?>
581 <?php database_js() ?>
583 </head>
585 <body>
588 <?php
589 if (isset($_GET['help'])) {
590 print_install_help($_GET['help']);
591 close_window_button();
592 } else {
596 <table class="main" cellpadding="3" cellspacing="0">
597 <tr>
598 <td class="td_mainlogo">
599 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"/></p>
600 </td>
601 <td class="td_mainlogo" valign="bottom">
602 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
603 </td>
604 </tr>
606 <tr>
607 <td class="td_mainheading" colspan="2">
608 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
609 <?php /// Exceptionaly, depending of the DB selected, we show some different text
610 /// from the standard one to show better instructions for each DB
611 if ($nextstage == DATABASE) {
612 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
613 echo '<div id="mysql">' . get_string('databasesettingssub_mysql', 'install');
614 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
615 echo '</div>';
617 echo '<div id="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
618 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
619 echo '</div>';
621 echo '<div id="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
623 echo '<div id="mssql">' . get_string('databasesettingssub_mssql', 'install');
624 /// Link to mssql installation page
625 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
626 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
627 echo ">";
628 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
629 echo get_string('moodledocslink', 'install') . '</a></p>';
630 echo '</div>';
632 echo '<div id="mssql_n">' . get_string('databasesettingssub_mssql_n', 'install');
633 /// Link to mssql installation page
634 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
635 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
636 echo ">";
637 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
638 echo get_string('moodledocslink', 'install') . '</a></p>';
639 echo '</div>';
641 echo '<div id="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
642 /// Link to mssql installation page
643 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
644 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
645 echo ">";
646 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
647 echo get_string('moodledocslink', 'install') . '</a></p>';
648 echo '</div>';
650 echo '<div id="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
651 /// Link to oracle installation page
652 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
653 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_Oracle_for_PHP')\"";
654 echo ">";
655 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
656 echo get_string('moodledocslink', 'install') . '</a></p>';
657 echo '</div>';
658 } else {
659 if (!empty($substagetext[$nextstage])) {
660 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
664 </td>
665 </tr>
667 <tr>
668 <td class="td_main" colspan="2">
670 <?php
672 if (!empty($errormsg)) echo "<p class=\"errormsg\" style=\"text-align:center\">$errormsg</p>\n";
675 if ($nextstage == SAVE) {
676 $INSTALL['stage'] = WELCOME;
677 $options = array();
678 $options['lang'] = $INSTALL['language'];
679 if ($configsuccess) {
680 echo "<p class=\"p_install\">".get_string('configfilewritten', 'install')."</p>\n";
682 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
683 echo "<tr>\n";
684 echo "<td>&nbsp;</td>\n";
685 echo "<td>&nbsp;</td>\n";
686 echo "<td align=\"right\">\n";
687 print_single_button("index.php", $options, get_string('continue'));
688 echo "</td>\n";
689 echo "</tr>\n";
690 echo "</table>\n";
692 } else {
693 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
695 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
696 echo "<tr>\n";
697 echo "<td>&nbsp;</td>\n";
698 echo "<td align=\"center\">\n";
699 $installoptions = array();
700 $installoptions['download'] = 1;
701 print_single_button("install.php", $installoptions, get_string('download', 'install'));
702 echo "</td>\n";
703 echo "<td align=\"right\">\n";
704 print_single_button("index.php", $options, get_string('continue'));
705 echo "</td>\n";
706 echo "</tr>\n";
707 echo "</table>\n";
709 echo "<hr />\n";
710 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
711 echo "<pre>\n";
712 print_r(s($str));
713 echo "</pre>\n";
714 echo "</div>\n";
716 } else {
717 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
718 form_table($nextstage, $formaction);
723 </td>
724 </tr>
725 </table>
727 <?php
731 </body>
732 </html>
743 <?php
746 //==========================================================================//
748 function form_table($nextstage = WELCOME, $formaction = "install.php") {
749 global $INSTALL, $db;
751 /// Print the standard form if we aren't in the DOWNLOADLANG page
752 /// because it has its own form.
753 if ($nextstage != DOWNLOADLANG) {
754 $needtoopenform = false;
756 <form id="installform" method="post" action="<?php echo $formaction ?>">
757 <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
759 <?php
760 } else {
761 $needtoopenform = true;
764 <table class="install_table" cellspacing="3" cellpadding="3">
766 <?php
767 /// what we do depends on the stage we're at
768 switch ($nextstage) {
769 case WELCOME: /// Welcome and language settings
771 <tr>
772 <td class="td_left"><p class="p_install"><?php print_string('language') ?></p></td>
773 <td class="td_right">
774 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
775 </td>
776 </tr>
778 <?php
779 break;
780 case COMPATIBILITY: /// Compatibilty check
781 $compatsuccess = true;
783 /// Check that PHP is of a sufficient version
784 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
785 /// Check session auto start
786 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
787 /// Check magic quotes
788 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
789 /// Check unsupported PHP configuration
790 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
791 /// Check safe mode
792 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
793 /// Check file uploads
794 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
795 /// Check GD version
796 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
797 /// Check memory limit
798 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
801 break;
802 case DIRECTORY: /// Directory settings
805 <tr>
806 <td class="td_left"><p class="p_install"><?php print_string('wwwroot', 'install') ?></p></td>
807 <td class="td_right">
808 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
809 </td>
810 </tr>
811 <tr>
812 <td class="td_left"><p class="p_install"><?php print_string('dirroot', 'install') ?></p></td>
813 <td class="td_right">
814 <input type="text" size="40" name="dirrootform" disabled="disabled" value="<?php p($INSTALL['dirrootform'],true) ?>" />
815 </td>
816 </tr>
817 <tr>
818 <td class="td_left"><p class="p_install"><?php print_string('dataroot', 'install') ?></p></td>
819 <td class="td_right">
820 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
821 </td>
822 </tr>
824 <?php
825 break;
826 case DATABASE: /// Database settings
829 <tr>
830 <td class="td_left"><p class="p_install"><?php print_string('dbtype', 'install') ?></p></td>
831 <td class="td_right">
832 <?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
833 'mysqli' => get_string('mysqli', 'install'),
834 'oci8po' => get_string('oci8po', 'install'),
835 'postgres7' => get_string('postgres7', 'install'),
836 'mssql' => get_string('mssql', 'install'),
837 'mssql_n' => get_string('mssql_n', 'install'),
838 'odbc_mssql' => get_string('odbc_mssql', 'install')),
839 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
840 </td>
841 </tr>
842 <tr>
843 <td class="td_left"><p class="p_install"><?php print_string('dbhost', 'install') ?></p></td>
844 <td class="td_right">
845 <input type="text" class="input_database" name="dbhost" value="<?php p($INSTALL['dbhost']) ?>" />
846 </td>
847 </tr>
848 <tr>
849 <td class="td_left"><p class="p_install"><?php print_string('database', 'install') ?></p></td>
850 <td class="td_right">
851 <input type="text" class="input_database" name="dbname" value="<?php p($INSTALL['dbname']) ?>" />
852 </td>
853 </tr>
854 <tr>
855 <td class="td_left"><p class="p_install"><?php print_string('user') ?></p></td>
856 <td class="td_right">
857 <input type="text" class="input_database" name="dbuser" value="<?php p($INSTALL['dbuser']) ?>" />
858 </td>
859 </tr>
860 <tr>
861 <td class="td_left"><p class="p_install"><?php print_string('password') ?></p></td>
862 <td class="td_right">
863 <input type="password" class="input_database" name="dbpass" value="<?php p($INSTALL['dbpass']) ?>" />
864 </td>
865 </tr>
866 <tr>
867 <td class="td_left"><p class="p_install"><?php print_string('dbprefix', 'install') ?></p></td>
868 <td class="td_right">
869 <input type="text" class="input_database" name="prefix" value="<?php p($INSTALL['prefix']) ?>" />
870 </td>
871 </tr>
873 <?php
874 break;
875 case ADMIN: /// Administration directory setting
878 <tr>
879 <td class="td_left"><p class="p_install"><?php print_string('admindirname', 'install') ?></p></td>
880 <td class="td_right">
881 <input type="text" size="40" name="admindirname" value="<?php p($INSTALL['admindirname']) ?>" />
882 </td>
883 </tr>
886 <?php
887 break;
888 case ENVIRONMENT: /// Environment checks
891 <tr>
892 <td colspan="2">
893 <?php
894 error_reporting(0); // Hide errors
895 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
896 error_reporting(7); // Show errors
897 if ($dbconnected) {
898 /// Execute environment check, printing results
899 check_moodle_environment($INSTALL['release'], $environment_results, true);
900 } else {
901 /// We never should reach this because DB has been tested before arriving here
902 $errormsg = get_string('dbconnectionerror', 'install');
903 $nextstage = DATABASE;
904 echo '<p class="errormsg" style="text-align:center">'.get_string('dbconnectionerror', 'install').'</p>';
907 </td>
908 </tr>
910 <?php
911 break;
912 case DOWNLOADLANG: /// Download language from download.moodle.org
915 <tr>
916 <td colspan="2">
917 <?php
918 /// Get array of languages, we are going to use it
919 $languages=get_installer_list_of_languages();
920 /// Print the download form (button) if necessary
921 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
922 $options = array();
923 $options['downloadlangpack'] = true;
924 $options['stage'] = DOWNLOADLANG;
925 $options['same'] = true;
926 print_simple_box_start('center');
927 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'post');
928 print_simple_box_end();
929 } else {
930 /// Show result info
931 /// English lang packs aren't downloaded
932 if (substr($INSTALL['language'],0,2) == 'en') {
933 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
934 } else {
935 if ($INSTALL['downloadlangpackerror']) {
936 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
937 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
938 } else {
939 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
944 </td>
945 </tr>
947 <?php
948 break;
949 default:
953 <tr>
954 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
956 <?php
957 if ($needtoopenform) {
959 <form id="installform" method="post" action="<?php echo $formaction ?>">
960 <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
961 <?php
965 <?php echo ($nextstage < SAVE) ? "<div><input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: ".fix_align_rtl("right")."\"/></div>\n" : "&nbsp;\n" ?>
966 <?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" ?>
968 <?php
969 if ($needtoopenform) {
971 </form>
972 <?php
977 </td>
979 </tr>
981 </table>
982 <?php
983 if (!$needtoopenform) {
985 </form>
986 <?php
990 <?php
995 //==========================================================================//
997 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
998 echo "<tr>\n";
999 echo "<td class=\"td_left_nowrap\" valign=\"top\"><p class=\"p_install\">$testtext</p></td>\n";
1000 if ($success) {
1001 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1002 echo "<td valign=\"top\">&nbsp;</td>\n";
1003 } else {
1004 echo "<td valign=\"top\">";
1005 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1006 echo "</p></td>\n";
1007 echo "<td valign=\"top\">";
1008 echo "<p class=\"p_install\">$errormessage ";
1009 install_helpbutton("install.php?help=$helpfield");
1010 echo "</p></td>\n";
1012 echo "</tr>\n";
1013 return $success;
1017 //==========================================================================//
1019 function install_helpbutton($url, $title='') {
1020 if ($title == '') {
1021 $title = get_string('help');
1023 echo "<a href=\"javascript:void(0)\" ";
1024 echo "onclick=\"return window.open('$url','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400')\"";
1025 echo ">";
1026 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\"/>";
1027 echo "</a>\n";
1032 //==========================================================================//
1034 function print_install_help($help) {
1035 switch ($help) {
1036 case 'phpversionhelp':
1037 print_string($help, 'install', phpversion());
1038 break;
1039 case 'memorylimithelp':
1040 print_string($help, 'install', get_memory_limit());
1041 break;
1042 default:
1043 print_string($help, 'install');
1048 //==========================================================================//
1050 function get_memory_limit() {
1051 if ($limit = ini_get('memory_limit')) {
1052 return $limit;
1053 } else {
1054 return get_cfg_var('memory_limit');
1058 //==========================================================================//
1060 function check_memory_limit() {
1062 /// if limit is already 40 or more then we don't care if we can change it or not
1063 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1064 return true;
1067 /// Otherwise, see if we can change it ourselves
1068 @ini_set('memory_limit', '40M');
1069 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1072 //==========================================================================//
1074 function inst_check_php_version() {
1075 if (!check_php_version("4.3.0")) {
1076 return false;
1077 } else if (check_php_version("5.0.0")) {
1078 return check_php_version("5.1.0"); // 5.0.x is too buggy
1080 return true; // 4.3.x or 4.4.x is fine
1082 //==========================================================================//
1084 /* This function returns a list of languages and their full names. The
1085 * list of available languages is fetched from install/lang/xx/installer.php
1086 * and it's used exclusively by the installation process
1087 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1089 function get_installer_list_of_languages() {
1091 global $CFG;
1093 $languages = array();
1095 /// Get raw list of lang directories
1096 $langdirs = get_list_of_plugins('install/lang');
1097 asort($langdirs);
1098 /// Get some info from each lang
1099 foreach ($langdirs as $lang) {
1100 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1101 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1102 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1103 $shortlang = substr($lang, 0, -5);
1104 } else {
1105 $shortlang = $lang;
1107 if ($lang == 'en') { //Explain this is non-utf8 en
1108 $shortlang = 'non-utf8 en';
1110 if (!empty($string['thislanguage'])) {
1111 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1113 unset($string);
1116 /// Return array
1117 return $languages;
1120 //==========================================================================//
1122 function css_styles() {
1125 <style type="text/css">
1127 body { background-color: #ffeece; }
1128 p, li, td {
1129 font-family: helvetica, arial, sans-serif;
1130 font-size: 10pt;
1132 a { text-decoration: none; color: blue; }
1133 a img {
1134 border: none;
1136 .errormsg {
1137 color: red;
1138 font-weight: bold;
1140 blockquote {
1141 font-family: courier, monospace;
1142 font-size: 10pt;
1144 .input_database {
1145 width: 270px;
1147 .install_table {
1148 width: 500px;
1149 margin-left:auto;
1150 margin-right:auto;
1152 .td_left {
1153 text-align: <?php echo fix_align_rtl("right") ?>;
1154 font-weight: bold;
1156 .td_left_nowrap{
1157 text-align: <?php echo fix_align_rtl("right") ?>;
1158 font-weight: bold;
1159 white-space: nowrap;
1160 width: 160px;
1161 padding-left: 10px;
1163 .td_right {
1164 text-align: <?php echo fix_align_rtl("left") ?>;
1166 .main {
1167 width: 500px;
1168 border-width: 1px;
1169 border-style: solid;
1170 border-color: #ffc85f;
1171 margin-left:auto;
1172 margin-right:auto;
1173 -moz-border-radius-bottomleft: 15px;
1174 -moz-border-radius-bottomright: 15px;
1176 .td_mainheading {
1177 background-color: #fee6b9;
1178 padding-left: 10px;
1180 .td_main {
1181 text-align: center;
1183 .td_mainlogo {
1184 vertical-align: middle;
1186 .p_mainlogo {
1187 margin-top: 0px;
1188 margin-bottom: 0px;
1190 .p_mainheading {
1191 font-size: 11pt;
1192 margin-top: 16px;
1193 margin-bottom: 16px;
1195 .p_subheading {
1196 font-size: 10pt;
1197 padding-left: 10px;
1198 margin-top: 16px;
1199 margin-bottom: 16px;
1201 .p_mainheader{
1202 text-align: right;
1203 font-size: 20pt;
1204 font-weight: bold;
1205 margin-top: 0px;
1206 margin-bottom: 0px;
1208 .p_pass {
1209 color: green;
1210 font-weight: bold;
1211 margin-top: 0px;
1212 margin-bottom: 0px;
1214 .p_fail {
1215 color: red;
1216 font-weight: bold;
1217 margin-top: 0px;
1218 margin-bottom: 0px;
1220 .p_caution {
1221 color: #ff6600;
1222 font-weight: bold;
1223 margin-top: 0px;
1224 margin-bottom: 0px;
1226 .p_help {
1227 text-align: center;
1228 font-family: helvetica, arial, sans-serif;
1229 font-size: 14pt;
1230 font-weight: bold;
1231 color: #333333;
1232 margin-top: 0px;
1233 margin-bottom: 0px;
1235 /* This override the p tag for every p tag in this installation script,
1236 but not in lang\xxx\installer.php
1238 .p_install {
1239 margin-top: 0px;
1240 margin-bottom: 0px;
1242 .environmenttable {
1243 font-size: 10pt;
1244 border-color: #ffc85f;
1246 table.environmenttable .error {
1247 background-color : red;
1248 color : inherit;
1251 table.environmenttable .warn {
1252 background-color : yellow;
1255 table.environmenttable .ok {
1256 background-color : lightgreen;
1258 .header {
1259 background-color: #fee6b9;
1260 font-size: 10pt;
1262 .cell {
1263 background-color: #ffeece;
1264 font-size: 10pt;
1266 .error {
1267 color: #ff0000;
1269 .errorboxcontent {
1270 text-align: center;
1271 font-weight: bold;
1272 padding-left: 20px;
1273 color: #ff0000;
1275 .invisiblefieldset {
1276 display:inline;
1277 border:0px;
1278 padding:0px;
1279 margin:0px;
1281 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1282 display: none;
1285 </style>
1287 <?php
1290 //==========================================================================//
1292 function database_js() {
1295 <script type="text/javascript" defer="defer">
1296 function toggledbinfo() {
1297 //Calculate selected value
1298 var showid = 'mysql';
1299 if (document.getElementById('installform').dbtype.value) {
1300 showid = document.getElementById('installform').dbtype.value;
1302 if (document.getElementById) {
1303 //Hide all the divs
1304 document.getElementById('mysql').style.display = '';
1305 document.getElementById('mysqli').style.display = '';
1306 document.getElementById('postgres7').style.display = '';
1307 document.getElementById('mssql').style.display = '';
1308 document.getElementById('mssql_n').style.display = '';
1309 document.getElementById('odbc_mssql').style.display = '';
1310 document.getElementById('oci8po').style.display = '';
1311 //Show the selected div
1312 document.getElementById(showid).style.display = 'block';
1313 } else if (document.all) {
1314 //This is the way old msie versions work
1315 //Hide all the divs
1316 document.all['mysql'].style.display = '';
1317 document.all['mysqli'].style.display = '';
1318 document.all['postgres7'].style.display = '';
1319 document.all['mssql'].style.display = '';
1320 document.all['mssql_n'].style.display = '';
1321 document.all['odbc_mssql'].style.display = '';
1322 document.all['oci8po'].style.display = '';
1323 //Show the selected div
1324 document.all[showid].style.display = 'block';
1325 } else if (document.layers) {
1326 //This is the way nn4 works
1327 //Hide all the divs
1328 document.layers['mysql'].style.display = '';
1329 document.layers['mysqli'].style.display = '';
1330 document.layers['postgres7'].style.display = '';
1331 document.layers['mssql'].style.display = '';
1332 document.layers['mssql_n'].style.display = '';
1333 document.layers['odbc_mssql'].style.display = '';
1334 document.layers['oci8po'].style.display = '';
1335 //Show the selected div
1336 document.layers[showid].style.display = 'block';
1339 </script>
1341 <?php
1345 * Add slashes for single quotes and backslashes
1346 * so they can be included in single quoted string
1347 * (for config.php)
1349 function addsingleslashes($input){
1350 return preg_replace("/(['\\\])/", "\\\\$1", $input);