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/setuplib.php');
129 require_once('./lib/moodlelib.php');
130 require_once('./lib/weblib.php');
131 require_once('./lib/adodb/adodb.inc.php');
132 require_once('./lib/environmentlib.php');
133 require_once('./lib/xmlize.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'];
150 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
151 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
152 DIRECTORY
=> get_string('directorysettingshead', 'install'),
153 DATABASE
=> get_string('databasesettingshead', 'install'),
154 ADMIN
=> get_string('admindirsettinghead', 'install'),
155 ENVIRONMENT
=> get_string('environmenthead', 'install'),
156 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
157 SAVE
=> get_string('configurationcompletehead', 'install')
160 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
161 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
162 DIRECTORY
=> get_string('directorysettingssub', 'install'),
163 DATABASE
=> get_string('databasesettingssub', 'install'),
164 ADMIN
=> get_string('admindirsettingsub', 'install'),
165 ENVIRONMENT
=> get_string('environmentsub', 'install'),
166 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
167 SAVE
=> get_string('configurationcompletesub', 'install')
172 //==========================================================================//
174 /// Are we in help mode?
176 if (isset($_GET['help'])) {
182 //==========================================================================//
184 /// Are we in config download mode?
186 if (isset($_GET['download'])) {
187 header("Content-Type: application/download\n");
188 header("Content-Disposition: attachment; filename=\"config.php\"");
189 echo $INSTALL['config'];
197 //==========================================================================//
199 /// Check the directory settings
201 if ($INSTALL['stage'] == DIRECTORY
) {
206 if (ini_get('allow_url_fopen')) {
207 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
208 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
209 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
212 if ($fh) fclose($fh);
215 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
216 $errormsg .= get_string('dirrooterror', 'install').'<br />';
217 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
219 if ($fh) fclose($fh);
222 $CFG->dataroot
= $INSTALL['dataroot'];
223 if (make_upload_directory('sessions', false) === false ) {
224 $errormsg .= get_string('datarooterror', 'install').'<br />';
226 if ($fh) fclose($fh);
228 if (!empty($errormsg)) $nextstage = DIRECTORY
;
235 //==========================================================================//
237 /// Check database settings if stage 3 data submitted
238 /// Try to connect to the database. If that fails then try to create the database
240 if ($INSTALL['stage'] == DATABASE
) {
242 /// First of all, analyze skipdbencodingtest status
243 if (isset($_POST['skipdbencodingtest'])) {
244 $INSTALL['skipdbencodingtest'] = true;
246 $INSTALL['skipdbencodingtest'] = false;
249 /// different format for postgres7 by socket
250 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
251 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
252 $INSTALL['dbuser'] = '';
253 $INSTALL['dbpass'] = '';
254 $INSTALL['dbname'] = '';
256 if ($INSTALL['prefix'] == '') { /// must have a prefix
257 $INSTALL['prefix'] = 'mdl_';
261 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
262 if (!extension_loaded('mysql')) {
263 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
264 $nextstage = DATABASE
;
268 if (empty($errormsg)) {
270 error_reporting(0); // Hide errors
272 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
273 /// The following doesn't seem to work but we're working on it
274 /// If you come up with a solution for creating a database in MySQL
275 /// feel free to put it in and let us know
276 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
277 switch ($INSTALL['dbtype']) { /// Try to create a database
279 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
280 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
282 $errormsg = get_string('dbcreationerror', 'install');
283 $nextstage = DATABASE
;
289 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
290 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
291 if (empty($INSTALL['skipdbencodingtest'])) {
292 /// We haven't checked the skip test checkbox, so perform the test
294 switch ($INSTALL['dbtype']) {
296 ///Get MySQL character_set_database value
297 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
298 if ($rs && $rs->RecordCount() > 0) {
299 $records = $rs->GetAssoc(true);
300 $encoding = $records['character_set_database']['Value'];
301 if (strtoupper($encoding) == 'UTF8') {
302 $INSTALL['dbencodingtestresults'] = true;
304 // Try to set the encoding now!
305 if (! $db->Metatables()) { // We have no tables so go ahead
306 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
307 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
309 $records = $rs->GetAssoc(true);
310 $encoding = $records['character_set_database']['Value'];
312 if (strtoupper($encoding) == 'UTF8') {
313 $INSTALL['dbencodingtestresults'] = true;
315 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
316 $nextstage = DATABASE
;
317 $INSTALL['showskipdbencodingtest'] = true;
318 $INSTALL['dbencodingtestresults'] = false;
321 $INSTALL['showskipdbencodingtest'] = true;
322 $INSTALL['dbencodingtestresults'] = false;
328 ///Get PostgreSQL server_encoding value
329 $rs = $db->Execute("SHOW server_encoding");
330 if ($rs && $rs->RecordCount() > 0) {
331 $encoding = $rs->fields
['server_encoding'];
332 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
333 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
334 $nextstage = DATABASE
;
335 $INSTALL['showskipdbencodingtest'] = true;
336 $INSTALL['dbencodingtestresults'] = false;
338 $INSTALL['dbencodingtestresults'] = true;
349 if (($dbconnected === false) and (empty($errormsg)) ) {
350 $errormsg = get_string('dbconnectionerror', 'install');
351 $nextstage = DATABASE
;
357 //==========================================================================//
359 /// If the next stage is admin directory settings OR we have just come from there then
360 /// check the admin directory.
361 /// If we can open a file then we know that the admin name is correct.
363 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
364 if (!ini_get('allow_url_fopen')) {
365 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
366 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
367 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
370 if ($nextstage != ADMIN
) {
371 $errormsg = get_string('admindirerror', 'install');
377 //==========================================================================//
379 // Check if we can navigate from the environemt page (because it's ok)
381 if ($INSTALL['stage'] == ENVIRONMENT
) {
382 error_reporting(0); // Hide errors
383 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
384 error_reporting(7); // Show errors
386 /// Execute environment check, printing results
387 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
388 $nextstage = ENVIRONMENT
;
391 /// We never should reach this because DB has been tested before arriving here
392 $errormsg = get_string('dbconnectionerror', 'install');
393 $nextstage = DATABASE
;
399 //==========================================================================//
401 // Try to download the lang pack if it has been selected
403 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
405 $downloadsuccess = false;
408 error_reporting(0); // Hide errors
410 /// Create necessary lang dir
411 if (!make_upload_directory('lang', false)) {
412 $downloaderror = get_string('cannotcreatelangdir', 'error');
415 /// Download and install component
416 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
417 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
418 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
421 if ($cd->get_error() == 'remotedownloadnotallowed') {
423 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'zip';
424 $a->dest
= $CFG->dataroot
.'/lang';
425 $downloaderror = get_string($cd->get_error(), 'error', $a);
427 $downloaderror = get_string($cd->get_error(), 'error');
432 $downloadsuccess = true;
435 //We shouldn't reach this point
438 //We shouldn't reach this point
441 error_reporting(7); // Show errors
443 if ($downloadsuccess) {
444 $INSTALL['downloadlangpack'] = false;
445 $INSTALL['showdownloadlangpack'] = false;
446 $INSTALL['downloadlangpackerror'] = $downloaderror;
448 $INSTALL['downloadlangpack'] = false;
449 $INSTALL['showdownloadlangpack'] = false;
450 $INSTALL['downloadlangpackerror'] = $downloaderror;
456 //==========================================================================//
458 /// Display or print the data
459 /// Put the data into a string
460 /// Try to open config file for writing.
462 if ($nextstage == SAVE
) {
464 $str = '<?php /// Moodle Configuration File '."\r\n";
467 $str .= 'unset($CFG);'."\r\n";
470 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
471 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
472 if (!empty($INSTALL['dbname'])) {
473 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
474 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
475 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
477 $str .= '$CFG->dbpersist = false;'."\r\n";
478 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
481 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
482 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
483 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
484 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
487 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
490 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
491 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
495 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
496 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
497 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
502 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
508 $INSTALL['config'] = $str;
513 //==========================================================================//
516 <html dir
="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
518 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
519 <title
>Moodle Install
</title
>
520 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
521 <?php
css_styles() ?
>
529 if (isset($_GET['help'])) {
530 print_install_help($_GET['help']);
531 close_window_button();
536 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
538 <td
class="td_mainlogo">
539 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
541 <td
class="td_mainlogo" valign
="bottom">
542 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
547 <td
class="td_mainheading" colspan
="2">
548 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
549 <?php
if (!empty($substagetext[$nextstage])) { ?
>
550 <p
class="p_subheading"><?php
echo $substagetext[$nextstage] ?
></p
>
556 <td
class="td_main" colspan
="2">
560 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
563 if ($nextstage == SAVE
) {
564 $INSTALL['stage'] = WELCOME
;
566 $options['lang'] = $INSTALL['language'];
567 if ($configsuccess) {
568 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
570 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
572 echo "<td width=\"33.3%\"> </td>\n";
573 echo "<td width=\"33.3%\"> </td>\n";
574 echo "<td width=\"33.3%\" align=\"right\">\n";
575 print_single_button("index.php", $options, get_string('continue')." »");
581 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
583 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
585 echo "<td width=\"33.3%\"> </td>\n";
586 echo "<td width=\"33.3%\" align=\"center\">\n";
587 $installoptions = array();
588 $installoptions['download'] = 1;
589 print_single_button("install.php", $installoptions, get_string('download', 'install'));
591 echo "<td width=\"33.3%\" align=\"right\">\n";
592 print_single_button("index.php", $options, get_string('continue')." »");
598 echo "<div style=\"text-align: left\">\n";
599 print_object(s($str));
603 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
604 form_table($nextstage, $formaction);
631 //==========================================================================//
634 function print_object($object) {
642 //==========================================================================//
644 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
645 global $INSTALL, $db;
647 /// Print the standard form if we aren't in the DOWNLOADLANG page
648 /// because it has its own form.
649 if ($nextstage != DOWNLOADLANG
) {
650 $needtoopenform = false;
652 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
653 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
657 $needtoopenform = true;
660 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
663 /// what we do depends on the stage we're at
664 switch ($nextstage) {
665 case WELCOME
: /// Welcome and language settings
668 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
669 <td
class="td_right">
670 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
676 case COMPATIBILITY
: /// Compatibilty check
677 $compatsuccess = true;
679 /// Check that PHP is of a sufficient version
680 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
681 /// Check session auto start
682 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
683 /// Check magic quotes
684 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
685 /// Check unsupported PHP configuration
686 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
688 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
689 /// Check file uploads
690 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
692 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
693 /// Check memory limit
694 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
698 case DIRECTORY
: /// Directory settings
702 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
703 <td
class="td_right">
704 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
708 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
709 <td
class="td_right">
710 <input type
="text" size
="40" name
="dirrootform" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
714 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
715 <td
class="td_right">
716 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
722 case DATABASE
: /// Database settings
726 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
727 <td
class="td_right">
728 <?php
choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?
>
732 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
733 <td
class="td_right">
734 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
738 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
739 <td
class="td_right">
740 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
744 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
745 <td
class="td_right">
746 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
750 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
751 <td
class="td_right">
752 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
756 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
757 <td
class="td_right">
758 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
761 <?php
if ($INSTALL['showskipdbencodingtest']) { ?
>
763 <td
class="td_left" colspan
="2">
764 <?php
print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?
>
771 case ADMIN
: /// Administration directory setting
775 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
776 <td
class="td_right">
777 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
784 case ENVIRONMENT
: /// Environment checks
790 error_reporting(0); // Hide errors
791 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
792 error_reporting(7); // Show errors
794 /// Execute environment check, printing results
795 check_moodle_environment($INSTALL['release'], $environment_results, true);
797 /// We never should reach this because DB has been tested before arriving here
798 $errormsg = get_string('dbconnectionerror', 'install');
799 $nextstage = DATABASE
;
800 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
808 case DOWNLOADLANG
: /// Download language from download.moodle.org
814 /// Get array of languages, we are going to use it
815 $languages=get_installer_list_of_languages();
816 /// Print the download form (button) if necessary
817 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
819 $options['downloadlangpack'] = true;
820 $options['stage'] = DOWNLOADLANG
;
821 $options['same'] = true;
822 print_simple_box_start('center');
823 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
824 print_simple_box_end();
827 /// English lang packs aren't downloaded
828 if (substr($INSTALL['language'],0,2) == 'en') {
829 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
831 if ($INSTALL['downloadlangpackerror']) {
832 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
833 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
835 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
850 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
853 if ($needtoopenform) {
855 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
856 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
861 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: right\"/>\n" : " \n" ?
>
862 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: left\"/>\n" : " \n" ?
>
865 if ($needtoopenform) {
879 if (!$needtoopenform) {
891 //==========================================================================//
893 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
895 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
897 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
898 echo "<td valign=\"top\"> </td>\n";
900 echo "<td valign=\"top\"";
901 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
903 echo "<td valign=\"top\">";
904 echo "<p>$errormessage ";
905 install_helpbutton("install.php?help=$helpfield");
913 //==========================================================================//
915 function install_helpbutton($url, $title='') {
917 $title = get_string('help');
919 echo "<a href=\"javascript: void(0)\">";
920 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
921 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
922 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
928 //==========================================================================//
930 function print_install_help($help) {
932 case 'phpversionhelp':
933 print_string($help, 'install', phpversion());
935 case 'memorylimithelp':
936 print_string($help, 'install', get_memory_limit());
939 print_string($help, 'install');
944 //==========================================================================//
946 function get_memory_limit() {
947 if ($limit = ini_get('memory_limit')) {
950 return get_cfg_var('memory_limit');
954 //==========================================================================//
956 function check_memory_limit() {
958 /// if limit is already 16M or more then we don't care if we can change it or not
959 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
963 /// Otherwise, see if we can change it ourselves
964 @ini_set
('memory_limit', '16M');
965 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
968 //==========================================================================//
970 function inst_check_php_version() {
971 if (!check_php_version("4.3.0")) {
973 } else if (check_php_version("5.0.0")) {
974 return check_php_version("5.1.0"); // 5.0.x is too buggy
976 return true; // 4.3.x or 4.4.x is fine
978 //==========================================================================//
980 /* This function returns a list of languages and their full names. The
981 * list of available languages is fetched from install/lang/xx/installer.php
982 * and it's used exclusively by the installation process
983 * @return array An associative array with contents in the form of LanguageCode => LanguageName
985 function get_installer_list_of_languages() {
989 $languages = array();
991 /// Get raw list of lang directories
992 $langdirs = get_list_of_plugins('install/lang');
994 /// Get some info from each lang
995 foreach ($langdirs as $lang) {
996 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
997 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
998 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
999 $shortlang = substr($lang, 0, -5);
1003 if ($lang == 'en') { //Explain this is non-utf8 en
1004 $shortlang = 'non-utf8 en';
1006 if (!empty($string['thislanguage'])) {
1007 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1016 //==========================================================================//
1018 function css_styles() {
1021 <style type
="text/css">
1023 body
{ background
-color
: #ffeece; }
1025 font
-family
: helvetica
, arial
, sans
-serif
;
1028 a
{ text
-decoration
: none
; color
: blue
; }
1034 font
-family
: courier
, monospace
;
1050 border
-style
: solid
;
1051 border
-color
: #ffc85f;
1052 -moz
-border
-radius
-bottomleft
: 15px
;
1053 -moz
-border
-radius
-bottomright
: 15px
;
1056 background
-color
: #fee6b9;
1092 font
-family
: helvetica
, arial
, sans
-serif
;
1099 border
-color
: #ffc85f;
1102 background
-color
: #fee6b9;
1106 background
-color
: #ffeece;