adding current groupid to grade_export class - soon to be used in plugins
[moodle-pu.git] / lib / setup.php
blob779cae82c3f5f4f273107c18903eda302341077e
1 <?php
2 /**
3 * setup.php - Sets up sessions, connects to databases and so on
5 * Normally this is only called by the main config.php file
6 * Normally this file does not need to be edited.
7 * @author Martin Dougiamas
8 * @version $Id$
9 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 * @package moodlecore
13 ////// DOCUMENTATION IN PHPDOC FORMAT FOR MOODLE GLOBALS AND COMMON OBJECT TYPES /////////////
14 /**
15 * $USER is a global instance of a typical $user record.
17 * Items found in the user record:
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.
28 * @global object(user) $USER
30 global $USER;
31 /**
32 * This global variable is read in from the 'config' table.
34 * Some typical settings in the $CFG global:
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->libdir - Path to moodle's library folder on server's filesystem.
39 * @global object(cfg) $CFG
41 global $CFG;
42 /**
43 * Definition of session type
44 * @global object(session) $SESSION
46 global $SESSION;
47 /**
48 * Definition of shared memory cache
50 global $MCACHE;
51 /**
52 * Definition of course type
53 * @global object(course) $COURSE
55 global $COURSE;
56 /**
57 * Definition of db type
58 * @global object(db) $db
60 global $db;
61 /**
62 * $THEME is a global that defines the site theme.
64 * Items found in the theme record:
65 * - $THEME->cellheading - Cell colors.
66 * - $THEME->cellheading2 - Alternate cell colors.
68 * @global object(theme) $THEME
70 global $THEME;
72 /**
73 * HTTPSPAGEREQUIRED is a global to define if the page being displayed must run under HTTPS.
75 * It's primary goal is to allow 100% HTTPS pages when $CFG->loginhttps is enabled. Default to false.
76 * It's enabled only by the httpsrequired() function and used in some pages to update some URLs
78 global $HTTPSPAGEREQUIRED;
81 /// First try to detect some attacks on older buggy PHP versions
82 if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
83 die('Fatal: Illegal GLOBALS overwrite attempt detected!');
87 if (!isset($CFG->wwwroot)) {
88 trigger_error('Fatal: $CFG->wwwroot is not configured! Exiting.');
89 die;
92 /// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
93 /// inside some URLs used in HTTPSPAGEREQUIRED pages.
94 $CFG->httpswwwroot = $CFG->wwwroot;
96 $CFG->libdir = $CFG->dirroot .'/lib';
98 require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
100 /// Time to start counting
101 init_performance_info();
104 /// If there are any errors in the standard libraries we want to know!
105 error_reporting(E_ALL);
107 /// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
108 /// http://www.google.com/webmasters/faq.html#prefetchblock
109 if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
110 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
111 trigger_error('Prefetch request forbidden.');
112 exit;
115 /// Connect to the database using adodb
117 /// Some defines required BEFORE including AdoDB library
118 define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
119 //(only meaningful for oci8po, it's the default
120 //for other DB drivers so this won't affect them)
122 require_once($CFG->libdir .'/adodb/adodb.inc.php'); // Database access functions
124 $db = &ADONewConnection($CFG->dbtype);
126 // See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly,
127 // we probably want to change this value to ''.
128 $db->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \'';
130 error_reporting(0); // Hide errors
132 if (!isset($CFG->dbpersist) or !empty($CFG->dbpersist)) { // Use persistent connection (default)
133 $dbconnected = $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
134 } else { // Use single connection
135 $dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
137 if (! $dbconnected) {
138 // In the name of protocol correctness, monitoring and performance
139 // profiling, set the appropriate error headers for machine comsumption
140 if (isset($_SERVER['SERVER_PROTOCOL'])) {
141 // Avoid it with cron.php. Note that we assume it's HTTP/1.x
142 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
144 // and then for human consumption...
145 echo '<html><body>';
146 echo '<table align="center"><tr>';
147 echo '<td style="color:#990000; text-align:center; font-size:large; border-width:1px; '.
148 ' border-color:#000000; border-style:solid; border-radius: 20px; border-collapse: collapse; '.
149 ' -moz-border-radius: 20px; padding: 15px">';
150 echo '<p>Error: Database connection failed.</p>';
151 echo '<p>It is possible that the database is overloaded or otherwise not running properly.</p>';
152 echo '<p>The site administrator should also check that the database details have been correctly specified in config.php</p>';
153 echo '</td></tr></table>';
154 echo '</body></html>';
156 if (!empty($CFG->emailconnectionerrorsto)) {
157 mail($CFG->emailconnectionerrorsto,
158 'WARNING: Database connection error: '.$CFG->wwwroot,
159 'Connection error: '.$CFG->wwwroot);
161 die;
164 /// Forcing ASSOC mode for ADOdb (some DBs default to FETCH_BOTH)
165 $db->SetFetchMode(ADODB_FETCH_ASSOC);
167 /// Starting here we have a correct DB conection but me must avoid
168 /// to execute any DB transaction until "set names" has been executed
169 /// some lines below!
171 error_reporting(E_ALL); // Show errors from now on.
173 if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
174 $CFG->prefix = '';
178 /// Define admin directory
180 if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
181 $CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
184 /// Increase memory limits if possible
185 raise_memory_limit('96M'); // We should never NEED this much but just in case...
187 /// Load up standard libraries
189 require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
190 require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
191 require_once($CFG->libdir .'/dmllib.php'); // Functions to handle DB data (DML)
192 require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
193 require_once($CFG->libdir .'/accesslib.php'); // Access control functions
194 require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
195 require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
196 require_once($CFG->libdir .'/eventslib.php'); // Events functions
197 require_once($CFG->libdir .'/grouplib.php'); // Groups functions
199 /// Disable errors for now - needed for installation when debug enabled in config.php
200 if (isset($CFG->debug)) {
201 $originalconfigdebug = $CFG->debug;
202 unset($CFG->debug);
203 } else {
204 $originalconfigdebug = -1;
207 /// Set the client/server and connection to utf8
208 /// and configure some other specific variables for each db
209 configure_dbconnection();
211 /// Load up any configuration from the config table
212 unset($CFG->rcache);
213 $CFG = get_config();
215 /// Turn on SQL logging if required
216 if (!empty($CFG->logsql)) {
217 $db->LogSQL();
220 /// Prevent warnings from roles when upgrading with debug on
221 if (isset($CFG->debug)) {
222 $originaldatabasedebug = $CFG->debug;
223 unset($CFG->debug);
224 } else {
225 $originaldatabasedebug = -1;
229 /// For now, only needed under apache (and probably unstable in other contexts)
230 if (function_exists('apache_child_terminate')) {
231 register_shutdown_function('moodle_request_shutdown');
234 //// Defining the site
235 if ($SITE = get_site()) {
237 * If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
239 define('SITEID', $SITE->id);
240 /// And the 'default' course
241 $COURSE = clone($SITE); // For now. This will usually get reset later in require_login() etc.
242 } else {
244 * @ignore
246 define('SITEID', 1);
247 /// And the 'default' course
248 $COURSE = new object; // no site created yet
249 $COURSE->id = 1;
253 /// Set error reporting back to normal
254 if ($originaldatabasedebug == -1) {
255 $CFG->debug = DEBUG_MINIMAL;
256 } else {
257 $CFG->debug = $originaldatabasedebug;
259 if ($originalconfigdebug !== -1) {
260 $CFG->debug = $originalconfigdebug;
262 unset($originalconfigdebug);
263 unset($originaldatabasedebug);
264 error_reporting($CFG->debug);
267 /// If we want to display Moodle errors, then try and set PHP errors to match
268 if (!isset($CFG->debugdisplay)) {
269 //keep it as is during installation
270 } else if (empty($CFG->debugdisplay)) {
271 @ini_set('display_errors', '0');
272 @ini_set('log_errors', '1');
273 } else {
274 @ini_set('display_errors', '1');
277 /// Shared-Memory cache init -- will set $MCACHE
278 /// $MCACHE is a global object that offers at least add(), set() and delete()
279 /// with similar semantics to the memcached PHP API http://php.net/memcache
280 if (!empty($CFG->cachetype)) {
281 if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) {
282 if (!init_memcached()) {
283 debugging("Error initialising memcached");
285 } elseif ($CFG->cachetype === 'eaccelerator') {
286 if (!init_eaccelerator()) {
287 debugging("Error initialising eaccelerator cache");
290 } else { // just make sure it is defined
291 $CFG->cachetype = '';
293 /// Ensure we define rcache - so we can later check for it
294 /// with a really fast and unambiguous $CFG->rcache === false
295 if (empty($CFG->rcache)) {
296 $CFG->rcache = false;
297 } else {
298 $CFG->rcache = true;
301 /// Set a default enrolment configuration (see bug 1598)
302 if (!isset($CFG->enrol)) {
303 $CFG->enrol = 'manual';
306 /// Set default enabled enrolment plugins
307 if (!isset($CFG->enrol_plugins_enabled)) {
308 $CFG->enrol_plugins_enabled = 'manual';
311 /// File permissions on created directories in the $CFG->dataroot
313 if (empty($CFG->directorypermissions)) {
314 $CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
317 /// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
318 /// - WINDOWS: for any Windows flavour.
319 /// - UNIX: for the rest
320 /// Also, $CFG->os can continue being used if more specialization is required
321 if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
322 $CFG->ostype = 'WINDOWS';
323 } else {
324 $CFG->ostype = 'UNIX';
326 $CFG->os = PHP_OS;
328 /// Set up default frame target string, based on $CFG->framename
329 $CFG->frametarget = frametarget();
331 /// Setup cache dir for Smarty and others
332 if (!file_exists($CFG->dataroot .'/cache')) {
333 make_upload_directory('cache');
336 /// Set up smarty template system
337 //require_once($CFG->libdir .'/smarty/Smarty.class.php');
338 //$smarty = new Smarty;
339 //$smarty->template_dir = $CFG->dirroot .'/templates/'. $CFG->template;
340 //if (!file_exists($CFG->dataroot .'/cache/smarty')) {
341 // make_upload_directory('cache/smarty');
343 //$smarty->compile_dir = $CFG->dataroot .'/cache/smarty';
345 /// Set up session handling
346 if(empty($CFG->respectsessionsettings)) {
347 if (empty($CFG->dbsessions)) { /// File-based sessions
349 // Some distros disable GC by setting probability to 0
350 // overriding the PHP default of 1
351 // (gc_probability is divided by gc_divisor, which defaults to 1000)
352 if (ini_get('session.gc_probability') == 0) {
353 ini_set('session.gc_probability', 1);
356 if (!empty($CFG->sessiontimeout)) {
357 ini_set('session.gc_maxlifetime', $CFG->sessiontimeout);
360 if (!file_exists($CFG->dataroot .'/sessions')) {
361 make_upload_directory('sessions');
363 ini_set('session.save_path', $CFG->dataroot .'/sessions');
365 } else { /// Database sessions
366 ini_set('session.save_handler', 'user');
368 $ADODB_SESSION_DRIVER = $CFG->dbtype;
369 $ADODB_SESSION_CONNECT = $CFG->dbhost;
370 $ADODB_SESSION_USER = $CFG->dbuser;
371 $ADODB_SESSION_PWD = $CFG->dbpass;
372 $ADODB_SESSION_DB = $CFG->dbname;
373 $ADODB_SESSION_TBL = $CFG->prefix.'sessions2';
374 if (!empty($CFG->sessiontimeout)) {
375 $ADODB_SESS_LIFE = $CFG->sessiontimeout;
378 require_once($CFG->libdir. '/adodb/session/adodb-session2.php');
381 /// Set sessioncookie variable if it isn't already
382 if (!isset($CFG->sessioncookie)) {
383 $CFG->sessioncookie = '';
386 /// Configure ampersands in URLs
388 @ini_set('arg_separator.output', '&amp;');
390 /// Location of standard files
392 $CFG->wordlist = $CFG->libdir .'/wordlist.txt';
393 $CFG->javascript = $CFG->libdir .'/javascript.php';
394 $CFG->moddata = 'moddata';
397 /// A hack to get around magic_quotes_gpc being turned off
398 /// It is strongly recommended to enable "magic_quotes_gpc"!
400 if (!ini_get_bool('magic_quotes_gpc') ) {
401 function addslashes_deep($value) {
402 $value = is_array($value) ?
403 array_map('addslashes_deep', $value) :
404 addslashes($value);
405 return $value;
407 $_POST = array_map('addslashes_deep', $_POST);
408 $_GET = array_map('addslashes_deep', $_GET);
409 $_COOKIE = array_map('addslashes_deep', $_COOKIE);
410 $_REQUEST = array_map('addslashes_deep', $_REQUEST);
411 if (!empty($_SERVER['REQUEST_URI'])) {
412 $_SERVER['REQUEST_URI'] = addslashes($_SERVER['REQUEST_URI']);
414 if (!empty($_SERVER['QUERY_STRING'])) {
415 $_SERVER['QUERY_STRING'] = addslashes($_SERVER['QUERY_STRING']);
417 if (!empty($_SERVER['HTTP_REFERER'])) {
418 $_SERVER['HTTP_REFERER'] = addslashes($_SERVER['HTTP_REFERER']);
420 if (!empty($_SERVER['PATH_INFO'])) {
421 $_SERVER['PATH_INFO'] = addslashes($_SERVER['PATH_INFO']);
423 if (!empty($_SERVER['PHP_SELF'])) {
424 $_SERVER['PHP_SELF'] = addslashes($_SERVER['PHP_SELF']);
426 if (!empty($_SERVER['PATH_TRANSLATED'])) {
427 $_SERVER['PATH_TRANSLATED'] = addslashes($_SERVER['PATH_TRANSLATED']);
432 /// The following code can emulate "register globals" if required.
433 /// This hack is no longer being applied as of Moodle 1.6 unless you really
434 /// really want to use it (by defining $CFG->enableglobalshack = true)
436 if (!empty($CFG->enableglobalshack)) {
437 if (!empty($CFG->detect_unchecked_vars)) {
438 global $UNCHECKED_VARS;
439 $UNCHECKED_VARS->url = $_SERVER['PHP_SELF'];
440 $UNCHECKED_VARS->vars = array();
443 if (isset($_GET)) {
444 extract($_GET, EXTR_SKIP); // Skip existing variables, ie CFG
445 if (!empty($CFG->detect_unchecked_vars)) {
446 foreach ($_GET as $key => $val) {
447 $UNCHECKED_VARS->vars[$key]=$val;
451 if (isset($_POST)) {
452 extract($_POST, EXTR_SKIP); // Skip existing variables, ie CFG
453 if (!empty($CFG->detect_unchecked_vars)) {
454 foreach ($_POST as $key => $val) {
455 $UNCHECKED_VARS->vars[$key]=$val;
459 if (isset($_SERVER)) {
460 extract($_SERVER);
465 /// Load up global environment variables
467 class object {};
469 //discard session ID from POST, GET and globals to tighten security,
470 //this session fixation prevention can not be used in cookieless mode
471 if (empty($CFG->usesid)) {
472 unset(${'MoodleSession'.$CFG->sessioncookie});
473 unset($_GET['MoodleSession'.$CFG->sessioncookie]);
474 unset($_POST['MoodleSession'.$CFG->sessioncookie]);
476 //compatibility hack for Moodle Cron, cookies not deleted, but set to "deleted" - should not be needed with $nomoodlecookie in cron.php now
477 if (!empty($_COOKIE['MoodleSession'.$CFG->sessioncookie]) && $_COOKIE['MoodleSession'.$CFG->sessioncookie] == "deleted") {
478 unset($_COOKIE['MoodleSession'.$CFG->sessioncookie]);
480 if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie]) && $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] == "deleted") {
481 unset($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie]);
483 if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
484 require_once("$CFG->dirroot/lib/cookieless.php");
485 sid_start_ob();
488 if (empty($nomoodlecookie)) {
489 session_name('MoodleSession'.$CFG->sessioncookie);
490 @session_start();
491 if (! isset($_SESSION['SESSION'])) {
492 $_SESSION['SESSION'] = new object;
493 $_SESSION['SESSION']->session_test = random_string(10);
494 if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) {
495 $_SESSION['SESSION']->has_timed_out = true;
497 setcookie('MoodleSessionTest'.$CFG->sessioncookie, $_SESSION['SESSION']->session_test, 0, '/');
498 $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] = $_SESSION['SESSION']->session_test;
500 if (! isset($_SESSION['USER'])) {
501 $_SESSION['USER'] = new object;
504 $SESSION = &$_SESSION['SESSION']; // Makes them easier to reference
505 $USER = &$_SESSION['USER'];
506 if (!isset($USER->id)) {
507 $USER->id = 0; // to enable proper function of $CFG->notloggedinroleid hack
510 else {
511 $SESSION = NULL;
512 $USER = new object();
513 $USER->id = 0; // user not logged in when session disabled
516 if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
517 $FULLME = FULLME;
518 $ME = FULLME;
519 } else {
520 $FULLME = qualified_me();
521 $ME = strip_querystring($FULLME);
524 /// In VERY rare cases old PHP server bugs (it has been found on PHP 4.1.2 running
525 /// as a CGI under IIS on Windows) may require that you uncomment the following:
526 // session_register("USER");
527 // session_register("SESSION");
531 /// Load up theme variables (colours etc)
533 if (!isset($CFG->themedir)) {
534 $CFG->themedir = $CFG->dirroot.'/theme';
535 $CFG->themewww = $CFG->wwwroot.'/theme';
537 $CFG->httpsthemewww = $CFG->themewww;
539 if (isset($_GET['theme'])) {
540 if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
541 $themename = clean_param($_GET['theme'], PARAM_SAFEDIR);
542 if (($themename != '') and file_exists($CFG->themedir.'/'.$themename)) {
543 $SESSION->theme = $themename;
545 unset($themename);
549 if (!isset($CFG->theme)) {
550 $CFG->theme = 'standardwhite';
553 /// now do a session test to prevent random user switching - observed on some PHP/Apache combinations,
554 /// disable checks when working in cookieless mode
555 if (empty($CFG->usesid) || !empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
556 if ($SESSION != NULL) {
557 if (empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) {
558 report_session_error();
559 } else if (isset($SESSION->session_test) && $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] != $SESSION->session_test) {
560 report_session_error();
566 /// Set language/locale of printed times. If user has chosen a language that
567 /// that is different from the site language, then use the locale specified
568 /// in the language file. Otherwise, if the admin hasn't specified a locale
569 /// then use the one from the default language. Otherwise (and this is the
570 /// majority of cases), use the stored locale specified by admin.
571 if ($SESSION !== NULL && isset($_GET['lang']) && ($lang = clean_param($_GET['lang'], PARAM_SAFEDIR))) {
572 if (file_exists($CFG->dataroot .'/lang/'. $lang) or file_exists($CFG->dirroot .'/lang/'. $lang)) {
573 $SESSION->lang = $lang;
574 } else if (file_exists($CFG->dataroot.'/lang/'.$lang.'_utf8') or
575 file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
576 $SESSION->lang = $lang.'_utf8';
580 setup_lang_from_browser();
582 unset($lang);
584 if (empty($CFG->lang)) {
585 if (empty($SESSION->lang)) {
586 $CFG->lang = 'en_utf8';
587 } else {
588 $CFG->lang = $SESSION->lang;
592 // set default locale and themes - might be changed again later from require_login()
593 course_setup();
595 if (!empty($CFG->opentogoogle)) {
596 if (empty($USER->id)) { // Ignore anyone logged in
597 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
598 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
599 $USER = guest_user();
600 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false ) {
601 $USER = guest_user();
602 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false ) {
603 $USER = guest_user();
604 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSNBOT') !== false ) {
605 $USER = guest_user();
608 if (empty($USER) && !empty($_SERVER['HTTP_REFERER'])) {
609 if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
610 $USER = guest_user();
611 } else if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false ) {
612 $USER = guest_user();
615 if (!empty($USER)) {
616 load_all_capabilities();
621 if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
622 if (isset($_SERVER['HTTP_USER_AGENT']) and empty($_SESSION['USER']->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
623 if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
624 (strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
625 if ($USER = get_complete_user_data("username", "w3cvalidator")) {
626 $USER->ignoresesskey = true;
627 } else {
628 $USER = guest_user();
634 /// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
635 /// LogFormat to get the current logged in username in moodle.
636 if ($USER && function_exists('apache_note') && !empty($CFG->apacheloguser)) {
637 $apachelog_username = clean_filename($USER->username);
638 $apachelog_name = clean_filename($USER->firstname. " ".$USER->lastname);
639 $apachelog_userid = $USER->id;
640 if (isset($USER->realuser)) {
641 if ($realuser = get_record('user', 'id', $USER->realuser)) {
642 $apachelog_username = clean_filename($realuser->username." as ".$apachelog_username);
643 $apachelog_name = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$apachelog_name);
644 $apachelog_userid = clean_filename($realuser->id." as ".$apachelog_userid);
647 switch ($CFG->apacheloguser) {
648 case 3:
649 $logname = $apachelog_username;
650 break;
651 case 2:
652 $logname = $apachelog_name;
653 break;
654 case 1:
655 default:
656 $logname = $apachelog_userid;
657 break;
659 apache_note('MOODLEUSER', $logname);
662 /// Adjust ALLOWED_TAGS
663 adjust_allowed_tags();
666 /// Use a custom script replacement if one exists
667 if (!empty($CFG->customscripts)) {
668 if (($customscript = custom_script_path()) !== false) {
669 require ($customscript);
673 /// note: we can not block non utf-8 installatrions here, because empty mysql database
674 /// might be converted to utf-8 in admin/index.php during installation