Automatic installer.php by installer_builder (20060329)
[moodle.git] / lib / setup.php
CommitLineData
da8759cb 1<?php
2/**
3 * setup.php - Sets up sessions, connects to databases and so on
4 *
75249234 5 * Normally this is only called by the main config.php file
6 * Normally this file does not need to be edited.
da8759cb 7 * @author Martin Dougiamas
8 * @version $Id$
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * @package moodlecore
11 */
12
13////// DOCUMENTATION IN PHPDOC FORMAT FOR MOODLE GLOBALS AND COMMON OBJECT TYPES /////////////
14/**
735b8567 15 * $USER is a global instance of a typical $user record.
da8759cb 16 *
735b8567 17 * Items found in the user record:
da8759cb 18 * - $USER->emailstop - Does the user want email sent to them?
19 * - $USER->email - The user's email address.
20 * - $USER->id - The unique integer identified of this user in the 'user' table.
21 * - $USER->email - The user's email address.
22 * - $USER->firstname - The user's first name.
23 * - $USER->lastname - The user's last name.
24 * - $USER->username - The user's login username.
25 * - $USER->secret - The user's ?.
26 * - $USER->lang - The user's language choice.
27 *
75249234 28 * @global object(user) $USER
da8759cb 29 */
674fb525 30global $USER;
da8759cb 31/**
735b8567 32 * This global variable is read in from the 'config' table.
da8759cb 33 *
735b8567 34 * Some typical settings in the $CFG global:
da8759cb 35 * - $CFG->wwwroot - Path to moodle index directory in url format.
36 * - $CFG->dataroot - Path to moodle index directory on server's filesystem.
37 * - $CFG->libroot - Path to moodle's library folder on server's filesystem.
38 *
674fb525 39 * @global object(cfg) $CFG
da8759cb 40 */
674fb525 41global $CFG;
da8759cb 42/**
43 * Definition of session type
75249234 44 * @global object(session) $SESSION
da8759cb 45 */
46global $SESSION;
47/**
48 * Definition of course type
75249234 49 * @global object(course) $COURSE
da8759cb 50 */
51global $COURSE;
52/**
53 * Definition of db type
75249234 54 * @global object(db) $db
da8759cb 55 */
56global $db;
57/**
58 * $THEME is a global that defines the site theme.
59 *
60 * Items found in the theme record:
61 * - $THEME->cellheading - Cell colors.
62 * - $THEME->cellheading2 - Alternate cell colors.
63 *
75249234 64 * @global object(theme) $THEME
da8759cb 65 */
66global $THEME;
f9903ed0 67
9d0dd812 68/**
69 * HTTPSPAGEREQUIRED is a global to define if the page being displayed must run under HTTPS.
70 *
71 * It's primary goal is to allow 100% HTTPS pages when $CFG->loginhttps is enabled. Default to false.
72 * It's enabled only by the httpsrequired() function and used in some pages to update some URLs
73*/
74global $HTTPSPAGEREQUIRED;
75
76
578dcc40 77/// First try to detect some attacks on older buggy PHP versions
735b8567 78 if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
578dcc40 79 die('Fatal: Illegal GLOBALS overwrite attempt detected!');
80 }
81
82
36ec6afe 83 if (!isset($CFG->wwwroot)) {
a670108e 84 trigger_error('Fatal: $CFG->wwwroot is not configured! Exiting.');
36ec6afe 85 die;
86 }
75249234 87
9d0dd812 88/// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
89/// inside some URLs used in HTTPSPAGEREQUIRED pages.
d3f9f1f8 90 $CFG->httpswwwroot = $CFG->wwwroot;
91
92 $CFG->libdir = $CFG->dirroot .'/lib';
93
94 require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
9d0dd812 95
c2fd9e95 96/// Time to start counting
66552670 97 init_performance_info();
98
b8cea9b2 99
74944b73 100/// If there are any errors in the standard libraries we want to know!
346b1a24 101 error_reporting(E_ALL);
f9903ed0 102
d7196099 103/// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
0a194c4c 104/// http://www.google.com/webmasters/faq.html#prefetchblock
d7196099 105 if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
0a194c4c 106 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
d7196099 107 trigger_error('Prefetch request forbidden.');
108 exit;
109 }
110
a8a71844 111/// Connect to the database using adodb
112
1685298e 113
da8759cb 114 require_once($CFG->libdir .'/adodb/adodb.inc.php'); // Database access functions
fa3ba0f6 115
75249234 116 $db = &ADONewConnection($CFG->dbtype);
fa3ba0f6 117
75249234 118 error_reporting(0); // Hide errors
9f71c9e7 119
120 if (!isset($CFG->dbpersist) or !empty($CFG->dbpersist)) { // Use persistent connection (default)
121 $dbconnected = $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
122 } else { // Use single connection
123 $dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
124 }
125 if (! $dbconnected) {
b350cb9d 126 // In the name of protocol correctness, monitoring and performance
127 // profiling, set the appropriate error headers for machine comsumption
128 if (isset($_SERVER['SERVER_PROTOCOL'])) {
129 // Avoid it with cron.php. Note that we assume it's HTTP/1.x
130 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
131 }
132 // and then for human consumption...
133 echo '<html><body>';
53f39b32 134 echo '<table align="center"><tr>';
135 echo '<td style="color:#990000; text-align:center; font-size:large; border-width:1px; '.
136 ' border-color:#000000; border-style:solid; border-radius: 20px; border-collapse: collapse; '.
137 ' -moz-border-radius: 20px; padding: 15px">';
138 echo '<p>Error: Database connection failed.</p>';
139 echo '<p>It is possible that the database is overloaded or otherwise not running properly.</p>';
140 echo '<p>The site administrator should also check that the database details have been correctly specified in config.php</p>';
141 echo '</td></tr></table>';
b350cb9d 142 echo '</body></html>';
880a6f6b 143
144 if (!empty($CFG->emailconnectionerrorsto)) {
145 mail($CFG->emailconnectionerrorsto,
146 'WARNING: Database connection error: '.$CFG->wwwroot,
147 'Connection error: '.$CFG->wwwroot);
148 }
9f71c9e7 149 die;
a8a71844 150 }
151
7104d80d 152/// Starting here we have a correct DB conection but me must avoid
153/// to execute any DB transaction until "set names" has been executed
154/// some lines below!
6aaa17c7 155
0cb29cc4 156 error_reporting(E_ALL); // Show errors from now on.
157
b6bae251 158 if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
da8759cb 159 $CFG->prefix = '';
b6bae251 160 }
161
162
dae73c05 163/// Define admin directory
164
165 if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
1040ea85 166 $CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
dae73c05 167 }
168
a8a71844 169
75249234 170/// Load up standard libraries
6aaa17c7 171
172 require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
da8759cb 173 require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
174 require_once($CFG->libdir .'/datalib.php'); // Functions for accessing databases
175 require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
1e3e716f 176
1e3e716f 177
22d42bf0 178/// Increase memory limits if possible
179
75249234 180 raise_memory_limit('64M'); // We should never NEED this much but just in case...
afb18f5a 181
182
74944b73 183/// Load up any configuration from the config table
a4080313 184 $CFG = get_config();
f9903ed0 185
ceff9307 186/// Turn on SQL logging if required
187 if (!empty($CFG->logsql)) {
188 $db->LogSQL();
189 }
1e3e716f 190
0182c65c 191
4fd7ccc0 192/// Set error reporting back to normal
6fbf8d8f 193 if (empty($CFG->debug)) {
194 $CFG->debug = 7;
195 }
16ba7351 196 error_reporting($CFG->debug);
4fd7ccc0 197
198
7104d80d 199/// If $CFG->unicodedb is not set, calculate it because we need
200/// "set names" (below) properly executed *before* performing any
201/// DB transaction
202 if ($dbconnected && !isset($CFG->unicodedb)) {
203 $CFG->unicodedb = setup_is_unicodedb();
204 }
205
206
207/// Set the client/server and connection to utf8 if necessary
208 if ($dbconnected && $CFG->unicodedb) {
209 if ($db->databaseType == 'mysql') {
210 $db->Execute("SET NAMES 'utf8'");
211 } else if ($db->databaseType == 'postgres7') {
212 $db->Execute("SET NAMES 'utf8'");
213 }
214 }
215/// Now that "set names" has been executed it is safe to
216/// work with the DB, but never before this!
217
218
0182c65c 219/// Set a default enrolment configuration (see bug 1598)
220 if (!isset($CFG->enrol)) {
a51e2a7f 221 $CFG->enrol = 'manual';
0182c65c 222 }
223
ed8365d9 224/// Set default enabled enrolment plugins
225 if (!isset($CFG->enrol_plugins_enabled)) {
226 $CFG->enrol_plugins_enabled = 'manual';
227 }
228
2e6d4273 229/// File permissions on created directories in the $CFG->dataroot
230
231 if (empty($CFG->directorypermissions)) {
232 $CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
233 }
234
d6ead3a2 235/// Setup cache dir for Smarty and others
236 if (!file_exists($CFG->dataroot .'/cache')) {
237 make_upload_directory('cache');
238 }
239
afb18f5a 240/// Set up smarty template system
75249234 241 //require_once($CFG->libdir .'/smarty/Smarty.class.php');
0182c65c 242 //$smarty = new Smarty;
243 //$smarty->template_dir = $CFG->dirroot .'/templates/'. $CFG->template;
d6ead3a2 244 //if (!file_exists($CFG->dataroot .'/cache/smarty')) {
245 // make_upload_directory('cache/smarty');
0182c65c 246 //}
d6ead3a2 247 //$smarty->compile_dir = $CFG->dataroot .'/cache/smarty';
2e6d4273 248
75249234 249/// Set up session handling
f93426cf 250 if(empty($CFG->respectsessionsettings)) {
251 if (empty($CFG->dbsessions)) { /// File-based sessions
75249234 252
f93426cf 253 // Some distros disable GC by setting probability to 0
75249234 254 // overriding the PHP default of 1
f93426cf 255 // (gc_probability is divided by gc_divisor, which defaults to 1000)
256 if (ini_get('session.gc_probability') == 0) {
257 ini_set('session.gc_probability', 1);
258 }
75249234 259
f93426cf 260 if (!empty($CFG->sessiontimeout)) {
261 ini_set('session.gc_maxlifetime', $CFG->sessiontimeout);
262 }
75249234 263
f93426cf 264 if (!file_exists($CFG->dataroot .'/sessions')) {
265 make_upload_directory('sessions');
266 }
267 ini_set('session.save_path', $CFG->dataroot .'/sessions');
75249234 268
f93426cf 269 } else { /// Database sessions
75249234 270 ini_set('session.save_handler', 'user');
271
272 $ADODB_SESSION_DRIVER = $CFG->dbtype;
273 $ADODB_SESSION_CONNECT = $CFG->dbhost;
274 $ADODB_SESSION_USER = $CFG->dbuser;
275 $ADODB_SESSION_PWD = $CFG->dbpass;
276 $ADODB_SESSION_DB = $CFG->dbname;
277 $ADODB_SESSION_TBL = $CFG->prefix.'sessions';
278
279 require_once($CFG->libdir. '/adodb/session/adodb-session.php');
42b90599 280 }
39e1c415 281 }
482b6e6e 282/// Set sessioncookie variable if it isn't already
283 if (!isset($CFG->sessioncookie)) {
284 $CFG->sessioncookie = '';
285 }
eb58acca 286
de7e4ac9 287/// Configure ampersands in URLs
288
289 @ini_set('arg_separator.output', '&amp;');
290
74944b73 291/// Location of standard files
f9903ed0 292
da8759cb 293 $CFG->wordlist = $CFG->libdir .'/wordlist.txt';
294 $CFG->javascript = $CFG->libdir .'/javascript.php';
1040ea85 295 $CFG->moddata = 'moddata';
f9903ed0 296
ae7aafeb 297
aa6af0f8 298/// A hack to get around magic_quotes_gpc being turned off
578dcc40 299/// It is strongly recommended to enable "magic_quotes_gpc"!
aa6af0f8 300
1040ea85 301 if (!ini_get_bool('magic_quotes_gpc') ) {
1d86c8ea 302 function addslashes_deep($value) {
75249234 303 $value = is_array($value) ?
1d86c8ea 304 array_map('addslashes_deep', $value) :
305 addslashes($value);
75249234 306 return $value;
24cc8ec9 307 }
1d86c8ea 308 $_POST = array_map('addslashes_deep', $_POST);
309 $_GET = array_map('addslashes_deep', $_GET);
310 $_COOKIE = array_map('addslashes_deep', $_COOKIE);
578dcc40 311 $_REQUEST = array_map('addslashes_deep', $_REQUEST);
312 if (!empty($_SERVER['REQUEST_URI'])) {
313 $_SERVER['REQUEST_URI'] = addslashes($_SERVER['REQUEST_URI']);
314 }
315 if (!empty($_SERVER['QUERY_STRING'])) {
316 $_SERVER['QUERY_STRING'] = addslashes($_SERVER['QUERY_STRING']);
317 }
318 if (!empty($_SERVER['HTTP_REFERER'])) {
319 $_SERVER['HTTP_REFERER'] = addslashes($_SERVER['HTTP_REFERER']);
320 }
321 if (!empty($_SERVER['PATH_INFO'])) {
322 $_SERVER['PATH_INFO'] = addslashes($_SERVER['PATH_INFO']);
323 }
324 if (!empty($_SERVER['PHP_SELF'])) {
325 $_SERVER['PHP_SELF'] = addslashes($_SERVER['PHP_SELF']);
326 }
327 if (!empty($_SERVER['PATH_TRANSLATED'])) {
328 $_SERVER['PATH_TRANSLATED'] = addslashes($_SERVER['PATH_TRANSLATED']);
329 }
aa6af0f8 330 }
7a302afc 331
ae7aafeb 332
74944b73 333/// The following is a hack to get around the problem of PHP installations
334/// that have "register_globals" turned off (default since PHP 4.1.0).
578dcc40 335/// This hack will be removed in 1.6.
336/// It is strongly recommended to disable "register_globals"!
373da1d4 337/// $CFG->disableglobalshack=true in config.php will override this (for dev testing)
338
339 if (empty($CFG->disableglobalshack)) {
735b8567 340 if (!empty($CFG->detect_unchecked_vars)) {
341 global $UNCHECKED_VARS;
342 $UNCHECKED_VARS->url = $_SERVER['PHP_SELF'];
343 $UNCHECKED_VARS->vars = array();
344 }
345
346 if (isset($_GET)) {
347 extract($_GET, EXTR_SKIP); // Skip existing variables, ie CFG
348 if (!empty($CFG->detect_unchecked_vars)) {
349 foreach ($_GET as $key => $val) {
350 $UNCHECKED_VARS->vars[$key]=$val;
351 }
352 }
353 }
354 if (isset($_POST)) {
355 extract($_POST, EXTR_SKIP); // Skip existing variables, ie CFG
356 if (!empty($CFG->detect_unchecked_vars)) {
357 foreach ($_POST as $key => $val) {
358 $UNCHECKED_VARS->vars[$key]=$val;
359 }
360 }
361 }
362 if (isset($_SERVER)) {
363 extract($_SERVER);
364 }
b0cb5e22 365 }
ae7aafeb 366
75249234 367
74944b73 368/// Load up global environment variables
f9903ed0 369
370 class object {};
24cc8ec9 371
16303ee9 372 //discard session ID from POST, GET and globals to tighten security,
373 //this session fixation prevention can not be used in cookieless mode
374 if (empty($CFG->usesid)) {
fd78420b 375 unset(${'MoodleSession'.$CFG->sessioncookie});
376 unset($_GET['MoodleSession'.$CFG->sessioncookie]);
377 unset($_POST['MoodleSession'.$CFG->sessioncookie]);
378 }
53a6c4cf 379 //compatibility hack for Moodle Cron, cookies not deleted, but set to "deleted"
380 if (!empty($_COOKIE['MoodleSession'.$CFG->sessioncookie]) && $_COOKIE['MoodleSession'.$CFG->sessioncookie] == "deleted") {
381 unset($_COOKIE['MoodleSession'.$CFG->sessioncookie]);
382 }
383 if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie]) && $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] == "deleted") {
384 unset($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie]);
385 }
16303ee9 386 if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
fd78420b 387 require_once("$CFG->dirroot/lib/cookieless.php");
388 sid_start_ob();
389 }
53a6c4cf 390
16e4918d 391 if (!isset($nomoodlecookie)) {
482b6e6e 392 session_name('MoodleSession'.$CFG->sessioncookie);
16e4918d 393 @session_start();
75249234 394 if (! isset($_SESSION['SESSION'])) {
395 $_SESSION['SESSION'] = new object;
00de82df 396 $_SESSION['SESSION']->session_test = random_string(10);
4dfa0925 397 if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) {
1c6932d8 398 $_SESSION['SESSION']->has_timed_out = true;
00de82df 399 }
4dfa0925 400 setcookie('MoodleSessionTest'.$CFG->sessioncookie, $_SESSION['SESSION']->session_test, 0, '/');
401 $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] = $_SESSION['SESSION']->session_test;
16e4918d 402 }
75249234 403 if (! isset($_SESSION['USER'])) {
404 $_SESSION['USER'] = new object;
16e4918d 405 }
75249234 406
16e4918d 407 $SESSION = &$_SESSION['SESSION']; // Makes them easier to reference
408 $USER = &$_SESSION['USER'];
08c17336 409 }
24cc8ec9 410 else {
411 $SESSION = NULL;
412 $USER = NULL;
413 }
08c17336 414
f9f4d999 415 if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
416 $FULLME = FULLME;
417 $ME = FULLME;
9d378732 418 } else {
9fa49e22 419 $FULLME = qualified_me();
9d378732 420 $ME = strip_querystring($FULLME);
9fa49e22 421 }
f9903ed0 422
75249234 423/// In VERY rare cases old PHP server bugs (it has been found on PHP 4.1.2 running
1063d088 424/// as a CGI under IIS on Windows) may require that you uncomment the following:
425// session_register("USER");
426// session_register("SESSION");
427
f9903ed0 428
18b9d664 429
430/// Load up theme variables (colours etc)
86cc3e75 431
432 if (!isset($CFG->themedir)) {
433 $CFG->themedir = $CFG->dirroot.'/theme/';
434 $CFG->themewww = $CFG->wwwroot.'/theme/';
435 }
436
18b9d664 437 if (isset($_GET['theme'])) {
32e2b302 438 if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
86cc3e75 439 if (!detect_munged_arguments($_GET['theme'], 0) and file_exists($CFG->themedir. $_GET['theme'])) {
18b9d664 440 $SESSION->theme = $_GET['theme'];
441 }
442 }
443 }
444
445 if (!isset($CFG->theme)) {
34137668 446 $CFG->theme = 'standardwhite';
18b9d664 447 }
448
449 theme_setup(); // Sets up theme global variables
450
16303ee9 451/// now do a session test to prevent random user switching - observed on some PHP/Apache combinations,
452/// disable checks when working in cookieless mode
453 if (empty($CFG->usesid) || !empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
454 if ($SESSION != NULL) {
fd78420b 455 if (empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) {
456 report_session_error();
457 } else if (isset($SESSION->session_test) && $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] != $SESSION->session_test) {
458 report_session_error();
459 }
00de82df 460 }
461 }
462
18b9d664 463
b8770bc0 464/// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
465/// - WINDOWS: for any Windows flavour.
466/// - UNIX: for the rest
467/// Also, $CFG->os can continue being used if more specialization is required
468if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
469 $CFG->ostype = 'WINDOWS';
470} else {
471 $CFG->ostype = 'UNIX';
472}
473$CFG->os = PHP_OS;
18b9d664 474
75249234 475/// Set language/locale of printed times. If user has chosen a language that
476/// that is different from the site language, then use the locale specified
339bb559 477/// in the language file. Otherwise, if the admin hasn't specified a locale
75249234 478/// then use the one from the default language. Otherwise (and this is the
339bb559 479/// majority of cases), use the stored locale specified by admin.
480
16ba7351 481 if (isset($_GET['lang'])) {
6aaa17c7 482 if (!detect_munged_arguments($lang, 0) and (file_exists($CFG->dataroot .'/lang/'. $lang) or
483 file_exists($CFG->dirroot .'/lang/'. $lang))) {
32c60ce3 484 $SESSION->lang = $lang;
32c60ce3 485 }
3e9b5d5a 486 }
16ba7351 487 if (empty($CFG->lang)) {
6aaa17c7 488 $CFG->lang = !empty($CFG->unicodedb) ? 'en_utf8' : 'en';
16ba7351 489 }
339bb559 490
a2fa19d8 491 moodle_setlocale();
1040ea85 492
18845ac3 493 if (!empty($CFG->opentogoogle)) {
a33c4e5a 494 if (empty($_SESSION['USER'])) { // Ignore anyone logged in
18845ac3 495 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
496 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
497 $USER = guest_user();
a33c4e5a 498 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false ) {
499 $USER = guest_user();
500 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false ) {
501 $USER = guest_user();
502 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSNBOT') !== false ) {
2d33fc00 503 $USER = guest_user();
504 }
18845ac3 505 }
a33c4e5a 506 if (empty($USER) && !empty($_SERVER['HTTP_REFERER'])) {
18845ac3 507 if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
508 $USER = guest_user();
33674080 509 } else if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false ) {
510 $USER = guest_user();
18845ac3 511 }
512 }
513 }
514 }
515
8d62ca68 516 if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
18a2b08d 517 if (empty($_SESSION['USER']->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
75249234 518 if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
98de6431 519 (strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
7c12949d 520 if ($USER = get_complete_user_data("username", "w3cvalidator")) {
b60f0ee5 521 $USER->ignoresesskey = true;
003c49cb 522 } else {
9610a66e 523 $USER = guest_user();
524 }
525 }
526 }
527 }
528
a559eee6 529/// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
530/// LogFormat to get the current logged in username in moodle.
5c5c16bb 531 if ($USER && function_exists('apache_note') && !empty($CFG->apacheloguser)) {
2b287cac 532 $apachelog_username = clean_filename($USER->username);
533 $apachelog_name = clean_filename($USER->firstname. " ".$USER->lastname);
534 $apachelog_userid = $USER->id;
96e19e7b 535 if (isset($USER->realuser)) {
536 if ($realuser = get_record('user', 'id', $USER->realuser)) {
2b287cac 537 $apachelog_username = clean_filename($realuser->username." as ".$apachelog_username);
538 $apachelog_name = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$apachelog_name);
539 $apachelog_userid = clean_filename($realuser->id." as ".$apachelog_userid);
96e19e7b 540 }
541 }
5c5c16bb 542 switch ($CFG->apacheloguser) {
543 case 3:
2b287cac 544 $logname = $apachelog_username;
5c5c16bb 545 break;
546 case 2:
2b287cac 547 $logname = $apachelog_name;
5c5c16bb 548 break;
549 case 1:
550 default:
2b287cac 551 $logname = $apachelog_userid;
5c5c16bb 552 break;
553 }
554 apache_note('MOODLEUSER', $logname);
a559eee6 555 }
556
5982740d 557/// Adjust ALLOWED_TAGS
558 adjust_allowed_tags();
559
18259d4f 560
561/// Use a custom script replacement if one exists
562 if (!empty($CFG->customscripts)) {
563 if (($customscript = custom_script_path()) !== false) {
2b0b32d8 564 require ($customscript);
18259d4f 565 }
566 }
567
568
d3f9f1f8 569?>