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/xmlize.php');
135 require_once('./lib/componentlib.class.php');
136 require_once('./version.php');
138 /// Set version and release
139 $INSTALL['version'] = $version;
140 $INSTALL['release'] = $release;
142 /// Have the $db object ready because we are going to use it often
143 $db = &ADONewConnection($INSTALL['dbtype']);
145 /// guess the www root
146 if ($INSTALL['wwwroot'] == '') {
147 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
148 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
150 // now try to guess the correct dataroot not accessible via web
151 $CFG->wwwroot
= $INSTALL['wwwroot'];
152 $i = 0; //safety check - dirname might return some unexpected results
153 while(is_dataroot_insecure()) {
154 $parrent = dirname($CFG->dataroot
);
156 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
157 $CFG->dataroot
= ''; //can not find secure location for dataroot
160 $CFG->dataroot
= dirname($parrent).'/moodledata';
162 $INSTALL['dataroot'] = $CFG->dataroot
;
165 $headstagetext = array(WELCOME
=> get_string('chooselanguagehead', 'install'),
166 COMPATIBILITY
=> get_string('compatibilitysettingshead', 'install'),
167 DIRECTORY
=> get_string('directorysettingshead', 'install'),
168 DATABASE
=> get_string('databasesettingshead', 'install'),
169 ADMIN
=> get_string('admindirsettinghead', 'install'),
170 ENVIRONMENT
=> get_string('environmenthead', 'install'),
171 DOWNLOADLANG
=> get_string('downloadlanguagehead', 'install'),
172 SAVE
=> get_string('configurationcompletehead', 'install')
175 $substagetext = array(WELCOME
=> get_string('chooselanguagesub', 'install'),
176 COMPATIBILITY
=> get_string('compatibilitysettingssub', 'install'),
177 DIRECTORY
=> get_string('directorysettingssub', 'install'),
178 DATABASE
=> get_string('databasesettingssub', 'install'),
179 ADMIN
=> get_string('admindirsettingsub', 'install'),
180 ENVIRONMENT
=> get_string('environmentsub', 'install'),
181 DOWNLOADLANG
=> get_string('downloadlanguagesub', 'install'),
182 SAVE
=> get_string('configurationcompletesub', 'install')
187 //==========================================================================//
189 /// Are we in help mode?
191 if (isset($_GET['help'])) {
197 //==========================================================================//
199 /// Are we in config download mode?
201 if (isset($_GET['download'])) {
202 header("Content-Type: application/download\n");
203 header("Content-Disposition: attachment; filename=\"config.php\"");
204 echo $INSTALL['config'];
212 //==========================================================================//
214 /// Check the directory settings
216 if ($INSTALL['stage'] == DIRECTORY
) {
221 if (ini_get('allow_url_fopen')) {
222 if (($fh = @fopen
($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
223 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
224 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
227 if ($fh) fclose($fh);
230 if (($fh = @fopen
($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
231 $errormsg .= get_string('dirrooterror', 'install').'<br />';
232 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
234 if ($fh) fclose($fh);
237 $CFG->dataroot
= $INSTALL['dataroot'];
238 if (make_upload_directory('sessions', false) === false ) {
239 $errormsg .= get_string('datarooterror', 'install').'<br />';
241 if ($fh) fclose($fh);
243 if (!empty($errormsg)) $nextstage = DIRECTORY
;
250 //==========================================================================//
252 /// Check database settings if stage 3 data submitted
253 /// Try to connect to the database. If that fails then try to create the database
255 if ($INSTALL['stage'] == DATABASE
) {
257 /// First of all, analyze skipdbencodingtest status
258 if (isset($_POST['skipdbencodingtest'])) {
259 $INSTALL['skipdbencodingtest'] = true;
261 $INSTALL['skipdbencodingtest'] = false;
264 /// different format for postgres7 by socket
265 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' ||
$INSTALL['dbhost'] == '127.0.0.1')) {
266 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
267 $INSTALL['dbuser'] = '';
268 $INSTALL['dbpass'] = '';
269 $INSTALL['dbname'] = '';
271 if ($INSTALL['prefix'] == '') { /// must have a prefix
272 $INSTALL['prefix'] = 'mdl_';
276 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
277 if (!extension_loaded('mysql')) {
278 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
279 $nextstage = DATABASE
;
283 if (empty($errormsg)) {
285 error_reporting(0); // Hide errors
287 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
288 /// The following doesn't seem to work but we're working on it
289 /// If you come up with a solution for creating a database in MySQL
290 /// feel free to put it in and let us know
291 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
292 switch ($INSTALL['dbtype']) { /// Try to create a database
294 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
295 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
297 $errormsg = get_string('dbcreationerror', 'install');
298 $nextstage = DATABASE
;
304 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
305 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
306 if (empty($INSTALL['skipdbencodingtest'])) {
307 /// We haven't checked the skip test checkbox, so perform the test
309 switch ($INSTALL['dbtype']) {
311 ///Get MySQL character_set_database value
312 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
313 if ($rs && $rs->RecordCount() > 0) {
314 $records = $rs->GetAssoc(true);
315 $encoding = $records['character_set_database']['Value'];
316 if (strtoupper($encoding) == 'UTF8') {
317 $INSTALL['dbencodingtestresults'] = true;
319 // Try to set the encoding now!
320 if (! $db->Metatables()) { // We have no tables so go ahead
321 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
322 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
324 $records = $rs->GetAssoc(true);
325 $encoding = $records['character_set_database']['Value'];
327 if (strtoupper($encoding) == 'UTF8') {
328 $INSTALL['dbencodingtestresults'] = true;
330 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
331 $nextstage = DATABASE
;
332 $INSTALL['showskipdbencodingtest'] = true;
333 $INSTALL['dbencodingtestresults'] = false;
336 $INSTALL['showskipdbencodingtest'] = true;
337 $INSTALL['dbencodingtestresults'] = false;
343 ///Get PostgreSQL server_encoding value
344 $rs = $db->Execute("SHOW server_encoding");
345 if ($rs && $rs->RecordCount() > 0) {
346 $encoding = $rs->fields
['server_encoding'];
347 if (strtoupper($encoding) != 'UNICODE' && strtoupper($encoding) != 'UTF8') {
348 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
349 $nextstage = DATABASE
;
350 $INSTALL['showskipdbencodingtest'] = true;
351 $INSTALL['dbencodingtestresults'] = false;
353 $INSTALL['dbencodingtestresults'] = true;
364 if (($dbconnected === false) and (empty($errormsg)) ) {
365 $errormsg = get_string('dbconnectionerror', 'install');
366 $nextstage = DATABASE
;
372 //==========================================================================//
374 /// If the next stage is admin directory settings OR we have just come from there then
375 /// check the admin directory.
376 /// If we can open a file then we know that the admin name is correct.
378 if ($nextstage == ADMIN
or $INSTALL['stage'] == ADMIN
) {
379 if (!ini_get('allow_url_fopen')) {
380 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
381 } else if (($fh = @fopen
($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
382 $nextstage = ($goforward) ? ENVIRONMENT
: DATABASE
;
385 if ($nextstage != ADMIN
) {
386 $errormsg = get_string('admindirerror', 'install');
392 //==========================================================================//
394 // Check if we can navigate from the environemt page (because it's ok)
396 if ($INSTALL['stage'] == ENVIRONMENT
) {
397 error_reporting(0); // Hide errors
398 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
399 error_reporting(7); // Show errors
401 /// Execute environment check, printing results
402 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
403 $nextstage = ENVIRONMENT
;
406 /// We never should reach this because DB has been tested before arriving here
407 $errormsg = get_string('dbconnectionerror', 'install');
408 $nextstage = DATABASE
;
414 //==========================================================================//
416 // Try to download the lang pack if it has been selected
418 if ($INSTALL['stage'] == DOWNLOADLANG
&& $INSTALL['downloadlangpack']) {
420 $downloadsuccess = false;
423 error_reporting(0); // Hide errors
425 /// Create necessary lang dir
426 if (!make_upload_directory('lang', false)) {
427 $downloaderror = get_string('cannotcreatelangdir', 'error');
430 /// Download and install component
431 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
432 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
433 $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED
436 if ($cd->get_error() == 'remotedownloadnotallowed') {
438 $a->url
= 'http://download.moodle.org/lang16/'.$pack.'zip';
439 $a->dest
= $CFG->dataroot
.'/lang';
440 $downloaderror = get_string($cd->get_error(), 'error', $a);
442 $downloaderror = get_string($cd->get_error(), 'error');
447 $downloadsuccess = true;
450 //We shouldn't reach this point
453 //We shouldn't reach this point
456 error_reporting(7); // Show errors
458 if ($downloadsuccess) {
459 $INSTALL['downloadlangpack'] = false;
460 $INSTALL['showdownloadlangpack'] = false;
461 $INSTALL['downloadlangpackerror'] = $downloaderror;
463 $INSTALL['downloadlangpack'] = false;
464 $INSTALL['showdownloadlangpack'] = false;
465 $INSTALL['downloadlangpackerror'] = $downloaderror;
471 //==========================================================================//
473 /// Display or print the data
474 /// Put the data into a string
475 /// Try to open config file for writing.
477 if ($nextstage == SAVE
) {
479 $str = '<?php /// Moodle Configuration File '."\r\n";
482 $str .= 'unset($CFG);'."\r\n";
485 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
486 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
487 if (!empty($INSTALL['dbname'])) {
488 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
489 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
490 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
492 $str .= '$CFG->dbpersist = false;'."\r\n";
493 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
496 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
497 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
498 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
499 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
502 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
505 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
506 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
510 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
511 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
512 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
517 if (( $configsuccess = ($fh = @fopen
($configfile, 'w')) ) !== false) {
523 $INSTALL['config'] = $str;
528 //==========================================================================//
531 <html dir
="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
533 <link rel
="shortcut icon" href
="theme/standard/favicon.ico" />
534 <title
>Moodle Install
</title
>
535 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
536 <?php
css_styles() ?
>
544 if (isset($_GET['help'])) {
545 print_install_help($_GET['help']);
546 close_window_button();
551 <table
class="main" align
="center" cellpadding
="3" cellspacing
="0">
553 <td
class="td_mainlogo">
554 <p
class="p_mainlogo"><img src
="pix/moodlelogo-med.gif" width
="240" height
="60" alt
="Moodle logo"></p
>
556 <td
class="td_mainlogo" valign
="bottom">
557 <p
class="p_mainheader"><?php
print_string('installation', 'install') ?
></p
>
562 <td
class="td_mainheading" colspan
="2">
563 <p
class="p_mainheading"><?php
echo $headstagetext[$nextstage] ?
></p
>
564 <?php
if (!empty($substagetext[$nextstage])) { ?
>
565 <p
class="p_subheading"><?php
echo $substagetext[$nextstage] ?
></p
>
571 <td
class="td_main" colspan
="2">
575 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
578 if ($nextstage == SAVE
) {
579 $INSTALL['stage'] = WELCOME
;
581 $options['lang'] = $INSTALL['language'];
582 if ($configsuccess) {
583 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
585 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
587 echo "<td width=\"33.3%\"> </td>\n";
588 echo "<td width=\"33.3%\"> </td>\n";
589 echo "<td width=\"33.3%\" align=\"right\">\n";
590 print_single_button("index.php", $options, get_string('continue')." »");
596 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
598 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
600 echo "<td width=\"33.3%\"> </td>\n";
601 echo "<td width=\"33.3%\" align=\"center\">\n";
602 $installoptions = array();
603 $installoptions['download'] = 1;
604 print_single_button("install.php", $installoptions, get_string('download', 'install'));
606 echo "<td width=\"33.3%\" align=\"right\">\n";
607 print_single_button("index.php", $options, get_string('continue')." »");
613 echo "<div style=\"text-align: left\">\n";
614 print_object(s($str));
618 $formaction = (isset($_GET['configfile'])) ?
"install.php?configfile=".$_GET['configfile'] : "install.php";
619 form_table($nextstage, $formaction);
646 //==========================================================================//
649 function print_object($object) {
657 //==========================================================================//
659 function form_table($nextstage = WELCOME
, $formaction = "install.php") {
660 global $INSTALL, $db;
662 /// Print the standard form if we aren't in the DOWNLOADLANG page
663 /// because it has its own form.
664 if ($nextstage != DOWNLOADLANG
) {
665 $needtoopenform = false;
667 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
668 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
672 $needtoopenform = true;
675 <table
class="install_table" cellspacing
="3" cellpadding
="3" align
="center">
678 /// what we do depends on the stage we're at
679 switch ($nextstage) {
680 case WELCOME
: /// Welcome and language settings
683 <td
class="td_left"><p
><?php
print_string('language') ?
></p
></td
>
684 <td
class="td_right">
685 <?php
choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?
>
691 case COMPATIBILITY
: /// Compatibilty check
692 $compatsuccess = true;
694 /// Check that PHP is of a sufficient version
695 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
696 /// Check session auto start
697 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
698 /// Check magic quotes
699 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
700 /// Check unsupported PHP configuration
701 print_compatibility_row(ini_get_bool('magic_quotes_gpc') ||
(!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
703 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
704 /// Check file uploads
705 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
707 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
708 /// Check memory limit
709 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
713 case DIRECTORY
: /// Directory settings
717 <td
class="td_left"><p
><?php
print_string('wwwroot', 'install') ?
></p
></td
>
718 <td
class="td_right">
719 <input type
="text" size
="40"name
="wwwrootform" value
="<?php p($INSTALL['wwwrootform'],true) ?>" />
723 <td
class="td_left"><p
><?php
print_string('dirroot', 'install') ?
></p
></td
>
724 <td
class="td_right">
725 <input type
="text" size
="40" name
="dirrootform" value
="<?php p($INSTALL['dirrootform'],true) ?>" />
729 <td
class="td_left"><p
><?php
print_string('dataroot', 'install') ?
></p
></td
>
730 <td
class="td_right">
731 <input type
="text" size
="40" name
="dataroot" value
="<?php p($INSTALL['dataroot'],true) ?>" />
737 case DATABASE
: /// Database settings
741 <td
class="td_left"><p
><?php
print_string('dbtype', 'install') ?
></p
></td
>
742 <td
class="td_right">
743 <?php
choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?
>
747 <td
class="td_left"><p
><?php
print_string('dbhost', 'install') ?
></p
></td
>
748 <td
class="td_right">
749 <input type
="text" size
="40" name
="dbhost" value
="<?php echo $INSTALL['dbhost'] ?>" />
753 <td
class="td_left"><p
><?php
print_string('database', 'install') ?
></p
></td
>
754 <td
class="td_right">
755 <input type
="text" size
="40" name
="dbname" value
="<?php echo $INSTALL['dbname'] ?>" />
759 <td
class="td_left"><p
><?php
print_string('user') ?
></p
></td
>
760 <td
class="td_right">
761 <input type
="text" size
="40" name
="dbuser" value
="<?php echo $INSTALL['dbuser'] ?>" />
765 <td
class="td_left"><p
><?php
print_string('password') ?
></p
></td
>
766 <td
class="td_right">
767 <input type
="password" size
="40" name
="dbpass" value
="<?php echo $INSTALL['dbpass'] ?>" />
771 <td
class="td_left"><p
><?php
print_string('dbprefix', 'install') ?
></p
></td
>
772 <td
class="td_right">
773 <input type
="text" size
="40" name
="prefix" value
="<?php echo $INSTALL['prefix'] ?>" />
776 <?php
if ($INSTALL['showskipdbencodingtest']) { ?
>
778 <td
class="td_left" colspan
="2">
779 <?php
print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?
>
786 case ADMIN
: /// Administration directory setting
790 <td
class="td_left"><p
><?php
print_string('admindirname', 'install') ?
></p
></td
>
791 <td
class="td_right">
792 <input type
="text" size
="40" name
="admindirname" value
="<?php echo $INSTALL['admindirname'] ?>" />
799 case ENVIRONMENT
: /// Environment checks
805 error_reporting(0); // Hide errors
806 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
807 error_reporting(7); // Show errors
809 /// Execute environment check, printing results
810 check_moodle_environment($INSTALL['release'], $environment_results, true);
812 /// We never should reach this because DB has been tested before arriving here
813 $errormsg = get_string('dbconnectionerror', 'install');
814 $nextstage = DATABASE
;
815 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
823 case DOWNLOADLANG
: /// Download language from download.moodle.org
829 /// Get array of languages, we are going to use it
830 $languages=get_installer_list_of_languages();
831 /// Print the download form (button) if necessary
832 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
834 $options['downloadlangpack'] = true;
835 $options['stage'] = DOWNLOADLANG
;
836 $options['same'] = true;
837 print_simple_box_start('center');
838 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST');
839 print_simple_box_end();
842 /// English lang packs aren't downloaded
843 if (substr($INSTALL['language'],0,2) == 'en') {
844 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
846 if ($INSTALL['downloadlangpackerror']) {
847 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
848 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
850 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
865 <td colspan
="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
868 if ($needtoopenform) {
870 <form name
="installform" method
="post" action
="<?php echo $formaction ?>">
871 <input type
="hidden" name
="stage" value
="<?php echo $nextstage ?>" />
876 <?php
echo ($nextstage < SAVE
) ?
"<input type=\"submit\" name=\"next\" value=\"".get_string('next')." »\" style=\"float: right\"/>\n" : " \n" ?
>
877 <?php
echo ($nextstage > WELCOME
) ?
"<input type=\"submit\" name=\"prev\" value=\"« ".get_string('previous')."\" style=\"float: left\"/>\n" : " \n" ?
>
880 if ($needtoopenform) {
894 if (!$needtoopenform) {
906 //==========================================================================//
908 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
910 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
912 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
913 echo "<td valign=\"top\"> </td>\n";
915 echo "<td valign=\"top\"";
916 echo ($caution) ?
"<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
918 echo "<td valign=\"top\">";
919 echo "<p>$errormessage ";
920 install_helpbutton("install.php?help=$helpfield");
928 //==========================================================================//
930 function install_helpbutton($url, $title='') {
932 $title = get_string('help');
934 echo "<a href=\"javascript: void(0)\">";
935 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
936 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
937 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
943 //==========================================================================//
945 function print_install_help($help) {
947 case 'phpversionhelp':
948 print_string($help, 'install', phpversion());
950 case 'memorylimithelp':
951 print_string($help, 'install', get_memory_limit());
954 print_string($help, 'install');
959 //==========================================================================//
961 function get_memory_limit() {
962 if ($limit = ini_get('memory_limit')) {
965 return get_cfg_var('memory_limit');
969 //==========================================================================//
971 function check_memory_limit() {
973 /// if limit is already 16M or more then we don't care if we can change it or not
974 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
978 /// Otherwise, see if we can change it ourselves
979 @ini_set
('memory_limit', '16M');
980 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
983 //==========================================================================//
985 function inst_check_php_version() {
986 if (!check_php_version("4.3.0")) {
988 } else if (check_php_version("5.0.0")) {
989 return check_php_version("5.1.0"); // 5.0.x is too buggy
991 return true; // 4.3.x or 4.4.x is fine
993 //==========================================================================//
995 /* This function returns a list of languages and their full names. The
996 * list of available languages is fetched from install/lang/xx/installer.php
997 * and it's used exclusively by the installation process
998 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1000 function get_installer_list_of_languages() {
1004 $languages = array();
1006 /// Get raw list of lang directories
1007 $langdirs = get_list_of_plugins('install/lang');
1009 /// Get some info from each lang
1010 foreach ($langdirs as $lang) {
1011 if (file_exists($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php')) {
1012 include($CFG->dirroot
.'/install/lang/'. $lang .'/installer.php');
1013 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1014 $shortlang = substr($lang, 0, -5);
1018 if ($lang == 'en') { //Explain this is non-utf8 en
1019 $shortlang = 'non-utf8 en';
1021 if (!empty($string['thislanguage'])) {
1022 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
1031 //==========================================================================//
1033 function css_styles() {
1036 <style type
="text/css">
1038 body
{ background
-color
: #ffeece; }
1040 font
-family
: helvetica
, arial
, sans
-serif
;
1043 a
{ text
-decoration
: none
; color
: blue
; }
1049 font
-family
: courier
, monospace
;
1065 border
-style
: solid
;
1066 border
-color
: #ffc85f;
1067 -moz
-border
-radius
-bottomleft
: 15px
;
1068 -moz
-border
-radius
-bottomright
: 15px
;
1071 background
-color
: #fee6b9;
1107 font
-family
: helvetica
, arial
, sans
-serif
;
1114 border
-color
: #ffc85f;
1117 background
-color
: #fee6b9;
1121 background
-color
: #ffeece;