Removed links to locallib.php
[moodle-linuxchix.git] / install.php
blob7765dccd8392b93dc7f2af36d0ab8a6ba3f4d358
1 <?php /// $Id$
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');
8 die;
9 } else {
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 ('SAVE', 6); /// 6. Save or display the settings
22 define ('REDIRECT', 7); /// 7. Redirect to index.php
23 ///==========================================================================//
27 /// Begin the session as we are holding all information in a session
28 /// variable until the end.
30 session_name('MoodleSession');
31 @session_start();
33 if (! isset($_SESSION['INSTALL'])) {
34 $_SESSION['INSTALL'] = array();
37 $INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
40 /// If it's our first time through this script then we need to set some default values
42 if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
44 /// set defaults
45 $INSTALL['language'] = 'en';
47 $INSTALL['dbhost'] = 'localhost';
48 $INSTALL['dbuser'] = '';
49 $INSTALL['dbpass'] = '';
50 $INSTALL['dbtype'] = 'mysql';
51 $INSTALL['dbname'] = 'moodle';
52 $INSTALL['prefix'] = 'mdl_';
54 $INSTALL['dbencodingtestresults'] = false;
55 $INSTALL['showskipdbencodingtest'] = false;
56 $INSTALL['skipdbencodingtest'] = false;
58 $INSTALL['wwwroot'] = '';
59 $INSTALL['dirroot'] = dirname(__FILE__);
60 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
62 $INSTALL['admindirname'] = 'admin';
64 $INSTALL['stage'] = WELCOME;
67 //==========================================================================//
69 /// Was data submitted?
71 if (isset($_POST['stage'])) {
73 /// Get the stage for which the form was set and the next stage we are going to
76 if ( $goforward = (! empty( $_POST['next'] )) ) {
77 $nextstage = $_POST['stage'] + 1;
78 } else {
79 $nextstage = $_POST['stage'] - 1;
83 if ($nextstage < 0) $nextstage = WELCOME;
86 /// Store any posted data
87 foreach ($_POST as $setting=>$value) {
88 $INSTALL[$setting] = $value;
91 } else {
93 $goforward = true;
94 $nextstage = WELCOME;
98 //==========================================================================//
100 /// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
102 $SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
103 $CFG->dirroot = $INSTALL['dirroot'];
104 $CFG->libdir = $INSTALL['dirroot'].'/lib';
105 $CFG->dataroot = $INSTALL['dataroot'];
106 $CFG->admin = $INSTALL['admindirname'];
107 $CFG->directorypermissions = 00777;
109 /// Include some moodle libraries
111 require_once('./lib/setuplib.php');
112 require_once('./lib/moodlelib.php');
113 require_once('./lib/weblib.php');
114 require_once('./lib/adodb/adodb.inc.php');
115 require_once('./lib/environmentlib.php');
116 require_once('./lib/xmlize.php');
117 require_once('./version.php');
119 /// Set version and release
120 $INSTALL['version'] = $version;
121 $INSTALL['release'] = $release;
123 /// Have the $db object ready because we are going to use it often
124 $db = &ADONewConnection($INSTALL['dbtype']);
126 /// guess the www root
127 if ($INSTALL['wwwroot'] == '') {
128 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
131 $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
132 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
133 DIRECTORY => get_string('directorysettingshead', 'install'),
134 DATABASE => get_string('databasesettingshead', 'install'),
135 ADMIN => get_string('admindirsettinghead', 'install'),
136 ENVIRONMENT => get_string('environmenthead', 'install'),
137 SAVE => get_string('configurationcompletehead', 'install')
140 $substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
141 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
142 DIRECTORY => get_string('directorysettingssub', 'install'),
143 DATABASE => get_string('databasesettingssub', 'install'),
144 ADMIN => get_string('admindirsettingsub', 'install'),
145 ENVIRONMENT => get_string('environmentsub', 'install'),
146 SAVE => get_string('configurationcompletesub', 'install')
151 //==========================================================================//
153 /// Are we in help mode?
155 if (isset($_GET['help'])) {
156 $nextstage = -1;
161 //==========================================================================//
163 /// Are we in config download mode?
165 if (isset($_GET['download'])) {
166 header("Content-Type: application/download\n");
167 header("Content-Disposition: attachment; filename=\"config.php\"");
168 echo $INSTALL['config'];
169 exit;
176 //==========================================================================//
178 /// Check the directory settings
180 if ($INSTALL['stage'] == DIRECTORY) {
182 error_reporting(0);
185 /// check dirroot
186 if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) {
187 $CFG->dirroot = dirname(__FILE__);
188 $INSTALL['dirroot'] = dirname(__FILE__);
189 $errormsg .= get_string('dirrooterror', 'install').'<br />';
191 if ($fh) fclose($fh);
193 $CFG->dirroot = $INSTALL['dirroot'];
195 /// check wwwroot
196 if (ini_get('allow_url_fopen')) {
197 if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) {
198 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
201 if ($fh) fclose($fh);
203 /// check dataroot
204 $CFG->dataroot = $INSTALL['dataroot'];
205 if (make_upload_directory('sessions', false) === false ) {
206 $errormsg = get_string('datarooterror', 'install').'<br />';
208 if ($fh) fclose($fh);
210 if (!empty($errormsg)) $nextstage = DIRECTORY;
212 error_reporting(7);
217 //==========================================================================//
219 /// Check database settings if stage 3 data submitted
220 /// Try to connect to the database. If that fails then try to create the database
222 if ($INSTALL['stage'] == DATABASE) {
224 /// First of all, analyze skipdbencodingtest status
225 if (isset($_POST['skipdbencodingtest'])) {
226 $INSTALL['skipdbencodingtest'] = true;
227 } else {
228 $INSTALL['skipdbencodingtest'] = false;
231 /// different format for postgres7 by socket
232 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
233 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
234 $INSTALL['dbuser'] = '';
235 $INSTALL['dbpass'] = '';
236 $INSTALL['dbname'] = '';
238 if ($INSTALL['prefix'] == '') { /// must have a prefix
239 $INSTALL['prefix'] = 'mdl_';
243 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
244 if (!extension_loaded('mysql')) {
245 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
246 $nextstage = DATABASE;
250 if (empty($errormsg)) {
252 error_reporting(0); // Hide errors
254 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
255 /// The following doesn't seem to work but we're working on it
256 /// If you come up with a solution for creating a database in MySQL
257 /// feel free to put it in and let us know
258 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
259 switch ($INSTALL['dbtype']) { /// Try to create a database
260 case 'mysql':
261 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
262 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
263 } else {
264 $errormsg = get_string('dbcreationerror', 'install');
265 $nextstage = DATABASE;
267 break;
270 } else {
271 /// We have been able to connect properly, just test the database encoding now. It should be Unicode for 1.6
272 /// installations (although not mandatory for now). Just show one message about it and allow to skip this test.
273 if (empty($INSTALL['skipdbencodingtest'])) {
274 /// We haven't checked the skip test checkbox, so perform the test
275 $encoding = '';
276 switch ($INSTALL['dbtype']) {
277 case 'mysql':
278 ///Get MySQL character_set_database value
279 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
280 if ($rs && $rs->RecordCount() > 0) {
281 $records = $rs->GetAssoc(true);
282 $encoding = $records['character_set_database']['Value'];
283 if (strtoupper($encoding) != 'UTF8') {
284 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
285 $nextstage = DATABASE;
286 $INSTALL['showskipdbencodingtest'] = true;
287 $INSTALL['dbencodingtestresults'] = false;
288 } else {
289 $INSTALL['dbencodingtestresults'] = true;
292 break;
293 case 'postgres7':
294 ///Get PostgreSQL server_encoding value
295 $rs = $db->Execute("SHOW server_encoding");
296 if ($rs && $rs->RecordCount() > 0) {
297 $encoding = $rs->fields['server_encoding'];
298 if (strtoupper($encoding) != 'UNICODE') {
299 $errormsg = get_string('dbwrongencoding', 'install', $encoding);
300 $nextstage = DATABASE;
301 $INSTALL['showskipdbencodingtest'] = true;
302 $INSTALL['dbencodingtestresults'] = false;
303 } else {
304 $INSTALL['dbencodingtestresults'] = true;
307 break;
313 error_reporting(7);
315 if (($dbconnected === false) and (empty($errormsg)) ) {
316 $errormsg = get_string('dbconnectionerror', 'install');
317 $nextstage = DATABASE;
323 //==========================================================================//
325 /// If the next stage is admin directory settings OR we have just come from there then
326 /// check the admin directory.
327 /// If we can open a file then we know that the admin name is correct.
329 if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
330 if (!ini_get('allow_url_fopen')) {
331 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
332 } else if (($fh = @fopen($INSTALL['wwwroot'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
333 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
334 fclose($fh);
335 } else {
336 if ($nextstage != ADMIN) {
337 $errormsg = get_string('admindirerror', 'install');
338 $nextstage = ADMIN;
343 //==========================================================================//
345 // Check if we can navigate from the environemt page (because it's ok)
347 if ($INSTALL['stage'] == ENVIRONMENT) {
348 error_reporting(0); // Hide errors
349 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
350 error_reporting(7); // Show errors
351 if ($dbconnected) {
352 /// Execute environment check, printing results
353 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
354 $nextstage = ENVIRONMENT;
356 } else {
357 /// We never should reach this because DB has been tested before arriving here
358 $errormsg = get_string('dbconnectionerror', 'install');
359 $nextstage = DATABASE;
364 //==========================================================================//
366 /// Display or print the data
367 /// Put the data into a string
368 /// Try to open config file for writing.
370 if ($nextstage == SAVE) {
372 $str = '<?php /// Moodle Configuration File '."\r\n";
373 $str .= "\r\n";
375 $str .= 'unset($CFG);'."\r\n";
376 $str .= "\r\n";
378 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
379 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
380 if (!empty($INSTALL['dbname'])) {
381 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
382 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
383 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
385 $str .= '$CFG->dbpersist = false;'."\r\n";
386 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
387 $str .= "\r\n";
389 $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\r\n";
390 $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\r\n";
391 $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\r\n";
392 $str .= '$CFG->admin = \''.$INSTALL['admindirname']."';\r\n";
393 $str .= "\r\n";
395 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
396 $str .= "\r\n";
398 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
399 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
400 $str .= "\r\n";
403 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
404 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
405 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
406 $str .= '?>';
408 umask(0137);
410 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
411 fwrite($fh, $str);
412 fclose($fh);
416 $INSTALL['config'] = $str;
421 //==========================================================================//
427 <html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
428 <head>
429 <link rel="shortcut icon" href="theme/standard/favicon.ico" />
430 <title>Moodle Install</title>
431 <meta http-equiv="content-type" content="text/html; charset=<?php p(current_charset()) ?>" />
432 <?php css_styles() ?>
434 </head>
436 <body>
439 <?php
440 if (isset($_GET['help'])) {
441 print_install_help($_GET['help']);
442 close_window_button();
443 } else {
447 <table class="main" align="center" cellpadding="3" cellspacing="0">
448 <tr>
449 <td class="td_mainlogo">
450 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt=\"\"></p>
451 </td>
452 <td class="td_mainlogo" valign="bottom">
453 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
454 </td>
455 </tr>
457 <tr>
458 <td class="td_mainheading" colspan="2">
459 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
460 <?php if (!empty($substagetext[$nextstage])) { ?>
461 <p class="p_subheading"><?php echo $substagetext[$nextstage] ?></p>
462 <?php } ?>
463 </td>
464 </tr>
466 <tr>
467 <td class="td_main" colspan="2">
469 <?php
471 if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
474 if ($nextstage == SAVE) {
475 $INSTALL['stage'] = WELCOME;
476 $options = array();
477 $options['lang'] = $INSTALL['language'];
478 if ($configsuccess) {
479 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
481 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
482 echo "<tr>\n";
483 echo "<td width=\"33.3%\">&nbsp;</td>\n";
484 echo "<td width=\"33.3%\">&nbsp;</td>\n";
485 echo "<td width=\"33.3%\" align=\"right\">\n";
486 print_single_button("index.php", $options, get_string('continue')." &raquo;");
487 echo "</td>\n";
488 echo "</tr>\n";
489 echo "</table>\n";
491 } else {
492 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
494 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
495 echo "<tr>\n";
496 echo "<td width=\"33.3%\">&nbsp;</td>\n";
497 echo "<td width=\"33.3%\" align=\"center\">\n";
498 $installoptions = array();
499 $installoptions['download'] = 1;
500 print_single_button("install.php", $installoptions, get_string('download', 'install'));
501 echo "</td>\n";
502 echo "<td width=\"33.3%\" align=\"right\">\n";
503 print_single_button("index.php", $options, get_string('continue')." &raquo;");
504 echo "</td>\n";
505 echo "</tr>\n";
506 echo "</table>\n";
508 echo "<hr />\n";
509 echo "<div style=\"text-align: left\">\n";
510 print_object(htmlentities($str));
511 echo "</div>\n";
513 } else {
514 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
515 form_table($nextstage, $formaction);
520 </td>
521 </tr>
522 </table>
524 <?php
528 </body>
529 </html>
540 <?php
542 //==========================================================================//
545 function print_object($object) {
546 echo "<pre>\n";
547 print_r($object);
548 echo "</pre>\n";
553 //==========================================================================//
555 function form_table($nextstage = WELCOME, $formaction = "install.php") {
556 global $INSTALL, $db;
558 /// standard lines for all forms
561 <form name="installform" method="post" action="<?php echo $formaction ?>">
562 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
563 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
565 <?php
566 /// what we do depends on the stage we're at
567 switch ($nextstage) {
568 case WELCOME: /// Welcome and language settings
570 <tr>
571 <td class="td_left"><p><?php print_string('language') ?></p></td>
572 <td class="td_right">
573 <?php choose_from_menu (get_list_of_languages(), 'language', $INSTALL['language'], '') ?>
574 </td>
575 </tr>
577 <?php
578 break;
579 case COMPATIBILITY: /// Compatibilty check
580 $compatsuccess = true;
582 /// Check that PHP is of a sufficient version
583 print_compatibility_row(check_php_version("4.1.0"), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
584 /// Check session auto start
585 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
586 /// Check magic quotes
587 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
588 /// Check unsupported PHP configuration
589 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
590 /// Check safe mode
591 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
592 /// Check file uploads
593 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
594 /// Check GD version
595 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
596 /// Check memory limit
597 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
600 break;
601 case DIRECTORY: /// Directory settings
604 <tr>
605 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
606 <td class="td_right">
607 <input type="text" size="40"name="wwwroot" value="<?php echo $INSTALL['wwwroot'] ?>" />
608 </td>
609 </tr>
610 <tr>
611 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
612 <td class="td_right">
613 <input type="text" size="40" name="dirroot" value="<?php echo $INSTALL['dirroot'] ?>" />
614 </td>
615 </tr>
616 <tr>
617 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
618 <td class="td_right">
619 <input type="text" size="40" name="dataroot" value="<?php echo $INSTALL['dataroot'] ?>" />
620 </td>
621 </tr>
623 <?php
624 break;
625 case DATABASE: /// Database settings
628 <tr>
629 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
630 <td class="td_right">
631 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>
632 </td>
633 </tr>
634 <tr>
635 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
636 <td class="td_right">
637 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
638 </td>
639 </tr>
640 <tr>
641 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
642 <td class="td_right">
643 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
644 </td>
645 </tr>
646 <tr>
647 <td class="td_left"><p><?php print_string('user') ?></p></td>
648 <td class="td_right">
649 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
650 </td>
651 </tr>
652 <tr>
653 <td class="td_left"><p><?php print_string('password') ?></p></td>
654 <td class="td_right">
655 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
656 </td>
657 </tr>
658 <tr>
659 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
660 <td class="td_right">
661 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
662 </td>
663 </tr>
664 <?php if ($INSTALL['showskipdbencodingtest']) { ?>
665 <tr>
666 <td class="td_left" colspan="2">
667 <?php print_checkbox ('skipdbencodingtest', '1', $INSTALL['skipdbencodingtest'], get_string('skipdbencodingtest', 'install')) ?>
668 </td>
669 </tr>
670 <?php } ?>
672 <?php
673 break;
674 case ADMIN: /// Administration directory setting
677 <tr>
678 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
679 <td class="td_right">
680 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
681 </td>
682 </tr>
685 <?php
686 break;
687 case ENVIRONMENT: /// Environment checks
690 <tr>
691 <td colspan="2">
692 <?php
693 error_reporting(0); // Hide errors
694 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
695 error_reporting(7); // Show errors
696 if ($dbconnected) {
697 /// Execute environment check, printing results
698 check_moodle_environment($INSTALL['release'], $environment_results, true);
699 } else {
700 /// We never should reach this because DB has been tested before arriving here
701 $errormsg = get_string('dbconnectionerror', 'install');
702 $nextstage = DATABASE;
703 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
706 </td>
707 </tr>
711 <?php
712 break;
713 default:
717 <tr>
718 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
720 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
721 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
724 </td>
726 </tr>
728 </table>
729 </form>
731 <?php
736 //==========================================================================//
738 function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
739 echo "<tr>\n";
740 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
741 if ($success) {
742 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
743 echo "<td valign=\"top\">&nbsp;</td>\n";
744 } else {
745 echo "<td valign=\"top\"";
746 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
747 echo "</p></td>\n";
748 echo "<td valign=\"top\">";
749 echo "<p>$errormessage ";
750 install_helpbutton("install.php?help=$helpfield");
751 echo "</p></td>\n";
753 echo "</tr>\n";
754 return $success;
758 //==========================================================================//
760 function install_helpbutton($url, $title='') {
761 if ($title == '') {
762 $title = get_string('help');
764 echo "<a href=\"javascript: void(0)\">";
765 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
766 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
767 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
768 echo "</a>\n";
773 //==========================================================================//
775 function print_install_help($help) {
776 switch ($help) {
777 case 'phpversionhelp':
778 print_string($help, 'install', phpversion());
779 break;
780 case 'memorylimithelp':
781 print_string($help, 'install', get_memory_limit());
782 break;
783 default:
784 print_string($help, 'install');
789 //==========================================================================//
791 function get_memory_limit() {
792 if ($limit = ini_get('memory_limit')) {
793 return $limit;
794 } else {
795 return get_cfg_var('memory_limit');
799 //==========================================================================//
801 function check_memory_limit() {
803 /// if limit is already 16M or more then we don't care if we can change it or not
804 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
805 return true;
808 /// Otherwise, see if we can change it ourselves
809 @ini_set('memory_limit', '16M');
810 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
813 //==========================================================================//
815 function css_styles() {
818 <style type="text/css">
820 body { background-color: #ffeece; }
821 p, li, td {
822 font-family: helvetica, arial, sans-serif;
823 font-size: 10pt;
825 a { text-decoration: none; color: blue; }
826 .errormsg {
827 color: red;
828 font-weight: bold;
830 blockquote {
831 font-family: courier, monospace;
832 font-size: 10pt;
834 .install_table {
835 width: 500px;
837 .td_left {
838 text-align: right;
839 font-weight: bold;
841 .td_right {
842 text-align: left;
844 .main {
845 width: 500px;
846 border-width: 1px;
847 border-style: solid;
848 border-color: #ffc85f;
849 -moz-border-radius-bottomleft: 15px;
850 -moz-border-radius-bottomright: 15px;
852 .td_mainheading {
853 background-color: #fee6b9;
854 padding: 10px;
856 .td_main {
857 text-align: center;
859 .td_mainlogo {
861 .p_mainlogo {
863 .p_mainheading {
864 font-size: 11pt;
866 .p_subheading {
867 font-size: 10pt;
868 padding: 10px;
870 .p_mainheader{
871 text-align: right;
872 font-size: 20pt;
873 font-weight: bold;
875 .p_pass {
876 color: green;
877 font-weight: bold;
879 .p_fail {
880 color: red;
881 font-weight: bold;
883 .p_caution {
884 color: #ff6600;
885 font-weight: bold;
887 .p_help {
888 text-align: center;
889 font-family: helvetica, arial, sans-serif;
890 font-size: 14pt;
891 font-weight: bold;
892 color: #333333;
894 .environmenttable {
895 font-size: 10pt;
896 border-color: #ffc85f;
898 .header {
899 background-color: #fee6b9;
900 font-size: 10pt;
902 .cell {
903 background-color: #ffeece;
904 font-size: 10pt;
906 .error {
907 color: #ff0000;
909 .errorboxcontent {
910 text-align: center;
911 font-weight: bold;
912 padding: 20px;
913 color: #ff0000;
916 </style>
918 <?php