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 $gpc = ini_get('magic_quotes_gpc');
97 $gpc = ($gpc == '1' or strtolower($gpc) == 'on');
99 /// Store any posted data
100 foreach ($_POST as $setting=>$value) {
102 $value = stripslashes($value);
105 $INSTALL[$setting] = $value;
108 if ( $goforward = (! empty( $_POST['next'] )) ) {
109 $nextstage = $_POST['stage'] +
1;
110 } else if (! empty( $_POST['prev'])) {
111 $nextstage = $_POST['stage'] - 1;
112 $INSTALL['stage'] = $_POST['stage'] - 1;
113 } else if (! empty( $_POST['same'] )) {
114 $nextstage = $_POST['stage'];
117 $nextstage = (int)$nextstage;
119 if ($nextstage < 0) {
120 $nextstage = WELCOME
;
127 $nextstage = WELCOME
;
131 //==========================================================================//
133 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
135 $SESSION->lang
= (!empty($_POST['language'])) ?
$_POST['language'] : $INSTALL['language'];
136 $CFG->dirroot
= $INSTALL['dirroot'];
137 $CFG->libdir
= $INSTALL['dirroot'].'/lib';
138 $CFG->dataroot
= $INSTALL['dataroot'];
139 $CFG->admin
= $INSTALL['admindirname'];
140 $CFG->directorypermissions
= 00777;
141 $CFG->running_installer
= true;
142 $CFG->docroot
= 'http://docs.moodle.org';
145 /// Include some moodle libraries
147 require_once($CFG->libdir
.'/adminlib.php');
148 require_once($CFG->libdir
.'/setuplib.php');
149 require_once($CFG->libdir
.'/moodlelib.php');
150 require_once($CFG->libdir
.'/weblib.php');
151 require_once($CFG->libdir
.'/deprecatedlib.php');
152 require_once($CFG->libdir
.'/adodb/adodb.inc.php');
153 require_once($CFG->libdir
.'/environmentlib.php');
154 require_once($CFG->libdir
.'/xmlize.php');
155 require_once($CFG->libdir
.'/componentlib.class.php');
156 require_once($CFG->dirroot
.'/version.php');
158 /// Set version and release
159 $INSTALL['version'] = $version;
160 $INSTALL['release'] = $release;
162 /// Have the $db object ready because we are going to use it often
163 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
164 $db = &ADONewConnection($INSTALL['dbtype']);
165 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
167 /// guess the www root
168 if ($INSTALL['wwwroot'] == '') {
169 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
170 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
172 // now try to guess the correct dataroot not accessible via web
173 $CFG->wwwroot
= $INSTALL['wwwroot'];
174 $i = 0; //safety check - dirname might return some unexpected results
175 while(is_dataroot_insecure()) {
176 $parrent = dirname($CFG->dataroot
);
178 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
179 $CFG->dataroot
= ''; //can not find secure location for dataroot
182 $CFG->dataroot
= dirname($parrent).'/moodledata';
184 $INSTALL['dataroot'] = $CFG->dataroot
;
187 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
188 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
189 DIRECTORY
=> get_string('directorysettingshead', 'install'),
190 DATABASE
=> get_string('databasesettingshead', 'install'),
191 ADMIN
=> get_string('admindirsettinghead', 'install'),
192 ENVIRONMENT
=> get_string('environmenthead', 'install'),
193 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
194 SAVE
=> get_string('configurationcompletehead', 'install')
197 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
198 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
199 DIRECTORY
=> get_string('directorysettingssub', 'install'),
200 DATABASE
=> get_string('databasesettingssub', 'install'),
201 ADMIN
=> get_string('admindirsettingsub', 'install'),
202 ENVIRONMENT
=> get_string('environmentsub', 'install'),
203 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
204 SAVE
=> get_string('configurationcompletesub', 'install')
209 //==========================================================================//
211 /// Are we in help mode?
213 if (isset($_GET['help'])) {
219 //==========================================================================//
221 /// Are we in config download mode?
223 if (isset($_GET['download'])) {
224 header("Content-Type: application/x-forcedownload\n");
225 header("Content-Disposition: attachment; filename=\"config.php\"");
226 echo $INSTALL['config'];
234 //==========================================================================//
236 /// Check the directory settings
238 if ($INSTALL['stage'] == DIRECTORY
) {
243 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
244 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
245 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
246 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
249 if ($fh) fclose($fh);
252 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
253 $errormsg .= get_string('dirrooterror', 'install').'<br />';
254 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
256 if ($fh) fclose($fh);
259 $CFG->dataroot
= $INSTALL['dataroot'];
260 if (make_upload_directory('sessions', false) === false ) {
261 $errormsg .= get_string('datarooterror', 'install').'<br />';
263 if ($fh) fclose($fh);
265 if (!empty($errormsg)) $nextstage = DIRECTORY
;
272 //==========================================================================//
274 /// Check database settings if stage 3 data submitted
275 /// Try to connect to the database. If that fails then try to create the database
277 if ($INSTALL['stage'] == DATABASE
) {
279 /// different format for postgres7 by socket
280 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
281 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
282 $INSTALL['dbuser'] = '';
283 $INSTALL['dbpass'] = '';
284 $INSTALL['dbname'] = '';
286 if ($INSTALL['prefix'] == '') { /// must have a prefix
287 $INSTALL['prefix'] = 'mdl_';
291 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
292 if (!extension_loaded('mysql')) {
293 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
294 $nextstage = DATABASE
;
298 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
299 if (!extension_loaded('mysqli')) {
300 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
301 $nextstage = DATABASE
;
305 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
306 if (!extension_loaded('pgsql')) {
307 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
308 $nextstage = DATABASE
;
312 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
313 if (!function_exists('mssql_connect')) {
314 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
315 $nextstage = DATABASE
;
319 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
320 if (!function_exists('mssql_connect')) {
321 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
322 $nextstage = DATABASE
;
326 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
327 if (!extension_loaded('odbc')) {
328 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
329 $nextstage = DATABASE
;
333 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
334 if (!extension_loaded('oci8')) {
335 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
336 $nextstage = DATABASE
;
340 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
341 $errormsg = get_string('dbwrongprefix', 'install');
342 $nextstage = DATABASE
;
345 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
346 $errormsg = get_string('dbwrongprefix', 'install');
347 $nextstage = DATABASE
;
350 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
351 $errormsg = get_string('dbwronghostserver', 'install');
352 $nextstage = DATABASE
;
355 if (empty($errormsg)) {
357 error_reporting(0); // Hide errors
359 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
360 $db->database
= ''; // reset database name cached by ADODB. Trick from MDL-9609
361 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
362 switch ($INSTALL['dbtype']) { /// Try to create a database
365 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
366 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
368 $errormsg = get_string('dbcreationerror', 'install');
369 $nextstage = DATABASE
;
375 /// We have been able to connect properly, just test the database encoding now.
376 /// It must be Unicode for 1.8 installations.
378 switch ($INSTALL['dbtype']) {
381 /// Get MySQL character_set_database value
382 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
383 if ($rs && !$rs->EOF
) {
384 $records = $rs->GetAssoc(true);
385 $encoding = $records['character_set_database']['Value'];
386 if (strtoupper($encoding) != 'UTF8') {
387 /// Try to set the encoding now!
388 if (! $db->Metatables()) { // We have no tables so go ahead
389 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
390 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
394 /// If conversion fails, skip, let environment testing do the job
398 /// Skip, let environment testing do the job
401 /// Skip, let environment testing do the job
409 if (($dbconnected === false) and (empty($errormsg)) ) {
410 $errormsg = get_string('dbconnectionerror', 'install');
411 $nextstage = DATABASE
;
417 //==========================================================================//
419 /// If the next stage is admin directory settings OR we have just come from there then
420 /// check the admin directory.
421 /// If we can open a file then we know that the admin name is correct.
423 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
424 if (!ini_get('allow_url_fopen')) {
425 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
426 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
427 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
430 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
431 //if ($nextstage != ADMIN) {
432 // $errormsg = get_string('admindirerror', 'install');
433 // $nextstage = ADMIN;
438 //==========================================================================//
440 // Check if we can navigate from the environemt page (because it's ok)
442 if ($INSTALL['stage'] == ENVIRONMENT
) {
443 error_reporting(0); // Hide errors
444 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
445 error_reporting(7); // Show errors
447 /// Execute environment check, printing results
448 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
449 $nextstage = ENVIRONMENT
;
452 /// We never should reach this because DB has been tested before arriving here
453 $errormsg = get_string('dbconnectionerror', 'install');
454 $nextstage = DATABASE
;
460 //==========================================================================//
462 // Try to download the lang pack if it has been selected
464 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
466 $downloadsuccess = false;
469 error_reporting(0); // Hide errors
471 /// Create necessary lang dir
472 if (!make_upload_directory('lang', false)) {
473 $downloaderror = get_string('cannotcreatelangdir', 'error');
476 /// Download and install component
477 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
478 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
479 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
481 case COMPONENT_ERROR
:
482 if ($cd->get_error() == 'remotedownloaderror') {
484 $a->url
= 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip';
485 $a->dest
= $CFG->dataroot
.'/lang';
486 $downloaderror = get_string($cd->get_error(), 'error', $a);
488 $downloaderror = get_string($cd->get_error(), 'error');
491 case COMPONENT_UPTODATE
:
492 case COMPONENT_INSTALLED
:
493 $downloadsuccess = true;
496 //We shouldn't reach this point
499 //We shouldn't reach this point
502 error_reporting(7); // Show errors
504 if ($downloadsuccess) {
505 $INSTALL['downloadlangpack'] = false;
506 $INSTALL['showdownloadlangpack'] = false;
507 $INSTALL['downloadlangpackerror'] = $downloaderror;
509 $INSTALL['downloadlangpack'] = false;
510 $INSTALL['showdownloadlangpack'] = false;
511 $INSTALL['downloadlangpackerror'] = $downloaderror;
517 //==========================================================================//
519 /// Display or print the data
520 /// Put the data into a string
521 /// Try to open config file for writing.
523 if ($nextstage == SAVE
) {
525 $str = '<?php /// Moodle Configuration File '."\r\n";
528 $str .= 'unset($CFG);'."\r\n";
531 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
532 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
533 if (!empty($INSTALL['dbname'])) {
534 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
535 // support single quotes in db user/passwords
536 $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
537 $str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
539 $str .= '$CFG->dbpersist = false;'."\r\n";
540 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
543 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
544 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
545 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
546 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
549 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
552 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
553 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
554 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
559 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
565 $INSTALL['config'] = $str;
570 //==========================================================================//
573 <html dir
="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
575 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
576 <title
>Moodle Install
</title
>
577 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
578 <?php
css_styles() ?
>
579 <?php
database_js() ?
>
587 if (isset($_GET['help'])) {
588 print_install_help($_GET['help']);
589 close_window_button();
594 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
596 <td
class="td_mainlogo">
597 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
599 <td
class="td_mainlogo" valign
="bottom">
600 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
605 <td
class="td_mainheading" colspan
="2">
606 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
607 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
608 /// from the standard one to show better instructions for each DB
609 if ($nextstage == DATABASE
) {
610 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
611 echo '<div id="mysql" name="mysql">' . get_string('databasesettingssub_mysql', 'install');
612 echo '<p align="center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
615 echo '<div id="mysqli" name="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
616 echo '<p align="center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
619 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
621 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
622 /// Link to mssql installation page
623 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
624 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
625 echo get_string('moodledocslink', 'install') . '</a></p>';
628 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
629 /// Link to mssql installation page
630 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
631 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
632 echo get_string('moodledocslink', 'install') . '</a></p>';
635 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
636 /// Link to mssql installation page
637 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
638 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
639 echo get_string('moodledocslink', 'install') . '</a></p>';
642 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
643 /// Link to oracle installation page
644 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
645 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
646 echo get_string('moodledocslink', 'install') . '</a></p>';
649 if (!empty($substagetext[$nextstage])) {
650 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
658 <td
class="td_main" colspan
="2">
662 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
665 if ($nextstage == SAVE
) {
666 $INSTALL['stage'] = WELCOME
;
668 $options['lang'] = $INSTALL['language'];
669 if ($configsuccess) {
670 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
672 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
674 echo "<td width=\"33.3%\"> </td>\n";
675 echo "<td width=\"33.3%\"> </td>\n";
676 echo "<td width=\"33.3%\" align=\"right\">\n";
677 print_single_button("index.php", $options, get_string('continue'));
683 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
685 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
687 echo "<td width=\"33.3%\"> </td>\n";
688 echo "<td width=\"33.3%\" align=\"center\">\n";
689 $installoptions = array();
690 $installoptions['download'] = 1;
691 print_single_button("install.php", $installoptions, get_string('download', 'install'));
693 echo "<td width=\"33.3%\" align=\"right\">\n";
694 print_single_button("index.php", $options, get_string('continue'));
700 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
707 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
708 form_table($nextstage, $formaction);
736 //==========================================================================//
738 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
739 global $INSTALL, $db;
741 /// Print the standard form if we aren't in the DOWNLOADLANG page
742 /// because it has its own form.
743 if ($nextstage != DOWNLOADLANG
) {
744 $needtoopenform = false;
746 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
747 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
751 $needtoopenform = true;
754 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
757 /// what we do depends on the stage we're at
758 switch ($nextstage) {
759 case WELCOME
: /// Welcome and language settings
762 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
763 <td
class="td_right">
764 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
770 case COMPATIBILITY
: /// Compatibilty check
771 $compatsuccess = true;
773 /// Check that PHP is of a sufficient version
774 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
775 /// Check session auto start
776 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
777 /// Check magic quotes
778 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
779 /// Check unsupported PHP configuration
780 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
782 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
783 /// Check file uploads
784 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
786 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
787 /// Check memory limit
788 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
792 case DIRECTORY
: /// Directory settings
796 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
797 <td
class="td_right">
798 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
802 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
803 <td
class="td_right">
804 <input type
="text" size
="40" name
="dirrootform" disabled
="disabled" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
808 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
809 <td
class="td_right">
810 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
816 case DATABASE
: /// Database settings
820 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
821 <td
class="td_right">
822 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
823 'mysqli' => get_string('mysqli', 'install'),
824 'oci8po' => get_string('oci8po', 'install'),
825 'postgres7' => get_string('postgres7', 'install'),
826 'mssql' => get_string('mssql', 'install'),
827 'mssql_n' => get_string('mssql_n', 'install'),
828 'odbc_mssql' => get_string('odbc_mssql', 'install')),
829 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
833 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
834 <td
class="td_right">
835 <input type
="text" size
="40" name
="dbhost" value
="<?php p($INSTALL['dbhost']) ?>" />
839 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
840 <td
class="td_right">
841 <input type
="text" size
="40" name
="dbname" value
="<?php p($INSTALL['dbname']) ?>" />
845 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
846 <td
class="td_right">
847 <input type
="text" size
="40" name
="dbuser" value
="<?php p($INSTALL['dbuser']) ?>" />
851 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
852 <td
class="td_right">
853 <input type
="password" size
="40" name
="dbpass" value
="<?php p($INSTALL['dbpass']) ?>" />
857 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
858 <td
class="td_right">
859 <input type
="text" size
="40" name
="prefix" value
="<?php p($INSTALL['prefix']) ?>" />
865 case ADMIN
: /// Administration directory setting
869 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
870 <td
class="td_right">
871 <input type
="text" size
="40" name
="admindirname" value
="<?php p($INSTALL['admindirname']) ?>" />
878 case ENVIRONMENT
: /// Environment checks
884 error_reporting(0); // Hide errors
885 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
886 error_reporting(7); // Show errors
888 /// Execute environment check, printing results
889 check_moodle_environment($INSTALL['release'], $environment_results, true);
891 /// We never should reach this because DB has been tested before arriving here
892 $errormsg = get_string('dbconnectionerror', 'install');
893 $nextstage = DATABASE
;
894 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
902 case DOWNLOADLANG
: /// Download language from download.moodle.org
908 /// Get array of languages, we are going to use it
909 $languages=get_installer_list_of_languages();
910 /// Print the download form (button) if necessary
911 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
913 $options['downloadlangpack'] = true;
914 $options['stage'] = DOWNLOADLANG
;
915 $options['same'] = true;
916 print_simple_box_start('center');
917 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
918 print_simple_box_end();
921 /// English lang packs aren't downloaded
922 if (substr($INSTALL['language'],0,2) == 'en') {
923 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
925 if ($INSTALL['downloadlangpackerror']) {
926 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
927 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
929 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
944 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
947 if ($needtoopenform) {
949 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
950 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
955 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: ".fix_align_rtl("right")."\"/>\n" : " \n" ?
>
956 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/>\n" : " \n" ?
>
959 if ($needtoopenform) {
973 if (!$needtoopenform) {
985 //==========================================================================//
987 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
989 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
991 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
992 echo "<td valign=\"top\"> </td>\n";
994 echo "<td valign=\"top\"";
995 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
997 echo "<td valign=\"top\">";
998 echo "<p>$errormessage ";
999 install_helpbutton("install.php?help=$helpfield");
1007 //==========================================================================//
1009 function install_helpbutton($url, $title='') {
1011 $title = get_string('help');
1013 echo "<a href=\"javascript: void(0)\">";
1014 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
1015 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1021 //==========================================================================//
1023 function print_install_help($help) {
1025 case 'phpversionhelp':
1026 print_string($help, 'install', phpversion());
1028 case 'memorylimithelp':
1029 print_string($help, 'install', get_memory_limit());
1032 print_string($help, 'install');
1037 //==========================================================================//
1039 function get_memory_limit() {
1040 if ($limit = ini_get('memory_limit')) {
1043 return get_cfg_var('memory_limit');
1047 //==========================================================================//
1049 function check_memory_limit() {
1051 /// if limit is already 40 or more then we don't care if we can change it or not
1052 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1056 /// Otherwise, see if we can change it ourselves
1057 @ini_set
('memory_limit', '40M');
1058 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1061 //==========================================================================//
1063 function inst_check_php_version() {
1064 if (!check_php_version("4.3.0")) {
1066 } else if (check_php_version("5.0.0")) {
1067 return check_php_version("5.1.0"); // 5.0.x is too buggy
1069 return true; // 4.3.x or 4.4.x is fine
1071 //==========================================================================//
1073 /* This function returns a list of languages and their full names. The
1074 * list of available languages is fetched from install/lang/xx/installer.php
1075 * and it's used exclusively by the installation process
1076 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1078 function get_installer_list_of_languages() {
1082 $languages = array();
1084 /// Get raw list of lang directories
1085 $langdirs = get_list_of_plugins('install/lang');
1087 /// Get some info from each lang
1088 foreach ($langdirs as $lang) {
1089 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1090 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1091 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1092 $shortlang = substr($lang, 0, -5);
1096 if ($lang == 'en') { //Explain this is non-utf8 en
1097 $shortlang = 'non-utf8 en';
1099 if (!empty($string['thislanguage'])) {
1100 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1109 //==========================================================================//
1111 function css_styles() {
1114 <style type
="text/css">
1116 body
{ background
-color
: #ffeece; }
1118 font
-family
: helvetica
, arial
, sans
-serif
;
1121 a
{ text
-decoration
: none
; color
: blue
; }
1130 font
-family
: courier
, monospace
;
1137 text
-align
: <?php
echo fix_align_rtl("right") ?
>;
1141 text
-align
: <?php
echo fix_align_rtl("left") ?
>;
1146 border
-style
: solid
;
1147 border
-color
: #ffc85f;
1148 -moz
-border
-radius
-bottomleft
: 15px
;
1149 -moz
-border
-radius
-bottomright
: 15px
;
1152 background
-color
: #fee6b9;
1188 font
-family
: helvetica
, arial
, sans
-serif
;
1195 border
-color
: #ffc85f;
1197 table
.environmenttable
.error
{
1198 background
-color
: red
;
1202 table
.environmenttable
.warn
{
1203 background
-color
: yellow
;
1206 table
.environmenttable
.ok
{
1207 background
-color
: lightgreen
;
1210 background
-color
: #fee6b9;
1214 background
-color
: #ffeece;
1226 .invisiblefieldset
{
1232 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1241 //==========================================================================//
1243 function database_js() {
1246 <script type
="text/javascript" defer
="defer">
1247 function toggledbinfo() {
1248 //Calculate selected value
1249 var showid
= 'mysql';
1250 if (document
.getElementById('installform').dbtype
.value
) {
1251 showid
= document
.getElementById('installform').dbtype
.value
;
1253 if (document
.getElementById
) {
1255 document
.getElementById('mysql').style
.display
= '';
1256 document
.getElementById('mysqli').style
.display
= '';
1257 document
.getElementById('postgres7').style
.display
= '';
1258 document
.getElementById('mssql').style
.display
= '';
1259 document
.getElementById('mssql_n').style
.display
= '';
1260 document
.getElementById('odbc_mssql').style
.display
= '';
1261 document
.getElementById('oci8po').style
.display
= '';
1262 //Show the selected div
1263 document
.getElementById(showid
).style
.display
= 'block';
1264 } else if (document
.all
) {
1265 //This is the way old msie versions work
1267 document
.all
['mysql'].style
.display
= '';
1268 document
.all
['mysqli'].style
.display
= '';
1269 document
.all
['postgres7'].style
.display
= '';
1270 document
.all
['mssql'].style
.display
= '';
1271 document
.all
['mssql_n'].style
.display
= '';
1272 document
.all
['odbc_mssql'].style
.display
= '';
1273 document
.all
['oci8po'].style
.display
= '';
1274 //Show the selected div
1275 document
.all
[showid
].style
.display
= 'block';
1276 } else if (document
.layers
) {
1277 //This is the way nn4 works
1279 document
.layers
['mysql'].style
.display
= '';
1280 document
.layers
['mysqli'].style
.display
= '';
1281 document
.layers
['postgres7'].style
.display
= '';
1282 document
.layers
['mssql'].style
.display
= '';
1283 document
.layers
['mssql_n'].style
.display
= '';
1284 document
.layers
['odbc_mssql'].style
.display
= '';
1285 document
.layers
['oci8po'].style
.display
= '';
1286 //Show the selected div
1287 document
.layers
[showid
].style
.display
= 'block';
1296 * Add slashes for single quotes and backslashes
1297 * so they can be included in single quoted string
1300 function addsingleslashes($input){
1301 return preg_replace("/(['\\\])/", "\\\\$1", $input);