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 /// make sure PHP errors are displayed to help diagnose problems
37 @error_reporting
(1023); //E_ALL not used because we do not want strict notices in PHP5 yet
38 @ini_set
('display_errors', '1');
40 if (! isset($_SESSION['INSTALL'])) {
41 $_SESSION['INSTALL'] = array();
44 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
46 /// detect if install was attempted from diferent directory, if yes reset session to prevent errors,
47 /// dirroot location now fixed in installer
48 if (!empty($INSTALL['dirroot']) and $INSTALL['dirroot'] != dirname(__FILE__
)) {
49 $_SESSION['INSTALL'] = array();
52 /// If it's our first time through this script then we need to set some default values
54 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
57 $INSTALL['language'] = 'en_utf8';
59 $INSTALL['dbhost'] = 'localhost';
60 $INSTALL['dbuser'] = '';
61 $INSTALL['dbpass'] = '';
62 $INSTALL['dbtype'] = 'mysql';
63 $INSTALL['dbname'] = 'moodle';
64 $INSTALL['prefix'] = 'mdl_';
66 $INSTALL['downloadlangpack'] = false;
67 $INSTALL['showdownloadlangpack'] = true;
68 $INSTALL['downloadlangpackerror'] = '';
70 /// To be used by the Installer
71 $INSTALL['wwwroot'] = '';
72 $INSTALL['dirroot'] = dirname(__FILE__
);
73 $INSTALL['dataroot'] = dirname(dirname(__FILE__
)) . DIRECTORY_SEPARATOR
. 'moodledata';
75 /// To be configured in the Installer
76 $INSTALL['wwwrootform'] = '';
77 $INSTALL['dirrootform'] = dirname(__FILE__
);
79 $INSTALL['admindirname'] = 'admin';
81 $INSTALL['stage'] = WELCOME
;
84 //==========================================================================//
86 /// Set the page to Unicode always
88 header('Content-Type: text/html; charset=UTF-8');
90 /// Was data submitted?
92 if (isset($_POST['stage'])) {
94 /// Get the stage for which the form was set and the next stage we are going to
96 /// Store any posted data
97 foreach ($_POST as $setting=>$value) {
98 $INSTALL[$setting] = $value;
101 if ( $goforward = (! empty( $_POST['next'] )) ) {
102 $nextstage = $_POST['stage'] +
1;
103 } else if (! empty( $_POST['prev'])) {
104 $nextstage = $_POST['stage'] - 1;
105 $INSTALL['stage'] = $_POST['stage'] - 1;
106 } else if (! empty( $_POST['same'] )) {
107 $nextstage = $_POST['stage'];
111 if ($nextstage < 0) {
112 $nextstage = WELCOME
;
119 $nextstage = WELCOME
;
123 //==========================================================================//
125 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
127 $SESSION->lang
= (!empty($_POST['language'])) ?
$_POST['language'] : $INSTALL['language'];
128 $CFG->dirroot
= $INSTALL['dirroot'];
129 $CFG->libdir
= $INSTALL['dirroot'].'/lib';
130 $CFG->dataroot
= $INSTALL['dataroot'];
131 $CFG->admin
= $INSTALL['admindirname'];
132 $CFG->directorypermissions
= 00777;
133 $CFG->running_installer
= true;
136 /// Include some moodle libraries
138 require_once($CFG->libdir
.'/adminlib.php');
139 require_once($CFG->libdir
.'/setuplib.php');
140 require_once($CFG->libdir
.'/moodlelib.php');
141 require_once($CFG->libdir
.'/weblib.php');
142 require_once($CFG->libdir
.'/deprecatedlib.php');
143 require_once($CFG->libdir
.'/adodb/adodb.inc.php');
144 require_once($CFG->libdir
.'/environmentlib.php');
145 require_once($CFG->libdir
.'/xmlize.php');
146 require_once($CFG->libdir
.'/componentlib.class.php');
147 require_once($CFG->dirroot
.'/version.php');
149 /// Set version and release
150 $INSTALL['version'] = $version;
151 $INSTALL['release'] = $release;
153 /// Have the $db object ready because we are going to use it often
154 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
155 $db = &ADONewConnection($INSTALL['dbtype']);
156 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
158 /// guess the www root
159 if ($INSTALL['wwwroot'] == '') {
160 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
161 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
163 // now try to guess the correct dataroot not accessible via web
164 $CFG->wwwroot
= $INSTALL['wwwroot'];
165 $i = 0; //safety check - dirname might return some unexpected results
166 while(is_dataroot_insecure()) {
167 $parrent = dirname($CFG->dataroot
);
169 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
170 $CFG->dataroot
= ''; //can not find secure location for dataroot
173 $CFG->dataroot
= dirname($parrent).'/moodledata';
175 $INSTALL['dataroot'] = $CFG->dataroot
;
178 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
179 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
180 DIRECTORY
=> get_string('directorysettingshead', 'install'),
181 DATABASE
=> get_string('databasesettingshead', 'install'),
182 ADMIN
=> get_string('admindirsettinghead', 'install'),
183 ENVIRONMENT
=> get_string('environmenthead', 'install'),
184 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
185 SAVE
=> get_string('configurationcompletehead', 'install')
188 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
189 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
190 DIRECTORY
=> get_string('directorysettingssub', 'install'),
191 DATABASE
=> get_string('databasesettingssub', 'install'),
192 ADMIN
=> get_string('admindirsettingsub', 'install'),
193 ENVIRONMENT
=> get_string('environmentsub', 'install'),
194 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
195 SAVE
=> get_string('configurationcompletesub', 'install')
200 //==========================================================================//
202 /// Are we in help mode?
204 if (isset($_GET['help'])) {
210 //==========================================================================//
212 /// Are we in config download mode?
214 if (isset($_GET['download'])) {
215 header("Content-Type: application/x-forcedownload\n");
216 header("Content-Disposition: attachment; filename=\"config.php\"");
217 echo $INSTALL['config'];
225 //==========================================================================//
227 /// Check the directory settings
229 if ($INSTALL['stage'] == DIRECTORY
) {
234 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
235 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
236 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
237 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
240 if ($fh) fclose($fh);
243 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
244 $errormsg .= get_string('dirrooterror', 'install').'<br />';
245 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
247 if ($fh) fclose($fh);
250 $CFG->dataroot
= $INSTALL['dataroot'];
251 if (make_upload_directory('sessions', false) === false ) {
252 $errormsg .= get_string('datarooterror', 'install').'<br />';
254 if ($fh) fclose($fh);
256 if (!empty($errormsg)) $nextstage = DIRECTORY
;
263 //==========================================================================//
265 /// Check database settings if stage 3 data submitted
266 /// Try to connect to the database. If that fails then try to create the database
268 if ($INSTALL['stage'] == DATABASE
) {
270 /// different format for postgres7 by socket
271 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
272 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
273 $INSTALL['dbuser'] = '';
274 $INSTALL['dbpass'] = '';
275 $INSTALL['dbname'] = '';
277 if ($INSTALL['prefix'] == '') { /// must have a prefix
278 $INSTALL['prefix'] = 'mdl_';
282 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
283 if (!extension_loaded('mysql')) {
284 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
285 $nextstage = DATABASE
;
289 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
290 if (!extension_loaded('mysqli')) {
291 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
292 $nextstage = DATABASE
;
296 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
297 if (!extension_loaded('pgsql')) {
298 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
299 $nextstage = DATABASE
;
303 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
304 if (!function_exists('mssql_connect')) {
305 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
306 $nextstage = DATABASE
;
310 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
311 if (!function_exists('mssql_connect')) {
312 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
313 $nextstage = DATABASE
;
317 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
318 if (!extension_loaded('odbc')) {
319 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
320 $nextstage = DATABASE
;
324 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
325 if (!extension_loaded('oci8')) {
326 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
327 $nextstage = DATABASE
;
331 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
332 $errormsg = get_string('dbwrongprefix', 'install');
333 $nextstage = DATABASE
;
336 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
337 $errormsg = get_string('dbwrongprefix', 'install');
338 $nextstage = DATABASE
;
341 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
342 $errormsg = get_string('dbwronghostserver', 'install');
343 $nextstage = DATABASE
;
346 if (empty($errormsg)) {
348 error_reporting(0); // Hide errors
350 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
351 /// The following doesn't seem to work but we're working on it
352 /// If you come up with a solution for creating a database in MySQL
353 /// feel free to put it in and let us know
354 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
355 switch ($INSTALL['dbtype']) { /// Try to create a database
358 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
359 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
361 $errormsg = get_string('dbcreationerror', 'install');
362 $nextstage = DATABASE
;
368 /// We have been able to connect properly, just test the database encoding now.
369 /// It must be Unicode for 1.8 installations.
371 switch ($INSTALL['dbtype']) {
374 /// Get MySQL character_set_database value
375 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
376 if ($rs && !$rs->EOF
) {
377 $records = $rs->GetAssoc(true);
378 $encoding = $records['character_set_database']['Value'];
379 if (strtoupper($encoding) != 'UTF8') {
380 /// Try to set the encoding now!
381 if (! $db->Metatables()) { // We have no tables so go ahead
382 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
383 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
387 /// If conversion fails, skip, let environment testing do the job
391 /// Skip, let environment testing do the job
394 /// Skip, let environment testing do the job
402 if (($dbconnected === false) and (empty($errormsg)) ) {
403 $errormsg = get_string('dbconnectionerror', 'install');
404 $nextstage = DATABASE
;
410 //==========================================================================//
412 /// If the next stage is admin directory settings OR we have just come from there then
413 /// check the admin directory.
414 /// If we can open a file then we know that the admin name is correct.
416 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
417 if (!ini_get('allow_url_fopen')) {
418 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
419 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
420 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
423 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
424 //if ($nextstage != ADMIN) {
425 // $errormsg = get_string('admindirerror', 'install');
426 // $nextstage = ADMIN;
431 //==========================================================================//
433 // Check if we can navigate from the environemt page (because it's ok)
435 if ($INSTALL['stage'] == ENVIRONMENT
) {
436 error_reporting(0); // Hide errors
437 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
438 error_reporting(7); // Show errors
440 /// Execute environment check, printing results
441 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
442 $nextstage = ENVIRONMENT
;
445 /// We never should reach this because DB has been tested before arriving here
446 $errormsg = get_string('dbconnectionerror', 'install');
447 $nextstage = DATABASE
;
453 //==========================================================================//
455 // Try to download the lang pack if it has been selected
457 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
459 $downloadsuccess = false;
462 error_reporting(0); // Hide errors
464 /// Create necessary lang dir
465 if (!make_upload_directory('lang', false)) {
466 $downloaderror = get_string('cannotcreatelangdir', 'error');
469 /// Download and install component
470 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
471 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
472 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
475 if ($cd->get_error() == 'remotedownloadnotallowed') {
477 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'.zip';
478 $a->dest
= $CFG->dataroot
.'/lang';
479 $downloaderror = get_string($cd->get_error(), 'error', $a);
481 $downloaderror = get_string($cd->get_error(), 'error');
486 $downloadsuccess = true;
489 //We shouldn't reach this point
492 //We shouldn't reach this point
495 error_reporting(7); // Show errors
497 if ($downloadsuccess) {
498 $INSTALL['downloadlangpack'] = false;
499 $INSTALL['showdownloadlangpack'] = false;
500 $INSTALL['downloadlangpackerror'] = $downloaderror;
502 $INSTALL['downloadlangpack'] = false;
503 $INSTALL['showdownloadlangpack'] = false;
504 $INSTALL['downloadlangpackerror'] = $downloaderror;
510 //==========================================================================//
512 /// Display or print the data
513 /// Put the data into a string
514 /// Try to open config file for writing.
516 if ($nextstage == SAVE
) {
518 $str = '<?php /// Moodle Configuration File '."\r\n";
521 $str .= 'unset($CFG);'."\r\n";
524 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
525 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
526 if (!empty($INSTALL['dbname'])) {
527 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
528 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
529 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
531 $str .= '$CFG->dbpersist = false;'."\r\n";
532 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
535 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
536 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
537 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
538 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
541 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
544 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
545 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
546 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
551 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
557 $INSTALL['config'] = $str;
562 //==========================================================================//
565 <html dir
="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
567 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
568 <title
>Moodle Install
</title
>
569 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
570 <?php
css_styles() ?
>
571 <?php
database_js() ?
>
579 if (isset($_GET['help'])) {
580 print_install_help($_GET['help']);
581 close_window_button();
586 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
588 <td
class="td_mainlogo">
589 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
591 <td
class="td_mainlogo" valign
="bottom">
592 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
597 <td
class="td_mainheading" colspan
="2">
598 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
599 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
600 /// from the standard one to show better instructions for each DB
601 if ($nextstage == DATABASE
) {
602 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
603 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
605 echo '<div id="mysqli" name="mysqli">' . get_string('databasesettingssub_mysqli', 'install') . '</div>';
607 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
609 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
610 /// Link to mssql installation page
611 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
612 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
613 echo get_string('moodledocslink', 'install') . '</a></p>';
616 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
617 /// Link to mssql installation page
618 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
619 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
620 echo get_string('moodledocslink', 'install') . '</a></p>';
623 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
624 /// Link to mssql installation page
625 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
626 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
627 echo get_string('moodledocslink', 'install') . '</a></p>';
630 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
631 /// Link to oracle installation page
632 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
633 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
634 echo get_string('moodledocslink', 'install') . '</a></p>';
637 if (!empty($substagetext[$nextstage])) {
638 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
646 <td
class="td_main" colspan
="2">
650 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
653 if ($nextstage == SAVE
) {
654 $INSTALL['stage'] = WELCOME
;
656 $options['lang'] = $INSTALL['language'];
657 if ($configsuccess) {
658 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
660 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
662 echo "<td width=\"33.3%\"> </td>\n";
663 echo "<td width=\"33.3%\"> </td>\n";
664 echo "<td width=\"33.3%\" align=\"right\">\n";
665 print_single_button("index.php", $options, get_string('continue'));
671 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
673 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
675 echo "<td width=\"33.3%\"> </td>\n";
676 echo "<td width=\"33.3%\" align=\"center\">\n";
677 $installoptions = array();
678 $installoptions['download'] = 1;
679 print_single_button("install.php", $installoptions, get_string('download', 'install'));
681 echo "<td width=\"33.3%\" align=\"right\">\n";
682 print_single_button("index.php", $options, get_string('continue'));
688 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
695 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
696 form_table($nextstage, $formaction);
724 //==========================================================================//
726 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
727 global $INSTALL, $db;
729 /// Print the standard form if we aren't in the DOWNLOADLANG page
730 /// because it has its own form.
731 if ($nextstage != DOWNLOADLANG
) {
732 $needtoopenform = false;
734 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
735 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
739 $needtoopenform = true;
742 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
745 /// what we do depends on the stage we're at
746 switch ($nextstage) {
747 case WELCOME
: /// Welcome and language settings
750 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
751 <td
class="td_right">
752 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
758 case COMPATIBILITY
: /// Compatibilty check
759 $compatsuccess = true;
761 /// Check that PHP is of a sufficient version
762 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
763 /// Check session auto start
764 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
765 /// Check magic quotes
766 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
767 /// Check unsupported PHP configuration
768 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
770 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
771 /// Check file uploads
772 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
774 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
775 /// Check memory limit
776 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
780 case DIRECTORY
: /// Directory settings
784 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
785 <td
class="td_right">
786 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
790 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
791 <td
class="td_right">
792 <input type
="text" size
="40" name
="dirrootform" disabled
="disabled" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
796 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
797 <td
class="td_right">
798 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
804 case DATABASE
: /// Database settings
808 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
809 <td
class="td_right">
810 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
811 'mysqli' => get_string('mysqli', 'install'),
812 'oci8po' => get_string('oci8po', 'install'),
813 'postgres7' => get_string('postgres7', 'install'),
814 'mssql' => get_string('mssql', 'install'),
815 'mssql_n' => get_string('mssql_n', 'install'),
816 'odbc_mssql' => get_string('odbc_mssql', 'install')),
817 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
821 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
822 <td
class="td_right">
823 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
827 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
828 <td
class="td_right">
829 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
833 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
834 <td
class="td_right">
835 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
839 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
840 <td
class="td_right">
841 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
845 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
846 <td
class="td_right">
847 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
853 case ADMIN
: /// Administration directory setting
857 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
858 <td
class="td_right">
859 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
866 case ENVIRONMENT
: /// Environment checks
872 error_reporting(0); // Hide errors
873 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
874 error_reporting(7); // Show errors
876 /// Execute environment check, printing results
877 check_moodle_environment($INSTALL['release'], $environment_results, true);
879 /// We never should reach this because DB has been tested before arriving here
880 $errormsg = get_string('dbconnectionerror', 'install');
881 $nextstage = DATABASE
;
882 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
890 case DOWNLOADLANG
: /// Download language from download.moodle.org
896 /// Get array of languages, we are going to use it
897 $languages=get_installer_list_of_languages();
898 /// Print the download form (button) if necessary
899 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
901 $options['downloadlangpack'] = true;
902 $options['stage'] = DOWNLOADLANG
;
903 $options['same'] = true;
904 print_simple_box_start('center');
905 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
906 print_simple_box_end();
909 /// English lang packs aren't downloaded
910 if (substr($INSTALL['language'],0,2) == 'en') {
911 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
913 if ($INSTALL['downloadlangpackerror']) {
914 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
915 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
917 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
932 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
935 if ($needtoopenform) {
937 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
938 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
943 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: ".fix_align_rtl("right")."\"/>\n" : " \n" ?
>
944 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/>\n" : " \n" ?
>
947 if ($needtoopenform) {
961 if (!$needtoopenform) {
973 //==========================================================================//
975 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
977 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
979 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
980 echo "<td valign=\"top\"> </td>\n";
982 echo "<td valign=\"top\"";
983 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
985 echo "<td valign=\"top\">";
986 echo "<p>$errormessage ";
987 install_helpbutton("install.php?help=$helpfield");
995 //==========================================================================//
997 function install_helpbutton($url, $title='') {
999 $title = get_string('help');
1001 echo "<a href=\"javascript: void(0)\">";
1002 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
1003 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1009 //==========================================================================//
1011 function print_install_help($help) {
1013 case 'phpversionhelp':
1014 print_string($help, 'install', phpversion());
1016 case 'memorylimithelp':
1017 print_string($help, 'install', get_memory_limit());
1020 print_string($help, 'install');
1025 //==========================================================================//
1027 function get_memory_limit() {
1028 if ($limit = ini_get('memory_limit')) {
1031 return get_cfg_var('memory_limit');
1035 //==========================================================================//
1037 function check_memory_limit() {
1039 /// if limit is already 40 or more then we don't care if we can change it or not
1040 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1044 /// Otherwise, see if we can change it ourselves
1045 @ini_set
('memory_limit', '40M');
1046 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1049 //==========================================================================//
1051 function inst_check_php_version() {
1052 if (!check_php_version("4.3.0")) {
1054 } else if (check_php_version("5.0.0")) {
1055 return check_php_version("5.1.0"); // 5.0.x is too buggy
1057 return true; // 4.3.x or 4.4.x is fine
1059 //==========================================================================//
1061 /* This function returns a list of languages and their full names. The
1062 * list of available languages is fetched from install/lang/xx/installer.php
1063 * and it's used exclusively by the installation process
1064 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1066 function get_installer_list_of_languages() {
1070 $languages = array();
1072 /// Get raw list of lang directories
1073 $langdirs = get_list_of_plugins('install/lang');
1075 /// Get some info from each lang
1076 foreach ($langdirs as $lang) {
1077 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1078 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1079 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1080 $shortlang = substr($lang, 0, -5);
1084 if ($lang == 'en') { //Explain this is non-utf8 en
1085 $shortlang = 'non-utf8 en';
1087 if (!empty($string['thislanguage'])) {
1088 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1097 //==========================================================================//
1099 function css_styles() {
1102 <style type
="text/css">
1104 body
{ background
-color
: #ffeece; }
1106 font
-family
: helvetica
, arial
, sans
-serif
;
1109 a
{ text
-decoration
: none
; color
: blue
; }
1118 font
-family
: courier
, monospace
;
1125 text
-align
: <?php
echo fix_align_rtl("right") ?
>;
1129 text
-align
: <?php
echo fix_align_rtl("left") ?
>;
1134 border
-style
: solid
;
1135 border
-color
: #ffc85f;
1136 -moz
-border
-radius
-bottomleft
: 15px
;
1137 -moz
-border
-radius
-bottomright
: 15px
;
1140 background
-color
: #fee6b9;
1176 font
-family
: helvetica
, arial
, sans
-serif
;
1183 border
-color
: #ffc85f;
1185 table
.environmenttable
.error
{
1186 background
-color
: red
;
1190 table
.environmenttable
.warn
{
1191 background
-color
: yellow
;
1194 table
.environmenttable
.ok
{
1195 background
-color
: lightgreen
;
1198 background
-color
: #fee6b9;
1202 background
-color
: #ffeece;
1214 .invisiblefieldset
{
1220 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1229 //==========================================================================//
1231 function database_js() {
1234 <script type
="text/javascript" defer
="defer">
1235 function toggledbinfo() {
1236 //Calculate selected value
1237 var showid
= 'mysql';
1238 if (document
.getElementById('installform').dbtype
.value
) {
1239 showid
= document
.getElementById('installform').dbtype
.value
;
1241 if (document
.getElementById
) {
1243 document
.getElementById('mysql').style
.display
= '';
1244 document
.getElementById('mysqli').style
.display
= '';
1245 document
.getElementById('postgres7').style
.display
= '';
1246 document
.getElementById('mssql').style
.display
= '';
1247 document
.getElementById('mssql_n').style
.display
= '';
1248 document
.getElementById('odbc_mssql').style
.display
= '';
1249 document
.getElementById('oci8po').style
.display
= '';
1250 //Show the selected div
1251 document
.getElementById(showid
).style
.display
= 'block';
1252 } else if (document
.all
) {
1253 //This is the way old msie versions work
1255 document
.all
['mysql'].style
.display
= '';
1256 document
.all
['mysqli'].style
.display
= '';
1257 document
.all
['postgres7'].style
.display
= '';
1258 document
.all
['mssql'].style
.display
= '';
1259 document
.all
['mssql_n'].style
.display
= '';
1260 document
.all
['odbc_mssql'].style
.display
= '';
1261 document
.all
['oci8po'].style
.display
= '';
1262 //Show the selected div
1263 document
.all
[showid
].style
.display
= 'block';
1264 } else if (document
.layers
) {
1265 //This is the way nn4 works
1267 document
.layers
['mysql'].style
.display
= '';
1268 document
.layers
['mysqli'].style
.display
= '';
1269 document
.layers
['postgres7'].style
.display
= '';
1270 document
.layers
['mssql'].style
.display
= '';
1271 document
.layers
['mssql_n'].style
.display
= '';
1272 document
.layers
['odbc_mssql'].style
.display
= '';
1273 document
.layers
['oci8po'].style
.display
= '';
1274 //Show the selected div
1275 document
.layers
[showid
].style
.display
= 'block';