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 ///==========================================================================//
28 /// Begin the session as we are holding all information in a session
29 /// variable until the end.
31 session_name('MoodleSession');
34 if (! isset($_SESSION['INSTALL'])) {
35 $_SESSION['INSTALL'] = array();
38 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
41 /// If it's our first time through this script then we need to set some default values
43 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
46 $INSTALL['language'] = 'en_utf8';
48 $INSTALL['dbhost'] = 'localhost';
49 $INSTALL['dbuser'] = '';
50 $INSTALL['dbpass'] = '';
51 $INSTALL['dbtype'] = 'mysql';
52 $INSTALL['dbname'] = 'moodle';
53 $INSTALL['prefix'] = 'mdl_';
55 $INSTALL['dbencodingtestresults'] = false;
56 $INSTALL['showskipdbencodingtest'] = false;
57 $INSTALL['skipdbencodingtest'] = false;
59 $INSTALL['downloadlangpack'] = false;
60 $INSTALL['showdownloadlangpack'] = true;
61 $INSTALL['downloadlangpackerror'] = '';
63 /// To be used by the Installer
64 $INSTALL['wwwroot'] = '';
65 $INSTALL['dirroot'] = dirname(__FILE__
);
66 $INSTALL['dataroot'] = dirname(dirname(__FILE__
)) . '/moodledata';
68 /// To be configured in the Installer
69 $INSTALL['wwwrootform'] = '';
70 $INSTALL['dirrootform'] = dirname(__FILE__
);
72 $INSTALL['admindirname'] = 'admin';
74 $INSTALL['stage'] = WELCOME
;
77 //==========================================================================//
79 /// Set the page to Unicode always
81 header('Content-Type: text/html; charset=UTF-8');
83 /// Was data submitted?
85 if (isset($_POST['stage'])) {
87 /// Get the stage for which the form was set and the next stage we are going to
90 if ( $goforward = (! empty( $_POST['next'] )) ) {
91 $nextstage = $_POST['stage'] +
1;
92 } else if (! empty( $_POST['prev'])) {
93 $nextstage = $_POST['stage'] - 1;
94 } else if (! empty( $_POST['same'] )) {
95 $nextstage = $_POST['stage'];
99 if ($nextstage < 0) $nextstage = WELCOME
;
102 /// Store any posted data
103 foreach ($_POST as $setting=>$value) {
104 $INSTALL[$setting] = $value;
110 $nextstage = WELCOME
;
114 //==========================================================================//
116 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
118 $SESSION->lang
= (!empty($_POST['language'])) ?
$_POST['language'] : $INSTALL['language'];
119 $CFG->dirroot
= $INSTALL['dirroot'];
120 $CFG->libdir
= $INSTALL['dirroot'].'/lib';
121 $CFG->dataroot
= $INSTALL['dataroot'];
122 $CFG->admin
= $INSTALL['admindirname'];
123 $CFG->directorypermissions
= 00777;
124 $CFG->running_installer
= true;
126 /// Include some moodle libraries
128 require_once('./lib/adminlib.php');
129 require_once('./lib/setuplib.php');
130 require_once('./lib/moodlelib.php');
131 require_once('./lib/weblib.php');
132 require_once('./lib/adodb/adodb.inc.php');
133 require_once('./lib/environmentlib.php');
134 require_once('./lib/componentlib.class.php');
135 require_once('./version.php');
137 /// Set version and release
138 $INSTALL['version'] = $version;
139 $INSTALL['release'] = $release;
141 /// Have the $db object ready because we are going to use it often
142 $db = &ADONewConnection($INSTALL['dbtype']);
144 /// guess the www root
145 if ($INSTALL['wwwroot'] == '') {
146 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
147 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
149 // now try to guess the correct dataroot not accessible via web
150 $CFG->wwwroot
= $INSTALL['wwwroot'];
151 $i = 0; //safety check - dirname might return some unexpected results
152 while(is_dataroot_insecure()) {
153 $parrent = dirname($CFG->dataroot
);
155 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
156 $CFG->dataroot
= ''; //can not find secure location for dataroot
159 $CFG->dataroot
= dirname($parrent).'/moodledata';
161 $INSTALL['dataroot'] = $CFG->dataroot
;
164 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
165 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
166 DIRECTORY
=> get_string('directorysettingshead', 'install'),
167 DATABASE
=> get_string('databasesettingshead', 'install'),
168 ADMIN
=> get_string('admindirsettinghead', 'install'),
169 ENVIRONMENT
=> get_string('environmenthead', 'install'),
170 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
171 SAVE
=> get_string('configurationcompletehead', 'install')
174 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
175 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
176 DIRECTORY
=> get_string('directorysettingssub', 'install'),
177 DATABASE
=> get_string('databasesettingssub', 'install'),
178 ADMIN
=> get_string('admindirsettingsub', 'install'),
179 ENVIRONMENT
=> get_string('environmentsub', 'install'),
180 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
181 SAVE
=> get_string('configurationcompletesub', 'install')
186 //==========================================================================//
188 /// Are we in help mode?
190 if (isset($_GET['help'])) {
196 //==========================================================================//
198 /// Are we in config download mode?
200 if (isset($_GET['download'])) {
201 header("Content-Type: application/download\n");
202 header("Content-Disposition: attachment; filename=\"config.php\"");
203 echo $INSTALL['config'];
211 //==========================================================================//
213 /// Check the directory settings
215 if ($INSTALL['stage'] == DIRECTORY
) {
220 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
221 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
222 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
223 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
226 if ($fh) fclose($fh);
229 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
230 $errormsg .= get_string('dirrooterror', 'install').'<br />';
231 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
233 if ($fh) fclose($fh);
236 $CFG->dataroot
= $INSTALL['dataroot'];
237 if (make_upload_directory('sessions', false) === false ) {
238 $errormsg .= get_string('datarooterror', 'install').'<br />';
240 if ($fh) fclose($fh);
242 if (!empty($errormsg)) $nextstage = DIRECTORY
;
249 //==========================================================================//
251 /// Check database settings if stage 3 data submitted
252 /// Try to connect to the database. If that fails then try to create the database
254 if ($INSTALL['stage'] == DATABASE
) {
256 /// First of all, analyze skipdbencodingtest status
257 if (isset($_POST['skipdbencodingtest'])) {
258 $INSTALL['skipdbencodingtest'] = true;
260 $INSTALL['skipdbencodingtest'] = false;
263 /// different format for postgres7 by socket
264 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
265 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
266 $INSTALL['dbuser'] = '';
267 $INSTALL['dbpass'] = '';
268 $INSTALL['dbname'] = '';
270 if ($INSTALL['prefix'] == '') { /// must have a prefix
271 $INSTALL['prefix'] = 'mdl_';
275 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
276 if (!extension_loaded('mysql')) {
277 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
278 $nextstage = DATABASE
;
282 if (empty($errormsg)) {
284 error_reporting(0); // Hide errors
286 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
287 /// The following doesn't seem to work but we're working on it
288 /// If you come up with a solution for creating a database in MySQL
289 /// feel free to put it in and let us know
290 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
291 switch ($INSTALL['dbtype']) { /// Try to create a database
293 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
294 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
296 $errormsg = get_string('dbcreationerror', 'install');
297 $nextstage = DATABASE
;
303 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
304 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
305 if (empty($INSTALL['skipdbencodingtest'])) {
306 /// We haven't checked the skip test checkbox, so perform the test
308 switch ($INSTALL['dbtype']) {
310 ///Get MySQL character_set_database value
311 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
312 if ($rs && $rs->RecordCount() > 0) {
313 $records = $rs->GetAssoc(true);
314 $encoding = $records['character_set_database']['Value'];
315 if (strtoupper($encoding) == 'UTF8') {
316 $INSTALL['dbencodingtestresults'] = true;
318 // Try to set the encoding now!
319 if (! $db->Metatables()) { // We have no tables so go ahead
320 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
321 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
323 $records = $rs->GetAssoc(true);
324 $encoding = $records['character_set_database']['Value'];
326 if (strtoupper($encoding) == 'UTF8') {
327 $INSTALL['dbencodingtestresults'] = true;
329 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
330 $nextstage = DATABASE
;
331 $INSTALL['showskipdbencodingtest'] = true;
332 $INSTALL['dbencodingtestresults'] = false;
335 $INSTALL['showskipdbencodingtest'] = true;
336 $INSTALL['dbencodingtestresults'] = false;
342 ///Get PostgreSQL server_encoding value
343 $rs = $db->Execute("SHOW server_encoding");
344 if ($rs && $rs->RecordCount() > 0) {
345 $encoding = $rs->fields
['server_encoding'];
346 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
347 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
348 $nextstage = DATABASE
;
349 $INSTALL['showskipdbencodingtest'] = true;
350 $INSTALL['dbencodingtestresults'] = false;
352 $INSTALL['dbencodingtestresults'] = true;
363 if (($dbconnected === false) and (empty($errormsg)) ) {
364 $errormsg = get_string('dbconnectionerror', 'install');
365 $nextstage = DATABASE
;
371 //==========================================================================//
373 /// If the next stage is admin directory settings OR we have just come from there then
374 /// check the admin directory.
375 /// If we can open a file then we know that the admin name is correct.
377 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
378 if (!ini_get('allow_url_fopen') ||
true) { // MDL-4218 fopen URL is not reliable
379 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
380 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
381 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
384 if ($nextstage != ADMIN
) {
385 $errormsg = get_string('admindirerror', 'install');
391 //==========================================================================//
393 // Check if we can navigate from the environemt page (because it's ok)
395 if ($INSTALL['stage'] == ENVIRONMENT
) {
396 error_reporting(0); // Hide errors
397 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
398 error_reporting(7); // Show errors
400 /// Execute environment check, printing results
401 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
402 $nextstage = ENVIRONMENT
;
405 /// We never should reach this because DB has been tested before arriving here
406 $errormsg = get_string('dbconnectionerror', 'install');
407 $nextstage = DATABASE
;
413 //==========================================================================//
415 // Try to download the lang pack if it has been selected
417 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
419 $downloadsuccess = false;
422 error_reporting(0); // Hide errors
424 /// Create necessary lang dir
425 if (!make_upload_directory('lang', false)) {
426 $downloaderror = get_string('cannotcreatelangdir', 'error');
429 /// Download and install component
430 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
431 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
432 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
435 if ($cd->get_error() == 'remotedownloadnotallowed') {
437 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'zip';
438 $a->dest
= $CFG->dataroot
.'/lang';
439 $downloaderror = get_string($cd->get_error(), 'error', $a);
441 $downloaderror = get_string($cd->get_error(), 'error');
446 $downloadsuccess = true;
449 //We shouldn't reach this point
452 //We shouldn't reach this point
455 error_reporting(7); // Show errors
457 if ($downloadsuccess) {
458 $INSTALL['downloadlangpack'] = false;
459 $INSTALL['showdownloadlangpack'] = false;
460 $INSTALL['downloadlangpackerror'] = $downloaderror;
462 $INSTALL['downloadlangpack'] = false;
463 $INSTALL['showdownloadlangpack'] = false;
464 $INSTALL['downloadlangpackerror'] = $downloaderror;
470 //==========================================================================//
472 /// Display or print the data
473 /// Put the data into a string
474 /// Try to open config file for writing.
476 if ($nextstage == SAVE
) {
478 $str = '<?php /// Moodle Configuration File '."\r\n";
481 $str .= 'unset($CFG);'."\r\n";
484 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
485 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
486 if (!empty($INSTALL['dbname'])) {
487 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
488 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
489 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
491 $str .= '$CFG->dbpersist = false;'."\r\n";
492 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
495 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
496 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
497 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
498 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
501 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
504 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
505 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
509 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
510 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
511 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
516 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
522 $INSTALL['config'] = $str;
527 //==========================================================================//
530 <html dir
="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
532 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
533 <title
>Moodle Install
</title
>
534 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
535 <?php
css_styles() ?
>
543 if (isset($_GET['help'])) {
544 print_install_help($_GET['help']);
545 close_window_button();
550 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
552 <td
class="td_mainlogo">
553 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
555 <td
class="td_mainlogo" valign
="bottom">
556 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
561 <td
class="td_mainheading" colspan
="2">
562 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
563 <?php
if (!empty($substagetext[$nextstage])) { ?
>
564 <p
class="p_subheading"><?php
echo $substagetext[$nextstage] ?
></p
>
570 <td
class="td_main" colspan
="2">
574 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
577 if ($nextstage == SAVE
) {
578 $INSTALL['stage'] = WELCOME
;
580 $options['lang'] = $INSTALL['language'];
581 if ($configsuccess) {
582 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
584 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
586 echo "<td width=\"33.3%\"> </td>\n";
587 echo "<td width=\"33.3%\"> </td>\n";
588 echo "<td width=\"33.3%\" align=\"right\">\n";
589 print_single_button("index.php", $options, get_string('continue')." »");
595 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
597 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
599 echo "<td width=\"33.3%\"> </td>\n";
600 echo "<td width=\"33.3%\" align=\"center\">\n";
601 $installoptions = array();
602 $installoptions['download'] = 1;
603 print_single_button("install.php", $installoptions, get_string('download', 'install'));
605 echo "<td width=\"33.3%\" align=\"right\">\n";
606 print_single_button("index.php", $options, get_string('continue')." »");
612 echo "<div style=\"text-align: left\">\n";
613 print_object(s($str));
617 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
618 form_table($nextstage, $formaction);
645 //==========================================================================//
648 function print_object($object) {
656 //==========================================================================//
658 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
659 global $INSTALL, $db;
663 /// Print the standard form if we aren't in the DOWNLOADLANG page
664 /// because it has its own form.
665 if ($nextstage != DOWNLOADLANG
) {
666 $needtoopenform = false;
668 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
669 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
673 $needtoopenform = true;
676 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
679 /// what we do depends on the stage we're at
680 switch ($nextstage) {
681 case WELCOME
: /// Welcome and language settings
684 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
685 <td
class="td_right">
686 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
692 case COMPATIBILITY
: /// Compatibilty check
693 $compatsuccess = true;
695 /// Check that PHP is of a sufficient version
696 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
697 $enablenext = $enablenext && inst_check_php_version();
698 /// Check session auto start
699 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
700 $enablenext = $enablenext && !ini_get_bool('session.auto_start');
701 /// Check magic quotes
702 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
703 $enablenext = $enablenext && !ini_get_bool('magic_quotes_runtime');
704 /// Check unsupported PHP configuration
705 print_compatibility_row(!ini_get_bool('register_globals'), get_string('globalsquotes', 'install'), get_string('globalswarning', 'install'));
706 $enablenext = $enablenext && !ini_get_bool('register_globals');
708 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
709 /// Check file uploads
710 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
712 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
713 /// Check memory limit
714 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
718 case DIRECTORY
: /// Directory settings
722 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
723 <td
class="td_right">
724 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
728 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
729 <td
class="td_right">
730 <input type
="text" size
="40" name
="dirrootform" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
734 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
735 <td
class="td_right">
736 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
742 case DATABASE
: /// Database settings
746 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
747 <td
class="td_right">
748 <?php
choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?
>
752 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
753 <td
class="td_right">
754 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
758 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
759 <td
class="td_right">
760 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
764 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
765 <td
class="td_right">
766 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
770 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
771 <td
class="td_right">
772 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
776 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
777 <td
class="td_right">
778 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
781 <?php
if ($INSTALL['showskipdbencodingtest']) { ?
>
783 <td
class="td_left" colspan
="2">
784 <?php
print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?
>
791 case ADMIN
: /// Administration directory setting
795 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
796 <td
class="td_right">
797 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
804 case ENVIRONMENT
: /// Environment checks
810 error_reporting(0); // Hide errors
811 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
812 error_reporting(7); // Show errors
814 /// Execute environment check, printing results
815 check_moodle_environment($INSTALL['release'], $environment_results, true);
817 /// We never should reach this because DB has been tested before arriving here
818 $errormsg = get_string('dbconnectionerror', 'install');
819 $nextstage = DATABASE
;
820 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
828 case DOWNLOADLANG
: /// Download language from download.moodle.org
834 /// Get array of languages, we are going to use it
835 $languages=get_installer_list_of_languages();
836 /// Print the download form (button) if necessary
837 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
839 $options['downloadlangpack'] = true;
840 $options['stage'] = DOWNLOADLANG
;
841 $options['same'] = true;
842 print_simple_box_start('center');
843 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
844 print_simple_box_end();
847 /// English lang packs aren't downloaded
848 if (substr($INSTALL['language'],0,2) == 'en') {
849 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
851 if ($INSTALL['downloadlangpackerror']) {
852 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
853 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
855 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
870 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
873 if ($needtoopenform) {
875 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
876 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
880 $disabled = $enablenext ?
'' : 'disabled="disabled"';
883 <?php
echo ($nextstage < SAVE
) ?
"<input $disabled type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: right\"/>\n" : " \n" ?
>
884 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: left\"/>\n" : " \n" ?
>
887 if ($needtoopenform) {
901 if (!$needtoopenform) {
913 //==========================================================================//
915 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
917 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
919 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
920 echo "<td valign=\"top\"> </td>\n";
922 echo "<td valign=\"top\"";
923 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
925 echo "<td valign=\"top\">";
926 echo "<p>$errormessage ";
927 if ($helpfield !== '') {
928 install_helpbutton("install.php?help=$helpfield");
937 //==========================================================================//
939 function install_helpbutton($url, $title='') {
941 $title = get_string('help');
943 echo "<a href=\"javascript: void(0)\">";
944 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
945 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
946 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
952 //==========================================================================//
954 function print_install_help($help) {
956 case 'phpversionhelp':
957 print_string($help, 'install', phpversion());
959 case 'memorylimithelp':
960 print_string($help, 'install', get_memory_limit());
963 print_string($help, 'install');
968 //==========================================================================//
970 function get_memory_limit() {
971 if ($limit = ini_get('memory_limit')) {
974 return get_cfg_var('memory_limit');
978 //==========================================================================//
980 function check_memory_limit() {
982 /// if limit is already 16M or more then we don't care if we can change it or not
983 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
987 /// Otherwise, see if we can change it ourselves
988 @ini_set
('memory_limit', '16M');
989 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
992 //==========================================================================//
994 function inst_check_php_version() {
995 if (!check_php_version("4.3.0")) {
997 } else if (check_php_version("5.0.0")) {
998 return check_php_version("5.1.0"); // 5.0.x is too buggy
1000 return true; // 4.3.x or 4.4.x is fine
1002 //==========================================================================//
1004 /* This function returns a list of languages and their full names. The
1005 * list of available languages is fetched from install/lang/xx/installer.php
1006 * and it's used exclusively by the installation process
1007 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1009 function get_installer_list_of_languages() {
1013 $languages = array();
1015 /// Get raw list of lang directories
1016 $langdirs = get_list_of_plugins('install/lang');
1018 /// Get some info from each lang
1019 foreach ($langdirs as $lang) {
1020 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1021 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1022 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1023 $shortlang = substr($lang, 0, -5);
1027 if ($lang == 'en') { //Explain this is non-utf8 en
1028 $shortlang = 'non-utf8 en';
1030 if (!empty($string['thislanguage'])) {
1031 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1040 //==========================================================================//
1042 function css_styles() {
1045 <style type
="text/css">
1047 body
{ background
-color
: #ffeece; }
1049 font
-family
: helvetica
, arial
, sans
-serif
;
1052 a
{ text
-decoration
: none
; color
: blue
; }
1058 font
-family
: courier
, monospace
;
1074 border
-style
: solid
;
1075 border
-color
: #ffc85f;
1076 -moz
-border
-radius
-bottomleft
: 15px
;
1077 -moz
-border
-radius
-bottomright
: 15px
;
1080 background
-color
: #fee6b9;
1116 font
-family
: helvetica
, arial
, sans
-serif
;
1123 border
-color
: #ffc85f;
1125 table
.environmenttable
.error
{
1126 background
-color
: red
;
1130 table
.environmenttable
.warn
{
1131 background
-color
: yellow
;
1134 table
.environmenttable
.ok
{
1135 background
-color
: lightgreen
;
1138 background
-color
: #fee6b9;
1142 background
-color
: #ffeece;