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