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