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'] == 'mysqli') { /// Check MySQLi extension is present
286 if (!extension_loaded('mysqli')) {
287 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
288 $nextstage = DATABASE
;
292 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
293 if (!extension_loaded('pgsql')) {
294 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
295 $nextstage = DATABASE
;
299 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
300 if (!function_exists('mssql_connect')) {
301 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
302 $nextstage = DATABASE
;
306 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
307 if (!function_exists('mssql_connect')) {
308 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
309 $nextstage = DATABASE
;
313 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
314 if (!extension_loaded('odbc')) {
315 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
316 $nextstage = DATABASE
;
320 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
321 if (!extension_loaded('oci8')) {
322 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
323 $nextstage = DATABASE
;
327 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
328 $errormsg = get_string('dbwrongprefix', 'install');
329 $nextstage = DATABASE
;
332 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
333 $errormsg = get_string('dbwrongprefix', 'install');
334 $nextstage = DATABASE
;
337 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
338 $errormsg = get_string('dbwronghostserver', 'install');
339 $nextstage = DATABASE
;
342 if (empty($errormsg)) {
344 error_reporting(0); // Hide errors
346 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
347 /// The following doesn't seem to work but we're working on it
348 /// If you come up with a solution for creating a database in MySQL
349 /// feel free to put it in and let us know
350 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
351 switch ($INSTALL['dbtype']) { /// Try to create a database
354 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
355 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
357 $errormsg = get_string('dbcreationerror', 'install');
358 $nextstage = DATABASE
;
364 /// We have been able to connect properly, just test the database encoding now.
365 /// It must be Unicode for 1.8 installations.
367 switch ($INSTALL['dbtype']) {
370 /// Get MySQL character_set_database value
371 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
372 if ($rs && $rs->RecordCount() > 0) {
373 $records = $rs->GetAssoc(true);
374 $encoding = $records['character_set_database']['Value'];
375 if (strtoupper($encoding) != 'UTF8') {
376 /// Try to set the encoding now!
377 if (! $db->Metatables()) { // We have no tables so go ahead
378 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
379 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
383 /// If conversion fails, skip, let environment testing do the job
387 /// Skip, let environment testing do the job
390 /// Skip, let environment testing do the job
398 if (($dbconnected === false) and (empty($errormsg)) ) {
399 $errormsg = get_string('dbconnectionerror', 'install');
400 $nextstage = DATABASE
;
406 //==========================================================================//
408 /// If the next stage is admin directory settings OR we have just come from there then
409 /// check the admin directory.
410 /// If we can open a file then we know that the admin name is correct.
412 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
413 if (!ini_get('allow_url_fopen')) {
414 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
415 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
416 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
419 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
420 //if ($nextstage != ADMIN) {
421 // $errormsg = get_string('admindirerror', 'install');
422 // $nextstage = ADMIN;
427 //==========================================================================//
429 // Check if we can navigate from the environemt page (because it's ok)
431 if ($INSTALL['stage'] == ENVIRONMENT
) {
432 error_reporting(0); // Hide errors
433 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
434 error_reporting(7); // Show errors
436 /// Execute environment check, printing results
437 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
438 $nextstage = ENVIRONMENT
;
441 /// We never should reach this because DB has been tested before arriving here
442 $errormsg = get_string('dbconnectionerror', 'install');
443 $nextstage = DATABASE
;
449 //==========================================================================//
451 // Try to download the lang pack if it has been selected
453 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
455 $downloadsuccess = false;
458 error_reporting(0); // Hide errors
460 /// Create necessary lang dir
461 if (!make_upload_directory('lang', false)) {
462 $downloaderror = get_string('cannotcreatelangdir', 'error');
465 /// Download and install component
466 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
467 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
468 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
471 if ($cd->get_error() == 'remotedownloadnotallowed') {
473 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'.zip';
474 $a->dest
= $CFG->dataroot
.'/lang';
475 $downloaderror = get_string($cd->get_error(), 'error', $a);
477 $downloaderror = get_string($cd->get_error(), 'error');
482 $downloadsuccess = true;
485 //We shouldn't reach this point
488 //We shouldn't reach this point
491 error_reporting(7); // Show errors
493 if ($downloadsuccess) {
494 $INSTALL['downloadlangpack'] = false;
495 $INSTALL['showdownloadlangpack'] = false;
496 $INSTALL['downloadlangpackerror'] = $downloaderror;
498 $INSTALL['downloadlangpack'] = false;
499 $INSTALL['showdownloadlangpack'] = false;
500 $INSTALL['downloadlangpackerror'] = $downloaderror;
506 //==========================================================================//
508 /// Display or print the data
509 /// Put the data into a string
510 /// Try to open config file for writing.
512 if ($nextstage == SAVE
) {
514 $str = '<?php /// Moodle Configuration File '."\r\n";
517 $str .= 'unset($CFG);'."\r\n";
520 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
521 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
522 if (!empty($INSTALL['dbname'])) {
523 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
524 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
525 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
527 $str .= '$CFG->dbpersist = false;'."\r\n";
528 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
531 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
532 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
533 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
534 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
537 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
540 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
541 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
542 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
547 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
553 $INSTALL['config'] = $str;
558 //==========================================================================//
561 <html dir
="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
563 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
564 <title
>Moodle Install
</title
>
565 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
566 <?php
css_styles() ?
>
567 <?php
database_js() ?
>
575 if (isset($_GET['help'])) {
576 print_install_help($_GET['help']);
577 close_window_button();
582 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
584 <td
class="td_mainlogo">
585 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
587 <td
class="td_mainlogo" valign
="bottom">
588 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
593 <td
class="td_mainheading" colspan
="2">
594 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
595 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
596 /// from the standard one to show better instructions for each DB
597 if ($nextstage == DATABASE
) {
598 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
599 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install') . '</div>';
601 echo '<div id="mysqli" name="mysqli">' . get_string('databasesettingssub_mysqli', 'install') . '</div>';
603 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
605 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
606 /// Link to mssql installation page
607 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
608 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
609 echo get_string('moodledocslink', 'install') . '</a></p>';
612 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
613 /// Link to mssql installation page
614 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
615 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
616 echo get_string('moodledocslink', 'install') . '</a></p>';
619 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
620 /// Link to mssql installation page
621 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
622 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
623 echo get_string('moodledocslink', 'install') . '</a></p>';
626 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
627 /// Link to oracle installation page
628 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
629 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
630 echo get_string('moodledocslink', 'install') . '</a></p>';
633 if (!empty($substagetext[$nextstage])) {
634 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
642 <td
class="td_main" colspan
="2">
646 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
649 if ($nextstage == SAVE
) {
650 $INSTALL['stage'] = WELCOME
;
652 $options['lang'] = $INSTALL['language'];
653 if ($configsuccess) {
654 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
656 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
658 echo "<td width=\"33.3%\"> </td>\n";
659 echo "<td width=\"33.3%\"> </td>\n";
660 echo "<td width=\"33.3%\" align=\"right\">\n";
661 print_single_button("index.php", $options, get_string('continue'));
667 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
669 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
671 echo "<td width=\"33.3%\"> </td>\n";
672 echo "<td width=\"33.3%\" align=\"center\">\n";
673 $installoptions = array();
674 $installoptions['download'] = 1;
675 print_single_button("install.php", $installoptions, get_string('download', 'install'));
677 echo "<td width=\"33.3%\" align=\"right\">\n";
678 print_single_button("index.php", $options, get_string('continue'));
684 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
691 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
692 form_table($nextstage, $formaction);
720 //==========================================================================//
722 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
723 global $INSTALL, $db;
725 /// Print the standard form if we aren't in the DOWNLOADLANG page
726 /// because it has its own form.
727 if ($nextstage != DOWNLOADLANG
) {
728 $needtoopenform = false;
730 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
731 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
735 $needtoopenform = true;
738 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
741 /// what we do depends on the stage we're at
742 switch ($nextstage) {
743 case WELCOME
: /// Welcome and language settings
746 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
747 <td
class="td_right">
748 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
754 case COMPATIBILITY
: /// Compatibilty check
755 $compatsuccess = true;
757 /// Check that PHP is of a sufficient version
758 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
759 /// Check session auto start
760 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
761 /// Check magic quotes
762 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
763 /// Check unsupported PHP configuration
764 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
766 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
767 /// Check file uploads
768 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
770 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
771 /// Check memory limit
772 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
776 case DIRECTORY
: /// Directory settings
780 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
781 <td
class="td_right">
782 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
786 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
787 <td
class="td_right">
788 <input type
="text" size
="40" name
="dirrootform" disabled
="disabled" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
792 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
793 <td
class="td_right">
794 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
800 case DATABASE
: /// Database settings
804 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
805 <td
class="td_right">
806 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
807 'mysqli' => get_string('mysqli', 'install'),
808 'oci8po' => get_string('oci8po', 'install'),
809 'postgres7' => get_string('postgres7', 'install'),
810 'mssql' => get_string('mssql', 'install'),
811 'mssql_n' => get_string('mssql_n', 'install'),
812 'odbc_mssql' => get_string('odbc_mssql', 'install')),
813 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
817 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
818 <td
class="td_right">
819 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
823 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
824 <td
class="td_right">
825 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
829 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
830 <td
class="td_right">
831 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
835 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
836 <td
class="td_right">
837 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
841 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
842 <td
class="td_right">
843 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
849 case ADMIN
: /// Administration directory setting
853 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
854 <td
class="td_right">
855 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
862 case ENVIRONMENT
: /// Environment checks
868 error_reporting(0); // Hide errors
869 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
870 error_reporting(7); // Show errors
872 /// Execute environment check, printing results
873 check_moodle_environment($INSTALL['release'], $environment_results, true);
875 /// We never should reach this because DB has been tested before arriving here
876 $errormsg = get_string('dbconnectionerror', 'install');
877 $nextstage = DATABASE
;
878 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
886 case DOWNLOADLANG
: /// Download language from download.moodle.org
892 /// Get array of languages, we are going to use it
893 $languages=get_installer_list_of_languages();
894 /// Print the download form (button) if necessary
895 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
897 $options['downloadlangpack'] = true;
898 $options['stage'] = DOWNLOADLANG
;
899 $options['same'] = true;
900 print_simple_box_start('center');
901 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
902 print_simple_box_end();
905 /// English lang packs aren't downloaded
906 if (substr($INSTALL['language'],0,2) == 'en') {
907 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
909 if ($INSTALL['downloadlangpackerror']) {
910 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
911 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
913 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
928 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
931 if ($needtoopenform) {
933 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
934 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
939 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: ".fix_align_rtl("right")."\"/>\n" : " \n" ?
>
940 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/>\n" : " \n" ?
>
943 if ($needtoopenform) {
957 if (!$needtoopenform) {
969 //==========================================================================//
971 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
973 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
975 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
976 echo "<td valign=\"top\"> </td>\n";
978 echo "<td valign=\"top\"";
979 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
981 echo "<td valign=\"top\">";
982 echo "<p>$errormessage ";
983 install_helpbutton("install.php?help=$helpfield");
991 //==========================================================================//
993 function install_helpbutton($url, $title='') {
995 $title = get_string('help');
997 echo "<a href=\"javascript: void(0)\">";
998 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
999 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1005 //==========================================================================//
1007 function print_install_help($help) {
1009 case 'phpversionhelp':
1010 print_string($help, 'install', phpversion());
1012 case 'memorylimithelp':
1013 print_string($help, 'install', get_memory_limit());
1016 print_string($help, 'install');
1021 //==========================================================================//
1023 function get_memory_limit() {
1024 if ($limit = ini_get('memory_limit')) {
1027 return get_cfg_var('memory_limit');
1031 //==========================================================================//
1033 function check_memory_limit() {
1035 /// if limit is already 40 or more then we don't care if we can change it or not
1036 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1040 /// Otherwise, see if we can change it ourselves
1041 @ini_set
('memory_limit', '40M');
1042 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1045 //==========================================================================//
1047 function inst_check_php_version() {
1048 if (!check_php_version("4.3.0")) {
1050 } else if (check_php_version("5.0.0")) {
1051 return check_php_version("5.1.0"); // 5.0.x is too buggy
1053 return true; // 4.3.x or 4.4.x is fine
1055 //==========================================================================//
1057 /* This function returns a list of languages and their full names. The
1058 * list of available languages is fetched from install/lang/xx/installer.php
1059 * and it's used exclusively by the installation process
1060 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1062 function get_installer_list_of_languages() {
1066 $languages = array();
1068 /// Get raw list of lang directories
1069 $langdirs = get_list_of_plugins('install/lang');
1071 /// Get some info from each lang
1072 foreach ($langdirs as $lang) {
1073 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1074 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1075 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1076 $shortlang = substr($lang, 0, -5);
1080 if ($lang == 'en') { //Explain this is non-utf8 en
1081 $shortlang = 'non-utf8 en';
1083 if (!empty($string['thislanguage'])) {
1084 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1093 //==========================================================================//
1095 function css_styles() {
1098 <style type
="text/css">
1100 body
{ background
-color
: #ffeece; }
1102 font
-family
: helvetica
, arial
, sans
-serif
;
1105 a
{ text
-decoration
: none
; color
: blue
; }
1114 font
-family
: courier
, monospace
;
1121 text
-align
: <?php
echo fix_align_rtl("right") ?
>;
1125 text
-align
: <?php
echo fix_align_rtl("left") ?
>;
1130 border
-style
: solid
;
1131 border
-color
: #ffc85f;
1132 -moz
-border
-radius
-bottomleft
: 15px
;
1133 -moz
-border
-radius
-bottomright
: 15px
;
1136 background
-color
: #fee6b9;
1172 font
-family
: helvetica
, arial
, sans
-serif
;
1179 border
-color
: #ffc85f;
1181 table
.environmenttable
.error
{
1182 background
-color
: red
;
1186 table
.environmenttable
.warn
{
1187 background
-color
: yellow
;
1190 table
.environmenttable
.ok
{
1191 background
-color
: lightgreen
;
1194 background
-color
: #fee6b9;
1198 background
-color
: #ffeece;
1210 .invisiblefieldset
{
1216 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1225 //==========================================================================//
1227 function database_js() {
1230 <script type
="text/javascript" defer
="defer">
1231 function toggledbinfo() {
1232 //Calculate selected value
1233 var showid
= 'mysql';
1234 if (document
.getElementById('installform').dbtype
.value
) {
1235 showid
= document
.getElementById('installform').dbtype
.value
;
1237 if (document
.getElementById
) {
1239 document
.getElementById('mysql').style
.display
= '';
1240 document
.getElementById('mysqli').style
.display
= '';
1241 document
.getElementById('postgres7').style
.display
= '';
1242 document
.getElementById('mssql').style
.display
= '';
1243 document
.getElementById('mssql_n').style
.display
= '';
1244 document
.getElementById('odbc_mssql').style
.display
= '';
1245 document
.getElementById('oci8po').style
.display
= '';
1246 //Show the selected div
1247 document
.getElementById(showid
).style
.display
= 'block';
1248 } else if (document
.all
) {
1249 //This is the way old msie versions work
1251 document
.all
['mysql'].style
.display
= '';
1252 document
.all
['mysqli'].style
.display
= '';
1253 document
.all
['postgres7'].style
.display
= '';
1254 document
.all
['mssql'].style
.display
= '';
1255 document
.all
['mssql_n'].style
.display
= '';
1256 document
.all
['odbc_mssql'].style
.display
= '';
1257 document
.all
['oci8po'].style
.display
= '';
1258 //Show the selected div
1259 document
.all
[showid
].style
.display
= 'block';
1260 } else if (document
.layers
) {
1261 //This is the way nn4 works
1263 document
.layers
['mysql'].style
.display
= '';
1264 document
.layers
['mysqli'].style
.display
= '';
1265 document
.layers
['postgres7'].style
.display
= '';
1266 document
.layers
['mssql'].style
.display
= '';
1267 document
.layers
['mssql_n'].style
.display
= '';
1268 document
.layers
['odbc_mssql'].style
.display
= '';
1269 document
.layers
['oci8po'].style
.display
= '';
1270 //Show the selected div
1271 document
.layers
[showid
].style
.display
= 'block';