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'];
110 $nextstage = (int)$nextstage;
112 if ($nextstage < 0) {
113 $nextstage = WELCOME
;
120 $nextstage = WELCOME
;
124 //==========================================================================//
126 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
128 $SESSION->lang
= (!empty($_POST['language'])) ?
$_POST['language'] : $INSTALL['language'];
129 $CFG->dirroot
= $INSTALL['dirroot'];
130 $CFG->libdir
= $INSTALL['dirroot'].'/lib';
131 $CFG->dataroot
= $INSTALL['dataroot'];
132 $CFG->admin
= $INSTALL['admindirname'];
133 $CFG->directorypermissions
= 00777;
134 $CFG->running_installer
= true;
137 /// Include some moodle libraries
139 require_once($CFG->libdir
.'/adminlib.php');
140 require_once($CFG->libdir
.'/setuplib.php');
141 require_once($CFG->libdir
.'/moodlelib.php');
142 require_once($CFG->libdir
.'/weblib.php');
143 require_once($CFG->libdir
.'/deprecatedlib.php');
144 require_once($CFG->libdir
.'/adodb/adodb.inc.php');
145 require_once($CFG->libdir
.'/environmentlib.php');
146 require_once($CFG->libdir
.'/xmlize.php');
147 require_once($CFG->libdir
.'/componentlib.class.php');
148 require_once($CFG->dirroot
.'/version.php');
150 /// Set version and release
151 $INSTALL['version'] = $version;
152 $INSTALL['release'] = $release;
154 /// Have the $db object ready because we are going to use it often
155 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
156 $db = &ADONewConnection($INSTALL['dbtype']);
157 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
159 /// guess the www root
160 if ($INSTALL['wwwroot'] == '') {
161 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
162 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
164 // now try to guess the correct dataroot not accessible via web
165 $CFG->wwwroot
= $INSTALL['wwwroot'];
166 $i = 0; //safety check - dirname might return some unexpected results
167 while(is_dataroot_insecure()) {
168 $parrent = dirname($CFG->dataroot
);
170 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
171 $CFG->dataroot
= ''; //can not find secure location for dataroot
174 $CFG->dataroot
= dirname($parrent).'/moodledata';
176 $INSTALL['dataroot'] = $CFG->dataroot
;
179 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
180 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
181 DIRECTORY
=> get_string('directorysettingshead', 'install'),
182 DATABASE
=> get_string('databasesettingshead', 'install'),
183 ADMIN
=> get_string('admindirsettinghead', 'install'),
184 ENVIRONMENT
=> get_string('environmenthead', 'install'),
185 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
186 SAVE
=> get_string('configurationcompletehead', 'install')
189 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
190 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
191 DIRECTORY
=> get_string('directorysettingssub', 'install'),
192 DATABASE
=> get_string('databasesettingssub', 'install'),
193 ADMIN
=> get_string('admindirsettingsub', 'install'),
194 ENVIRONMENT
=> get_string('environmentsub', 'install'),
195 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
196 SAVE
=> get_string('configurationcompletesub', 'install')
201 //==========================================================================//
203 /// Are we in help mode?
205 if (isset($_GET['help'])) {
211 //==========================================================================//
213 /// Are we in config download mode?
215 if (isset($_GET['download'])) {
216 header("Content-Type: application/x-forcedownload\n");
217 header("Content-Disposition: attachment; filename=\"config.php\"");
218 echo $INSTALL['config'];
226 //==========================================================================//
228 /// Check the directory settings
230 if ($INSTALL['stage'] == DIRECTORY
) {
235 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
236 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
237 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
238 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
241 if ($fh) fclose($fh);
244 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
245 $errormsg .= get_string('dirrooterror', 'install').'<br />';
246 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
248 if ($fh) fclose($fh);
251 $CFG->dataroot
= $INSTALL['dataroot'];
252 if (make_upload_directory('sessions', false) === false ) {
253 $errormsg .= get_string('datarooterror', 'install').'<br />';
255 if ($fh) fclose($fh);
257 if (!empty($errormsg)) $nextstage = DIRECTORY
;
264 //==========================================================================//
266 /// Check database settings if stage 3 data submitted
267 /// Try to connect to the database. If that fails then try to create the database
269 if ($INSTALL['stage'] == DATABASE
) {
271 /// different format for postgres7 by socket
272 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
273 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
274 $INSTALL['dbuser'] = '';
275 $INSTALL['dbpass'] = '';
276 $INSTALL['dbname'] = '';
278 if ($INSTALL['prefix'] == '') { /// must have a prefix
279 $INSTALL['prefix'] = 'mdl_';
283 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
284 if (!extension_loaded('mysql')) {
285 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
286 $nextstage = DATABASE
;
290 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
291 if (!extension_loaded('mysqli')) {
292 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
293 $nextstage = DATABASE
;
297 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
298 if (!extension_loaded('pgsql')) {
299 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
300 $nextstage = DATABASE
;
304 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
305 if (!function_exists('mssql_connect')) {
306 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
307 $nextstage = DATABASE
;
311 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
312 if (!function_exists('mssql_connect')) {
313 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
314 $nextstage = DATABASE
;
318 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
319 if (!extension_loaded('odbc')) {
320 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
321 $nextstage = DATABASE
;
325 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
326 if (!extension_loaded('oci8')) {
327 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
328 $nextstage = DATABASE
;
332 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
333 $errormsg = get_string('dbwrongprefix', 'install');
334 $nextstage = DATABASE
;
337 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
338 $errormsg = get_string('dbwrongprefix', 'install');
339 $nextstage = DATABASE
;
342 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
343 $errormsg = get_string('dbwronghostserver', 'install');
344 $nextstage = DATABASE
;
347 if (empty($errormsg)) {
349 error_reporting(0); // Hide errors
351 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
352 $db->database
= ''; // reset database name cached by ADODB. Trick from MDL-9609
353 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
354 switch ($INSTALL['dbtype']) { /// Try to create a database
357 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
358 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
360 $errormsg = get_string('dbcreationerror', 'install');
361 $nextstage = DATABASE
;
367 /// We have been able to connect properly, just test the database encoding now.
368 /// It must be Unicode for 1.8 installations.
370 switch ($INSTALL['dbtype']) {
373 /// Get MySQL character_set_database value
374 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
375 if ($rs && !$rs->EOF
) {
376 $records = $rs->GetAssoc(true);
377 $encoding = $records['character_set_database']['Value'];
378 if (strtoupper($encoding) != 'UTF8') {
379 /// Try to set the encoding now!
380 if (! $db->Metatables()) { // We have no tables so go ahead
381 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
382 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
386 /// If conversion fails, skip, let environment testing do the job
390 /// Skip, let environment testing do the job
393 /// Skip, let environment testing do the job
401 if (($dbconnected === false) and (empty($errormsg)) ) {
402 $errormsg = get_string('dbconnectionerror', 'install');
403 $nextstage = DATABASE
;
409 //==========================================================================//
411 /// If the next stage is admin directory settings OR we have just come from there then
412 /// check the admin directory.
413 /// If we can open a file then we know that the admin name is correct.
415 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
416 if (!ini_get('allow_url_fopen')) {
417 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
418 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
419 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
422 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
423 //if ($nextstage != ADMIN) {
424 // $errormsg = get_string('admindirerror', 'install');
425 // $nextstage = ADMIN;
430 //==========================================================================//
432 // Check if we can navigate from the environemt page (because it's ok)
434 if ($INSTALL['stage'] == ENVIRONMENT
) {
435 error_reporting(0); // Hide errors
436 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
437 error_reporting(7); // Show errors
439 /// Execute environment check, printing results
440 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
441 $nextstage = ENVIRONMENT
;
444 /// We never should reach this because DB has been tested before arriving here
445 $errormsg = get_string('dbconnectionerror', 'install');
446 $nextstage = DATABASE
;
452 //==========================================================================//
454 // Try to download the lang pack if it has been selected
456 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
458 $downloadsuccess = false;
461 error_reporting(0); // Hide errors
463 /// Create necessary lang dir
464 if (!make_upload_directory('lang', false)) {
465 $downloaderror = get_string('cannotcreatelangdir', 'error');
468 /// Download and install component
469 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
470 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
471 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
473 case COMPONENT_ERROR
:
474 if ($cd->get_error() == 'remotedownloaderror') {
476 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'.zip';
477 $a->dest
= $CFG->dataroot
.'/lang';
478 $downloaderror = get_string($cd->get_error(), 'error', $a);
480 $downloaderror = get_string($cd->get_error(), 'error');
483 case COMPONENT_UPTODATE
:
484 case COMPONENT_INSTALLED
:
485 $downloadsuccess = true;
488 //We shouldn't reach this point
491 //We shouldn't reach this point
494 error_reporting(7); // Show errors
496 if ($downloadsuccess) {
497 $INSTALL['downloadlangpack'] = false;
498 $INSTALL['showdownloadlangpack'] = false;
499 $INSTALL['downloadlangpackerror'] = $downloaderror;
501 $INSTALL['downloadlangpack'] = false;
502 $INSTALL['showdownloadlangpack'] = false;
503 $INSTALL['downloadlangpackerror'] = $downloaderror;
509 //==========================================================================//
511 /// Display or print the data
512 /// Put the data into a string
513 /// Try to open config file for writing.
515 if ($nextstage == SAVE
) {
517 $str = '<?php /// Moodle Configuration File '."\r\n";
520 $str .= 'unset($CFG);'."\r\n";
523 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
524 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
525 if (!empty($INSTALL['dbname'])) {
526 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
527 // support single quotes in db user/passwords
528 $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
529 $str .= '$CFG->dbpass = \''.addsingleslashes($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');
604 echo '<p align="center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
607 echo '<div id="mysqli" name="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
608 echo '<p align="center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
611 echo '<div id="postgres7" name="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
613 echo '<div id="mssql" name="mssql">' . get_string('databasesettingssub_mssql', 'install');
614 /// Link to mssql installation page
615 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
616 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
617 echo get_string('moodledocslink', 'install') . '</a></p>';
620 echo '<div id="mssql_n" name="mssql">' . get_string('databasesettingssub_mssql_n', 'install');
621 /// Link to mssql installation page
622 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
623 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
624 echo get_string('moodledocslink', 'install') . '</a></p>';
627 echo '<div id="odbc_mssql" name="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
628 /// Link to mssql installation page
629 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_MSSQL_for_PHP" target="_blank">';
630 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
631 echo get_string('moodledocslink', 'install') . '</a></p>';
634 echo '<div id="oci8po" name="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
635 /// Link to oracle installation page
636 echo '<p align="right"><a href="http://docs.moodle.org/en/Installing_Oracle_for_PHP" target="_blank">';
637 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
638 echo get_string('moodledocslink', 'install') . '</a></p>';
641 if (!empty($substagetext[$nextstage])) {
642 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
650 <td
class="td_main" colspan
="2">
654 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
657 if ($nextstage == SAVE
) {
658 $INSTALL['stage'] = WELCOME
;
660 $options['lang'] = $INSTALL['language'];
661 if ($configsuccess) {
662 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
664 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
666 echo "<td width=\"33.3%\"> </td>\n";
667 echo "<td width=\"33.3%\"> </td>\n";
668 echo "<td width=\"33.3%\" align=\"right\">\n";
669 print_single_button("index.php", $options, get_string('continue'));
675 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
677 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
679 echo "<td width=\"33.3%\"> </td>\n";
680 echo "<td width=\"33.3%\" align=\"center\">\n";
681 $installoptions = array();
682 $installoptions['download'] = 1;
683 print_single_button("install.php", $installoptions, get_string('download', 'install'));
685 echo "<td width=\"33.3%\" align=\"right\">\n";
686 print_single_button("index.php", $options, get_string('continue'));
692 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
699 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
700 form_table($nextstage, $formaction);
728 //==========================================================================//
730 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
731 global $INSTALL, $db;
733 /// Print the standard form if we aren't in the DOWNLOADLANG page
734 /// because it has its own form.
735 if ($nextstage != DOWNLOADLANG
) {
736 $needtoopenform = false;
738 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
739 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
743 $needtoopenform = true;
746 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
749 /// what we do depends on the stage we're at
750 switch ($nextstage) {
751 case WELCOME
: /// Welcome and language settings
754 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
755 <td
class="td_right">
756 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
762 case COMPATIBILITY
: /// Compatibilty check
763 $compatsuccess = true;
765 /// Check that PHP is of a sufficient version
766 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
767 /// Check session auto start
768 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
769 /// Check magic quotes
770 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
771 /// Check unsupported PHP configuration
772 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
774 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
775 /// Check file uploads
776 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
778 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
779 /// Check memory limit
780 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
784 case DIRECTORY
: /// Directory settings
788 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
789 <td
class="td_right">
790 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
794 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
795 <td
class="td_right">
796 <input type
="text" size
="40" name
="dirrootform" disabled
="disabled" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
800 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
801 <td
class="td_right">
802 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
808 case DATABASE
: /// Database settings
812 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
813 <td
class="td_right">
814 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
815 'mysqli' => get_string('mysqli', 'install'),
816 'oci8po' => get_string('oci8po', 'install'),
817 'postgres7' => get_string('postgres7', 'install'),
818 'mssql' => get_string('mssql', 'install'),
819 'mssql_n' => get_string('mssql_n', 'install'),
820 'odbc_mssql' => get_string('odbc_mssql', 'install')),
821 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
825 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
826 <td
class="td_right">
827 <input type
="text" size
="40" name
="dbhost" value
="<?php p($INSTALL['dbhost']) ?>" />
831 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
832 <td
class="td_right">
833 <input type
="text" size
="40" name
="dbname" value
="<?php p($INSTALL['dbname']) ?>" />
837 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
838 <td
class="td_right">
839 <input type
="text" size
="40" name
="dbuser" value
="<?php p($INSTALL['dbuser']) ?>" />
843 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
844 <td
class="td_right">
845 <input type
="password" size
="40" name
="dbpass" value
="<?php p($INSTALL['dbpass']) ?>" />
849 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
850 <td
class="td_right">
851 <input type
="text" size
="40" name
="prefix" value
="<?php p($INSTALL['prefix']) ?>" />
857 case ADMIN
: /// Administration directory setting
861 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
862 <td
class="td_right">
863 <input type
="text" size
="40" name
="admindirname" value
="<?php p($INSTALL['admindirname']) ?>" />
870 case ENVIRONMENT
: /// Environment checks
876 error_reporting(0); // Hide errors
877 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
878 error_reporting(7); // Show errors
880 /// Execute environment check, printing results
881 check_moodle_environment($INSTALL['release'], $environment_results, true);
883 /// We never should reach this because DB has been tested before arriving here
884 $errormsg = get_string('dbconnectionerror', 'install');
885 $nextstage = DATABASE
;
886 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
894 case DOWNLOADLANG
: /// Download language from download.moodle.org
900 /// Get array of languages, we are going to use it
901 $languages=get_installer_list_of_languages();
902 /// Print the download form (button) if necessary
903 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
905 $options['downloadlangpack'] = true;
906 $options['stage'] = DOWNLOADLANG
;
907 $options['same'] = true;
908 print_simple_box_start('center');
909 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
910 print_simple_box_end();
913 /// English lang packs aren't downloaded
914 if (substr($INSTALL['language'],0,2) == 'en') {
915 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
917 if ($INSTALL['downloadlangpackerror']) {
918 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
919 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
921 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
936 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
939 if ($needtoopenform) {
941 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
942 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
947 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: ".fix_align_rtl("right")."\"/>\n" : " \n" ?
>
948 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/>\n" : " \n" ?
>
951 if ($needtoopenform) {
965 if (!$needtoopenform) {
977 //==========================================================================//
979 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
981 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
983 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
984 echo "<td valign=\"top\"> </td>\n";
986 echo "<td valign=\"top\"";
987 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
989 echo "<td valign=\"top\">";
990 echo "<p>$errormessage ";
991 install_helpbutton("install.php?help=$helpfield");
999 //==========================================================================//
1001 function install_helpbutton($url, $title='') {
1003 $title = get_string('help');
1005 echo "<a href=\"javascript: void(0)\">";
1006 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\" ";
1007 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
1013 //==========================================================================//
1015 function print_install_help($help) {
1017 case 'phpversionhelp':
1018 print_string($help, 'install', phpversion());
1020 case 'memorylimithelp':
1021 print_string($help, 'install', get_memory_limit());
1024 print_string($help, 'install');
1029 //==========================================================================//
1031 function get_memory_limit() {
1032 if ($limit = ini_get('memory_limit')) {
1035 return get_cfg_var('memory_limit');
1039 //==========================================================================//
1041 function check_memory_limit() {
1043 /// if limit is already 40 or more then we don't care if we can change it or not
1044 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1048 /// Otherwise, see if we can change it ourselves
1049 @ini_set
('memory_limit', '40M');
1050 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1053 //==========================================================================//
1055 function inst_check_php_version() {
1056 if (!check_php_version("4.3.0")) {
1058 } else if (check_php_version("5.0.0")) {
1059 return check_php_version("5.1.0"); // 5.0.x is too buggy
1061 return true; // 4.3.x or 4.4.x is fine
1063 //==========================================================================//
1065 /* This function returns a list of languages and their full names. The
1066 * list of available languages is fetched from install/lang/xx/installer.php
1067 * and it's used exclusively by the installation process
1068 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1070 function get_installer_list_of_languages() {
1074 $languages = array();
1076 /// Get raw list of lang directories
1077 $langdirs = get_list_of_plugins('install/lang');
1079 /// Get some info from each lang
1080 foreach ($langdirs as $lang) {
1081 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1082 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1083 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1084 $shortlang = substr($lang, 0, -5);
1088 if ($lang == 'en') { //Explain this is non-utf8 en
1089 $shortlang = 'non-utf8 en';
1091 if (!empty($string['thislanguage'])) {
1092 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1101 //==========================================================================//
1103 function css_styles() {
1106 <style type
="text/css">
1108 body
{ background
-color
: #ffeece; }
1110 font
-family
: helvetica
, arial
, sans
-serif
;
1113 a
{ text
-decoration
: none
; color
: blue
; }
1122 font
-family
: courier
, monospace
;
1129 text
-align
: <?php
echo fix_align_rtl("right") ?
>;
1133 text
-align
: <?php
echo fix_align_rtl("left") ?
>;
1138 border
-style
: solid
;
1139 border
-color
: #ffc85f;
1140 -moz
-border
-radius
-bottomleft
: 15px
;
1141 -moz
-border
-radius
-bottomright
: 15px
;
1144 background
-color
: #fee6b9;
1180 font
-family
: helvetica
, arial
, sans
-serif
;
1187 border
-color
: #ffc85f;
1189 table
.environmenttable
.error
{
1190 background
-color
: red
;
1194 table
.environmenttable
.warn
{
1195 background
-color
: yellow
;
1198 table
.environmenttable
.ok
{
1199 background
-color
: lightgreen
;
1202 background
-color
: #fee6b9;
1206 background
-color
: #ffeece;
1218 .invisiblefieldset
{
1224 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1233 //==========================================================================//
1235 function database_js() {
1238 <script type
="text/javascript" defer
="defer">
1239 function toggledbinfo() {
1240 //Calculate selected value
1241 var showid
= 'mysql';
1242 if (document
.getElementById('installform').dbtype
.value
) {
1243 showid
= document
.getElementById('installform').dbtype
.value
;
1245 if (document
.getElementById
) {
1247 document
.getElementById('mysql').style
.display
= '';
1248 document
.getElementById('mysqli').style
.display
= '';
1249 document
.getElementById('postgres7').style
.display
= '';
1250 document
.getElementById('mssql').style
.display
= '';
1251 document
.getElementById('mssql_n').style
.display
= '';
1252 document
.getElementById('odbc_mssql').style
.display
= '';
1253 document
.getElementById('oci8po').style
.display
= '';
1254 //Show the selected div
1255 document
.getElementById(showid
).style
.display
= 'block';
1256 } else if (document
.all
) {
1257 //This is the way old msie versions work
1259 document
.all
['mysql'].style
.display
= '';
1260 document
.all
['mysqli'].style
.display
= '';
1261 document
.all
['postgres7'].style
.display
= '';
1262 document
.all
['mssql'].style
.display
= '';
1263 document
.all
['mssql_n'].style
.display
= '';
1264 document
.all
['odbc_mssql'].style
.display
= '';
1265 document
.all
['oci8po'].style
.display
= '';
1266 //Show the selected div
1267 document
.all
[showid
].style
.display
= 'block';
1268 } else if (document
.layers
) {
1269 //This is the way nn4 works
1271 document
.layers
['mysql'].style
.display
= '';
1272 document
.layers
['mysqli'].style
.display
= '';
1273 document
.layers
['postgres7'].style
.display
= '';
1274 document
.layers
['mssql'].style
.display
= '';
1275 document
.layers
['mssql_n'].style
.display
= '';
1276 document
.layers
['odbc_mssql'].style
.display
= '';
1277 document
.layers
['oci8po'].style
.display
= '';
1278 //Show the selected div
1279 document
.layers
[showid
].style
.display
= 'block';
1288 * Add slashes for single quotes and backslashes
1289 * so they can be included in single quoted string
1292 function addsingleslashes($input){
1293 return preg_replace("/(['\\\])/", "\\\\$1", $input);