MDL-11276, average calculations are inaccurate in percentage form due to double rounding
[moodle-pu.git] / lib / setup.php
bloba0ded0af2d088aeaffec7a7f593d1f596ceb2499
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('register_shutdown_function')) {
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 /// Work around for a PHP bug see MDL-11237
392 @ini_set('pcre.backtrack_limit', 20971520); // 20 MB
394 /// Location of standard files
396 $CFG->wordlist = $CFG->libdir .'/wordlist.txt';
397 $CFG->javascript = $CFG->libdir .'/javascript.php';
398 $CFG->moddata = 'moddata';
401 /// A hack to get around magic_quotes_gpc being turned off
402 /// It is strongly recommended to enable "magic_quotes_gpc"!
404 if (!ini_get_bool('magic_quotes_gpc') ) {
405 function addslashes_deep($value) {
406 $value = is_array($value) ?
407 array_map('addslashes_deep', $value) :
408 addslashes($value);
409 return $value;
411 $_POST = array_map('addslashes_deep', $_POST);
412 $_GET = array_map('addslashes_deep', $_GET);
413 $_COOKIE = array_map('addslashes_deep', $_COOKIE);
414 $_REQUEST = array_map('addslashes_deep', $_REQUEST);
415 if (!empty($_SERVER['REQUEST_URI'])) {
416 $_SERVER['REQUEST_URI'] = addslashes($_SERVER['REQUEST_URI']);
418 if (!empty($_SERVER['QUERY_STRING'])) {
419 $_SERVER['QUERY_STRING'] = addslashes($_SERVER['QUERY_STRING']);
421 if (!empty($_SERVER['HTTP_REFERER'])) {
422 $_SERVER['HTTP_REFERER'] = addslashes($_SERVER['HTTP_REFERER']);
424 if (!empty($_SERVER['PATH_INFO'])) {
425 $_SERVER['PATH_INFO'] = addslashes($_SERVER['PATH_INFO']);
427 if (!empty($_SERVER['PHP_SELF'])) {
428 $_SERVER['PHP_SELF'] = addslashes($_SERVER['PHP_SELF']);
430 if (!empty($_SERVER['PATH_TRANSLATED'])) {
431 $_SERVER['PATH_TRANSLATED'] = addslashes($_SERVER['PATH_TRANSLATED']);
436 /// The following code can emulate "register globals" if required.
437 /// This hack is no longer being applied as of Moodle 1.6 unless you really
438 /// really want to use it (by defining $CFG->enableglobalshack = true)
440 if (!empty($CFG->enableglobalshack)) {
441 if (!empty($CFG->detect_unchecked_vars)) {
442 global $UNCHECKED_VARS;
443 $UNCHECKED_VARS->url = $_SERVER['PHP_SELF'];
444 $UNCHECKED_VARS->vars = array();
447 if (isset($_GET)) {
448 extract($_GET, EXTR_SKIP); // Skip existing variables, ie CFG
449 if (!empty($CFG->detect_unchecked_vars)) {
450 foreach ($_GET as $key => $val) {
451 $UNCHECKED_VARS->vars[$key]=$val;
455 if (isset($_POST)) {
456 extract($_POST, EXTR_SKIP); // Skip existing variables, ie CFG
457 if (!empty($CFG->detect_unchecked_vars)) {
458 foreach ($_POST as $key => $val) {
459 $UNCHECKED_VARS->vars[$key]=$val;
463 if (isset($_SERVER)) {
464 extract($_SERVER);
469 /// Load up global environment variables
471 class object {};
473 //discard session ID from POST, GET and globals to tighten security,
474 //this session fixation prevention can not be used in cookieless mode
475 if (empty($CFG->usesid)) {
476 unset(${'MoodleSession'.$CFG->sessioncookie});
477 unset($_GET['MoodleSession'.$CFG->sessioncookie]);
478 unset($_POST['MoodleSession'.$CFG->sessioncookie]);
480 //compatibility hack for Moodle Cron, cookies not deleted, but set to "deleted" - should not be needed with $nomoodlecookie in cron.php now
481 if (!empty($_COOKIE['MoodleSession'.$CFG->sessioncookie]) && $_COOKIE['MoodleSession'.$CFG->sessioncookie] == "deleted") {
482 unset($_COOKIE['MoodleSession'.$CFG->sessioncookie]);
484 if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie]) && $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] == "deleted") {
485 unset($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie]);
487 if (!empty($CFG->usesid) && empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
488 require_once("$CFG->dirroot/lib/cookieless.php");
489 sid_start_ob();
492 if (empty($nomoodlecookie)) {
493 session_name('MoodleSession'.$CFG->sessioncookie);
494 @session_start();
495 if (! isset($_SESSION['SESSION'])) {
496 $_SESSION['SESSION'] = new object;
497 $_SESSION['SESSION']->session_test = random_string(10);
498 if (!empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) {
499 $_SESSION['SESSION']->has_timed_out = true;
501 setcookie('MoodleSessionTest'.$CFG->sessioncookie, $_SESSION['SESSION']->session_test, 0, '/');
502 $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] = $_SESSION['SESSION']->session_test;
504 if (! isset($_SESSION['USER'])) {
505 $_SESSION['USER'] = new object;
508 $SESSION = &$_SESSION['SESSION']; // Makes them easier to reference
509 $USER = &$_SESSION['USER'];
510 if (!isset($USER->id)) {
511 $USER->id = 0; // to enable proper function of $CFG->notloggedinroleid hack
514 else {
515 $SESSION = NULL;
516 $USER = new object();
517 $USER->id = 0; // user not logged in when session disabled
520 if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
521 $FULLME = FULLME;
522 $ME = FULLME;
523 } else {
524 $FULLME = qualified_me();
525 $ME = strip_querystring($FULLME);
528 /// In VERY rare cases old PHP server bugs (it has been found on PHP 4.1.2 running
529 /// as a CGI under IIS on Windows) may require that you uncomment the following:
530 // session_register("USER");
531 // session_register("SESSION");
535 /// Load up theme variables (colours etc)
537 if (!isset($CFG->themedir)) {
538 $CFG->themedir = $CFG->dirroot.'/theme';
539 $CFG->themewww = $CFG->wwwroot.'/theme';
541 $CFG->httpsthemewww = $CFG->themewww;
543 if (isset($_GET['theme'])) {
544 if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
545 $themename = clean_param($_GET['theme'], PARAM_SAFEDIR);
546 if (($themename != '') and file_exists($CFG->themedir.'/'.$themename)) {
547 $SESSION->theme = $themename;
549 unset($themename);
553 if (!isset($CFG->theme)) {
554 $CFG->theme = 'standardwhite';
557 /// now do a session test to prevent random user switching - observed on some PHP/Apache combinations,
558 /// disable checks when working in cookieless mode
559 if (empty($CFG->usesid) || !empty($_COOKIE['MoodleSession'.$CFG->sessioncookie])) {
560 if ($SESSION != NULL) {
561 if (empty($_COOKIE['MoodleSessionTest'.$CFG->sessioncookie])) {
562 report_session_error();
563 } else if (isset($SESSION->session_test) && $_COOKIE['MoodleSessionTest'.$CFG->sessioncookie] != $SESSION->session_test) {
564 report_session_error();
570 /// Set language/locale of printed times. If user has chosen a language that
571 /// that is different from the site language, then use the locale specified
572 /// in the language file. Otherwise, if the admin hasn't specified a locale
573 /// then use the one from the default language. Otherwise (and this is the
574 /// majority of cases), use the stored locale specified by admin.
575 if ($SESSION !== NULL && isset($_GET['lang']) && ($lang = clean_param($_GET['lang'], PARAM_SAFEDIR))) {
576 if (file_exists($CFG->dataroot .'/lang/'. $lang) or file_exists($CFG->dirroot .'/lang/'. $lang)) {
577 $SESSION->lang = $lang;
578 } else if (file_exists($CFG->dataroot.'/lang/'.$lang.'_utf8') or
579 file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
580 $SESSION->lang = $lang.'_utf8';
584 setup_lang_from_browser();
586 unset($lang);
588 if (empty($CFG->lang)) {
589 if (empty($SESSION->lang)) {
590 $CFG->lang = 'en_utf8';
591 } else {
592 $CFG->lang = $SESSION->lang;
596 // set default locale and themes - might be changed again later from require_login()
597 course_setup();
599 if (!empty($CFG->opentogoogle)) {
600 if (empty($USER->id)) { // Ignore anyone logged in
601 if (!empty($_SERVER['HTTP_USER_AGENT'])) {
602 if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
603 $USER = guest_user();
604 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false ) { // Google
605 $USER = guest_user();
606 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false ) { // Yahoo
607 $USER = guest_user();
608 } else if (strpos($_SERVER['HTTP_USER_AGENT'], '[ZSEBOT]') !== false ) { // Zoomspider
609 $USER = guest_user();
610 } else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSNBOT') !== false ) { // MSN Search
611 $USER = guest_user();
614 if (empty($USER) && !empty($_SERVER['HTTP_REFERER'])) {
615 if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
616 $USER = guest_user();
617 } else if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false ) {
618 $USER = guest_user();
621 if (!empty($USER)) {
622 load_all_capabilities();
627 if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
628 if (isset($_SERVER['HTTP_USER_AGENT']) and empty($_SESSION['USER']->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
629 if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
630 (strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
631 if ($USER = get_complete_user_data("username", "w3cvalidator")) {
632 $USER->ignoresesskey = true;
633 } else {
634 $USER = guest_user();
640 /// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
641 /// LogFormat to get the current logged in username in moodle.
642 if ($USER && function_exists('apache_note') && !empty($CFG->apacheloguser)) {
643 $apachelog_username = clean_filename($USER->username);
644 $apachelog_name = clean_filename($USER->firstname. " ".$USER->lastname);
645 $apachelog_userid = $USER->id;
646 if (isset($USER->realuser)) {
647 if ($realuser = get_record('user', 'id', $USER->realuser)) {
648 $apachelog_username = clean_filename($realuser->username." as ".$apachelog_username);
649 $apachelog_name = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$apachelog_name);
650 $apachelog_userid = clean_filename($realuser->id." as ".$apachelog_userid);
653 switch ($CFG->apacheloguser) {
654 case 3:
655 $logname = $apachelog_username;
656 break;
657 case 2:
658 $logname = $apachelog_name;
659 break;
660 case 1:
661 default:
662 $logname = $apachelog_userid;
663 break;
665 apache_note('MOODLEUSER', $logname);
668 /// Adjust ALLOWED_TAGS
669 adjust_allowed_tags();
672 /// Use a custom script replacement if one exists
673 if (!empty($CFG->customscripts)) {
674 if (($customscript = custom_script_path()) !== false) {
675 require ($customscript);
679 /// note: we can not block non utf-8 installatrions here, because empty mysql database
680 /// might be converted to utf-8 in admin/index.php during installation