Automatic installer.php by installer_builder (20060309)
[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
b4dd571d 54 $INSTALL['dbencodingtestresults'] = false;
55 $INSTALL['showskipdbencodingtest'] = false;
56 $INSTALL['skipdbencodingtest'] = false;
57
8b5b1028 58 $INSTALL['wwwroot'] = '';
59 $INSTALL['dirroot'] = dirname(__FILE__);
60 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata';
61
62 $INSTALL['admindirname'] = 'admin';
63
3470b39f 64 $INSTALL['stage'] = WELCOME;
8b5b1028 65}
66
3b3b8029 67//==========================================================================//
68
69/// Was data submitted?
70
71if (isset($_POST['stage'])) {
72
73 /// Get the stage for which the form was set and the next stage we are going to
74
75
76 if ( $goforward = (! empty( $_POST['next'] )) ) {
77 $nextstage = $_POST['stage'] + 1;
78 } else {
79 $nextstage = $_POST['stage'] - 1;
80 }
81
82
83 if ($nextstage < 0) $nextstage = WELCOME;
84
85
86 /// Store any posted data
87 foreach ($_POST as $setting=>$value) {
88 $INSTALL[$setting] = $value;
89 }
90
91} else {
8b5b1028 92
3b3b8029 93 $goforward = true;
94 $nextstage = WELCOME;
95
96}
8b5b1028 97
98//==========================================================================//
99
100/// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
8d783716 101
8b5b1028 102$SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
103$CFG->dirroot = $INSTALL['dirroot'];
72452dc1 104$CFG->libdir = $INSTALL['dirroot'].'/lib';
8b5b1028 105$CFG->dataroot = $INSTALL['dataroot'];
3b3b8029 106$CFG->admin = $INSTALL['admindirname'];
4b9efec4 107$CFG->directorypermissions = 00777;
8b5b1028 108
8d783716 109/// Include some moodle libraries
110
72452dc1 111require_once('./lib/setuplib.php');
8b5b1028 112require_once('./lib/moodlelib.php');
113require_once('./lib/weblib.php');
114require_once('./lib/adodb/adodb.inc.php');
3b3b8029 115require_once('./lib/environmentlib.php');
116require_once('./lib/xmlize.php');
117require_once('./version.php');
8b5b1028 118
3b3b8029 119/// Set version and release
120$INSTALL['version'] = $version;
121$INSTALL['release'] = $release;
122
123/// Have the $db object ready because we are going to use it often
124$db = &ADONewConnection($INSTALL['dbtype']);
8b5b1028 125
126/// guess the www root
127if ($INSTALL['wwwroot'] == '') {
128 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
129}
130
e6f930f3 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'),
3b3b8029 136 ENVIRONMENT => get_string('environmenthead', 'install'),
e6f930f3 137 SAVE => get_string('configurationcompletehead', 'install')
138 );
8b5b1028 139
e6f930f3 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'),
3b3b8029 145 ENVIRONMENT => get_string('environmentsub', 'install'),
e6f930f3 146 SAVE => get_string('configurationcompletesub', 'install')
147 );
8b5b1028 148
8d783716 149
150
151//==========================================================================//
152
153/// Are we in help mode?
154
155if (isset($_GET['help'])) {
156 $nextstage = -1;
157}
158
159
51e3e0b9 160
edd3a5db 161//==========================================================================//
162
51e3e0b9 163/// Are we in config download mode?
edd3a5db 164
51e3e0b9 165if (isset($_GET['download'])) {
166 header("Content-Type: application/download\n");
167 header("Content-Disposition: attachment; filename=\"config.php\"");
168 echo $INSTALL['config'];
169 exit;
edd3a5db 170}
8d783716 171
51e3e0b9 172
173
8b5b1028 174
175
176//==========================================================================//
177
178/// Check the directory settings
8d783716 179
3470b39f 180if ($INSTALL['stage'] == DIRECTORY) {
8b5b1028 181
182 error_reporting(0);
51e3e0b9 183
184
185 /// check dirroot
186 if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) {
187 $CFG->dirroot = dirname(__FILE__);
188 $INSTALL['dirroot'] = dirname(__FILE__);
2df3a721 189 $errormsg .= get_string('dirrooterror', 'install').'<br />';
190 }
191 if ($fh) fclose($fh);
51e3e0b9 192
2df3a721 193 $CFG->dirroot = $INSTALL['dirroot'];
cd0e958e 194
2df3a721 195 /// check wwwroot
196 if (ini_get('allow_url_fopen')) {
51e3e0b9 197 if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) {
2df3a721 198 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
8b5b1028 199 }
200 }
2df3a721 201 if ($fh) fclose($fh);
202
203 /// check dataroot
204 $CFG->dataroot = $INSTALL['dataroot'];
205 if (make_upload_directory('sessions', false) === false ) {
206 $errormsg = get_string('datarooterror', 'install').'<br />';
207 }
208 if ($fh) fclose($fh);
8b5b1028 209
3470b39f 210 if (!empty($errormsg)) $nextstage = DIRECTORY;
8b5b1028 211
212 error_reporting(7);
213}
214
215
216
217//==========================================================================//
218
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
8d783716 221
3470b39f 222if ($INSTALL['stage'] == DATABASE) {
8b5b1028 223
b4dd571d 224 /// First of all, analyze skipdbencodingtest status
225 if (isset($_POST['skipdbencodingtest'])) {
226 $INSTALL['skipdbencodingtest'] = true;
227 } else {
228 $INSTALL['skipdbencodingtest'] = false;
229 }
51e3e0b9 230
8d783716 231 /// different format for postgres7 by socket
232 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
8b5b1028 233 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
8d783716 234 $INSTALL['dbuser'] = '';
235 $INSTALL['dbpass'] = '';
236 $INSTALL['dbname'] = '';
237
8b5b1028 238 if ($INSTALL['prefix'] == '') { /// must have a prefix
239 $INSTALL['prefix'] = 'mdl_';
240 }
241 }
242
fe515206 243 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
244 if (!extension_loaded('mysql')) {
245 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
3470b39f 246 $nextstage = DATABASE;
fe515206 247 }
248 }
8b5b1028 249
fe515206 250 if (empty($errormsg)) {
251
fe515206 252 error_reporting(0); // Hide errors
253
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');
3470b39f 265 $nextstage = DATABASE;
fe515206 266 }
267 break;
268 }
8b5b1028 269 }
b4dd571d 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;
290 }
291 }
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;
305 }
306 }
307 break;
308 }
309 }
8b5b1028 310 }
311 }
312
313 error_reporting(7);
314
315 if (($dbconnected === false) and (empty($errormsg)) ) {
316 $errormsg = get_string('dbconnectionerror', 'install');
3470b39f 317 $nextstage = DATABASE;
8b5b1028 318 }
319}
320
321
322
323//==========================================================================//
324
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.
328
3470b39f 329if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
91099e36 330 if (!ini_get('allow_url_fopen')) {
3b3b8029 331 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
91099e36 332 } else if (($fh = @fopen($INSTALL['wwwroot'].'/'.$INSTALL['admindirname'].'/site.html', 'r')) !== false) {
3b3b8029 333 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
8b5b1028 334 fclose($fh);
335 } else {
3470b39f 336 if ($nextstage != ADMIN) {
8b5b1028 337 $errormsg = get_string('admindirerror', 'install');
3470b39f 338 $nextstage = ADMIN;
8b5b1028 339 }
340 }
341}
342
3b3b8029 343//==========================================================================//
344
345// Check if we can navigate from the environemt page (because it's ok)
346
347if ($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;
355 }
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;
360 }
361}
8b5b1028 362
363
364//==========================================================================//
365
366/// Display or print the data
367/// Put the data into a string
368/// Try to open config file for writing.
8d783716 369
3470b39f 370if ($nextstage == SAVE) {
51e3e0b9 371
372 $str = '<?php /// Moodle Configuration File '."\r\n";
373 $str .= "\r\n";
374
375 $str .= 'unset($CFG);'."\r\n";
376 $str .= "\r\n";
377
378 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
c423badc 379 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
59812bc7 380 if (!empty($INSTALL['dbname'])) {
51e3e0b9 381 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
382 $str .= '$CFG->dbuser = \''.$INSTALL['dbuser']."';\r\n";
383 $str .= '$CFG->dbpass = \''.$INSTALL['dbpass']."';\r\n";
384 }
385 $str .= '$CFG->dbpersist = false;'."\r\n";
386 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
387 $str .= "\r\n";
388
389 $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\r\n";
390 $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\r\n";
391 $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\r\n";
e35d275e 392 $str .= '$CFG->admin = \''.$INSTALL['admindirname']."';\r\n";
51e3e0b9 393 $str .= "\r\n";
394
6e86ae68 395 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
51e3e0b9 396 $str .= "\r\n";
397
b4dd571d 398 if (!$INSTALL['skipdbencodingtest'] && $INSTALL['dbencodingtestresults']) {
399 $str .= '$CFG->unicodedb = true; // Database is utf8'."\r\n";
400 $str .= "\r\n";
401 }
402
51e3e0b9 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 .= '?>';
407
7c561c7a 408 umask(0137);
409
8b5b1028 410 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
411 fwrite($fh, $str);
412 fclose($fh);
413 }
7c561c7a 414
51e3e0b9 415
416 $INSTALL['config'] = $str;
8b5b1028 417}
418
419
420
421//==========================================================================//
422
423?>
424
425
426
427<html dir="<?php echo (get_string('this_direction') == 'rtl') ? 'rtl' : 'ltr' ?>">
428<head>
f96660f8 429<link rel="shortcut icon" href="theme/standard/favicon.ico" />
8b5b1028 430<title>Moodle Install</title>
09f97271 431<meta http-equiv="content-type" content="text/html; charset=<?php p(current_charset()) ?>" />
8b5b1028 432<?php css_styles() ?>
433
434</head>
435
436<body>
437
8d783716 438
439<?php
440if (isset($_GET['help'])) {
441 print_install_help($_GET['help']);
51e3e0b9 442 close_window_button();
8d783716 443} else {
444?>
445
8b5b1028 446
447<table class="main" align="center" cellpadding="3" cellspacing="0">
448 <tr>
8d783716 449 <td class="td_mainlogo">
839f2456 450 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt=\"\"></p>
8d783716 451 </td>
452 <td class="td_mainlogo" valign="bottom">
453 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
454 </td>
455 </tr>
456
457 <tr>
458 <td class="td_mainheading" colspan="2">
e6f930f3 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 } ?>
8d783716 463 </td>
8b5b1028 464 </tr>
465
466 <tr>
8d783716 467 <td class="td_main" colspan="2">
51e3e0b9 468
8b5b1028 469<?php
470
471if (!empty($errormsg)) echo "<p class=\"errormsg\" align=\"center\">$errormsg</p>\n";
472
473
3470b39f 474if ($nextstage == SAVE) {
475 $INSTALL['stage'] = WELCOME;
51e3e0b9 476 $options = array();
477 $options['lang'] = $INSTALL['language'];
8b5b1028 478 if ($configsuccess) {
479 echo "<p>".get_string('configfilewritten', 'install')."</p>\n";
51e3e0b9 480
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";
490
8b5b1028 491 } else {
51e3e0b9 492 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
493
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";
507
8b5b1028 508 echo "<hr />\n";
51e3e0b9 509 echo "<div style=\"text-align: left\">\n";
510 print_object(htmlentities($str));
511 echo "</div>\n";
8b5b1028 512 }
8b5b1028 513} else {
514 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
515 form_table($nextstage, $formaction);
516}
517
518?>
519
520 </td>
521 </tr>
522</table>
523
8d783716 524<?php
525}
526?>
527
8b5b1028 528</body>
529</html>
530
531
532
533
534
535
536
537
538
539
51e3e0b9 540<?php
8b5b1028 541
542//==========================================================================//
543
544
545function print_object($object) {
546 echo "<pre>\n";
547 print_r($object);
548 echo "</pre>\n";
549}
550
551
552
553//==========================================================================//
554
3470b39f 555function form_table($nextstage = WELCOME, $formaction = "install.php") {
3b3b8029 556 global $INSTALL, $db;
8b5b1028 557
558 /// standard lines for all forms
559?>
560
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">
564
565<?php
566 /// what we do depends on the stage we're at
567 switch ($nextstage) {
3470b39f 568 case WELCOME: /// Welcome and language settings
8b5b1028 569?>
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>
576
577<?php
8d783716 578 break;
3470b39f 579 case COMPATIBILITY: /// Compatibilty check
8d783716 580 $compatsuccess = true;
51e3e0b9 581
8d783716 582 /// Check that PHP is of a sufficient version
51e3e0b9 583 print_compatibility_row(check_php_version("4.1.0"), get_string('phpversion', 'install'), get_string('phpversionerror', 'install'), 'phpversionhelp');
8d783716 584 /// Check session auto start
585 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
8d783716 586 /// Check magic quotes
587 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
4d46a3f0 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');
51e3e0b9 590 /// Check safe mode
591 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
8d783716 592 /// Check file uploads
51e3e0b9 593 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
8d783716 594 /// Check GD version
51e3e0b9 595 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
8d783716 596 /// Check memory limit
51e3e0b9 597 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
8d783716 598
599
8b5b1028 600 break;
3470b39f 601 case DIRECTORY: /// Directory settings
8b5b1028 602?>
603
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>
622
623<?php
624 break;
3470b39f 625 case DATABASE: /// Database settings
8b5b1028 626?>
627
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">
2df3a721 655 <input type="password" size="40" name="dbpass" value="<?php echo $INSTALL['dbpass'] ?>" />
8b5b1028 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>
b4dd571d 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 } ?>
8b5b1028 671
672<?php
673 break;
3470b39f 674 case ADMIN: /// Administration directory setting
8b5b1028 675?>
676
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>
683
684
3b3b8029 685<?php
686 break;
687 case ENVIRONMENT: /// Environment checks
688?>
689
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>';
704 }
705 ?>
706 </td>
707 </tr>
708
709
710
8b5b1028 711<?php
712 break;
713 default:
714 }
715?>
cd0e958e 716
51e3e0b9 717 <tr>
3470b39f 718 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
51e3e0b9 719
3470b39f 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" ?>
cd0e958e 722
7c561c7a 723
51e3e0b9 724 </td>
cd0e958e 725
51e3e0b9 726 </tr>
727
728 </table>
8b5b1028 729 </form>
730
731<?php
732}
733
734
735
8d783716 736//==========================================================================//
737
51e3e0b9 738function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
8d783716 739 echo "<tr>\n";
51e3e0b9 740 echo "<td class=\"td_left\" valign=\"top\" nowrap width=\"160\"><p>$testtext</p></td>\n";
8d783716 741 if ($success) {
51e3e0b9 742 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
743 echo "<td valign=\"top\">&nbsp;</td>\n";
8d783716 744 } else {
51e3e0b9 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";
8d783716 752 }
753 echo "</tr>\n";
754 return $success;
755}
756
757
758//==========================================================================//
759
760function install_helpbutton($url, $title='') {
761 if ($title == '') {
762 $title = get_string('help');
763 }
764 echo "<a href=\"javascript: void(0)\">";
1fd3772b 765 echo "<img src=\"./pix/help.gif\" height=\"17\" width=\"17\" alt=\"$title\"";
839f2456 766 echo "border=\"0\" align=\"middle\" title=\"$title\" ";
8d783716 767 echo "onClick=\"return window.open('$url', 'Help', 'menubar=0,location=0,scrollbars,resizable,width=500,height=400')\">";
768 echo "</a>\n";
769}
51e3e0b9 770
8d783716 771
772
773//==========================================================================//
774
775function print_install_help($help) {
8d783716 776 switch ($help) {
777 case 'phpversionhelp':
778 print_string($help, 'install', phpversion());
779 break;
780 case 'memorylimithelp':
94ba66ce 781 print_string($help, 'install', get_memory_limit());
8d783716 782 break;
783 default:
784 print_string($help, 'install');
785 }
8d783716 786}
787
788
789//==========================================================================//
790
791function get_memory_limit() {
792 if ($limit = ini_get('memory_limit')) {
793 return $limit;
794 } else {
795 return get_cfg_var('memory_limit');
796 }
797}
798
799//==========================================================================//
800
801function check_memory_limit() {
802
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;
806 }
807
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);
811}
812
8b5b1028 813//==========================================================================//
814
815function css_styles() {
816?>
817
818<style type="text/css">
819
820 body { background-color: #ffeece; }
3b3b8029 821 p, li, td {
8d783716 822 font-family: helvetica, arial, sans-serif;
823 font-size: 10pt;
824 }
8b5b1028 825 a { text-decoration: none; color: blue; }
826 .errormsg {
827 color: red;
828 font-weight: bold;
829 }
8d783716 830 blockquote {
51e3e0b9 831 font-family: courier, monospace;
8d783716 832 font-size: 10pt;
833 }
8b5b1028 834 .install_table {
835 width: 500px;
836 }
837 .td_left {
838 text-align: right;
839 font-weight: bold;
840 }
841 .td_right {
842 text-align: left;
843 }
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;
851 }
852 .td_mainheading {
853 background-color: #fee6b9;
8d783716 854 padding: 10px;
8b5b1028 855 }
856 .td_main {
857 text-align: center;
858 }
8d783716 859 .td_mainlogo {
860 }
861 .p_mainlogo {
862 }
8b5b1028 863 .p_mainheading {
8d783716 864 font-size: 11pt;
865 }
182dca14 866 .p_subheading {
867 font-size: 10pt;
868 padding: 10px;
869 }
8d783716 870 .p_mainheader{
871 text-align: right;
872 font-size: 20pt;
873 font-weight: bold;
874 }
875 .p_pass {
876 color: green;
877 font-weight: bold;
878 }
879 .p_fail {
880 color: red;
881 font-weight: bold;
882 }
51e3e0b9 883 .p_caution {
884 color: #ff6600;
885 font-weight: bold;
886 }
8d783716 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;
8b5b1028 893 }
3b3b8029 894 .environmenttable {
895 font-size: 10pt;
896 border-color: #ffc85f;
897 }
898 .header {
899 background-color: #fee6b9;
900 font-size: 10pt;
901 }
902 .cell {
903 background-color: #ffeece;
904 font-size: 10pt;
905 }
906 .error {
907 color: #ff0000;
908 }
909 .errorboxcontent {
910 text-align: center;
911 font-weight: bold;
912 padding: 20px;
913 color: #ff0000;
914 }
915
8b5b1028 916</style>
917
918<?php
919}
920?>