5 // Sets up sessions, connects to databases and so on
7 // Normally this is only called by the main config.php file
9 // Normally this file does not need to be edited.
11 //////////////////////////////////////////////////////////////
13 /// If there are any errors in the standard libraries we want to know!
14 error_reporting(E_ALL);
16 /// Connect to the database using adodb
18 require("$CFG->libdir/adodb/adodb.inc.php"); // Database access functions
19 ADOLoadCode($CFG->dbtype);
20 $db = &ADONewConnection();
21 if (! $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname)) {
22 echo "<P><FONT COLOR=RED>The database details specified in config.php are not correct, or the database is down.</P>";
26 if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
32 /// Load up standard libraries
34 require("$CFG->libdir/weblib.php"); // Functions for producing HTML
35 require("$CFG->libdir/datalib.php"); // Functions for accessing databases
36 require("$CFG->libdir/moodlelib.php"); // Other general-purpose functions
39 /// Load up any configuration from the config table
41 if ($configs = get_records("config")) {
43 foreach ($configs as $config) {
44 $CFG[$config->name] = $config->value;
52 /// Set error reporting back to normal
53 if (empty($CFG->debug)) {
56 error_reporting($CFG->debug);
59 /// Location of standard files
61 $CFG->wordlist = "$CFG->libdir/wordlist.txt";
62 $CFG->javascript = "$CFG->libdir/javascript.php";
63 $CFG->moddata = "moddata";
66 /// Load up theme variables (colours etc)
68 if (!isset($CFG->theme)) {
69 $CFG->theme = "standard";
71 include("$CFG->dirroot/theme/$CFG->theme/config.php");
73 $CFG->stylesheet = "$CFG->wwwroot/theme/$CFG->theme/styles.php";
74 $CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
75 $CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
79 /// Reference code to remove magic quotes from everything ... just in case.
80 /// If you have problems with slashes everywhere then you might want to
81 /// uncomment this code. It will not be necessary on 99.9% of PHP servers.
82 /// Got this from http://www.php.net/manual/en/configuration.php
83 // if (ini_get("magic_quotes_gpc") ) {
84 // foreach ($GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"] as $key => $value) {
85 // if (!is_array($value)) { // Simple value
86 // $newval = stripslashes($value);
87 // $GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"][$key] = $newval;
88 // if (ini_get("register_globals")) {
89 // $GLOBALS[$key] = $newval;
92 // foreach ($value as $k => $v) {
93 // $newval = stripslashes($v);
94 // $GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"][$key][$k] = $newval;
95 // if (ini_get("register_globals")) {
96 // $GLOBALS[$key][$k] = $newval;
103 /// The following is a hack to get around the problem of PHP installations
104 /// that have "register_globals" turned off (default since PHP 4.1.0).
105 /// Eventually I'll go through and upgrade all the code to make this unnecessary
107 if (isset($_REQUEST)) {
110 if (isset($_SERVER)) {
115 /// Load up global environment variables
120 if (! isset($_SESSION["SESSION"])) { $_SESSION["SESSION"] = new object; }
121 if (! isset($_SESSION["USER"])) { $_SESSION["USER"] = new object; }
122 extract($_SESSION); // Makes $SESSION and $USER available for read-only access
124 if (isset($FULLME)) {
127 $FULLME = qualified_me();
128 $ME = strip_querystring($FULLME);
132 /// Set language/locale of printed times. If user has chosen a language that
133 /// that is different from the site language, then use the locale specified
134 /// in the language file. Otherwise, if the admin hasn't specified a locale
135 /// then use the one from the default language. Otherwise (and this is the
136 /// majority of cases), use the stored locale specified by admin.
138 if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
139 $CFG->locale = get_string("locale");
140 } else if (empty($CFG->locale)) {
141 $CFG->locale = get_string("locale");
142 set_config("locale", $CFG->locale); // cache it to save lookups in future
144 setlocale (LC_TIME, $CFG->locale);
145 setlocale (LC_CTYPE, $CFG->locale);
146 setlocale (LC_COLLATE, $CFG->locale);