MDL-11719 increased size of idnumber in user table - needed for some enrolment plugin...
[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
53a0367d 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
23b86e1c 27/// This has to be defined to avoid a notice in current_language()
28define('SITEID', 0);
8d783716 29
8b5b1028 30/// Begin the session as we are holding all information in a session
31/// variable until the end.
32
33session_name('MoodleSession');
34@session_start();
35
41aa8437 36/// make sure PHP errors are displayed to help diagnose problems
37@error_reporting(1023); //E_ALL not used because we do not want strict notices in PHP5 yet
38@ini_set('display_errors', '1');
39
8b5b1028 40if (! isset($_SESSION['INSTALL'])) {
41 $_SESSION['INSTALL'] = array();
42}
43
44$INSTALL = &$_SESSION['INSTALL']; // Makes it easier to reference
45
d36afd6d 46/// detect if install was attempted from diferent directory, if yes reset session to prevent errors,
47/// dirroot location now fixed in installer
48if (!empty($INSTALL['dirroot']) and $INSTALL['dirroot'] != dirname(__FILE__)) {
49 $_SESSION['INSTALL'] = array();
50}
8d783716 51
52/// If it's our first time through this script then we need to set some default values
53
54if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
8b5b1028 55
56 /// set defaults
b9b4e32a 57 $INSTALL['language'] = 'en_utf8';
8b5b1028 58
59 $INSTALL['dbhost'] = 'localhost';
60 $INSTALL['dbuser'] = '';
61 $INSTALL['dbpass'] = '';
62 $INSTALL['dbtype'] = 'mysql';
63 $INSTALL['dbname'] = 'moodle';
64 $INSTALL['prefix'] = 'mdl_';
65
cdef6d42 66 $INSTALL['downloadlangpack'] = false;
67 $INSTALL['showdownloadlangpack'] = true;
68 $INSTALL['downloadlangpackerror'] = '';
69
70/// To be used by the Installer
8b5b1028 71 $INSTALL['wwwroot'] = '';
72 $INSTALL['dirroot'] = dirname(__FILE__);
9b70d314 73 $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'moodledata';
8b5b1028 74
cdef6d42 75/// To be configured in the Installer
76 $INSTALL['wwwrootform'] = '';
77 $INSTALL['dirrootform'] = dirname(__FILE__);
78
8b5b1028 79 $INSTALL['admindirname'] = 'admin';
80
3470b39f 81 $INSTALL['stage'] = WELCOME;
8b5b1028 82}
83
3b3b8029 84//==========================================================================//
85
bd507453 86/// Set the page to Unicode always
87
88header('Content-Type: text/html; charset=UTF-8');
89
3b3b8029 90/// Was data submitted?
91
92if (isset($_POST['stage'])) {
93
94 /// Get the stage for which the form was set and the next stage we are going to
95
56ca1c60 96 $gpc = ini_get('magic_quotes_gpc');
97 $gpc = ($gpc == '1' or strtolower($gpc) == 'on');
98
d36afd6d 99 /// Store any posted data
100 foreach ($_POST as $setting=>$value) {
56ca1c60 101 if ($gpc) {
102 $value = stripslashes($value);
103 }
104
d36afd6d 105 $INSTALL[$setting] = $value;
106 }
3b3b8029 107
108 if ( $goforward = (! empty( $_POST['next'] )) ) {
109 $nextstage = $_POST['stage'] + 1;
cdef6d42 110 } else if (! empty( $_POST['prev'])) {
3b3b8029 111 $nextstage = $_POST['stage'] - 1;
d36afd6d 112 $INSTALL['stage'] = $_POST['stage'] - 1;
cdef6d42 113 } else if (! empty( $_POST['same'] )) {
114 $nextstage = $_POST['stage'];
3b3b8029 115 }
116
f49312b6 117 $nextstage = (int)$nextstage;
3b3b8029 118
d36afd6d 119 if ($nextstage < 0) {
120 $nextstage = WELCOME;
3b3b8029 121 }
53a0367d 122
d36afd6d 123
3b3b8029 124} else {
8b5b1028 125
3b3b8029 126 $goforward = true;
127 $nextstage = WELCOME;
53a0367d 128
3b3b8029 129}
8b5b1028 130
131//==========================================================================//
132
133/// Fake some settings so that we can use selected functions from moodlelib.php and weblib.php
8d783716 134
8b5b1028 135$SESSION->lang = (!empty($_POST['language'])) ? $_POST['language'] : $INSTALL['language'];
136$CFG->dirroot = $INSTALL['dirroot'];
72452dc1 137$CFG->libdir = $INSTALL['dirroot'].'/lib';
8b5b1028 138$CFG->dataroot = $INSTALL['dataroot'];
3b3b8029 139$CFG->admin = $INSTALL['admindirname'];
4b9efec4 140$CFG->directorypermissions = 00777;
b9b4e32a 141$CFG->running_installer = true;
e4b89caa 142$CFG->docroot = 'http://docs.moodle.org';
2253a296 143$CFG->httpswwwroot = $INSTALL['wwwrootform']; // Needed by doc_link() in Server Checks page.
70205c74 144$COURSE->id = 0;
8b5b1028 145
8d783716 146/// Include some moodle libraries
147
d36afd6d 148require_once($CFG->libdir.'/adminlib.php');
149require_once($CFG->libdir.'/setuplib.php');
150require_once($CFG->libdir.'/moodlelib.php');
151require_once($CFG->libdir.'/weblib.php');
152require_once($CFG->libdir.'/deprecatedlib.php');
153require_once($CFG->libdir.'/adodb/adodb.inc.php');
154require_once($CFG->libdir.'/environmentlib.php');
155require_once($CFG->libdir.'/xmlize.php');
156require_once($CFG->libdir.'/componentlib.class.php');
157require_once($CFG->dirroot.'/version.php');
8b5b1028 158
3b3b8029 159/// Set version and release
160$INSTALL['version'] = $version;
161$INSTALL['release'] = $release;
162
163/// Have the $db object ready because we are going to use it often
86453d8b 164define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
3b3b8029 165$db = &ADONewConnection($INSTALL['dbtype']);
86453d8b 166$db->SetFetchMode(ADODB_FETCH_ASSOC);
8b5b1028 167
bb5a61a1 168/// guess the www root
8b5b1028 169if ($INSTALL['wwwroot'] == '') {
170 list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me());
cdef6d42 171 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
add47d44 172
173 // now try to guess the correct dataroot not accessible via web
174 $CFG->wwwroot = $INSTALL['wwwroot'];
175 $i = 0; //safety check - dirname might return some unexpected results
176 while(is_dataroot_insecure()) {
177 $parrent = dirname($CFG->dataroot);
178 $i++;
b735d140 179 if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
add47d44 180 $CFG->dataroot = ''; //can not find secure location for dataroot
181 break;
182 }
183 $CFG->dataroot = dirname($parrent).'/moodledata';
184 }
185 $INSTALL['dataroot'] = $CFG->dataroot;
8b5b1028 186}
187
e6f930f3 188$headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'),
189 COMPATIBILITY => get_string('compatibilitysettingshead', 'install'),
190 DIRECTORY => get_string('directorysettingshead', 'install'),
191 DATABASE => get_string('databasesettingshead', 'install'),
192 ADMIN => get_string('admindirsettinghead', 'install'),
3b3b8029 193 ENVIRONMENT => get_string('environmenthead', 'install'),
68a3f81d 194 DOWNLOADLANG => get_string('downloadlanguagehead', 'install'),
e6f930f3 195 SAVE => get_string('configurationcompletehead', 'install')
196 );
8b5b1028 197
e6f930f3 198$substagetext = array(WELCOME => get_string('chooselanguagesub', 'install'),
199 COMPATIBILITY => get_string('compatibilitysettingssub', 'install'),
200 DIRECTORY => get_string('directorysettingssub', 'install'),
201 DATABASE => get_string('databasesettingssub', 'install'),
202 ADMIN => get_string('admindirsettingsub', 'install'),
3b3b8029 203 ENVIRONMENT => get_string('environmentsub', 'install'),
68a3f81d 204 DOWNLOADLANG => get_string('downloadlanguagesub', 'install'),
e6f930f3 205 SAVE => get_string('configurationcompletesub', 'install')
206 );
8b5b1028 207
8d783716 208
209
210//==========================================================================//
211
212/// Are we in help mode?
213
214if (isset($_GET['help'])) {
215 $nextstage = -1;
216}
217
218
51e3e0b9 219
edd3a5db 220//==========================================================================//
221
51e3e0b9 222/// Are we in config download mode?
edd3a5db 223
51e3e0b9 224if (isset($_GET['download'])) {
53a0367d 225 header("Content-Type: application/x-forcedownload\n");
51e3e0b9 226 header("Content-Disposition: attachment; filename=\"config.php\"");
227 echo $INSTALL['config'];
228 exit;
edd3a5db 229}
8d783716 230
51e3e0b9 231
232
8b5b1028 233
234
235//==========================================================================//
236
237/// Check the directory settings
8d783716 238
3470b39f 239if ($INSTALL['stage'] == DIRECTORY) {
8b5b1028 240
241 error_reporting(0);
53a0367d 242
2df3a721 243 /// check wwwroot
e2850d15 244 if (ini_get('allow_url_fopen') && false) { /// This was not reliable
cdef6d42 245 if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
2df3a721 246 $errormsg .= get_string('wwwrooterror', 'install').'<br />';
cdef6d42 247 $INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
8b5b1028 248 }
249 }
2df3a721 250 if ($fh) fclose($fh);
53a0367d 251
cdef6d42 252 /// check dirroot
253 if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
254 $errormsg .= get_string('dirrooterror', 'install').'<br />';
255 $INSTALL['dirrootform'] = $INSTALL['dirroot'];
53a0367d 256 }
cdef6d42 257 if ($fh) fclose($fh);
2df3a721 258
259 /// check dataroot
260 $CFG->dataroot = $INSTALL['dataroot'];
261 if (make_upload_directory('sessions', false) === false ) {
cdef6d42 262 $errormsg .= get_string('datarooterror', 'install').'<br />';
2df3a721 263 }
53a0367d 264 if ($fh) fclose($fh);
8b5b1028 265
3470b39f 266 if (!empty($errormsg)) $nextstage = DIRECTORY;
8b5b1028 267
268 error_reporting(7);
269}
270
271
272
273//==========================================================================//
274
275/// Check database settings if stage 3 data submitted
276/// Try to connect to the database. If that fails then try to create the database
8d783716 277
3470b39f 278if ($INSTALL['stage'] == DATABASE) {
53a0367d 279
8d783716 280 /// different format for postgres7 by socket
281 if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
8b5b1028 282 $INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
8d783716 283 $INSTALL['dbuser'] = '';
284 $INSTALL['dbpass'] = '';
285 $INSTALL['dbname'] = '';
286
8b5b1028 287 if ($INSTALL['prefix'] == '') { /// must have a prefix
288 $INSTALL['prefix'] = 'mdl_';
289 }
290 }
291
fe515206 292 if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
293 if (!extension_loaded('mysql')) {
294 $errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
3470b39f 295 $nextstage = DATABASE;
fe515206 296 }
297 }
8b5b1028 298
e102e78a 299 if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
300 if (!extension_loaded('mysqli')) {
301 $errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
302 $nextstage = DATABASE;
303 }
304 }
305
86453d8b 306 if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
307 if (!extension_loaded('pgsql')) {
308 $errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
309 $nextstage = DATABASE;
310 }
311 }
312
313 if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
5f8deafa 314 if (!function_exists('mssql_connect')) {
86453d8b 315 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
316 $nextstage = DATABASE;
317 }
318 }
319
b9bc4d74 320 if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
5f8deafa 321 if (!function_exists('mssql_connect')) {
b9bc4d74 322 $errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
323 $nextstage = DATABASE;
324 }
325 }
326
86453d8b 327 if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
328 if (!extension_loaded('odbc')) {
329 $errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
330 $nextstage = DATABASE;
331 }
332 }
333
334 if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
335 if (!extension_loaded('oci8')) {
336 $errormsg = get_string('ociextensionisnotpresentinphp', 'install');
337 $nextstage = DATABASE;
338 }
339 }
340
e102e78a 341 if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
86453d8b 342 $errormsg = get_string('dbwrongprefix', 'install');
343 $nextstage = DATABASE;
344 }
345
346 if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
347 $errormsg = get_string('dbwrongprefix', 'install');
348 $nextstage = DATABASE;
349 }
350
351 if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
352 $errormsg = get_string('dbwronghostserver', 'install');
353 $nextstage = DATABASE;
354 }
355
fe515206 356 if (empty($errormsg)) {
357
53a0367d 358 error_reporting(0); // Hide errors
fe515206 359
360 if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
2a6d7f55 361 $db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
362 if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
fe515206 363 switch ($INSTALL['dbtype']) { /// Try to create a database
364 case 'mysql':
e102e78a 365 case 'mysqli':
2a6d7f55 366 if ($db->Execute("CREATE DATABASE {$INSTALL['dbname']} DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;")) {
fe515206 367 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
368 } else {
369 $errormsg = get_string('dbcreationerror', 'install');
3470b39f 370 $nextstage = DATABASE;
fe515206 371 }
372 break;
373 }
8b5b1028 374 }
b4dd571d 375 } else {
53a0367d 376 /// We have been able to connect properly, just test the database encoding now.
5d4e4271 377 /// It must be Unicode for 1.8 installations.
5d4e4271 378 $encoding = '';
379 switch ($INSTALL['dbtype']) {
380 case 'mysql':
e102e78a 381 case 'mysqli':
3facbe66 382 /// Get MySQL character_set_database value
5d4e4271 383 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
41aa8437 384 if ($rs && !$rs->EOF) {
5d4e4271 385 $records = $rs->GetAssoc(true);
386 $encoding = $records['character_set_database']['Value'];
3facbe66 387 if (strtoupper($encoding) != 'UTF8') {
388 /// Try to set the encoding now!
5d4e4271 389 if (! $db->Metatables()) { // We have no tables so go ahead
390 $db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
391 $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
392
86453d8b 393 }
394 }
5d4e4271 395 /// If conversion fails, skip, let environment testing do the job
396 }
397 break;
398 case 'postgres7':
399 /// Skip, let environment testing do the job
400 break;
401 case 'oci8po':
402 /// Skip, let environment testing do the job
403 break;
b4dd571d 404 }
8b5b1028 405 }
406 }
407
408 error_reporting(7);
409
410 if (($dbconnected === false) and (empty($errormsg)) ) {
411 $errormsg = get_string('dbconnectionerror', 'install');
3470b39f 412 $nextstage = DATABASE;
8b5b1028 413 }
414}
415
416
417
418//==========================================================================//
419
420/// If the next stage is admin directory settings OR we have just come from there then
421/// check the admin directory.
422/// If we can open a file then we know that the admin name is correct.
423
3470b39f 424if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
91099e36 425 if (!ini_get('allow_url_fopen')) {
3b3b8029 426 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
78850d9e 427 } else if (($fh = @fopen($INSTALL['wwwrootform'].'/'.$INSTALL['admindirname'].'/environment.xml', 'r')) !== false) {
3b3b8029 428 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
8b5b1028 429 fclose($fh);
430 } else {
e2850d15 431 $nextstage = ($goforward) ? ENVIRONMENT : DATABASE;
432 //if ($nextstage != ADMIN) {
433 // $errormsg = get_string('admindirerror', 'install');
434 // $nextstage = ADMIN;
435 // }
8b5b1028 436 }
437}
438
3b3b8029 439//==========================================================================//
440
441// Check if we can navigate from the environemt page (because it's ok)
442
443if ($INSTALL['stage'] == ENVIRONMENT) {
444 error_reporting(0); // Hide errors
445 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
446 error_reporting(7); // Show errors
447 if ($dbconnected) {
448 /// Execute environment check, printing results
449 if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
450 $nextstage = ENVIRONMENT;
451 }
452 } else {
453 /// We never should reach this because DB has been tested before arriving here
454 $errormsg = get_string('dbconnectionerror', 'install');
455 $nextstage = DATABASE;
456 }
457}
8b5b1028 458
cdef6d42 459
460
461//==========================================================================//
462
463// Try to download the lang pack if it has been selected
464
465if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
466
467 $downloadsuccess = false;
468 $downloaderror = '';
469
470 error_reporting(0); // Hide errors
471
472/// Create necessary lang dir
473 if (!make_upload_directory('lang', false)) {
474 $downloaderror = get_string('cannotcreatelangdir', 'error');
475 }
476
477/// Download and install component
478 if (($cd = new component_installer('http://download.moodle.org', 'lang16',
479 $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) {
f85236dc 480 $status = $cd->install(); //returns COMPONENT_(ERROR | UPTODATE | INSTALLED)
cdef6d42 481 switch ($status) {
f85236dc 482 case COMPONENT_ERROR:
a7d43f0d 483 if ($cd->get_error() == 'remotedownloaderror') {
cdef6d42 484 $a = new stdClass();
6a525ce2 485 $a->url = 'http://download.moodle.org/lang16/'.$INSTALL['language'].'.zip';
cdef6d42 486 $a->dest= $CFG->dataroot.'/lang';
487 $downloaderror = get_string($cd->get_error(), 'error', $a);
488 } else {
489 $downloaderror = get_string($cd->get_error(), 'error');
490 }
491 break;
f85236dc 492 case COMPONENT_UPTODATE:
493 case COMPONENT_INSTALLED:
cdef6d42 494 $downloadsuccess = true;
495 break;
496 default:
497 //We shouldn't reach this point
498 }
499 } else {
500 //We shouldn't reach this point
501 }
502
503 error_reporting(7); // Show errors
504
505 if ($downloadsuccess) {
506 $INSTALL['downloadlangpack'] = false;
507 $INSTALL['showdownloadlangpack'] = false;
508 $INSTALL['downloadlangpackerror'] = $downloaderror;
509 } else {
510 $INSTALL['downloadlangpack'] = false;
511 $INSTALL['showdownloadlangpack'] = false;
512 $INSTALL['downloadlangpackerror'] = $downloaderror;
513 }
53a0367d 514}
cdef6d42 515
516
517
8b5b1028 518//==========================================================================//
519
520/// Display or print the data
521/// Put the data into a string
522/// Try to open config file for writing.
8d783716 523
3470b39f 524if ($nextstage == SAVE) {
51e3e0b9 525
526 $str = '<?php /// Moodle Configuration File '."\r\n";
527 $str .= "\r\n";
528
529 $str .= 'unset($CFG);'."\r\n";
530 $str .= "\r\n";
531
532 $str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
c423badc 533 $str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
59812bc7 534 if (!empty($INSTALL['dbname'])) {
51e3e0b9 535 $str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
2961367e 536 // support single quotes in db user/passwords
537 $str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
538 $str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
51e3e0b9 539 }
540 $str .= '$CFG->dbpersist = false;'."\r\n";
541 $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
542 $str .= "\r\n";
543
9914f093 544 $str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
545 $str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
546 $str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
547 $str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
51e3e0b9 548 $str .= "\r\n";
549
6e86ae68 550 $str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
51e3e0b9 551 $str .= "\r\n";
552
553 $str .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n";
554 $str .= '// MAKE SURE WHEN YOU EDIT THIS FILE THAT THERE ARE NO SPACES, BLANK LINES,'."\r\n";
555 $str .= '// RETURNS, OR ANYTHING ELSE AFTER THE TWO CHARACTERS ON THE NEXT LINE.'."\r\n";
556 $str .= '?>';
557
7c561c7a 558 umask(0137);
559
8b5b1028 560 if (( $configsuccess = ($fh = @fopen($configfile, 'w')) ) !== false) {
561 fwrite($fh, $str);
562 fclose($fh);
563 }
53a0367d 564
51e3e0b9 565
566 $INSTALL['config'] = $str;
8b5b1028 567}
568
569
570
571//==========================================================================//
572
573?>
dc71bb7d 574<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
dfcdf072 575<html dir="<?php echo (right_to_left() ? 'rtl' : 'ltr'); ?>">
8b5b1028 576<head>
f96660f8 577<link rel="shortcut icon" href="theme/standard/favicon.ico" />
8b5b1028 578<title>Moodle Install</title>
bd507453 579<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8b5b1028 580<?php css_styles() ?>
86453d8b 581<?php database_js() ?>
8b5b1028 582
583</head>
584
585<body>
586
8d783716 587
588<?php
589if (isset($_GET['help'])) {
590 print_install_help($_GET['help']);
51e3e0b9 591 close_window_button();
8d783716 592} else {
593?>
594
8b5b1028 595
dc71bb7d 596<table class="main" cellpadding="3" cellspacing="0">
8b5b1028 597 <tr>
8d783716 598 <td class="td_mainlogo">
dc71bb7d 599 <p class="p_mainlogo"><img src="pix/moodlelogo-med.gif" width="240" height="60" alt="Moodle logo"/></p>
8d783716 600 </td>
601 <td class="td_mainlogo" valign="bottom">
602 <p class="p_mainheader"><?php print_string('installation', 'install') ?></p>
603 </td>
604 </tr>
605
606 <tr>
607 <td class="td_mainheading" colspan="2">
e6f930f3 608 <p class="p_mainheading"><?php echo $headstagetext[$nextstage] ?></p>
86453d8b 609 <?php /// Exceptionaly, depending of the DB selected, we show some different text
610 /// from the standard one to show better instructions for each DB
611 if ($nextstage == DATABASE) {
a09f3b7d 612 echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
dc71bb7d 613 echo '<div id="mysql">' . get_string('databasesettingssub_mysql', 'install');
614 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
47bf57d6 615 echo '</div>';
86453d8b 616
dc71bb7d 617 echo '<div id="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
618 echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
47bf57d6 619 echo '</div>';
e102e78a 620
dc71bb7d 621 echo '<div id="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
86453d8b 622
dc71bb7d 623 echo '<div id="mssql">' . get_string('databasesettingssub_mssql', 'install');
86453d8b 624 /// Link to mssql installation page
dc71bb7d 625 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
626 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
627 echo ">";
3d616aa0 628 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
86453d8b 629 echo get_string('moodledocslink', 'install') . '</a></p>';
630 echo '</div>';
631
dc71bb7d 632 echo '<div id="mssql_n">' . get_string('databasesettingssub_mssql_n', 'install');
b9bc4d74 633 /// Link to mssql installation page
dc71bb7d 634 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
635 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
636 echo ">";
3d616aa0 637 echo '<img src="pix/docs.gif' . '" alt="Docs" />';
b9bc4d74 638 echo get_string('moodledocslink', 'install') . '</a></p>';
639 echo '</div>';
640
dc71bb7d 641 echo '<div id="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
86453d8b 642 /// Link to mssql installation page
dc71bb7d 643 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
644 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
645 echo ">";
3d616aa0 646 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
86453d8b 647 echo get_string('moodledocslink', 'install') . '</a></p>';
648 echo '</div>';
649
dc71bb7d 650 echo '<div id="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
b9bc4d74 651 /// Link to oracle installation page
dc71bb7d 652 echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
653 echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_Oracle_for_PHP')\"";
654 echo ">";
3d616aa0 655 echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
86453d8b 656 echo get_string('moodledocslink', 'install') . '</a></p>';
657 echo '</div>';
658 } else {
659 if (!empty($substagetext[$nextstage])) {
660 echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
661 }
662 }
663 ?>
8d783716 664 </td>
8b5b1028 665 </tr>
666
667 <tr>
8d783716 668 <td class="td_main" colspan="2">
53a0367d 669
8b5b1028 670<?php
671
dc71bb7d 672if (!empty($errormsg)) echo "<p class=\"errormsg\" style=\"text-align:center\">$errormsg</p>\n";
8b5b1028 673
674
3470b39f 675if ($nextstage == SAVE) {
676 $INSTALL['stage'] = WELCOME;
51e3e0b9 677 $options = array();
678 $options['lang'] = $INSTALL['language'];
8b5b1028 679 if ($configsuccess) {
dc71bb7d 680 echo "<p class=\"p_install\">".get_string('configfilewritten', 'install')."</p>\n";
51e3e0b9 681
682 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
683 echo "<tr>\n";
dc71bb7d 684 echo "<td>&nbsp;</td>\n";
685 echo "<td>&nbsp;</td>\n";
686 echo "<td align=\"right\">\n";
5bc28e71 687 print_single_button("index.php", $options, get_string('continue'));
51e3e0b9 688 echo "</td>\n";
689 echo "</tr>\n";
690 echo "</table>\n";
691
8b5b1028 692 } else {
51e3e0b9 693 echo "<p class=\"errormsg\">".get_string('configfilenotwritten', 'install')."</p>";
53a0367d 694
51e3e0b9 695 echo "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n";
696 echo "<tr>\n";
dc71bb7d 697 echo "<td>&nbsp;</td>\n";
698 echo "<td align=\"center\">\n";
51e3e0b9 699 $installoptions = array();
53a0367d 700 $installoptions['download'] = 1;
51e3e0b9 701 print_single_button("install.php", $installoptions, get_string('download', 'install'));
702 echo "</td>\n";
dc71bb7d 703 echo "<td align=\"right\">\n";
5bc28e71 704 print_single_button("index.php", $options, get_string('continue'));
51e3e0b9 705 echo "</td>\n";
706 echo "</tr>\n";
707 echo "</table>\n";
708
8b5b1028 709 echo "<hr />\n";
99238bf4 710 echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
3efc0668 711 echo "<pre>\n";
712 print_r(s($str));
713 echo "</pre>\n";
51e3e0b9 714 echo "</div>\n";
8b5b1028 715 }
8b5b1028 716} else {
717 $formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
718 form_table($nextstage, $formaction);
719}
720
721?>
722
723 </td>
724 </tr>
725</table>
726
8d783716 727<?php
728}
729?>
730
8b5b1028 731</body>
732</html>
733
734
735
736
737
738
739
740
741
742
53a0367d 743<?php
8b5b1028 744
8b5b1028 745
746//==========================================================================//
747
3470b39f 748function form_table($nextstage = WELCOME, $formaction = "install.php") {
3b3b8029 749 global $INSTALL, $db;
8b5b1028 750
cdef6d42 751 /// Print the standard form if we aren't in the DOWNLOADLANG page
752 /// because it has its own form.
753 if ($nextstage != DOWNLOADLANG) {
754 $needtoopenform = false;
8b5b1028 755?>
d2ce367f 756 <form id="installform" method="post" action="<?php echo $formaction ?>">
dc71bb7d 757 <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
8b5b1028 758
cdef6d42 759<?php
760 } else {
761 $needtoopenform = true;
762 }
763?>
dc71bb7d 764 <table class="install_table" cellspacing="3" cellpadding="3">
8b5b1028 765
766<?php
767 /// what we do depends on the stage we're at
768 switch ($nextstage) {
3470b39f 769 case WELCOME: /// Welcome and language settings
8b5b1028 770?>
771 <tr>
dc71bb7d 772 <td class="td_left"><p class="p_install"><?php print_string('language') ?></p></td>
8b5b1028 773 <td class="td_right">
b9b4e32a 774 <?php choose_from_menu (get_installer_list_of_languages(), 'language', $INSTALL['language'], '') ?>
8b5b1028 775 </td>
776 </tr>
777
778<?php
8d783716 779 break;
3470b39f 780 case COMPATIBILITY: /// Compatibilty check
8d783716 781 $compatsuccess = true;
53a0367d 782
8d783716 783 /// Check that PHP is of a sufficient version
b4ac6245 784 print_compatibility_row(inst_check_php_version(), get_string('phpversion', 'install'), get_string('php52versionerror', 'install'), 'php52versionhelp');
8d783716 785 /// Check session auto start
786 print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart', 'install'), get_string('sessionautostarterror', 'install'), 'sessionautostarthelp');
8d783716 787 /// Check magic quotes
788 print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime', 'install'), get_string('magicquotesruntimeerror', 'install'), 'magicquotesruntimehelp');
4d46a3f0 789 /// Check unsupported PHP configuration
790 print_compatibility_row(ini_get_bool('magic_quotes_gpc') || (!ini_get_bool('register_globals')), get_string('globalsquotes', 'install'), get_string('globalsquoteserror', 'install'), 'globalsquoteshelp');
53a0367d 791 /// Check safe mode
51e3e0b9 792 print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode', 'install'), get_string('safemodeerror', 'install'), 'safemodehelp', true);
8d783716 793 /// Check file uploads
51e3e0b9 794 print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads', 'install'), get_string('fileuploadserror', 'install'), 'fileuploadshelp', true);
8d783716 795 /// Check GD version
51e3e0b9 796 print_compatibility_row(check_gd_version(), get_string('gdversion', 'install'), get_string('gdversionerror', 'install'), 'gdversionhelp', true);
8d783716 797 /// Check memory limit
51e3e0b9 798 print_compatibility_row(check_memory_limit(), get_string('memorylimit', 'install'), get_string('memorylimiterror', 'install'), 'memorylimithelp', true);
8d783716 799
800
8b5b1028 801 break;
3470b39f 802 case DIRECTORY: /// Directory settings
8b5b1028 803?>
804
805 <tr>
dc71bb7d 806 <td class="td_left"><p class="p_install"><?php print_string('wwwroot', 'install') ?></p></td>
8b5b1028 807 <td class="td_right">
9914f093 808 <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true) ?>" />
8b5b1028 809 </td>
810 </tr>
811 <tr>
dc71bb7d 812 <td class="td_left"><p class="p_install"><?php print_string('dirroot', 'install') ?></p></td>
8b5b1028 813 <td class="td_right">
d36afd6d 814 <input type="text" size="40" name="dirrootform" disabled="disabled" value="<?php p($INSTALL['dirrootform'],true) ?>" />
8b5b1028 815 </td>
816 </tr>
817 <tr>
dc71bb7d 818 <td class="td_left"><p class="p_install"><?php print_string('dataroot', 'install') ?></p></td>
8b5b1028 819 <td class="td_right">
9914f093 820 <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true) ?>" />
8b5b1028 821 </td>
822 </tr>
823
824<?php
825 break;
3470b39f 826 case DATABASE: /// Database settings
8b5b1028 827?>
828
829 <tr>
dc71bb7d 830 <td class="td_left"><p class="p_install"><?php print_string('dbtype', 'install') ?></p></td>
8b5b1028 831 <td class="td_right">
86453d8b 832 <?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
e102e78a 833 'mysqli' => get_string('mysqli', 'install'),
86453d8b 834 'oci8po' => get_string('oci8po', 'install'),
53a0367d 835 'postgres7' => get_string('postgres7', 'install'),
836 'mssql' => get_string('mssql', 'install'),
837 'mssql_n' => get_string('mssql_n', 'install'),
838 'odbc_mssql' => get_string('odbc_mssql', 'install')),
86453d8b 839 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
8b5b1028 840 </td>
841 </tr>
842 <tr>
dc71bb7d 843 <td class="td_left"><p class="p_install"><?php print_string('dbhost', 'install') ?></p></td>
8b5b1028 844 <td class="td_right">
dc71bb7d 845 <input type="text" class="input_database" name="dbhost" value="<?php p($INSTALL['dbhost']) ?>" />
8b5b1028 846 </td>
847 </tr>
848 <tr>
dc71bb7d 849 <td class="td_left"><p class="p_install"><?php print_string('database', 'install') ?></p></td>
8b5b1028 850 <td class="td_right">
dc71bb7d 851 <input type="text" class="input_database" name="dbname" value="<?php p($INSTALL['dbname']) ?>" />
8b5b1028 852 </td>
853 </tr>
854 <tr>
dc71bb7d 855 <td class="td_left"><p class="p_install"><?php print_string('user') ?></p></td>
8b5b1028 856 <td class="td_right">
dc71bb7d 857 <input type="text" class="input_database" name="dbuser" value="<?php p($INSTALL['dbuser']) ?>" />
8b5b1028 858 </td>
859 </tr>
860 <tr>
dc71bb7d 861 <td class="td_left"><p class="p_install"><?php print_string('password') ?></p></td>
8b5b1028 862 <td class="td_right">
dc71bb7d 863 <input type="password" class="input_database" name="dbpass" value="<?php p($INSTALL['dbpass']) ?>" />
8b5b1028 864 </td>
865 </tr>
866 <tr>
dc71bb7d 867 <td class="td_left"><p class="p_install"><?php print_string('dbprefix', 'install') ?></p></td>
8b5b1028 868 <td class="td_right">
dc71bb7d 869 <input type="text" class="input_database" name="prefix" value="<?php p($INSTALL['prefix']) ?>" />
8b5b1028 870 </td>
871 </tr>
872
873<?php
874 break;
3470b39f 875 case ADMIN: /// Administration directory setting
8b5b1028 876?>
877
878 <tr>
dc71bb7d 879 <td class="td_left"><p class="p_install"><?php print_string('admindirname', 'install') ?></p></td>
8b5b1028 880 <td class="td_right">
f49312b6 881 <input type="text" size="40" name="admindirname" value="<?php p($INSTALL['admindirname']) ?>" />
8b5b1028 882 </td>
883 </tr>
884
885
3b3b8029 886<?php
887 break;
888 case ENVIRONMENT: /// Environment checks
889?>
890
891 <tr>
892 <td colspan="2">
893 <?php
894 error_reporting(0); // Hide errors
895 $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
896 error_reporting(7); // Show errors
897 if ($dbconnected) {
898 /// Execute environment check, printing results
899 check_moodle_environment($INSTALL['release'], $environment_results, true);
900 } else {
901 /// We never should reach this because DB has been tested before arriving here
902 $errormsg = get_string('dbconnectionerror', 'install');
903 $nextstage = DATABASE;
dc71bb7d 904 echo '<p class="errormsg" style="text-align:center">'.get_string('dbconnectionerror', 'install').'</p>';
3b3b8029 905 }
906 ?>
907 </td>
908 </tr>
909
68a3f81d 910<?php
911 break;
912 case DOWNLOADLANG: /// Download language from download.moodle.org
913?>
914
915 <tr>
916 <td colspan="2">
917 <?php
cdef6d42 918 /// Get array of languages, we are going to use it
919 $languages=get_installer_list_of_languages();
920 /// Print the download form (button) if necessary
921 if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
922 $options = array();
923 $options['downloadlangpack'] = true;
924 $options['stage'] = DOWNLOADLANG;
925 $options['same'] = true;
926 print_simple_box_start('center');
dc71bb7d 927 print_single_button('install.php', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'post');
cdef6d42 928 print_simple_box_end();
68a3f81d 929 } else {
53a0367d 930 /// Show result info
cdef6d42 931 /// English lang packs aren't downloaded
932 if (substr($INSTALL['language'],0,2) == 'en') {
933 print_simple_box(get_string('downloadlanguagenotneeded', 'install', $languages[$INSTALL['language']]), 'center', '80%');
934 } else {
935 if ($INSTALL['downloadlangpackerror']) {
936 echo "<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
937 print_simple_box(get_string('langdownloaderror', 'install', $languages[$INSTALL['language']]), 'center', '80%');
938 } else {
939 print_simple_box(get_string('langdownloadok', 'install', $languages[$INSTALL['language']]), 'center', '80%');
940 }
941 }
68a3f81d 942 }
943 ?>
944 </td>
945 </tr>
3b3b8029 946
8b5b1028 947<?php
948 break;
949 default:
950 }
951?>
cd0e958e 952
51e3e0b9 953 <tr>
3470b39f 954 <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 3 : 2; ?>">
51e3e0b9 955
cdef6d42 956<?php
957 if ($needtoopenform) {
958?>
d2ce367f 959 <form id="installform" method="post" action="<?php echo $formaction ?>">
dc71bb7d 960 <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
cdef6d42 961<?php
962 }
963?>
964
dc71bb7d 965 <?php echo ($nextstage < SAVE) ? "<div><input type=\"submit\" name=\"next\" value=\"".get_string('next')." &raquo;\" style=\"float: ".fix_align_rtl("right")."\"/></div>\n" : "&nbsp;\n" ?>
966 <?php echo ($nextstage > WELCOME) ? "<div><input type=\"submit\" name=\"prev\" value=\"&laquo; ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/></div>\n" : "&nbsp;\n" ?>
cd0e958e 967
cdef6d42 968<?php
969 if ($needtoopenform) {
970?>
971 </form>
972<?php
973 }
974?>
975
7c561c7a 976
51e3e0b9 977 </td>
cd0e958e 978
51e3e0b9 979 </tr>
53a0367d 980
51e3e0b9 981 </table>
cdef6d42 982<?php
983 if (!$needtoopenform) {
984?>
8b5b1028 985 </form>
cdef6d42 986<?php
987 }
988?>
8b5b1028 989
990<?php
991}
992
993
994
8d783716 995//==========================================================================//
996
51e3e0b9 997function print_compatibility_row($success, $testtext, $errormessage, $helpfield='', $caution=false) {
8d783716 998 echo "<tr>\n";
dc71bb7d 999 echo "<td class=\"td_left_nowrap\" valign=\"top\"><p class=\"p_install\">$testtext</p></td>\n";
8d783716 1000 if ($success) {
51e3e0b9 1001 echo "<td valign=\"top\"><p class=\"p_pass\">".get_string('pass', 'install')."</p></td>\n";
1002 echo "<td valign=\"top\">&nbsp;</td>\n";
8d783716 1003 } else {
dc71bb7d 1004 echo "<td valign=\"top\">";
51e3e0b9 1005 echo ($caution) ? "<p class=\"p_caution\">".get_string('caution', 'install') : "<p class=\"p_fail\">".get_string('fail', 'install');
1006 echo "</p></td>\n";
1007 echo "<td valign=\"top\">";
dc71bb7d 1008 echo "<p class=\"p_install\">$errormessage ";
51e3e0b9 1009 install_helpbutton("install.php?help=$helpfield");
1010 echo "</p></td>\n";
8d783716 1011 }
1012 echo "</tr>\n";
1013 return $success;
1014}
1015
1016
1017//==========================================================================//
1018
1019function install_helpbutton($url, $title='') {
1020 if ($title == '') {
1021 $title = get_string('help');
1022 }
dc71bb7d 1023 echo "<a href=\"javascript:void(0)\" ";
1024 echo "onclick=\"return window.open('$url','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400')\"";
1025 echo ">";
1026 echo "<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\"/>";
8d783716 1027 echo "</a>\n";
1028}
53a0367d 1029
8d783716 1030
1031
1032//==========================================================================//
1033
1034function print_install_help($help) {
8d783716 1035 switch ($help) {
1036 case 'phpversionhelp':
1037 print_string($help, 'install', phpversion());
1038 break;
1039 case 'memorylimithelp':
94ba66ce 1040 print_string($help, 'install', get_memory_limit());
8d783716 1041 break;
1042 default:
1043 print_string($help, 'install');
1044 }
8d783716 1045}
1046
1047
1048//==========================================================================//
1049
1050function get_memory_limit() {
1051 if ($limit = ini_get('memory_limit')) {
1052 return $limit;
1053 } else {
1054 return get_cfg_var('memory_limit');
1055 }
1056}
1057
1058//==========================================================================//
1059
1060function check_memory_limit() {
1061
1cc1456b 1062 /// if limit is already 40 or more then we don't care if we can change it or not
1063 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
8d783716 1064 return true;
1065 }
1a639adc 1066
8d783716 1067 /// Otherwise, see if we can change it ourselves
1cc1456b 1068 @ini_set('memory_limit', '40M');
1069 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
8d783716 1070}
1071
8b5b1028 1072//==========================================================================//
b9b4e32a 1073
d976b5fe 1074function inst_check_php_version() {
b4ac6245 1075 return check_php_version("5.2.0");
d976b5fe 1076}
1077//==========================================================================//
1078
b9b4e32a 1079/* This function returns a list of languages and their full names. The
1080 * list of available languages is fetched from install/lang/xx/installer.php
1081 * and it's used exclusively by the installation process
1082 * @return array An associative array with contents in the form of LanguageCode => LanguageName
1083 */
1084function get_installer_list_of_languages() {
1085
1086 global $CFG;
1087
1088 $languages = array();
1089
1090/// Get raw list of lang directories
1091 $langdirs = get_list_of_plugins('install/lang');
1092 asort($langdirs);
1093/// Get some info from each lang
1094 foreach ($langdirs as $lang) {
1095 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
1096 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
1a8bdfc4 1097 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
1098 $shortlang = substr($lang, 0, -5);
1099 } else {
1100 $shortlang = $lang;
1101 }
1102 if ($lang == 'en') { //Explain this is non-utf8 en
1103 $shortlang = 'non-utf8 en';
1104 }
b9b4e32a 1105 if (!empty($string['thislanguage'])) {
1a8bdfc4 1106 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
b9b4e32a 1107 }
1108 unset($string);
1109 }
1110 }
1111/// Return array
1112 return $languages;
1113}
1114
1115//==========================================================================//
8b5b1028 1116
1117function css_styles() {
1118?>
1119
1120<style type="text/css">
1121
1122 body { background-color: #ffeece; }
53a0367d 1123 p, li, td {
8d783716 1124 font-family: helvetica, arial, sans-serif;
1125 font-size: 10pt;
1126 }
8b5b1028 1127 a { text-decoration: none; color: blue; }
5782d818 1128 a img {
1129 border: none;
1130 }
8b5b1028 1131 .errormsg {
1132 color: red;
1133 font-weight: bold;
1134 }
8d783716 1135 blockquote {
51e3e0b9 1136 font-family: courier, monospace;
8d783716 1137 font-size: 10pt;
1138 }
dc71bb7d 1139 .input_database {
1140 width: 270px;
1141 }
8b5b1028 1142 .install_table {
1143 width: 500px;
dc71bb7d 1144 margin-left:auto;
1145 margin-right:auto;
8b5b1028 1146 }
1147 .td_left {
99238bf4 1148 text-align: <?php echo fix_align_rtl("right") ?>;
8b5b1028 1149 font-weight: bold;
1150 }
dc71bb7d 1151 .td_left_nowrap{
1152 text-align: <?php echo fix_align_rtl("right") ?>;
1153 font-weight: bold;
1154 white-space: nowrap;
1155 width: 160px;
1156 padding-left: 10px;
1157 }
8b5b1028 1158 .td_right {
99238bf4 1159 text-align: <?php echo fix_align_rtl("left") ?>;
8b5b1028 1160 }
1161 .main {
1162 width: 500px;
1163 border-width: 1px;
1164 border-style: solid;
1165 border-color: #ffc85f;
dc71bb7d 1166 margin-left:auto;
1167 margin-right:auto;
8b5b1028 1168 -moz-border-radius-bottomleft: 15px;
1169 -moz-border-radius-bottomright: 15px;
1170 }
1171 .td_mainheading {
1172 background-color: #fee6b9;
dc71bb7d 1173 padding-left: 10px;
8b5b1028 1174 }
1175 .td_main {
1176 text-align: center;
1177 }
8d783716 1178 .td_mainlogo {
dc71bb7d 1179 vertical-align: middle;
8d783716 1180 }
1181 .p_mainlogo {
dc71bb7d 1182 margin-top: 0px;
1183 margin-bottom: 0px;
8d783716 1184 }
8b5b1028 1185 .p_mainheading {
8d783716 1186 font-size: 11pt;
dc71bb7d 1187 margin-top: 16px;
1188 margin-bottom: 16px;
8d783716 1189 }
182dca14 1190 .p_subheading {
1191 font-size: 10pt;
dc71bb7d 1192 padding-left: 10px;
1193 margin-top: 16px;
1194 margin-bottom: 16px;
182dca14 1195 }
8d783716 1196 .p_mainheader{
dc71bb7d 1197 text-align: right;
8d783716 1198 font-size: 20pt;
1199 font-weight: bold;
dc71bb7d 1200 margin-top: 0px;
1201 margin-bottom: 0px;
8d783716 1202 }
1203 .p_pass {
1204 color: green;
1205 font-weight: bold;
dc71bb7d 1206 margin-top: 0px;
1207 margin-bottom: 0px;
8d783716 1208 }
1209 .p_fail {
1210 color: red;
1211 font-weight: bold;
dc71bb7d 1212 margin-top: 0px;
1213 margin-bottom: 0px;
8d783716 1214 }
51e3e0b9 1215 .p_caution {
1216 color: #ff6600;
1217 font-weight: bold;
dc71bb7d 1218 margin-top: 0px;
1219 margin-bottom: 0px;
51e3e0b9 1220 }
8d783716 1221 .p_help {
1222 text-align: center;
1223 font-family: helvetica, arial, sans-serif;
1224 font-size: 14pt;
1225 font-weight: bold;
1226 color: #333333;
dc71bb7d 1227 margin-top: 0px;
1228 margin-bottom: 0px;
1229 }
1230 /* This override the p tag for every p tag in this installation script,
1231 but not in lang\xxx\installer.php
1232 */
1233 .p_install {
1234 margin-top: 0px;
1235 margin-bottom: 0px;
8b5b1028 1236 }
3b3b8029 1237 .environmenttable {
1238 font-size: 10pt;
1239 border-color: #ffc85f;
1240 }
53a0367d 1241 table.environmenttable .error {
1242 background-color : red;
1243 color : inherit;
1244 }
1245
1246 table.environmenttable .warn {
1247 background-color : yellow;
1248 }
1249
1250 table.environmenttable .ok {
1251 background-color : lightgreen;
1252 }
3b3b8029 1253 .header {
1254 background-color: #fee6b9;
1255 font-size: 10pt;
1256 }
1257 .cell {
1258 background-color: #ffeece;
1259 font-size: 10pt;
1260 }
1261 .error {
1262 color: #ff0000;
1263 }
1264 .errorboxcontent {
1265 text-align: center;
1266 font-weight: bold;
dc71bb7d 1267 padding-left: 20px;
3b3b8029 1268 color: #ff0000;
1269 }
69cb58ef 1270 .invisiblefieldset {
1271 display:inline;
1272 border:0px;
1273 padding:0px;
1274 margin:0px;
1275 }
e102e78a 1276 #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
86453d8b 1277 display: none;
1278 }
3b3b8029 1279
8b5b1028 1280</style>
1281
86453d8b 1282<?php
1283}
1284
1285//==========================================================================//
1286
1287function database_js() {
1288?>
1289
a09f3b7d 1290<script type="text/javascript" defer="defer">
86453d8b 1291function toggledbinfo() {
1292 //Calculate selected value
1293 var showid = 'mysql';
3facbe66 1294 if (document.getElementById('installform').dbtype.value) {
1295 showid = document.getElementById('installform').dbtype.value;
86453d8b 1296 }
1297 if (document.getElementById) {
1298 //Hide all the divs
1299 document.getElementById('mysql').style.display = '';
e102e78a 1300 document.getElementById('mysqli').style.display = '';
86453d8b 1301 document.getElementById('postgres7').style.display = '';
1302 document.getElementById('mssql').style.display = '';
b9bc4d74 1303 document.getElementById('mssql_n').style.display = '';
86453d8b 1304 document.getElementById('odbc_mssql').style.display = '';
1305 document.getElementById('oci8po').style.display = '';
1306 //Show the selected div
1307 document.getElementById(showid).style.display = 'block';
1308 } else if (document.all) {
1309 //This is the way old msie versions work
1310 //Hide all the divs
1311 document.all['mysql'].style.display = '';
e102e78a 1312 document.all['mysqli'].style.display = '';
86453d8b 1313 document.all['postgres7'].style.display = '';
1314 document.all['mssql'].style.display = '';
b9bc4d74 1315 document.all['mssql_n'].style.display = '';
86453d8b 1316 document.all['odbc_mssql'].style.display = '';
1317 document.all['oci8po'].style.display = '';
1318 //Show the selected div
1319 document.all[showid].style.display = 'block';
1320 } else if (document.layers) {
1321 //This is the way nn4 works
1322 //Hide all the divs
1323 document.layers['mysql'].style.display = '';
e102e78a 1324 document.layers['mysqli'].style.display = '';
86453d8b 1325 document.layers['postgres7'].style.display = '';
1326 document.layers['mssql'].style.display = '';
b9bc4d74 1327 document.layers['mssql_n'].style.display = '';
86453d8b 1328 document.layers['odbc_mssql'].style.display = '';
1329 document.layers['oci8po'].style.display = '';
1330 //Show the selected div
1331 document.layers[showid].style.display = 'block';
1332 }
1333}
1334</script>
1335
8b5b1028 1336<?php
1337}
2961367e 1338
1339/**
5690e088 1340 * Add slashes for single quotes and backslashes
1341 * so they can be included in single quoted string
1342 * (for config.php)
2961367e 1343 */
1344function addsingleslashes($input){
5690e088 1345 return preg_replace("/(['\\\])/", "\\\\$1", $input);
2961367e 1346}
8b5b1028 1347?>