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');
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');
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']) ) {
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;
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/weblib.php');
132 require_once('./lib/adodb/adodb.inc.php');
133 require_once('./lib/environmentlib.php');
134 require_once('./lib/xmlize.php');
135 require_once('./lib/componentlib.class.php');
136 require_once('./version.php');
138 /// Set version and release
139 $INSTALL['version'] = $version;
140 $INSTALL['release'] = $release;
142 /// Have the $db object ready because we are going to use it often
143 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
144 $db = &ADONewConnection($INSTALL['dbtype']);
145 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
147 /// guess the www root
148 if ($INSTALL['wwwroot'] == '') {
149 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
150 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
152 // now try to guess the correct dataroot not accessible via web
153 $CFG->wwwroot
= $INSTALL['wwwroot'];
154 $i = 0; //safety check - dirname might return some unexpected results
155 while(is_dataroot_insecure()) {
156 $parrent = dirname($CFG->dataroot
);
158 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
159 $CFG->dataroot
= ''; //can not find secure location for dataroot
162 $CFG->dataroot
= dirname($parrent).'/moodledata';
164 $INSTALL['dataroot'] = $CFG->dataroot
;
167 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
168 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
169 DIRECTORY
=> get_string('directorysettingshead', 'install'),
170 DATABASE
=> get_string('databasesettingshead', 'install'),
171 ADMIN
=> get_string('admindirsettinghead', 'install'),
172 ENVIRONMENT
=> get_string('environmenthead', 'install'),
173 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
174 SAVE
=> get_string('configurationcompletehead', 'install')
177 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
178 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
179 DIRECTORY
=> get_string('directorysettingssub', 'install'),
180 DATABASE
=> get_string('databasesettingssub', 'install'),
181 ADMIN
=> get_string('admindirsettingsub', 'install'),
182 ENVIRONMENT
=> get_string('environmentsub', 'install'),
183 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
184 SAVE
=> get_string('configurationcompletesub', 'install')
189 //==========================================================================//
191 /// Are we in help mode?
193 if (isset($_GET['help'])) {
199 //==========================================================================//
201 /// Are we in config download mode?
203 if (isset($_GET['download'])) {
204 header("Content-Type: application/download\n");
205 header("Content-Disposition: attachment; filename=\"config.php\"");
206 echo $INSTALL['config'];
214 //==========================================================================//
216 /// Check the directory settings
218 if ($INSTALL['stage'] == DIRECTORY
) {
223 if (ini_get('allow_url_fopen')) {
224 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
225 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
226 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
229 if ($fh) fclose($fh);
232 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
233 $errormsg .= get_string('dirrooterror', 'install').'<br />';
234 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
236 if ($fh) fclose($fh);
239 $CFG->dataroot
= $INSTALL['dataroot'];
240 if (make_upload_directory('sessions', false) === false ) {
241 $errormsg .= get_string('datarooterror', 'install').'<br />';
243 if ($fh) fclose($fh);
245 if (!empty($errormsg)) $nextstage = DIRECTORY
;
252 //==========================================================================//
254 /// Check database settings if stage 3 data submitted
255 /// Try to connect to the database. If that fails then try to create the database
257 if ($INSTALL['stage'] == DATABASE
) {
259 /// First of all, analyze skipdbencodingtest status
260 if (isset($_POST['skipdbencodingtest'])) {
261 $INSTALL['skipdbencodingtest'] = true;
263 $INSTALL['skipdbencodingtest'] = false;
266 /// different format for postgres7 by socket
267 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
268 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
269 $INSTALL['dbuser'] = '';
270 $INSTALL['dbpass'] = '';
271 $INSTALL['dbname'] = '';
273 if ($INSTALL['prefix'] == '') { /// must have a prefix
274 $INSTALL['prefix'] = 'mdl_';
278 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
279 if (!extension_loaded('mysql')) {
280 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
281 $nextstage = DATABASE
;
285 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
286 if (!extension_loaded('pgsql')) {
287 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
288 $nextstage = DATABASE
;
292 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
293 if (!extension_loaded('mssql')) {
294 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
295 $nextstage = DATABASE
;
299 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
300 if (!extension_loaded('mssql')) {
301 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
302 $nextstage = DATABASE
;
306 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
307 if (!extension_loaded('odbc')) {
308 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
309 $nextstage = DATABASE
;
313 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
314 if (!extension_loaded('oci8')) {
315 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
316 $nextstage = DATABASE
;
320 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
321 $errormsg = get_string('dbwrongprefix', 'install');
322 $nextstage = DATABASE
;
325 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
326 $errormsg = get_string('dbwrongprefix', 'install');
327 $nextstage = DATABASE
;
330 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
331 $errormsg = get_string('dbwronghostserver', 'install');
332 $nextstage = DATABASE
;
336 if (empty($errormsg)) {
338 error_reporting(0); // Hide errors
340 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
341 /// The following doesn't seem to work but we're working on it
342 /// If you come up with a solution for creating a database in MySQL
343 /// feel free to put it in and let us know
344 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
345 switch ($INSTALL['dbtype']) { /// Try to create a database
347 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
348 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
350 $errormsg = get_string('dbcreationerror', 'install');
351 $nextstage = DATABASE
;
357 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
358 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
359 if (empty($INSTALL['skipdbencodingtest'])) {
360 /// We haven't checked the skip test checkbox, so perform the test
362 switch ($INSTALL['dbtype']) {
364 ///Get MySQL character_set_database value
365 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
366 if ($rs && $rs->RecordCount() > 0) {
367 $records = $rs->GetAssoc(true);
368 $encoding = $records['character_set_database']['Value'];
369 if (strtoupper($encoding) == 'UTF8') {
370 $INSTALL['dbencodingtestresults'] = true;
372 // Try to set the encoding now!
373 if (! $db->Metatables()) { // We have no tables so go ahead
374 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
375 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
377 $records = $rs->GetAssoc(true);
378 $encoding = $records['character_set_database']['Value'];
380 if (strtoupper($encoding) == 'UTF8') {
381 $INSTALL['dbencodingtestresults'] = true;
383 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
384 $nextstage = DATABASE
;
385 $INSTALL['showskipdbencodingtest'] = true;
386 $INSTALL['dbencodingtestresults'] = false;
389 $INSTALL['showskipdbencodingtest'] = true;
390 $INSTALL['dbencodingtestresults'] = false;
396 ///Get PostgreSQL server_encoding value
397 $rs = $db->Execute("SHOW server_encoding");
398 if ($rs && $rs->RecordCount() > 0) {
399 $encoding = $rs->fields
['server_encoding'];
400 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
401 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
402 $nextstage = DATABASE
;
403 $INSTALL['showskipdbencodingtest'] = true;
404 $INSTALL['dbencodingtestresults'] = false;
406 $INSTALL['dbencodingtestresults'] = true;
411 ///Get Oracle NLS_CHARACTERSET value
412 $rs = $db->Execute("SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET'");
413 if ($rs && $rs->RecordCount() > 0) {
414 $encoding = $rs->fields
['value'];
415 if (strtoupper($encoding) != 'AL32UTF8') {
416 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
417 $nextstage = DATABASE
;
418 $INSTALL['dbencodingtestresults'] = false;
420 $INSTALL['dbencodingtestresults'] = true;
423 /// Get client NLS_LANG environment variable
424 if (strpos(getenv('NLS_LANG'), 'AL32UTF8') === false) { // Oracle client must be correct UTF8
425 $errormsg = get_string('dbwrongnlslang', 'install', $encoding);
426 $nextstage = DATABASE
;
427 $INSTALL['dbencodingtestresults'] = false;
437 if (($dbconnected === false) and (empty($errormsg)) ) {
438 $errormsg = get_string('dbconnectionerror', 'install');
439 $nextstage = DATABASE
;
445 //==========================================================================//
447 /// If the next stage is admin directory settings OR we have just come from there then
448 /// check the admin directory.
449 /// If we can open a file then we know that the admin name is correct.
451 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
452 if (!ini_get('allow_url_fopen')) {
453 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
454 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
455 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
458 if ($nextstage != ADMIN
) {
459 $errormsg = get_string('admindirerror', 'install');
465 //==========================================================================//
467 // Check if we can navigate from the environemt page (because it's ok)
469 if ($INSTALL['stage'] == ENVIRONMENT
) {
470 error_reporting(0); // Hide errors
471 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
472 error_reporting(7); // Show errors
474 /// Execute environment check, printing results
475 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
476 $nextstage = ENVIRONMENT
;
479 /// We never should reach this because DB has been tested before arriving here
480 $errormsg = get_string('dbconnectionerror', 'install');
481 $nextstage = DATABASE
;
487 //==========================================================================//
489 // Try to download the lang pack if it has been selected
491 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
493 $downloadsuccess = false;
496 error_reporting(0); // Hide errors
498 /// Create necessary lang dir
499 if (!make_upload_directory('lang', false)) {
500 $downloaderror = get_string('cannotcreatelangdir', 'error');
503 /// Download and install component
504 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
505 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
506 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
509 if ($cd->get_error() == 'remotedownloadnotallowed') {
511 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'zip';
512 $a->dest
= $CFG->dataroot
.'/lang';
513 $downloaderror = get_string($cd->get_error(), 'error', $a);
515 $downloaderror = get_string($cd->get_error(), 'error');
520 $downloadsuccess = true;
523 //We shouldn't reach this point
526 //We shouldn't reach this point
529 error_reporting(7); // Show errors
531 if ($downloadsuccess) {
532 $INSTALL['downloadlangpack'] = false;
533 $INSTALL['showdownloadlangpack'] = false;
534 $INSTALL['downloadlangpackerror'] = $downloaderror;
536 $INSTALL['downloadlangpack'] = false;
537 $INSTALL['showdownloadlangpack'] = false;
538 $INSTALL['downloadlangpackerror'] = $downloaderror;
544 //==========================================================================//
546 /// Display or print the data
547 /// Put the data into a string
548 /// Try to open config file for writing.
550 if ($nextstage == SAVE
) {
552 $str = '<?php /// Moodle Configuration File '."\r\n";
555 $str .= 'unset($CFG);'."\r\n";
558 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
559 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
560 if (!empty($INSTALL['dbname'])) {
561 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
562 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
563 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
565 $str .= '$CFG->dbpersist = false;'."\r\n";
566 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
569 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
570 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
571 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
572 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
575 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
578 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
579 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
583 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
584 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
585 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
590 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
596 $INSTALL['config'] = $str;
601 //==========================================================================//
604 <html dir
="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
606 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
607 <title
>Moodle Install
</title
>
608 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
609 <?php
css_styles() ?
>
610 <?php
database_js() ?
>
618 if (isset($_GET['help'])) {
619 print_install_help($_GET['help']);
620 close_window_button();
625 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
627 <td
class="td_mainlogo">
628 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
630 <td
class="td_mainlogo" valign
="bottom">
631 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
636 <td
class="td_mainheading" colspan
="2">
637 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
638 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
639 /// from the standard one to show better instructions for each DB
640 if ($nextstage == DATABASE
) {
641 echo '<script language="JavaScript" type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
642 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
644 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
646 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
647 /// Link to mssql installation page
648 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
649 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
650 echo get_string('moodledocslink', 'install') . '</a></p>';
653 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
654 /// Link to mssql installation page
655 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
656 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
657 echo get_string('moodledocslink', 'install') . '</a></p>';
660 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
661 /// Link to mssql installation page
662 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
663 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
664 echo get_string('moodledocslink', 'install') . '</a></p>';
667 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
668 /// Link to oracle installation page
669 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
670 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
671 echo get_string('moodledocslink', 'install') . '</a></p>';
674 if (!empty($substagetext[$nextstage])) {
675 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
683 <td
class="td_main" colspan
="2">
687 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
690 if ($nextstage == SAVE
) {
691 $INSTALL['stage'] = WELCOME
;
693 $options['lang'] = $INSTALL['language'];
694 if ($configsuccess) {
695 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
697 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
699 echo "<td width=\"33.3%\"> </td>\n";
700 echo "<td width=\"33.3%\"> </td>\n";
701 echo "<td width=\"33.3%\" align=\"right\">\n";
702 print_single_button("index.php", $options, get_string('continue')." »");
708 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
710 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
712 echo "<td width=\"33.3%\"> </td>\n";
713 echo "<td width=\"33.3%\" align=\"center\">\n";
714 $installoptions = array();
715 $installoptions['download'] = 1;
716 print_single_button("install.php", $installoptions, get_string('download', 'install'));
718 echo "<td width=\"33.3%\" align=\"right\">\n";
719 print_single_button("index.php", $options, get_string('continue')." »");
725 echo "<div style=\"text-align: left\">\n";
726 print_object(s($str));
730 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
731 form_table($nextstage, $formaction);
758 //==========================================================================//
761 function print_object($object) {
769 //==========================================================================//
771 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
772 global $INSTALL, $db;
774 /// Print the standard form if we aren't in the DOWNLOADLANG page
775 /// because it has its own form.
776 if ($nextstage != DOWNLOADLANG
) {
777 $needtoopenform = false;
779 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
780 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
784 $needtoopenform = true;
787 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
790 /// what we do depends on the stage we're at
791 switch ($nextstage) {
792 case WELCOME
: /// Welcome and language settings
795 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
796 <td
class="td_right">
797 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
803 case COMPATIBILITY
: /// Compatibilty check
804 $compatsuccess = true;
806 /// Check that PHP is of a sufficient version
807 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
808 /// Check session auto start
809 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
810 /// Check magic quotes
811 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
812 /// Check unsupported PHP configuration
813 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
815 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
816 /// Check file uploads
817 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
819 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
820 /// Check memory limit
821 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
825 case DIRECTORY
: /// Directory settings
829 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
830 <td
class="td_right">
831 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
835 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
836 <td
class="td_right">
837 <input type
="text" size
="40" name
="dirrootform" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
841 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
842 <td
class="td_right">
843 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
849 case DATABASE
: /// Database settings
853 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
854 <td
class="td_right">
855 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
856 'oci8po' => get_string('oci8po', 'install'),
857 'postgres7' => get_string('postgres7', 'install'),
858 'mssql' => get_string('mssql', 'install'),
859 'mssql_n' => get_string('mssql_n', 'install'),
860 'odbc_mssql' => get_string('odbc_mssql', 'install')),
861 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
865 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
866 <td
class="td_right">
867 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
871 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
872 <td
class="td_right">
873 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
877 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
878 <td
class="td_right">
879 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
883 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
884 <td
class="td_right">
885 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
889 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
890 <td
class="td_right">
891 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
894 <?php
if ($INSTALL['showskipdbencodingtest']) { ?
>
896 <td
class="td_left" colspan
="2">
897 <?php
print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?
>
904 case ADMIN
: /// Administration directory setting
908 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
909 <td
class="td_right">
910 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
917 case ENVIRONMENT
: /// Environment checks
923 error_reporting(0); // Hide errors
924 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
925 error_reporting(7); // Show errors
927 /// Execute environment check, printing results
928 check_moodle_environment($INSTALL['release'], $environment_results, true);
930 /// We never should reach this because DB has been tested before arriving here
931 $errormsg = get_string('dbconnectionerror', 'install');
932 $nextstage = DATABASE
;
933 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
941 case DOWNLOADLANG
: /// Download language from download.moodle.org
947 /// Get array of languages, we are going to use it
948 $languages=get_installer_list_of_languages();
949 /// Print the download form (button) if necessary
950 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
952 $options['downloadlangpack'] = true;
953 $options['stage'] = DOWNLOADLANG
;
954 $options['same'] = true;
955 print_simple_box_start('center');
956 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
957 print_simple_box_end();
960 /// English lang packs aren't downloaded
961 if (substr($INSTALL['language'],0,2) == 'en') {
962 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
964 if ($INSTALL['downloadlangpackerror']) {
965 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
966 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
968 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
983 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
986 if ($needtoopenform) {
988 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
989 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
994 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: right\"/>\n" : " \n" ?
>
995 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: left\"/>\n" : " \n" ?
>
998 if ($needtoopenform) {
1012 if (!$needtoopenform) {
1024 //==========================================================================//
1026 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
1028 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
1030 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1031 echo "<td valign=\"top\"> </td>\n";
1033 echo "<td valign=\"top\"";
1034 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1036 echo "<td valign=\"top\">";
1037 echo "<p>$errormessage ";
1038 install_helpbutton("install.php?help=$helpfield");
1046 //==========================================================================//
1048 function install_helpbutton($url, $title='') {
1050 $title = get_string('help');
1052 echo "<a href=\"javascript: void(0)\">";
1053 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
1054 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
1055 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1061 //==========================================================================//
1063 function print_install_help($help) {
1065 case 'phpversionhelp':
1066 print_string($help, 'install', phpversion());
1068 case 'memorylimithelp':
1069 print_string($help, 'install', get_memory_limit());
1072 print_string($help, 'install');
1077 //==========================================================================//
1079 function get_memory_limit() {
1080 if ($limit = ini_get('memory_limit')) {
1083 return get_cfg_var('memory_limit');
1087 //==========================================================================//
1089 function check_memory_limit() {
1091 /// if limit is already 16M or more then we don't care if we can change it or not
1092 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
1096 /// Otherwise, see if we can change it ourselves
1097 @ini_set
('memory_limit', '16M');
1098 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
1101 //==========================================================================//
1103 function inst_check_php_version() {
1104 if (!check_php_version("4.3.0")) {
1106 } else if (check_php_version("5.0.0")) {
1107 return check_php_version("5.1.0"); // 5.0.x is too buggy
1109 return true; // 4.3.x or 4.4.x is fine
1111 //==========================================================================//
1113 /* This function returns a list of languages and their full names. The
1114 * list of available languages is fetched from install/lang/xx/installer.php
1115 * and it's used exclusively by the installation process
1116 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1118 function get_installer_list_of_languages() {
1122 $languages = array();
1124 /// Get raw list of lang directories
1125 $langdirs = get_list_of_plugins('install/lang');
1127 /// Get some info from each lang
1128 foreach ($langdirs as $lang) {
1129 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1130 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1131 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1132 $shortlang = substr($lang, 0, -5);
1136 if ($lang == 'en') { //Explain this is non-utf8 en
1137 $shortlang = 'non-utf8 en';
1139 if (!empty($string['thislanguage'])) {
1140 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1149 //==========================================================================//
1151 function css_styles() {
1154 <style type
="text/css">
1156 body
{ background
-color
: #ffeece; }
1158 font
-family
: helvetica
, arial
, sans
-serif
;
1161 a
{ text
-decoration
: none
; color
: blue
; }
1167 font
-family
: courier
, monospace
;
1183 border
-style
: solid
;
1184 border
-color
: #ffc85f;
1185 -moz
-border
-radius
-bottomleft
: 15px
;
1186 -moz
-border
-radius
-bottomright
: 15px
;
1189 background
-color
: #fee6b9;
1225 font
-family
: helvetica
, arial
, sans
-serif
;
1232 border
-color
: #ffc85f;
1235 background
-color
: #fee6b9;
1239 background
-color
: #ffeece;
1251 #mysql, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1260 //==========================================================================//
1262 function database_js() {
1265 <script language
="JavaScript" type
="text/javascript" defer
="defer">
1266 function toggledbinfo() {
1267 //Calculate selected value
1268 var showid
= 'mysql';
1269 if (document
.installform
.dbtype
.value
) {
1270 showid
= document
.installform
.dbtype
.value
;
1272 if (document
.getElementById
) {
1274 document
.getElementById('mysql').style
.display
= '';
1275 document
.getElementById('postgres7').style
.display
= '';
1276 document
.getElementById('mssql').style
.display
= '';
1277 document
.getElementById('mssql_n').style
.display
= '';
1278 document
.getElementById('odbc_mssql').style
.display
= '';
1279 document
.getElementById('oci8po').style
.display
= '';
1280 //Show the selected div
1281 document
.getElementById(showid
).style
.display
= 'block';
1282 } else if (document
.all
) {
1283 //This is the way old msie versions work
1285 document
.all
['mysql'].style
.display
= '';
1286 document
.all
['postgres7'].style
.display
= '';
1287 document
.all
['mssql'].style
.display
= '';
1288 document
.all
['mssql_n'].style
.display
= '';
1289 document
.all
['odbc_mssql'].style
.display
= '';
1290 document
.all
['oci8po'].style
.display
= '';
1291 //Show the selected div
1292 document
.all
[showid
].style
.display
= 'block';
1293 } else if (document
.layers
) {
1294 //This is the way nn4 works
1296 document
.layers
['mysql'].style
.display
= '';
1297 document
.layers
['postgres7'].style
.display
= '';
1298 document
.layers
['mssql'].style
.display
= '';
1299 document
.layers
['mssql_n'].style
.display
= '';
1300 document
.layers
['odbc_mssql'].style
.display
= '';
1301 document
.layers
['oci8po'].style
.display
= '';
1302 //Show the selected div
1303 document
.layers
[showid
].style
.display
= 'block';