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/deprecatedlib.php');
132 require_once('./lib/weblib.php');
133 require_once('./lib/adodb/adodb.inc.php');
134 require_once('./lib/environmentlib.php');
135 require_once('./lib/xmlize.php');
136 require_once('./lib/componentlib.class.php');
137 require_once('./version.php');
139 /// Set version and release
140 $INSTALL['version'] = $version;
141 $INSTALL['release'] = $release;
143 /// Have the $db object ready because we are going to use it often
144 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
145 $db = &ADONewConnection($INSTALL['dbtype']);
146 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
148 /// guess the www root
149 if ($INSTALL['wwwroot'] == '') {
150 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
151 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
153 // now try to guess the correct dataroot not accessible via web
154 $CFG->wwwroot
= $INSTALL['wwwroot'];
155 $i = 0; //safety check - dirname might return some unexpected results
156 while(is_dataroot_insecure()) {
157 $parrent = dirname($CFG->dataroot
);
159 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
160 $CFG->dataroot
= ''; //can not find secure location for dataroot
163 $CFG->dataroot
= dirname($parrent).'/moodledata';
165 $INSTALL['dataroot'] = $CFG->dataroot
;
168 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
169 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
170 DIRECTORY
=> get_string('directorysettingshead', 'install'),
171 DATABASE
=> get_string('databasesettingshead', 'install'),
172 ADMIN
=> get_string('admindirsettinghead', 'install'),
173 ENVIRONMENT
=> get_string('environmenthead', 'install'),
174 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
175 SAVE
=> get_string('configurationcompletehead', 'install')
178 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
179 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
180 DIRECTORY
=> get_string('directorysettingssub', 'install'),
181 DATABASE
=> get_string('databasesettingssub', 'install'),
182 ADMIN
=> get_string('admindirsettingsub', 'install'),
183 ENVIRONMENT
=> get_string('environmentsub', 'install'),
184 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
185 SAVE
=> get_string('configurationcompletesub', 'install')
190 //==========================================================================//
192 /// Are we in help mode?
194 if (isset($_GET['help'])) {
200 //==========================================================================//
202 /// Are we in config download mode?
204 if (isset($_GET['download'])) {
205 header("Content-Type: application/download\n");
206 header("Content-Disposition: attachment; filename=\"config.php\"");
207 echo $INSTALL['config'];
215 //==========================================================================//
217 /// Check the directory settings
219 if ($INSTALL['stage'] == DIRECTORY
) {
224 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
225 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
226 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
227 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
230 if ($fh) fclose($fh);
233 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
234 $errormsg .= get_string('dirrooterror', 'install').'<br />';
235 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
237 if ($fh) fclose($fh);
240 $CFG->dataroot
= $INSTALL['dataroot'];
241 if (make_upload_directory('sessions', false) === false ) {
242 $errormsg .= get_string('datarooterror', 'install').'<br />';
244 if ($fh) fclose($fh);
246 if (!empty($errormsg)) $nextstage = DIRECTORY
;
253 //==========================================================================//
255 /// Check database settings if stage 3 data submitted
256 /// Try to connect to the database. If that fails then try to create the database
258 if ($INSTALL['stage'] == DATABASE
) {
260 /// First of all, analyze skipdbencodingtest status
261 if (isset($_POST['skipdbencodingtest'])) {
262 $INSTALL['skipdbencodingtest'] = true;
264 $INSTALL['skipdbencodingtest'] = false;
267 /// different format for postgres7 by socket
268 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
269 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
270 $INSTALL['dbuser'] = '';
271 $INSTALL['dbpass'] = '';
272 $INSTALL['dbname'] = '';
274 if ($INSTALL['prefix'] == '') { /// must have a prefix
275 $INSTALL['prefix'] = 'mdl_';
279 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
280 if (!extension_loaded('mysql')) {
281 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
282 $nextstage = DATABASE
;
286 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
287 if (!extension_loaded('pgsql')) {
288 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
289 $nextstage = DATABASE
;
293 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
294 if (!function_exists('mssql_connect')) {
295 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
296 $nextstage = DATABASE
;
300 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
301 if (!function_exists('mssql_connect')) {
302 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
303 $nextstage = DATABASE
;
307 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
308 if (!extension_loaded('odbc')) {
309 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
310 $nextstage = DATABASE
;
314 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
315 if (!extension_loaded('oci8')) {
316 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
317 $nextstage = DATABASE
;
321 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
322 $errormsg = get_string('dbwrongprefix', 'install');
323 $nextstage = DATABASE
;
326 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
327 $errormsg = get_string('dbwrongprefix', 'install');
328 $nextstage = DATABASE
;
331 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
332 $errormsg = get_string('dbwronghostserver', 'install');
333 $nextstage = DATABASE
;
337 if (empty($errormsg)) {
339 error_reporting(0); // Hide errors
341 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
342 /// The following doesn't seem to work but we're working on it
343 /// If you come up with a solution for creating a database in MySQL
344 /// feel free to put it in and let us know
345 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
346 switch ($INSTALL['dbtype']) { /// Try to create a database
348 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
349 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
351 $errormsg = get_string('dbcreationerror', 'install');
352 $nextstage = DATABASE
;
358 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
359 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
360 if (empty($INSTALL['skipdbencodingtest'])) {
361 /// We haven't checked the skip test checkbox, so perform the test
363 switch ($INSTALL['dbtype']) {
365 ///Get MySQL character_set_database value
366 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
367 if ($rs && $rs->RecordCount() > 0) {
368 $records = $rs->GetAssoc(true);
369 $encoding = $records['character_set_database']['Value'];
370 if (strtoupper($encoding) == 'UTF8') {
371 $INSTALL['dbencodingtestresults'] = true;
373 // Try to set the encoding now!
374 if (! $db->Metatables()) { // We have no tables so go ahead
375 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
376 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
378 $records = $rs->GetAssoc(true);
379 $encoding = $records['character_set_database']['Value'];
381 if (strtoupper($encoding) == 'UTF8') {
382 $INSTALL['dbencodingtestresults'] = true;
384 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
385 $nextstage = DATABASE
;
386 $INSTALL['showskipdbencodingtest'] = true;
387 $INSTALL['dbencodingtestresults'] = false;
390 $INSTALL['showskipdbencodingtest'] = true;
391 $INSTALL['dbencodingtestresults'] = false;
397 ///Get PostgreSQL server_encoding value
398 $rs = $db->Execute("SHOW server_encoding");
399 if ($rs && $rs->RecordCount() > 0) {
400 $encoding = $rs->fields
['server_encoding'];
401 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
402 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
403 $nextstage = DATABASE
;
404 $INSTALL['showskipdbencodingtest'] = true;
405 $INSTALL['dbencodingtestresults'] = false;
407 $INSTALL['dbencodingtestresults'] = true;
412 ///Get Oracle NLS_CHARACTERSET value
413 $rs = $db->Execute("SELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET'");
414 if ($rs && $rs->RecordCount() > 0) {
415 $encoding = $rs->fields
['value'];
416 if (strtoupper($encoding) != 'AL32UTF8') {
417 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
418 $nextstage = DATABASE
;
419 $INSTALL['dbencodingtestresults'] = false;
421 $INSTALL['dbencodingtestresults'] = true;
424 /// Get client NLS_LANG environment variable
425 if (strpos(getenv('NLS_LANG'), 'AL32UTF8') === false) { // Oracle client must be correct UTF8
426 $errormsg = get_string('dbwrongnlslang', 'install', $encoding);
427 $nextstage = DATABASE
;
428 $INSTALL['dbencodingtestresults'] = false;
438 if (($dbconnected === false) and (empty($errormsg)) ) {
439 $errormsg = get_string('dbconnectionerror', 'install');
440 $nextstage = DATABASE
;
446 //==========================================================================//
448 /// If the next stage is admin directory settings OR we have just come from there then
449 /// check the admin directory.
450 /// If we can open a file then we know that the admin name is correct.
452 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
453 if (!ini_get('allow_url_fopen') ||
true) { // MDL-4218 fopen URL is not reliable
454 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
455 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
456 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
459 if ($nextstage != ADMIN
) {
460 $errormsg = get_string('admindirerror', 'install');
466 //==========================================================================//
468 // Check if we can navigate from the environemt page (because it's ok)
470 if ($INSTALL['stage'] == ENVIRONMENT
) {
471 error_reporting(0); // Hide errors
472 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
473 error_reporting(7); // Show errors
475 /// Execute environment check, printing results
476 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
477 $nextstage = ENVIRONMENT
;
480 /// We never should reach this because DB has been tested before arriving here
481 $errormsg = get_string('dbconnectionerror', 'install');
482 $nextstage = DATABASE
;
488 //==========================================================================//
490 // Try to download the lang pack if it has been selected
492 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
494 $downloadsuccess = false;
497 error_reporting(0); // Hide errors
499 /// Create necessary lang dir
500 if (!make_upload_directory('lang', false)) {
501 $downloaderror = get_string('cannotcreatelangdir', 'error');
504 /// Download and install component
505 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
506 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
507 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
510 if ($cd->get_error() == 'remotedownloadnotallowed') {
512 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'zip';
513 $a->dest
= $CFG->dataroot
.'/lang';
514 $downloaderror = get_string($cd->get_error(), 'error', $a);
516 $downloaderror = get_string($cd->get_error(), 'error');
521 $downloadsuccess = true;
524 //We shouldn't reach this point
527 //We shouldn't reach this point
530 error_reporting(7); // Show errors
532 if ($downloadsuccess) {
533 $INSTALL['downloadlangpack'] = false;
534 $INSTALL['showdownloadlangpack'] = false;
535 $INSTALL['downloadlangpackerror'] = $downloaderror;
537 $INSTALL['downloadlangpack'] = false;
538 $INSTALL['showdownloadlangpack'] = false;
539 $INSTALL['downloadlangpackerror'] = $downloaderror;
545 //==========================================================================//
547 /// Display or print the data
548 /// Put the data into a string
549 /// Try to open config file for writing.
551 if ($nextstage == SAVE
) {
553 $str = '<?php /// Moodle Configuration File '."\r\n";
556 $str .= 'unset($CFG);'."\r\n";
559 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
560 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
561 if (!empty($INSTALL['dbname'])) {
562 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
563 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
564 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
566 $str .= '$CFG->dbpersist = false;'."\r\n";
567 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
570 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
571 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
572 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
573 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
576 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
579 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
580 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
584 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
585 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
586 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
591 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
597 $INSTALL['config'] = $str;
602 //==========================================================================//
605 <html dir
="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
607 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
608 <title
>Moodle Install
</title
>
609 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
610 <?php
css_styles() ?
>
611 <?php
database_js() ?
>
619 if (isset($_GET['help'])) {
620 print_install_help($_GET['help']);
621 close_window_button();
626 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
628 <td
class="td_mainlogo">
629 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
631 <td
class="td_mainlogo" valign
="bottom">
632 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
637 <td
class="td_mainheading" colspan
="2">
638 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
639 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
640 /// from the standard one to show better instructions for each DB
641 if ($nextstage == DATABASE
) {
642 echo '<script language="JavaScript" type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
643 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
645 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
647 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
648 /// Link to mssql installation page
649 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
650 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
651 echo get_string('moodledocslink', 'install') . '</a></p>';
654 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
655 /// Link to mssql installation page
656 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
657 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
658 echo get_string('moodledocslink', 'install') . '</a></p>';
661 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
662 /// Link to mssql installation page
663 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
664 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
665 echo get_string('moodledocslink', 'install') . '</a></p>';
668 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
669 /// Link to oracle installation page
670 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
671 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
672 echo get_string('moodledocslink', 'install') . '</a></p>';
675 if (!empty($substagetext[$nextstage])) {
676 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
684 <td
class="td_main" colspan
="2">
688 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
691 if ($nextstage == SAVE
) {
692 $INSTALL['stage'] = WELCOME
;
694 $options['lang'] = $INSTALL['language'];
695 if ($configsuccess) {
696 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
698 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
700 echo "<td width=\"33.3%\"> </td>\n";
701 echo "<td width=\"33.3%\"> </td>\n";
702 echo "<td width=\"33.3%\" align=\"right\">\n";
703 print_single_button("index.php", $options, get_string('continue'));
709 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
711 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
713 echo "<td width=\"33.3%\"> </td>\n";
714 echo "<td width=\"33.3%\" align=\"center\">\n";
715 $installoptions = array();
716 $installoptions['download'] = 1;
717 print_single_button("install.php", $installoptions, get_string('download', 'install'));
719 echo "<td width=\"33.3%\" align=\"right\">\n";
720 print_single_button("index.php", $options, get_string('continue'));
726 echo "<div style=\"text-align: left\">\n";
727 print_object(s($str));
731 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
732 form_table($nextstage, $formaction);
759 //==========================================================================//
762 function print_object($object) {
770 //==========================================================================//
772 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
773 global $INSTALL, $db;
775 /// Print the standard form if we aren't in the DOWNLOADLANG page
776 /// because it has its own form.
777 if ($nextstage != DOWNLOADLANG
) {
778 $needtoopenform = false;
780 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
781 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
785 $needtoopenform = true;
788 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
791 /// what we do depends on the stage we're at
792 switch ($nextstage) {
793 case WELCOME
: /// Welcome and language settings
796 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
797 <td
class="td_right">
798 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
804 case COMPATIBILITY
: /// Compatibilty check
805 $compatsuccess = true;
807 /// Check that PHP is of a sufficient version
808 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
809 /// Check session auto start
810 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
811 /// Check magic quotes
812 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
813 /// Check unsupported PHP configuration
814 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
816 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
817 /// Check file uploads
818 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
820 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
821 /// Check memory limit
822 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
826 case DIRECTORY
: /// Directory settings
830 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
831 <td
class="td_right">
832 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
836 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
837 <td
class="td_right">
838 <input type
="text" size
="40" name
="dirrootform" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
842 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
843 <td
class="td_right">
844 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
850 case DATABASE
: /// Database settings
854 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
855 <td
class="td_right">
856 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
857 'oci8po' => get_string('oci8po', 'install'),
858 'postgres7' => get_string('postgres7', 'install'),
859 'mssql' => get_string('mssql', 'install'),
860 'mssql_n' => get_string('mssql_n', 'install'),
861 'odbc_mssql' => get_string('odbc_mssql', 'install')),
862 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
866 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
867 <td
class="td_right">
868 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
872 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
873 <td
class="td_right">
874 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
878 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
879 <td
class="td_right">
880 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
884 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
885 <td
class="td_right">
886 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
890 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
891 <td
class="td_right">
892 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
895 <?php
if ($INSTALL['showskipdbencodingtest']) { ?
>
897 <td
class="td_left" colspan
="2">
898 <?php
print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?
>
905 case ADMIN
: /// Administration directory setting
909 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
910 <td
class="td_right">
911 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
918 case ENVIRONMENT
: /// Environment checks
924 error_reporting(0); // Hide errors
925 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
926 error_reporting(7); // Show errors
928 /// Execute environment check, printing results
929 check_moodle_environment($INSTALL['release'], $environment_results, true);
931 /// We never should reach this because DB has been tested before arriving here
932 $errormsg = get_string('dbconnectionerror', 'install');
933 $nextstage = DATABASE
;
934 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
942 case DOWNLOADLANG
: /// Download language from download.moodle.org
948 /// Get array of languages, we are going to use it
949 $languages=get_installer_list_of_languages();
950 /// Print the download form (button) if necessary
951 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
953 $options['downloadlangpack'] = true;
954 $options['stage'] = DOWNLOADLANG
;
955 $options['same'] = true;
956 print_simple_box_start('center');
957 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
958 print_simple_box_end();
961 /// English lang packs aren't downloaded
962 if (substr($INSTALL['language'],0,2) == 'en') {
963 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
965 if ($INSTALL['downloadlangpackerror']) {
966 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
967 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
969 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
984 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
987 if ($needtoopenform) {
989 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
990 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
995 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: right\"/>\n" : " \n" ?
>
996 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: left\"/>\n" : " \n" ?
>
999 if ($needtoopenform) {
1013 if (!$needtoopenform) {
1025 //==========================================================================//
1027 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
1029 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
1031 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1032 echo "<td valign=\"top\"> </td>\n";
1034 echo "<td valign=\"top\"";
1035 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1037 echo "<td valign=\"top\">";
1038 echo "<p>$errormessage ";
1039 install_helpbutton("install.php?help=$helpfield");
1047 //==========================================================================//
1049 function install_helpbutton($url, $title='') {
1051 $title = get_string('help');
1053 echo "<a href=\"javascript: void(0)\">";
1054 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
1055 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
1056 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1062 //==========================================================================//
1064 function print_install_help($help) {
1066 case 'phpversionhelp':
1067 print_string($help, 'install', phpversion());
1069 case 'memorylimithelp':
1070 print_string($help, 'install', get_memory_limit());
1073 print_string($help, 'install');
1078 //==========================================================================//
1080 function get_memory_limit() {
1081 if ($limit = ini_get('memory_limit')) {
1084 return get_cfg_var('memory_limit');
1088 //==========================================================================//
1090 function check_memory_limit() {
1092 /// if limit is already 16M or more then we don't care if we can change it or not
1093 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
1097 /// Otherwise, see if we can change it ourselves
1098 @ini_set
('memory_limit', '16M');
1099 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
1102 //==========================================================================//
1104 function inst_check_php_version() {
1105 if (!check_php_version("4.3.0")) {
1107 } else if (check_php_version("5.0.0")) {
1108 return check_php_version("5.1.0"); // 5.0.x is too buggy
1110 return true; // 4.3.x or 4.4.x is fine
1112 //==========================================================================//
1114 /* This function returns a list of languages and their full names. The
1115 * list of available languages is fetched from install/lang/xx/installer.php
1116 * and it's used exclusively by the installation process
1117 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1119 function get_installer_list_of_languages() {
1123 $languages = array();
1125 /// Get raw list of lang directories
1126 $langdirs = get_list_of_plugins('install/lang');
1128 /// Get some info from each lang
1129 foreach ($langdirs as $lang) {
1130 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1131 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1132 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1133 $shortlang = substr($lang, 0, -5);
1137 if ($lang == 'en') { //Explain this is non-utf8 en
1138 $shortlang = 'non-utf8 en';
1140 if (!empty($string['thislanguage'])) {
1141 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1150 //==========================================================================//
1152 function css_styles() {
1155 <style type
="text/css">
1157 body
{ background
-color
: #ffeece; }
1159 font
-family
: helvetica
, arial
, sans
-serif
;
1162 a
{ text
-decoration
: none
; color
: blue
; }
1168 font
-family
: courier
, monospace
;
1184 border
-style
: solid
;
1185 border
-color
: #ffc85f;
1186 -moz
-border
-radius
-bottomleft
: 15px
;
1187 -moz
-border
-radius
-bottomright
: 15px
;
1190 background
-color
: #fee6b9;
1226 font
-family
: helvetica
, arial
, sans
-serif
;
1233 border
-color
: #ffc85f;
1235 table
.environmenttable
.error
{
1236 background
-color
: red
;
1240 table
.environmenttable
.warn
{
1241 background
-color
: yellow
;
1244 table
.environmenttable
.ok
{
1245 background
-color
: lightgreen
;
1248 background
-color
: #fee6b9;
1252 background
-color
: #ffeece;
1264 #mysql, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1273 //==========================================================================//
1275 function database_js() {
1278 <script language
="JavaScript" type
="text/javascript" defer
="defer">
1279 function toggledbinfo() {
1280 //Calculate selected value
1281 var showid
= 'mysql';
1282 if (document
.installform
.dbtype
.value
) {
1283 showid
= document
.installform
.dbtype
.value
;
1285 if (document
.getElementById
) {
1287 document
.getElementById('mysql').style
.display
= '';
1288 document
.getElementById('postgres7').style
.display
= '';
1289 document
.getElementById('mssql').style
.display
= '';
1290 document
.getElementById('mssql_n').style
.display
= '';
1291 document
.getElementById('odbc_mssql').style
.display
= '';
1292 document
.getElementById('oci8po').style
.display
= '';
1293 //Show the selected div
1294 document
.getElementById(showid
).style
.display
= 'block';
1295 } else if (document
.all
) {
1296 //This is the way old msie versions work
1298 document
.all
['mysql'].style
.display
= '';
1299 document
.all
['postgres7'].style
.display
= '';
1300 document
.all
['mssql'].style
.display
= '';
1301 document
.all
['mssql_n'].style
.display
= '';
1302 document
.all
['odbc_mssql'].style
.display
= '';
1303 document
.all
['oci8po'].style
.display
= '';
1304 //Show the selected div
1305 document
.all
[showid
].style
.display
= 'block';
1306 } else if (document
.layers
) {
1307 //This is the way nn4 works
1309 document
.layers
['mysql'].style
.display
= '';
1310 document
.layers
['postgres7'].style
.display
= '';
1311 document
.layers
['mssql'].style
.display
= '';
1312 document
.layers
['mssql_n'].style
.display
= '';
1313 document
.layers
['odbc_mssql'].style
.display
= '';
1314 document
.layers
['oci8po'].style
.display
= '';
1315 //Show the selected div
1316 document
.layers
[showid
].style
.display
= 'block';