Fix for bug 4678 contributed by rwmoore
[moodle.git] / install.php
CommitLineData
8b5b1028 1<?php /// $Id$
2 /// install.php - helps admin user to create a config.php file
3
4/// If config.php exists already then we are not needed.
5
51e3e0b9 6if (file_exists('./config.php')) {
8b5b1028 7 header('Location: index.php');
51e3e0b9 8 die;
8b5b1028 9} else {
10 $configfile = './config.php';
11}
12
13///==========================================================================//
14/// We are doing this in stages
3470b39f 15define ('WELCOME', 0); /// 0. Welcome and language settings
16define ('COMPATIBILITY', 1); /// 1. Compatibility
17define ('DIRECTORY', 2); /// 2. Directory settings
18define ('DATABASE', 3); /// 2. Database settings
19define ('ADMIN', 4); /// 4. Administration directory name
3b3b8029 20define ('ENVIRONMENT', 5); /// 5. Administration directory name
21define ('SAVE', 6); /// 6. Save or display the settings
22define ('REDIRECT', 7); /// 7. Redirect to index.php
8b5b1028 23///==========================================================================//
24
25
8d783716 26
8b5b1028 27/// Begin the session as we are holding all information in a session
28/// variable until the end.
29
30session_name('MoodleSession');
31@session_start();
32
33if (! isset($_SESSION['INSTALL'])) {
34 $_SESSION['INSTALL'] = array();
35}
36
37$INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
38
8d783716 39
40/// If it's our first time through this script then we need to set some default values
41
42if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
8b5b1028 43
44 /// set defaults
45 $INSTALL['language'] = 'en';
46
47 $INSTALL['dbhost'] = 'localhost';
48 $INSTALL['dbuser'] = '';
49 $INSTALL['dbpass'] = '';
50 $INSTALL['dbtype'] = 'mysql';
51 $INSTALL['dbname'] = 'moodle';
52 $INSTALL['prefix'] = 'mdl_';
53
54 $INSTALL['wwwroot'] = '';
55 $INSTALL['dirroot'] = dirname(__FILE__);
56 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
57
58 $INSTALL['admindirname'] = 'admin';
59
3470b39f 60 $INSTALL['stage'] = WELCOME;
8b5b1028 61}
62
3b3b8029 63//==========================================================================//
64
65/// Was data submitted?
66
67if (isset($_POST['stage'])) {
68
69 /// Get the stage for which the form was set and the next stage we are going to
70
71
72 if ( $goforward = (! empty( $_POST['next'] )) ) {
73 $nextstage = $_POST['stage'] + 1;
74 } else {
75 $nextstage = $_POST['stage'] - 1;
76 }
77
78
79 if ($nextstage < 0) $nextstage = WELCOME;
80
81
82 /// Store any posted data
83 foreach ($_POST as $setting=>$value) {
84 $INSTALL[$setting] = $value;
85 }
86
87} else {
8b5b1028 88
3b3b8029 89 $goforward = true;
90 $nextstage = WELCOME;
91
92}
8b5b1028 93
94//==========================================================================//
95
96/// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
8d783716 97
8b5b1028 98$SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
99$CFG->dirroot = $INSTALL['dirroot'];
72452dc1 100$CFG->libdir = $INSTALL['dirroot'].'/lib';
8b5b1028 101$CFG->dataroot = $INSTALL['dataroot'];
3b3b8029 102$CFG->admin = $INSTALL['admindirname'];
4b9efec4 103$CFG->directorypermissions = 00777;
8b5b1028 104
8d783716 105/// Include some moodle libraries
106
72452dc1 107require_once('./lib/setuplib.php');
8b5b1028 108require_once('./lib/moodlelib.php');
109require_once('./lib/weblib.php');
110require_once('./lib/adodb/adodb.inc.php');
3b3b8029 111require_once('./lib/environmentlib.php');
112require_once('./lib/xmlize.php');
113require_once('./version.php');
8b5b1028 114
3b3b8029 115/// Set version and release
116$INSTALL['version'] = $version;
117$INSTALL['release'] = $release;
118
119/// Have the $db object ready because we are going to use it often
120$db = &ADONewConnection($INSTALL['dbtype']);
8b5b1028 121
122/// guess the www root
123if ($INSTALL['wwwroot'] == '') {
124 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
125}
126
e6f930f3 127$headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
128 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
129 DIRECTORY => get_string('directorysettingshead', 'install'),
130 DATABASE => get_string('databasesettingshead', 'install'),
131 ADMIN => get_string('admindirsettinghead', 'install'),
3b3b8029 132 ENVIRONMENT => get_string('environmenthead', 'install'),
e6f930f3 133 SAVE => get_string('configurationcompletehead', 'install')
134 );
8b5b1028 135
e6f930f3 136$substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
137 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
138 DIRECTORY => get_string('directorysettingssub', 'install'),
139 DATABASE => get_string('databasesettingssub', 'install'),
140 ADMIN => get_string('admindirsettingsub', 'install'),
3b3b8029 141 ENVIRONMENT => get_string('environmentsub', 'install'),
e6f930f3 142 SAVE => get_string('configurationcompletesub', 'install')
143 );
8b5b1028 144
8d783716 145
146
147//==========================================================================//
148
149/// Are we in help mode?
150
151if (isset($_GET['help'])) {
152 $nextstage = -1;
153}
154
155
51e3e0b9 156
edd3a5db 157//==========================================================================//
158
51e3e0b9 159/// Are we in config download mode?
edd3a5db 160
51e3e0b9 161if (isset($_GET['download'])) {
162 header("Content-Type: application/download\n");
163 header("Content-Disposition: attachment; filename=\"config.php\"");
164 echo $INSTALL['config'];
165 exit;
edd3a5db 166}
8d783716 167
51e3e0b9 168
169
8b5b1028 170
171
172//==========================================================================//
173
174/// Check the directory settings
8d783716 175
3470b39f 176if ($INSTALL['stage'] == DIRECTORY) {
8b5b1028 177
178 error_reporting(0);
51e3e0b9 179
180
181 /// check dirroot
182 if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) {
183 $CFG->dirroot = dirname(__FILE__);
184 $INSTALL['dirroot'] = dirname(__FILE__);
2df3a721 185 $errormsg .= get_string('dirrooterror', 'install').'<br />';
186 }
187 if ($fh) fclose($fh);
51e3e0b9 188
2df3a721 189 $CFG->dirroot = $INSTALL['dirroot'];
cd0e958e 190
2df3a721 191 /// check wwwroot
192 if (ini_get('allow_url_fopen')) {
51e3e0b9 193 if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) {
2df3a721 194 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
8b5b1028 195 }
196 }
2df3a721 197 if ($fh) fclose($fh);
198
199 /// check dataroot
200 $CFG->dataroot = $INSTALL['dataroot'];
201 if (make_upload_directory('sessions', false) === false ) {
202 $errormsg = get_string('datarooterror', 'install').'<br />';
203 }
204 if ($fh) fclose($fh);
8b5b1028 205
3470b39f 206 if (!empty($errormsg)) $nextstage = DIRECTORY;
8b5b1028 207
208 error_reporting(7);
209}
210
211
212
213//==========================================================================//
214
215/// Check database settings if stage 3 data submitted
216/// Try to connect to the database. If that fails then try to create the database
8d783716 217
3470b39f 218if ($INSTALL['stage'] == DATABASE) {
8b5b1028 219
220 if (empty($INSTALL['dbname'])) {
221 $INSTALL['dbname'] = 'moodle';
222 }
51e3e0b9 223
8d783716 224 /// different format for postgres7 by socket
225 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
8b5b1028 226 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
8d783716 227 $INSTALL['dbuser'] = '';
228 $INSTALL['dbpass'] = '';
229 $INSTALL['dbname'] = '';
230
8b5b1028 231 if ($INSTALL['prefix'] == '') { /// must have a prefix
232 $INSTALL['prefix'] = 'mdl_';
233 }
234 }
235
fe515206 236 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
237 if (!extension_loaded('mysql')) {
238 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
3470b39f 239 $nextstage = DATABASE;
fe515206 240 }
241 }
8b5b1028 242
fe515206 243 if (empty($errormsg)) {
244
fe515206 245 error_reporting(0); // Hide errors
246
247 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
248 /// The following doesn't seem to work but we're working on it
249 /// If you come up with a solution for creating a database in MySQL
250 /// feel free to put it in and let us know
251 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) {
252 switch ($INSTALL['dbtype']) { /// Try to create a database
253 case 'mysql':
254 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']};")) {
255 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
256 } else {
257 $errormsg = get_string('dbcreationerror', 'install');
3470b39f 258 $nextstage = DATABASE;
fe515206 259 }
260 break;
261 }
8b5b1028 262 }
263 }
264 }
265
266 error_reporting(7);
267
268 if (($dbconnected === false) and (empty($errormsg)) ) {
269 $errormsg = get_string('dbconnectionerror', 'install');
3470b39f 270 $nextstage = DATABASE;
8b5b1028 271 }
272}
273
274
275
276//==========================================================================//
277
278/// If the next stage is admin directory settings OR we have just come from there then
279/// check the admin directory.
280/// If we can open a file then we know that the admin name is correct.
281
3470b39f 282if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
91099e36 283 if (!ini_get('allow_url_fopen')) {
3b3b8029 284 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
91099e36 285 } else if (($fh = @fopen($INSTALL['wwwroot'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
3b3b8029 286 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
8b5b1028 287 fclose($fh);
288 } else {
3470b39f 289 if ($nextstage != ADMIN) {
8b5b1028 290 $errormsg = get_string('admindirerror', 'install');
3470b39f 291 $nextstage = ADMIN;
8b5b1028 292 }
293 }
294}
295
3b3b8029 296//==========================================================================//
297
298// Check if we can navigate from the environemt page (because it's ok)
299
300if ($INSTALL['stage'] == ENVIRONMENT) {
301 error_reporting(0); // Hide errors
302 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
303 error_reporting(7); // Show errors
304 if ($dbconnected) {
305 /// Execute environment check, printing results
306 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
307 $nextstage = ENVIRONMENT;
308 }
309 } else {
310 /// We never should reach this because DB has been tested before arriving here
311 $errormsg = get_string('dbconnectionerror', 'install');
312 $nextstage = DATABASE;
313 }
314}
8b5b1028 315
316
317//==========================================================================//
318
319/// Display or print the data
320/// Put the data into a string
321/// Try to open config file for writing.
8d783716 322
3470b39f 323if ($nextstage == SAVE) {
51e3e0b9 324
325 $str = '<?php /// Moodle Configuration File '."\r\n";
326 $str .= "\r\n";
327
328 $str .= 'unset($CFG);'."\r\n";
329 $str .= "\r\n";
330
331 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
c423badc 332 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
59812bc7 333 if (!empty($INSTALL['dbname'])) {
51e3e0b9 334 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
335 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
336 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
337 }
338 $str .= '$CFG->dbpersist = false;'."\r\n";
339 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
340 $str .= "\r\n";
341
342 $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\r\n";
343 $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\r\n";
344 $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\r\n";
e35d275e 345 $str .= '$CFG->admin = \''.$INSTALL['admindirname']."';\r\n";
51e3e0b9 346 $str .= "\r\n";
347
6e86ae68 348 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
51e3e0b9 349 $str .= "\r\n";
350
351 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
352 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
353 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
354 $str .= '?>';
355
7c561c7a 356 umask(0137);
357
8b5b1028 358 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
359 fwrite($fh, $str);
360 fclose($fh);
361 }
7c561c7a 362
51e3e0b9 363
364 $INSTALL['config'] = $str;
8b5b1028 365}
366
367
368
369//==========================================================================//
370
371?>
372
373
374
375<html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
376<head>
f96660f8 377<link rel="shortcut icon" href="theme/standard/favicon.ico" />
8b5b1028 378<title>Moodle Install</title>
09f97271 379<meta http-equiv="content-type" content="text/html; charset=<?php p(current_charset()) ?>" />
8b5b1028 380<?php css_styles() ?>
381
382</head>
383
384<body>
385
8d783716 386
387<?php
388if (isset($_GET['help'])) {
389 print_install_help($_GET['help']);
51e3e0b9 390 close_window_button();
8d783716 391} else {
392?>
393
8b5b1028 394
395<table class="main" align="center" cellpadding="3" cellspacing="0">
396 <tr>
8d783716 397 <td class="td_mainlogo">
839f2456 398 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt=\"\"></p>
8d783716 399 </td>
400 <td class="td_mainlogo" valign="bottom">
401 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
402 </td>
403 </tr>
404
405 <tr>
406 <td class="td_mainheading" colspan="2">
e6f930f3 407 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
408 <?php if (!empty($substagetext[$nextstage])) { ?>
409 <p class="p_subheading"><?php echo $substagetext[$nextstage] ?></p>
410 <?php } ?>
8d783716 411 </td>
8b5b1028 412 </tr>
413
414 <tr>
8d783716 415 <td class="td_main" colspan="2">
51e3e0b9 416
8b5b1028 417<?php
418
419if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
420
421
3470b39f 422if ($nextstage == SAVE) {
423 $INSTALL['stage'] = WELCOME;
51e3e0b9 424 $options = array();
425 $options['lang'] = $INSTALL['language'];
8b5b1028 426 if ($configsuccess) {
427 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
51e3e0b9 428
429 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
430 echo "<tr>\n";
431 echo "<td width=\"33.3%\">&nbsp;</td>\n";
432 echo "<td width=\"33.3%\">&nbsp;</td>\n";
433 echo "<td width=\"33.3%\" align=\"right\">\n";
434 print_single_button("index.php", $options, get_string('continue')." &raquo;");
435 echo "</td>\n";
436 echo "</tr>\n";
437 echo "</table>\n";
438
8b5b1028 439 } else {
51e3e0b9 440 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
441
442 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
443 echo "<tr>\n";
444 echo "<td width=\"33.3%\">&nbsp;</td>\n";
445 echo "<td width=\"33.3%\" align=\"center\">\n";
446 $installoptions = array();
447 $installoptions['download'] = 1;
448 print_single_button("install.php", $installoptions, get_string('download', 'install'));
449 echo "</td>\n";
450 echo "<td width=\"33.3%\" align=\"right\">\n";
451 print_single_button("index.php", $options, get_string('continue')." &raquo;");
452 echo "</td>\n";
453 echo "</tr>\n";
454 echo "</table>\n";
455
8b5b1028 456 echo "<hr />\n";
51e3e0b9 457 echo "<div style=\"text-align: left\">\n";
458 print_object(htmlentities($str));
459 echo "</div>\n";
8b5b1028 460 }
8b5b1028 461} else {
462 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
463 form_table($nextstage, $formaction);
464}
465
466?>
467
468 </td>
469 </tr>
470</table>
471
8d783716 472<?php
473}
474?>
475
8b5b1028 476</body>
477</html>
478
479
480
481
482
483
484
485
486
487
51e3e0b9 488<?php
8b5b1028 489
490//==========================================================================//
491
492
493function print_object($object) {
494 echo "<pre>\n";
495 print_r($object);
496 echo "</pre>\n";
497}
498
499
500
501//==========================================================================//
502
3470b39f 503function form_table($nextstage = WELCOME, $formaction = "install.php") {
3b3b8029 504 global $INSTALL, $db;
8b5b1028 505
506 /// standard lines for all forms
507?>
508
509 <form name="installform" method="post" action="<?php echo $formaction ?>">
510 <input type="hidden" name="stage" value="<?php echo $nextstage ?>" />
511 <table class="install_table" cellspacing="3" cellpadding="3" align="center">
512
513<?php
514 /// what we do depends on the stage we're at
515 switch ($nextstage) {
3470b39f 516 case WELCOME: /// Welcome and language settings
8b5b1028 517?>
518 <tr>
519 <td class="td_left"><p><?php print_string('language') ?></p></td>
520 <td class="td_right">
521 <?php choose_from_menu (get_list_of_languages(), 'language', $INSTALL['language'], '') ?>
522 </td>
523 </tr>
524
525<?php
8d783716 526 break;
3470b39f 527 case COMPATIBILITY: /// Compatibilty check
8d783716 528 $compatsuccess = true;
51e3e0b9 529
8d783716 530 /// Check that PHP is of a sufficient version
51e3e0b9 531 print_compatibility_row(check_php_version("4.1.0"), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
8d783716 532 /// Check session auto start
533 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
8d783716 534 /// Check magic quotes
535 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
4d46a3f0 536 /// Check unsupported PHP configuration
537 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
51e3e0b9 538 /// Check safe mode
539 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
8d783716 540 /// Check file uploads
51e3e0b9 541 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
8d783716 542 /// Check GD version
51e3e0b9 543 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
8d783716 544 /// Check memory limit
51e3e0b9 545 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
8d783716 546
547
8b5b1028 548 break;
3470b39f 549 case DIRECTORY: /// Directory settings
8b5b1028 550?>
551
552 <tr>
553 <td class="td_left"><p><?php print_string('wwwroot', 'install') ?></p></td>
554 <td class="td_right">
555 <input type="text" size="40"name="wwwroot" value="<?php echo $INSTALL['wwwroot'] ?>" />
556 </td>
557 </tr>
558 <tr>
559 <td class="td_left"><p><?php print_string('dirroot', 'install') ?></p></td>
560 <td class="td_right">
561 <input type="text" size="40" name="dirroot" value="<?php echo $INSTALL['dirroot'] ?>" />
562 </td>
563 </tr>
564 <tr>
565 <td class="td_left"><p><?php print_string('dataroot', 'install') ?></p></td>
566 <td class="td_right">
567 <input type="text" size="40" name="dataroot" value="<?php echo $INSTALL['dataroot'] ?>" />
568 </td>
569 </tr>
570
571<?php
572 break;
3470b39f 573 case DATABASE: /// Database settings
8b5b1028 574?>
575
576 <tr>
577 <td class="td_left"><p><?php print_string('dbtype', 'install') ?></p></td>
578 <td class="td_right">
579 <?php choose_from_menu (array("mysql" => "mysql", "postgres7" => "postgres7"), 'dbtype', $INSTALL['dbtype'], '') ?>
580 </td>
581 </tr>
582 <tr>
583 <td class="td_left"><p><?php print_string('dbhost', 'install') ?></p></td>
584 <td class="td_right">
585 <input type="text" size="40" name="dbhost" value="<?php echo $INSTALL['dbhost'] ?>" />
586 </td>
587 </tr>
588 <tr>
589 <td class="td_left"><p><?php print_string('database', 'install') ?></p></td>
590 <td class="td_right">
591 <input type="text" size="40" name="dbname" value="<?php echo $INSTALL['dbname'] ?>" />
592 </td>
593 </tr>
594 <tr>
595 <td class="td_left"><p><?php print_string('user') ?></p></td>
596 <td class="td_right">
597 <input type="text" size="40" name="dbuser" value="<?php echo $INSTALL['dbuser'] ?>" />
598 </td>
599 </tr>
600 <tr>
601 <td class="td_left"><p><?php print_string('password') ?></p></td>
602 <td class="td_right">
2df3a721 603 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
8b5b1028 604 </td>
605 </tr>
606 <tr>
607 <td class="td_left"><p><?php print_string('dbprefix', 'install') ?></p></td>
608 <td class="td_right">
609 <input type="text" size="40" name="prefix" value="<?php echo $INSTALL['prefix'] ?>" />
610 </td>
611 </tr>
612
613<?php
614 break;
3470b39f 615 case ADMIN: /// Administration directory setting
8b5b1028 616?>
617
618 <tr>
619 <td class="td_left"><p><?php print_string('admindirname', 'install') ?></p></td>
620 <td class="td_right">
621 <input type="text" size="40" name="admindirname" value="<?php echo $INSTALL['admindirname'] ?>" />
622 </td>
623 </tr>
624
625
3b3b8029 626<?php
627 break;
628 case ENVIRONMENT: /// Environment checks
629?>
630
631 <tr>
632 <td colspan="2">
633 <?php
634 error_reporting(0); // Hide errors
635 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
636 error_reporting(7); // Show errors
637 if ($dbconnected) {
638 /// Execute environment check, printing results
639 check_moodle_environment($INSTALL['release'], $environment_results, true);
640 } else {
641 /// We never should reach this because DB has been tested before arriving here
642 $errormsg = get_string('dbconnectionerror', 'install');
643 $nextstage = DATABASE;
644 echo '<p class="errormsg" align="center">'.get_string('dbconnectionerror', 'install').'</p>';
645 }
646 ?>
647 </td>
648 </tr>
649
650
651
8b5b1028 652<?php
653 break;
654 default:
655 }
656?>
cd0e958e 657
51e3e0b9 658 <tr>
3470b39f 659 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
51e3e0b9 660
3470b39f 661 <?php echo ($nextstage < SAVE) ? "<input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: right\"/>\n" : "&nbsp;\n" ?>
662 <?php echo ($nextstage > WELCOME) ? "<input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: left\"/>\n" : "&nbsp;\n" ?>
cd0e958e 663
7c561c7a 664
51e3e0b9 665 </td>
cd0e958e 666
51e3e0b9 667 </tr>
668
669 </table>
8b5b1028 670 </form>
671
672<?php
673}
674
675
676
8d783716 677//==========================================================================//
678
51e3e0b9 679function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
8d783716 680 echo "<tr>\n";
51e3e0b9 681 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
8d783716 682 if ($success) {
51e3e0b9 683 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
684 echo "<td valign=\"top\">&nbsp;</td>\n";
8d783716 685 } else {
51e3e0b9 686 echo "<td valign=\"top\"";
687 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
688 echo "</p></td>\n";
689 echo "<td valign=\"top\">";
690 echo "<p>$errormessage ";
691 install_helpbutton("install.php?help=$helpfield");
692 echo "</p></td>\n";
8d783716 693 }
694 echo "</tr>\n";
695 return $success;
696}
697
698
699//==========================================================================//
700
701function install_helpbutton($url, $title='') {
702 if ($title == '') {
703 $title = get_string('help');
704 }
705 echo "<a href=\"javascript: void(0)\">";
1fd3772b 706 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
839f2456 707 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
8d783716 708 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
709 echo "</a>\n";
710}
51e3e0b9 711
8d783716 712
713
714//==========================================================================//
715
716function print_install_help($help) {
8d783716 717 switch ($help) {
718 case 'phpversionhelp':
719 print_string($help, 'install', phpversion());
720 break;
721 case 'memorylimithelp':
94ba66ce 722 print_string($help, 'install', get_memory_limit());
8d783716 723 break;
724 default:
725 print_string($help, 'install');
726 }
8d783716 727}
728
729
730//==========================================================================//
731
732function get_memory_limit() {
733 if ($limit = ini_get('memory_limit')) {
734 return $limit;
735 } else {
736 return get_cfg_var('memory_limit');
737 }
738}
739
740//==========================================================================//
741
742function check_memory_limit() {
743
744 /// if limit is already 16M or more then we don't care if we can change it or not
745 if ((int)str_replace('M', '', get_memory_limit()) >= 16) {
746 return true;
747 }
748
749 /// Otherwise, see if we can change it ourselves
750 @ini_set('memory_limit', '16M');
751 return ((int)str_replace('M', '', get_memory_limit()) >= 16);
752}
753
8b5b1028 754//==========================================================================//
755
756function css_styles() {
757?>
758
759<style type="text/css">
760
761 body { background-color: #ffeece; }
3b3b8029 762 p, li, td {
8d783716 763 font-family: helvetica, arial, sans-serif;
764 font-size: 10pt;
765 }
8b5b1028 766 a { text-decoration: none; color: blue; }
767 .errormsg {
768 color: red;
769 font-weight: bold;
770 }
8d783716 771 blockquote {
51e3e0b9 772 font-family: courier, monospace;
8d783716 773 font-size: 10pt;
774 }
8b5b1028 775 .install_table {
776 width: 500px;
777 }
778 .td_left {
779 text-align: right;
780 font-weight: bold;
781 }
782 .td_right {
783 text-align: left;
784 }
785 .main {
786 width: 500px;
787 border-width: 1px;
788 border-style: solid;
789 border-color: #ffc85f;
790 -moz-border-radius-bottomleft: 15px;
791 -moz-border-radius-bottomright: 15px;
792 }
793 .td_mainheading {
794 background-color: #fee6b9;
8d783716 795 padding: 10px;
8b5b1028 796 }
797 .td_main {
798 text-align: center;
799 }
8d783716 800 .td_mainlogo {
801 }
802 .p_mainlogo {
803 }
8b5b1028 804 .p_mainheading {
8d783716 805 font-size: 11pt;
806 }
182dca14 807 .p_subheading {
808 font-size: 10pt;
809 padding: 10px;
810 }
8d783716 811 .p_mainheader{
812 text-align: right;
813 font-size: 20pt;
814 font-weight: bold;
815 }
816 .p_pass {
817 color: green;
818 font-weight: bold;
819 }
820 .p_fail {
821 color: red;
822 font-weight: bold;
823 }
51e3e0b9 824 .p_caution {
825 color: #ff6600;
826 font-weight: bold;
827 }
8d783716 828 .p_help {
829 text-align: center;
830 font-family: helvetica, arial, sans-serif;
831 font-size: 14pt;
832 font-weight: bold;
833 color: #333333;
8b5b1028 834 }
3b3b8029 835 .environmenttable {
836 font-size: 10pt;
837 border-color: #ffc85f;
838 }
839 .header {
840 background-color: #fee6b9;
841 font-size: 10pt;
842 }
843 .cell {
844 background-color: #ffeece;
845 font-size: 10pt;
846 }
847 .error {
848 color: #ff0000;
849 }
850 .errorboxcontent {
851 text-align: center;
852 font-weight: bold;
853 padding: 20px;
854 color: #ff0000;
855 }
856
8b5b1028 857</style>
858
859<?php
860}
861?>