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 ///==========================================================================//
27 /// This has to be defined to avoid a notice in current_language()
30 /// Begin the session as we are holding all information in a session
31 /// variable until the end.
33 session_name('MoodleSession');
36 if (! isset($_SESSION['INSTALL'])) {
37 $_SESSION['INSTALL'] = array();
40 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
42 /// detect if install was attempted from diferent directory, if yes reset session to prevent errors,
43 /// dirroot location now fixed in installer
44 if (!empty($INSTALL['dirroot']) and $INSTALL['dirroot'] != dirname(__FILE__
)) {
45 $_SESSION['INSTALL'] = array();
48 /// If it's our first time through this script then we need to set some default values
50 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
53 $INSTALL['language'] = 'en_utf8';
55 $INSTALL['dbhost'] = 'localhost';
56 $INSTALL['dbuser'] = '';
57 $INSTALL['dbpass'] = '';
58 $INSTALL['dbtype'] = 'mysql';
59 $INSTALL['dbname'] = 'moodle';
60 $INSTALL['prefix'] = 'mdl_';
62 $INSTALL['downloadlangpack'] = false;
63 $INSTALL['showdownloadlangpack'] = true;
64 $INSTALL['downloadlangpackerror'] = '';
66 /// To be used by the Installer
67 $INSTALL['wwwroot'] = '';
68 $INSTALL['dirroot'] = dirname(__FILE__
);
69 $INSTALL['dataroot'] = dirname(dirname(__FILE__
)) . DIRECTORY_SEPARATOR
. 'moodledata';
71 /// To be configured in the Installer
72 $INSTALL['wwwrootform'] = '';
73 $INSTALL['dirrootform'] = dirname(__FILE__
);
75 $INSTALL['admindirname'] = 'admin';
77 $INSTALL['stage'] = WELCOME
;
80 //==========================================================================//
82 /// Set the page to Unicode always
84 header('Content-Type: text/html; charset=UTF-8');
86 /// Was data submitted?
88 if (isset($_POST['stage'])) {
90 /// Get the stage for which the form was set and the next stage we are going to
92 /// Store any posted data
93 foreach ($_POST as $setting=>$value) {
94 $INSTALL[$setting] = $value;
97 if ( $goforward = (! empty( $_POST['next'] )) ) {
98 $nextstage = $_POST['stage'] +
1;
99 } else if (! empty( $_POST['prev'])) {
100 $nextstage = $_POST['stage'] - 1;
101 $INSTALL['stage'] = $_POST['stage'] - 1;
102 } else if (! empty( $_POST['same'] )) {
103 $nextstage = $_POST['stage'];
107 if ($nextstage < 0) {
108 $nextstage = WELCOME
;
115 $nextstage = WELCOME
;
119 //==========================================================================//
121 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
123 $SESSION->lang
= (!empty($_POST['language'])) ?
$_POST['language'] : $INSTALL['language'];
124 $CFG->dirroot
= $INSTALL['dirroot'];
125 $CFG->libdir
= $INSTALL['dirroot'].'/lib';
126 $CFG->dataroot
= $INSTALL['dataroot'];
127 $CFG->admin
= $INSTALL['admindirname'];
128 $CFG->directorypermissions
= 00777;
129 $CFG->running_installer
= true;
132 /// Include some moodle libraries
134 require_once($CFG->libdir
.'/adminlib.php');
135 require_once($CFG->libdir
.'/setuplib.php');
136 require_once($CFG->libdir
.'/moodlelib.php');
137 require_once($CFG->libdir
.'/weblib.php');
138 require_once($CFG->libdir
.'/deprecatedlib.php');
139 require_once($CFG->libdir
.'/adodb/adodb.inc.php');
140 require_once($CFG->libdir
.'/environmentlib.php');
141 require_once($CFG->libdir
.'/xmlize.php');
142 require_once($CFG->libdir
.'/componentlib.class.php');
143 require_once($CFG->dirroot
.'/version.php');
145 /// Set version and release
146 $INSTALL['version'] = $version;
147 $INSTALL['release'] = $release;
149 /// Have the $db object ready because we are going to use it often
150 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
151 $db = &ADONewConnection($INSTALL['dbtype']);
152 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
154 /// guess the www root
155 if ($INSTALL['wwwroot'] == '') {
156 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
157 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
159 // now try to guess the correct dataroot not accessible via web
160 $CFG->wwwroot
= $INSTALL['wwwroot'];
161 $i = 0; //safety check - dirname might return some unexpected results
162 while(is_dataroot_insecure()) {
163 $parrent = dirname($CFG->dataroot
);
165 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
166 $CFG->dataroot
= ''; //can not find secure location for dataroot
169 $CFG->dataroot
= dirname($parrent).'/moodledata';
171 $INSTALL['dataroot'] = $CFG->dataroot
;
174 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
175 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
176 DIRECTORY
=> get_string('directorysettingshead', 'install'),
177 DATABASE
=> get_string('databasesettingshead', 'install'),
178 ADMIN
=> get_string('admindirsettinghead', 'install'),
179 ENVIRONMENT
=> get_string('environmenthead', 'install'),
180 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
181 SAVE
=> get_string('configurationcompletehead', 'install')
184 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
185 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
186 DIRECTORY
=> get_string('directorysettingssub', 'install'),
187 DATABASE
=> get_string('databasesettingssub', 'install'),
188 ADMIN
=> get_string('admindirsettingsub', 'install'),
189 ENVIRONMENT
=> get_string('environmentsub', 'install'),
190 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
191 SAVE
=> get_string('configurationcompletesub', 'install')
196 //==========================================================================//
198 /// Are we in help mode?
200 if (isset($_GET['help'])) {
206 //==========================================================================//
208 /// Are we in config download mode?
210 if (isset($_GET['download'])) {
211 header("Content-Type: application/x-forcedownload\n");
212 header("Content-Disposition: attachment; filename=\"config.php\"");
213 echo $INSTALL['config'];
221 //==========================================================================//
223 /// Check the directory settings
225 if ($INSTALL['stage'] == DIRECTORY
) {
230 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
231 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
232 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
233 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
236 if ($fh) fclose($fh);
239 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
240 $errormsg .= get_string('dirrooterror', 'install').'<br />';
241 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
243 if ($fh) fclose($fh);
246 $CFG->dataroot
= $INSTALL['dataroot'];
247 if (make_upload_directory('sessions', false) === false ) {
248 $errormsg .= get_string('datarooterror', 'install').'<br />';
250 if ($fh) fclose($fh);
252 if (!empty($errormsg)) $nextstage = DIRECTORY
;
259 //==========================================================================//
261 /// Check database settings if stage 3 data submitted
262 /// Try to connect to the database. If that fails then try to create the database
264 if ($INSTALL['stage'] == DATABASE
) {
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 (!function_exists('mssql_connect')) {
294 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
295 $nextstage = DATABASE
;
299 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
300 if (!function_exists('mssql_connect')) {
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
;
335 if (empty($errormsg)) {
337 error_reporting(0); // Hide errors
339 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
340 /// The following doesn't seem to work but we're working on it
341 /// If you come up with a solution for creating a database in MySQL
342 /// feel free to put it in and let us know
343 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
344 switch ($INSTALL['dbtype']) { /// Try to create a database
346 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
347 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
349 $errormsg = get_string('dbcreationerror', 'install');
350 $nextstage = DATABASE
;
356 /// We have been able to connect properly, just test the database encoding now.
357 /// It must be Unicode for 1.8 installations.
359 switch ($INSTALL['dbtype']) {
361 /// Get MySQL character_set_database value
362 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
363 if ($rs && $rs->RecordCount() > 0) {
364 $records = $rs->GetAssoc(true);
365 $encoding = $records['character_set_database']['Value'];
366 if (strtoupper($encoding) != 'UTF8') {
367 /// Try to set the encoding now!
368 if (! $db->Metatables()) { // We have no tables so go ahead
369 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
370 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
374 /// If conversion fails, skip, let environment testing do the job
378 /// Skip, let environment testing do the job
381 /// Skip, let environment testing do the job
389 if (($dbconnected === false) and (empty($errormsg)) ) {
390 $errormsg = get_string('dbconnectionerror', 'install');
391 $nextstage = DATABASE
;
397 //==========================================================================//
399 /// If the next stage is admin directory settings OR we have just come from there then
400 /// check the admin directory.
401 /// If we can open a file then we know that the admin name is correct.
403 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
404 if (!ini_get('allow_url_fopen')) {
405 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
406 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
407 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
410 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
411 //if ($nextstage != ADMIN) {
412 // $errormsg = get_string('admindirerror', 'install');
413 // $nextstage = ADMIN;
418 //==========================================================================//
420 // Check if we can navigate from the environemt page (because it's ok)
422 if ($INSTALL['stage'] == ENVIRONMENT
) {
423 error_reporting(0); // Hide errors
424 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
425 error_reporting(7); // Show errors
427 /// Execute environment check, printing results
428 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
429 $nextstage = ENVIRONMENT
;
432 /// We never should reach this because DB has been tested before arriving here
433 $errormsg = get_string('dbconnectionerror', 'install');
434 $nextstage = DATABASE
;
440 //==========================================================================//
442 // Try to download the lang pack if it has been selected
444 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
446 $downloadsuccess = false;
449 error_reporting(0); // Hide errors
451 /// Create necessary lang dir
452 if (!make_upload_directory('lang', false)) {
453 $downloaderror = get_string('cannotcreatelangdir', 'error');
456 /// Download and install component
457 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
458 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
459 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
462 if ($cd->get_error() == 'remotedownloadnotallowed') {
464 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'.zip';
465 $a->dest
= $CFG->dataroot
.'/lang';
466 $downloaderror = get_string($cd->get_error(), 'error', $a);
468 $downloaderror = get_string($cd->get_error(), 'error');
473 $downloadsuccess = true;
476 //We shouldn't reach this point
479 //We shouldn't reach this point
482 error_reporting(7); // Show errors
484 if ($downloadsuccess) {
485 $INSTALL['downloadlangpack'] = false;
486 $INSTALL['showdownloadlangpack'] = false;
487 $INSTALL['downloadlangpackerror'] = $downloaderror;
489 $INSTALL['downloadlangpack'] = false;
490 $INSTALL['showdownloadlangpack'] = false;
491 $INSTALL['downloadlangpackerror'] = $downloaderror;
497 //==========================================================================//
499 /// Display or print the data
500 /// Put the data into a string
501 /// Try to open config file for writing.
503 if ($nextstage == SAVE
) {
505 $str = '<?php /// Moodle Configuration File '."\r\n";
508 $str .= 'unset($CFG);'."\r\n";
511 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
512 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
513 if (!empty($INSTALL['dbname'])) {
514 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
515 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
516 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
518 $str .= '$CFG->dbpersist = false;'."\r\n";
519 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
522 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
523 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
524 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
525 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
528 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
531 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
532 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
533 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
538 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
544 $INSTALL['config'] = $str;
549 //==========================================================================//
552 <html dir
="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
554 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
555 <title
>Moodle Install
</title
>
556 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
557 <?php
css_styles() ?
>
558 <?php
database_js() ?
>
566 if (isset($_GET['help'])) {
567 print_install_help($_GET['help']);
568 close_window_button();
573 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
575 <td
class="td_mainlogo">
576 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
578 <td
class="td_mainlogo" valign
="bottom">
579 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
584 <td
class="td_mainheading" colspan
="2">
585 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
586 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
587 /// from the standard one to show better instructions for each DB
588 if ($nextstage == DATABASE
) {
589 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
590 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
592 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
594 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
595 /// Link to mssql installation page
596 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
597 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
598 echo get_string('moodledocslink', 'install') . '</a></p>';
601 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
602 /// Link to mssql installation page
603 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
604 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" />';
605 echo get_string('moodledocslink', 'install') . '</a></p>';
608 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
609 /// Link to mssql installation page
610 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
611 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
612 echo get_string('moodledocslink', 'install') . '</a></p>';
615 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
616 /// Link to oracle installation page
617 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
618 echo '<img src="' . $INSTALL['wwwrootform'] . '/pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
619 echo get_string('moodledocslink', 'install') . '</a></p>';
622 if (!empty($substagetext[$nextstage])) {
623 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
631 <td
class="td_main" colspan
="2">
635 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
638 if ($nextstage == SAVE
) {
639 $INSTALL['stage'] = WELCOME
;
641 $options['lang'] = $INSTALL['language'];
642 if ($configsuccess) {
643 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
645 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
647 echo "<td width=\"33.3%\"> </td>\n";
648 echo "<td width=\"33.3%\"> </td>\n";
649 echo "<td width=\"33.3%\" align=\"right\">\n";
650 print_single_button("index.php", $options, get_string('continue'));
656 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
658 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
660 echo "<td width=\"33.3%\"> </td>\n";
661 echo "<td width=\"33.3%\" align=\"center\">\n";
662 $installoptions = array();
663 $installoptions['download'] = 1;
664 print_single_button("install.php", $installoptions, get_string('download', 'install'));
666 echo "<td width=\"33.3%\" align=\"right\">\n";
667 print_single_button("index.php", $options, get_string('continue'));
673 echo "<div style=\"text-align: left\">\n";
680 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
681 form_table($nextstage, $formaction);
709 //==========================================================================//
711 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
712 global $INSTALL, $db;
714 /// Print the standard form if we aren't in the DOWNLOADLANG page
715 /// because it has its own form.
716 if ($nextstage != DOWNLOADLANG
) {
717 $needtoopenform = false;
719 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
720 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
724 $needtoopenform = true;
727 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
730 /// what we do depends on the stage we're at
731 switch ($nextstage) {
732 case WELCOME
: /// Welcome and language settings
735 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
736 <td
class="td_right">
737 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
743 case COMPATIBILITY
: /// Compatibilty check
744 $compatsuccess = true;
746 /// Check that PHP is of a sufficient version
747 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
748 /// Check session auto start
749 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
750 /// Check magic quotes
751 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
752 /// Check unsupported PHP configuration
753 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
755 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
756 /// Check file uploads
757 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
759 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
760 /// Check memory limit
761 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
765 case DIRECTORY
: /// Directory settings
769 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
770 <td
class="td_right">
771 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
775 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
776 <td
class="td_right">
777 <input type
="text" size
="40" name
="dirrootform" disabled
="disabled" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
781 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
782 <td
class="td_right">
783 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
789 case DATABASE
: /// Database settings
793 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
794 <td
class="td_right">
795 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
796 'oci8po' => get_string('oci8po', 'install'),
797 'postgres7' => get_string('postgres7', 'install'),
798 'mssql' => get_string('mssql', 'install'),
799 'mssql_n' => get_string('mssql_n', 'install'),
800 'odbc_mssql' => get_string('odbc_mssql', 'install')),
801 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
805 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
806 <td
class="td_right">
807 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
811 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
812 <td
class="td_right">
813 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
817 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
818 <td
class="td_right">
819 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
823 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
824 <td
class="td_right">
825 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
829 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
830 <td
class="td_right">
831 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
837 case ADMIN
: /// Administration directory setting
841 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
842 <td
class="td_right">
843 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
850 case ENVIRONMENT
: /// Environment checks
856 error_reporting(0); // Hide errors
857 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
858 error_reporting(7); // Show errors
860 /// Execute environment check, printing results
861 check_moodle_environment($INSTALL['release'], $environment_results, true);
863 /// We never should reach this because DB has been tested before arriving here
864 $errormsg = get_string('dbconnectionerror', 'install');
865 $nextstage = DATABASE
;
866 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
874 case DOWNLOADLANG
: /// Download language from download.moodle.org
880 /// Get array of languages, we are going to use it
881 $languages=get_installer_list_of_languages();
882 /// Print the download form (button) if necessary
883 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
885 $options['downloadlangpack'] = true;
886 $options['stage'] = DOWNLOADLANG
;
887 $options['same'] = true;
888 print_simple_box_start('center');
889 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
890 print_simple_box_end();
893 /// English lang packs aren't downloaded
894 if (substr($INSTALL['language'],0,2) == 'en') {
895 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
897 if ($INSTALL['downloadlangpackerror']) {
898 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
899 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
901 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
916 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
919 if ($needtoopenform) {
921 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
922 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
927 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: right\"/>\n" : " \n" ?
>
928 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: left\"/>\n" : " \n" ?
>
931 if ($needtoopenform) {
945 if (!$needtoopenform) {
957 //==========================================================================//
959 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
961 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
963 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
964 echo "<td valign=\"top\"> </td>\n";
966 echo "<td valign=\"top\"";
967 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
969 echo "<td valign=\"top\">";
970 echo "<p>$errormessage ";
971 install_helpbutton("install.php?help=$helpfield");
979 //==========================================================================//
981 function install_helpbutton($url, $title='') {
983 $title = get_string('help');
985 echo "<a href=\"javascript: void(0)\">";
986 echo "<img src=\"./pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
987 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
993 //==========================================================================//
995 function print_install_help($help) {
997 case 'phpversionhelp':
998 print_string($help, 'install', phpversion());
1000 case 'memorylimithelp':
1001 print_string($help, 'install', get_memory_limit());
1004 print_string($help, 'install');
1009 //==========================================================================//
1011 function get_memory_limit() {
1012 if ($limit = ini_get('memory_limit')) {
1015 return get_cfg_var('memory_limit');
1019 //==========================================================================//
1021 function check_memory_limit() {
1023 /// if limit is already 40 or more then we don't care if we can change it or not
1024 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1028 /// Otherwise, see if we can change it ourselves
1029 @ini_set
('memory_limit', '40M');
1030 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1033 //==========================================================================//
1035 function inst_check_php_version() {
1036 if (!check_php_version("4.3.0")) {
1038 } else if (check_php_version("5.0.0")) {
1039 return check_php_version("5.1.0"); // 5.0.x is too buggy
1041 return true; // 4.3.x or 4.4.x is fine
1043 //==========================================================================//
1045 /* This function returns a list of languages and their full names. The
1046 * list of available languages is fetched from install/lang/xx/installer.php
1047 * and it's used exclusively by the installation process
1048 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1050 function get_installer_list_of_languages() {
1054 $languages = array();
1056 /// Get raw list of lang directories
1057 $langdirs = get_list_of_plugins('install/lang');
1059 /// Get some info from each lang
1060 foreach ($langdirs as $lang) {
1061 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1062 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1063 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1064 $shortlang = substr($lang, 0, -5);
1068 if ($lang == 'en') { //Explain this is non-utf8 en
1069 $shortlang = 'non-utf8 en';
1071 if (!empty($string['thislanguage'])) {
1072 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1081 //==========================================================================//
1083 function css_styles() {
1086 <style type
="text/css">
1088 body
{ background
-color
: #ffeece; }
1090 font
-family
: helvetica
, arial
, sans
-serif
;
1093 a
{ text
-decoration
: none
; color
: blue
; }
1102 font
-family
: courier
, monospace
;
1118 border
-style
: solid
;
1119 border
-color
: #ffc85f;
1120 -moz
-border
-radius
-bottomleft
: 15px
;
1121 -moz
-border
-radius
-bottomright
: 15px
;
1124 background
-color
: #fee6b9;
1160 font
-family
: helvetica
, arial
, sans
-serif
;
1167 border
-color
: #ffc85f;
1170 background
-color
: #fee6b9;
1174 background
-color
: #ffeece;
1186 .invisiblefieldset
{
1192 #mysql, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1201 //==========================================================================//
1203 function database_js() {
1206 <script type
="text/javascript" defer
="defer">
1207 function toggledbinfo() {
1208 //Calculate selected value
1209 var showid
= 'mysql';
1210 if (document
.getElementById('installform').dbtype
.value
) {
1211 showid
= document
.getElementById('installform').dbtype
.value
;
1213 if (document
.getElementById
) {
1215 document
.getElementById('mysql').style
.display
= '';
1216 document
.getElementById('postgres7').style
.display
= '';
1217 document
.getElementById('mssql').style
.display
= '';
1218 document
.getElementById('mssql_n').style
.display
= '';
1219 document
.getElementById('odbc_mssql').style
.display
= '';
1220 document
.getElementById('oci8po').style
.display
= '';
1221 //Show the selected div
1222 document
.getElementById(showid
).style
.display
= 'block';
1223 } else if (document
.all
) {
1224 //This is the way old msie versions work
1226 document
.all
['mysql'].style
.display
= '';
1227 document
.all
['postgres7'].style
.display
= '';
1228 document
.all
['mssql'].style
.display
= '';
1229 document
.all
['mssql_n'].style
.display
= '';
1230 document
.all
['odbc_mssql'].style
.display
= '';
1231 document
.all
['oci8po'].style
.display
= '';
1232 //Show the selected div
1233 document
.all
[showid
].style
.display
= 'block';
1234 } else if (document
.layers
) {
1235 //This is the way nn4 works
1237 document
.layers
['mysql'].style
.display
= '';
1238 document
.layers
['postgres7'].style
.display
= '';
1239 document
.layers
['mssql'].style
.display
= '';
1240 document
.layers
['mssql_n'].style
.display
= '';
1241 document
.layers
['odbc_mssql'].style
.display
= '';
1242 document
.layers
['oci8po'].style
.display
= '';
1243 //Show the selected div
1244 document
.layers
[showid
].style
.display
= 'block';