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';
143 $CFG->httpswwwroot
= $INSTALL['wwwrootform']; // Needed by doc_link() in Server Checks page.
146 /// Include some moodle libraries
148 require_once($CFG->libdir
.'/adminlib.php');
149 require_once($CFG->libdir
.'/setuplib.php');
150 require_once($CFG->libdir
.'/moodlelib.php');
151 require_once($CFG->libdir
.'/weblib.php');
152 require_once($CFG->libdir
.'/deprecatedlib.php');
153 require_once($CFG->libdir
.'/adodb/adodb.inc.php');
154 require_once($CFG->libdir
.'/environmentlib.php');
155 require_once($CFG->libdir
.'/xmlize.php');
156 require_once($CFG->libdir
.'/componentlib.class.php');
157 require_once($CFG->dirroot
.'/version.php');
159 /// Set version and release
160 $INSTALL['version'] = $version;
161 $INSTALL['release'] = $release;
163 /// Have the $db object ready because we are going to use it often
164 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
165 $db = &ADONewConnection($INSTALL['dbtype']);
166 $db->SetFetchMode(ADODB_FETCH_ASSOC
);
168 /// guess the www root
169 if ($INSTALL['wwwroot'] == '') {
170 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
171 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
173 // now try to guess the correct dataroot not accessible via web
174 $CFG->wwwroot
= $INSTALL['wwwroot'];
175 $i = 0; //safety check - dirname might return some unexpected results
176 while(is_dataroot_insecure()) {
177 $parrent = dirname($CFG->dataroot
);
179 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
180 $CFG->dataroot
= ''; //can not find secure location for dataroot
183 $CFG->dataroot
= dirname($parrent).'/moodledata';
185 $INSTALL['dataroot'] = $CFG->dataroot
;
188 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
189 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
190 DIRECTORY
=> get_string('directorysettingshead', 'install'),
191 DATABASE
=> get_string('databasesettingshead', 'install'),
192 ADMIN
=> get_string('admindirsettinghead', 'install'),
193 ENVIRONMENT
=> get_string('environmenthead', 'install'),
194 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
195 SAVE
=> get_string('configurationcompletehead', 'install')
198 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
199 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
200 DIRECTORY
=> get_string('directorysettingssub', 'install'),
201 DATABASE
=> get_string('databasesettingssub', 'install'),
202 ADMIN
=> get_string('admindirsettingsub', 'install'),
203 ENVIRONMENT
=> get_string('environmentsub', 'install'),
204 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
205 SAVE
=> get_string('configurationcompletesub', 'install')
210 //==========================================================================//
212 /// Are we in help mode?
214 if (isset($_GET['help'])) {
220 //==========================================================================//
222 /// Are we in config download mode?
224 if (isset($_GET['download'])) {
225 header("Content-Type: application/x-forcedownload\n");
226 header("Content-Disposition: attachment; filename=\"config.php\"");
227 echo $INSTALL['config'];
235 //==========================================================================//
237 /// Check the directory settings
239 if ($INSTALL['stage'] == DIRECTORY
) {
244 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
245 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
246 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
247 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
250 if ($fh) fclose($fh);
253 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
254 $errormsg .= get_string('dirrooterror', 'install').'<br />';
255 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
257 if ($fh) fclose($fh);
260 $CFG->dataroot
= $INSTALL['dataroot'];
261 if (make_upload_directory('sessions', false) === false ) {
262 $errormsg .= get_string('datarooterror', 'install').'<br />';
264 if ($fh) fclose($fh);
266 if (!empty($errormsg)) $nextstage = DIRECTORY
;
273 //==========================================================================//
275 /// Check database settings if stage 3 data submitted
276 /// Try to connect to the database. If that fails then try to create the database
278 if ($INSTALL['stage'] == DATABASE
) {
280 /// different format for postgres7 by socket
281 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
282 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
283 $INSTALL['dbuser'] = '';
284 $INSTALL['dbpass'] = '';
285 $INSTALL['dbname'] = '';
287 if ($INSTALL['prefix'] == '') { /// must have a prefix
288 $INSTALL['prefix'] = 'mdl_';
292 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
293 if (!extension_loaded('mysql')) {
294 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
295 $nextstage = DATABASE
;
299 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
300 if (!extension_loaded('mysqli')) {
301 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
302 $nextstage = DATABASE
;
306 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
307 if (!extension_loaded('pgsql')) {
308 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
309 $nextstage = DATABASE
;
313 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
314 if (!function_exists('mssql_connect')) {
315 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
316 $nextstage = DATABASE
;
320 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
321 if (!function_exists('mssql_connect')) {
322 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
323 $nextstage = DATABASE
;
327 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
328 if (!extension_loaded('odbc')) {
329 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
330 $nextstage = DATABASE
;
334 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
335 if (!extension_loaded('oci8')) {
336 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
337 $nextstage = DATABASE
;
341 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
342 $errormsg = get_string('dbwrongprefix', 'install');
343 $nextstage = DATABASE
;
346 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
347 $errormsg = get_string('dbwrongprefix', 'install');
348 $nextstage = DATABASE
;
351 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
352 $errormsg = get_string('dbwronghostserver', 'install');
353 $nextstage = DATABASE
;
356 if (empty($errormsg)) {
358 error_reporting(0); // Hide errors
360 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
361 $db->database
= ''; // reset database name cached by ADODB. Trick from MDL-9609
362 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
363 switch ($INSTALL['dbtype']) { /// Try to create a database
366 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
367 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
369 $errormsg = get_string('dbcreationerror', 'install');
370 $nextstage = DATABASE
;
376 /// We have been able to connect properly, just test the database encoding now.
377 /// It must be Unicode for 1.8 installations.
379 switch ($INSTALL['dbtype']) {
382 /// Get MySQL character_set_database value
383 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
384 if ($rs && !$rs->EOF
) {
385 $records = $rs->GetAssoc(true);
386 $encoding = $records['character_set_database']['Value'];
387 if (strtoupper($encoding) != 'UTF8') {
388 /// Try to set the encoding now!
389 if (! $db->Metatables()) { // We have no tables so go ahead
390 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
391 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
395 /// If conversion fails, skip, let environment testing do the job
399 /// Skip, let environment testing do the job
402 /// Skip, let environment testing do the job
410 if (($dbconnected === false) and (empty($errormsg)) ) {
411 $errormsg = get_string('dbconnectionerror', 'install');
412 $nextstage = DATABASE
;
418 //==========================================================================//
420 /// If the next stage is admin directory settings OR we have just come from there then
421 /// check the admin directory.
422 /// If we can open a file then we know that the admin name is correct.
424 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
425 if (!ini_get('allow_url_fopen')) {
426 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
427 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
428 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
431 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
432 //if ($nextstage != ADMIN) {
433 // $errormsg = get_string('admindirerror', 'install');
434 // $nextstage = ADMIN;
439 //==========================================================================//
441 // Check if we can navigate from the environemt page (because it's ok)
443 if ($INSTALL['stage'] == ENVIRONMENT
) {
444 error_reporting(0); // Hide errors
445 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
446 error_reporting(7); // Show errors
448 /// Execute environment check, printing results
449 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
450 $nextstage = ENVIRONMENT
;
453 /// We never should reach this because DB has been tested before arriving here
454 $errormsg = get_string('dbconnectionerror', 'install');
455 $nextstage = DATABASE
;
461 //==========================================================================//
463 // Try to download the lang pack if it has been selected
465 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
467 $downloadsuccess = false;
470 error_reporting(0); // Hide errors
472 /// Create necessary lang dir
473 if (!make_upload_directory('lang', false)) {
474 $downloaderror = get_string('cannotcreatelangdir', 'error');
477 /// Download and install component
478 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
479 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
480 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
482 case COMPONENT_ERROR
:
483 if ($cd->get_error() == 'remotedownloaderror') {
485 $a->url
= 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip';
486 $a->dest
= $CFG->dataroot
.'/lang';
487 $downloaderror = get_string($cd->get_error(), 'error', $a);
489 $downloaderror = get_string($cd->get_error(), 'error');
492 case COMPONENT_UPTODATE
:
493 case COMPONENT_INSTALLED
:
494 $downloadsuccess = true;
497 //We shouldn't reach this point
500 //We shouldn't reach this point
503 error_reporting(7); // Show errors
505 if ($downloadsuccess) {
506 $INSTALL['downloadlangpack'] = false;
507 $INSTALL['showdownloadlangpack'] = false;
508 $INSTALL['downloadlangpackerror'] = $downloaderror;
510 $INSTALL['downloadlangpack'] = false;
511 $INSTALL['showdownloadlangpack'] = false;
512 $INSTALL['downloadlangpackerror'] = $downloaderror;
518 //==========================================================================//
520 /// Display or print the data
521 /// Put the data into a string
522 /// Try to open config file for writing.
524 if ($nextstage == SAVE
) {
526 $str = '<?php /// Moodle Configuration File '."\r\n";
529 $str .= 'unset($CFG);'."\r\n";
532 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
533 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
534 if (!empty($INSTALL['dbname'])) {
535 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
536 // support single quotes in db user/passwords
537 $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
538 $str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
540 $str .= '$CFG->dbpersist = false;'."\r\n";
541 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
544 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
545 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
546 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
547 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
550 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
553 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
554 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
555 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
560 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
566 $INSTALL['config'] = $str;
571 //==========================================================================//
574 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
575 <html dir
="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
577 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
578 <title
>Moodle Install
</title
>
579 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
580 <?php
css_styles() ?
>
581 <?php
database_js() ?
>
589 if (isset($_GET['help'])) {
590 print_install_help($_GET['help']);
591 close_window_button();
596 <table
class="main" cellpadding
="3" cellspacing
="0">
598 <td
class="td_mainlogo">
599 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"/></p
>
601 <td
class="td_mainlogo" valign
="bottom">
602 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
607 <td
class="td_mainheading" colspan
="2">
608 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
609 <?php
/// Exceptionaly, depending of the DB selected, we show some different text
610 /// from the standard one to show better instructions for each DB
611 if ($nextstage == DATABASE
) {
612 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
613 echo '<div id="mysql">' . get_string('databasesettingssub_mysql', 'install');
614 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
617 echo '<div id="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
618 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
621 echo '<div id="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
623 echo '<div id="mssql">' . get_string('databasesettingssub_mssql', 'install');
624 /// Link to mssql installation page
625 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
626 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
628 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
629 echo get_string('moodledocslink', 'install') . '</a></p>';
632 echo '<div id="mssql_n">' . get_string('databasesettingssub_mssql_n', 'install');
633 /// Link to mssql installation page
634 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
635 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
637 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
638 echo get_string('moodledocslink', 'install') . '</a></p>';
641 echo '<div id="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
642 /// Link to mssql installation page
643 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
644 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
646 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
647 echo get_string('moodledocslink', 'install') . '</a></p>';
650 echo '<div id="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
651 /// Link to oracle installation page
652 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
653 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_Oracle_for_PHP')\"";
655 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
656 echo get_string('moodledocslink', 'install') . '</a></p>';
659 if (!empty($substagetext[$nextstage])) {
660 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
668 <td
class="td_main" colspan
="2">
672 if (!empty($errormsg)) echo "<p class=\"errormsg\" style=\"text-align:center\">$errormsg</p>\n";
675 if ($nextstage == SAVE
) {
676 $INSTALL['stage'] = WELCOME
;
678 $options['lang'] = $INSTALL['language'];
679 if ($configsuccess) {
680 echo "<p class=\"p_install\">".get_string('configfilewritten', 'install')."</p>\n";
682 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
684 echo "<td> </td>\n";
685 echo "<td> </td>\n";
686 echo "<td align=\"right\">\n";
687 print_single_button("index.php", $options, get_string('continue'));
693 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
695 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
697 echo "<td> </td>\n";
698 echo "<td align=\"center\">\n";
699 $installoptions = array();
700 $installoptions['download'] = 1;
701 print_single_button("install.php", $installoptions, get_string('download', 'install'));
703 echo "<td align=\"right\">\n";
704 print_single_button("index.php", $options, get_string('continue'));
710 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
717 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
718 form_table($nextstage, $formaction);
746 //==========================================================================//
748 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
749 global $INSTALL, $db;
751 /// Print the standard form if we aren't in the DOWNLOADLANG page
752 /// because it has its own form.
753 if ($nextstage != DOWNLOADLANG
) {
754 $needtoopenform = false;
756 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
757 <div
><input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" /></div
>
761 $needtoopenform = true;
764 <table
class="install_table" cellspacing
="3" cellpadding
="3">
767 /// what we do depends on the stage we're at
768 switch ($nextstage) {
769 case WELCOME
: /// Welcome and language settings
772 <td
class="td_left"><p
class="p_install"><?php
print_string('language') ?
></p
></td
>
773 <td
class="td_right">
774 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
780 case COMPATIBILITY
: /// Compatibilty check
781 $compatsuccess = true;
783 /// Check that PHP is of a sufficient version
784 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
785 /// Check session auto start
786 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
787 /// Check magic quotes
788 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
789 /// Check unsupported PHP configuration
790 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
792 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
793 /// Check file uploads
794 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
796 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
797 /// Check memory limit
798 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
802 case DIRECTORY
: /// Directory settings
806 <td
class="td_left"><p
class="p_install"><?php
print_string('wwwroot', 'install') ?
></p
></td
>
807 <td
class="td_right">
808 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
812 <td
class="td_left"><p
class="p_install"><?php
print_string('dirroot', 'install') ?
></p
></td
>
813 <td
class="td_right">
814 <input type
="text" size
="40" name
="dirrootform" disabled
="disabled" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
818 <td
class="td_left"><p
class="p_install"><?php
print_string('dataroot', 'install') ?
></p
></td
>
819 <td
class="td_right">
820 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
826 case DATABASE
: /// Database settings
830 <td
class="td_left"><p
class="p_install"><?php
print_string('dbtype', 'install') ?
></p
></td
>
831 <td
class="td_right">
832 <?php
choose_from_menu (array('mysql' => get_string('mysql', 'install'),
833 'mysqli' => get_string('mysqli', 'install'),
834 'oci8po' => get_string('oci8po', 'install'),
835 'postgres7' => get_string('postgres7', 'install'),
836 'mssql' => get_string('mssql', 'install'),
837 'mssql_n' => get_string('mssql_n', 'install'),
838 'odbc_mssql' => get_string('odbc_mssql', 'install')),
839 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?
>
843 <td
class="td_left"><p
class="p_install"><?php
print_string('dbhost', 'install') ?
></p
></td
>
844 <td
class="td_right">
845 <input type
="text" class="input_database" name
="dbhost" value
="<?php p($INSTALL['dbhost']) ?>" />
849 <td
class="td_left"><p
class="p_install"><?php
print_string('database', 'install') ?
></p
></td
>
850 <td
class="td_right">
851 <input type
="text" class="input_database" name
="dbname" value
="<?php p($INSTALL['dbname']) ?>" />
855 <td
class="td_left"><p
class="p_install"><?php
print_string('user') ?
></p
></td
>
856 <td
class="td_right">
857 <input type
="text" class="input_database" name
="dbuser" value
="<?php p($INSTALL['dbuser']) ?>" />
861 <td
class="td_left"><p
class="p_install"><?php
print_string('password') ?
></p
></td
>
862 <td
class="td_right">
863 <input type
="password" class="input_database" name
="dbpass" value
="<?php p($INSTALL['dbpass']) ?>" />
867 <td
class="td_left"><p
class="p_install"><?php
print_string('dbprefix', 'install') ?
></p
></td
>
868 <td
class="td_right">
869 <input type
="text" class="input_database" name
="prefix" value
="<?php p($INSTALL['prefix']) ?>" />
875 case ADMIN
: /// Administration directory setting
879 <td
class="td_left"><p
class="p_install"><?php
print_string('admindirname', 'install') ?
></p
></td
>
880 <td
class="td_right">
881 <input type
="text" size
="40" name
="admindirname" value
="<?php p($INSTALL['admindirname']) ?>" />
888 case ENVIRONMENT
: /// Environment checks
894 error_reporting(0); // Hide errors
895 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
896 error_reporting(7); // Show errors
898 /// Execute environment check, printing results
899 check_moodle_environment($INSTALL['release'], $environment_results, true);
901 /// We never should reach this because DB has been tested before arriving here
902 $errormsg = get_string('dbconnectionerror', 'install');
903 $nextstage = DATABASE
;
904 echo '<p class="errormsg" style="text-align:center">'.get_string('dbconnectionerror', 'install').'</p>';
912 case DOWNLOADLANG
: /// Download language from download.moodle.org
918 /// Get array of languages, we are going to use it
919 $languages=get_installer_list_of_languages();
920 /// Print the download form (button) if necessary
921 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
923 $options['downloadlangpack'] = true;
924 $options['stage'] = DOWNLOADLANG
;
925 $options['same'] = true;
926 print_simple_box_start('center');
927 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'post');
928 print_simple_box_end();
931 /// English lang packs aren't downloaded
932 if (substr($INSTALL['language'],0,2) == 'en') {
933 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
935 if ($INSTALL['downloadlangpackerror']) {
936 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
937 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
939 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
954 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
957 if ($needtoopenform) {
959 <form id
="installform" method
="post" action
="<?php echo $formaction ?>">
960 <div
><input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" /></div
>
965 <?php
echo ($nextstage < SAVE
) ?
"<div><input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: ".fix_align_rtl("right")."\"/></div>\n" : " \n" ?
>
966 <?php
echo ($nextstage > WELCOME
) ?
"<div><input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/></div>\n" : " \n" ?
>
969 if ($needtoopenform) {
983 if (!$needtoopenform) {
995 //==========================================================================//
997 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
999 echo "<td class=\"td_left_nowrap\" valign=\"top\"><p class=\"p_install\">$testtext</p></td>\n";
1001 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1002 echo "<td valign=\"top\"> </td>\n";
1004 echo "<td valign=\"top\">";
1005 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1007 echo "<td valign=\"top\">";
1008 echo "<p class=\"p_install\">$errormessage ";
1009 install_helpbutton("install.php?help=$helpfield");
1017 //==========================================================================//
1019 function install_helpbutton($url, $title='') {
1021 $title = get_string('help');
1023 echo "<a href=\"javascript:void(0)\" ";
1024 echo "onclick=\"return window.open('$url','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400')\"";
1026 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\"/>";
1032 //==========================================================================//
1034 function print_install_help($help) {
1036 case 'phpversionhelp':
1037 print_string($help, 'install', phpversion());
1039 case 'memorylimithelp':
1040 print_string($help, 'install', get_memory_limit());
1043 print_string($help, 'install');
1048 //==========================================================================//
1050 function get_memory_limit() {
1051 if ($limit = ini_get('memory_limit')) {
1054 return get_cfg_var('memory_limit');
1058 //==========================================================================//
1060 function check_memory_limit() {
1062 /// if limit is already 40 or more then we don't care if we can change it or not
1063 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
1067 /// Otherwise, see if we can change it ourselves
1068 @ini_set
('memory_limit', '40M');
1069 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
1072 //==========================================================================//
1074 function inst_check_php_version() {
1075 if (!check_php_version("4.3.0")) {
1077 } else if (check_php_version("5.0.0")) {
1078 return check_php_version("5.1.0"); // 5.0.x is too buggy
1080 return true; // 4.3.x or 4.4.x is fine
1082 //==========================================================================//
1084 /* This function returns a list of languages and their full names. The
1085 * list of available languages is fetched from install/lang/xx/installer.php
1086 * and it's used exclusively by the installation process
1087 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1089 function get_installer_list_of_languages() {
1093 $languages = array();
1095 /// Get raw list of lang directories
1096 $langdirs = get_list_of_plugins('install/lang');
1098 /// Get some info from each lang
1099 foreach ($langdirs as $lang) {
1100 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1101 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1102 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1103 $shortlang = substr($lang, 0, -5);
1107 if ($lang == 'en') { //Explain this is non-utf8 en
1108 $shortlang = 'non-utf8 en';
1110 if (!empty($string['thislanguage'])) {
1111 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1120 //==========================================================================//
1122 function css_styles() {
1125 <style type
="text/css">
1127 body
{ background
-color
: #ffeece; }
1129 font
-family
: helvetica
, arial
, sans
-serif
;
1132 a
{ text
-decoration
: none
; color
: blue
; }
1141 font
-family
: courier
, monospace
;
1153 text
-align
: <?php
echo fix_align_rtl("right") ?
>;
1157 text
-align
: <?php
echo fix_align_rtl("right") ?
>;
1159 white
-space
: nowrap
;
1164 text
-align
: <?php
echo fix_align_rtl("left") ?
>;
1169 border
-style
: solid
;
1170 border
-color
: #ffc85f;
1173 -moz
-border
-radius
-bottomleft
: 15px
;
1174 -moz
-border
-radius
-bottomright
: 15px
;
1177 background
-color
: #fee6b9;
1184 vertical
-align
: middle
;
1193 margin
-bottom
: 16px
;
1199 margin
-bottom
: 16px
;
1228 font
-family
: helvetica
, arial
, sans
-serif
;
1235 /* This override the p tag for every p tag in this installation script,
1236 but not in lang\xxx\installer.php
1244 border
-color
: #ffc85f;
1246 table
.environmenttable
.error
{
1247 background
-color
: red
;
1251 table
.environmenttable
.warn
{
1252 background
-color
: yellow
;
1255 table
.environmenttable
.ok
{
1256 background
-color
: lightgreen
;
1259 background
-color
: #fee6b9;
1263 background
-color
: #ffeece;
1275 .invisiblefieldset
{
1281 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
1290 //==========================================================================//
1292 function database_js() {
1295 <script type
="text/javascript" defer
="defer">
1296 function toggledbinfo() {
1297 //Calculate selected value
1298 var showid
= 'mysql';
1299 if (document
.getElementById('installform').dbtype
.value
) {
1300 showid
= document
.getElementById('installform').dbtype
.value
;
1302 if (document
.getElementById
) {
1304 document
.getElementById('mysql').style
.display
= '';
1305 document
.getElementById('mysqli').style
.display
= '';
1306 document
.getElementById('postgres7').style
.display
= '';
1307 document
.getElementById('mssql').style
.display
= '';
1308 document
.getElementById('mssql_n').style
.display
= '';
1309 document
.getElementById('odbc_mssql').style
.display
= '';
1310 document
.getElementById('oci8po').style
.display
= '';
1311 //Show the selected div
1312 document
.getElementById(showid
).style
.display
= 'block';
1313 } else if (document
.all
) {
1314 //This is the way old msie versions work
1316 document
.all
['mysql'].style
.display
= '';
1317 document
.all
['mysqli'].style
.display
= '';
1318 document
.all
['postgres7'].style
.display
= '';
1319 document
.all
['mssql'].style
.display
= '';
1320 document
.all
['mssql_n'].style
.display
= '';
1321 document
.all
['odbc_mssql'].style
.display
= '';
1322 document
.all
['oci8po'].style
.display
= '';
1323 //Show the selected div
1324 document
.all
[showid
].style
.display
= 'block';
1325 } else if (document
.layers
) {
1326 //This is the way nn4 works
1328 document
.layers
['mysql'].style
.display
= '';
1329 document
.layers
['mysqli'].style
.display
= '';
1330 document
.layers
['postgres7'].style
.display
= '';
1331 document
.layers
['mssql'].style
.display
= '';
1332 document
.layers
['mssql_n'].style
.display
= '';
1333 document
.layers
['odbc_mssql'].style
.display
= '';
1334 document
.layers
['oci8po'].style
.display
= '';
1335 //Show the selected div
1336 document
.layers
[showid
].style
.display
= 'block';
1345 * Add slashes for single quotes and backslashes
1346 * so they can be included in single quoted string
1349 function addsingleslashes($input){
1350 return preg_replace("/(['\\\])/", "\\\\$1", $input);