Prepend database name to all table names to avoid ADOdb bug when there
[moodle.git] / lib / setup.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2//
3// setup.php
4//
5// Sets up sessions, connects to databases and so on
6//
7// Normally this is only called by the main config.php file
8//
9// Normally this file does not need to be edited.
10//
f9903ed0 11//////////////////////////////////////////////////////////////
12
74944b73 13/// If there are any errors in the standard libraries we want to know!
346b1a24 14 error_reporting(E_ALL);
f9903ed0 15
a8a71844 16/// Connect to the database using adodb
17
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>";
23 die;
24 }
25
b6bae251 26 if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
27 $CFG->prefix = "";
28 }
7adcd58f 29 $CFG->prefix = "$CFG->dbname.$CFG->prefix";
b6bae251 30
31
a8a71844 32
74944b73 33/// Load up standard libraries
1e3e716f 34
9fa49e22 35 require("$CFG->libdir/weblib.php"); // Functions for producing HTML
36 require("$CFG->libdir/datalib.php"); // Functions for accessing databases
37 require("$CFG->libdir/moodlelib.php"); // Other general-purpose functions
1e3e716f 38
1e3e716f 39
74944b73 40/// Load up any configuration from the config table
41
9fa49e22 42 if ($configs = get_records("config")) {
74944b73 43 $CFG = (array)$CFG;
44 foreach ($configs as $config) {
45 $CFG[$config->name] = $config->value;
46 }
47 $CFG = (object)$CFG;
48 unset($configs);
49 unset($config);
50 }
f9903ed0 51
1e3e716f 52
4fd7ccc0 53/// Set error reporting back to normal
6fbf8d8f 54 if (empty($CFG->debug)) {
55 $CFG->debug = 7;
56 }
4fd7ccc0 57 error_reporting($CFG->debug);
58
59
74944b73 60/// Location of standard files
f9903ed0 61
f9903ed0 62 $CFG->wordlist = "$CFG->libdir/wordlist.txt";
63 $CFG->javascript = "$CFG->libdir/javascript.php";
ca4f8eb8 64 $CFG->moddata = "moddata";
f9903ed0 65
ae7aafeb 66
74944b73 67/// Load up theme variables (colours etc)
1e3e716f 68
74944b73 69 if (!isset($CFG->theme)) {
70 $CFG->theme = "standard";
71 }
45f21f94 72 include("$CFG->dirroot/theme/$CFG->theme/config.php");
1e3e716f 73
e6f10ec5 74 $CFG->stylesheet = "$CFG->wwwroot/theme/$CFG->theme/styles.php";
75 $CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
76 $CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
77
ae7aafeb 78
7a302afc 79
0ee8d920 80/// Reference code to remove magic quotes from everything ... just in case.
81/// If you have problems with slashes everywhere then you might want to
82/// uncomment this code. It will not be necessary on 99.9% of PHP servers.
83/// Got this from http://www.php.net/manual/en/configuration.php
84// if (ini_get("magic_quotes_gpc") ) {
85// foreach ($GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"] as $key => $value) {
86// if (!is_array($value)) { // Simple value
87// $newval = stripslashes($value);
88// $GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"][$key] = $newval;
89// if (ini_get("register_globals")) {
90// $GLOBALS[$key] = $newval;
91// }
92// } else { // Array
93// foreach ($value as $k => $v) {
94// $newval = stripslashes($v);
95// $GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"][$key][$k] = $newval;
96// if (ini_get("register_globals")) {
97// $GLOBALS[$key][$k] = $newval;
98// }
99// }
100// }
101// }
102// }
ae7aafeb 103
74944b73 104/// The following is a hack to get around the problem of PHP installations
105/// that have "register_globals" turned off (default since PHP 4.1.0).
106/// Eventually I'll go through and upgrade all the code to make this unnecessary
b0cb5e22 107
74944b73 108 if (isset($_REQUEST)) {
109 extract($_REQUEST);
110 }
111 if (isset($_SERVER)) {
112 extract($_SERVER);
b0cb5e22 113 }
ae7aafeb 114
f9903ed0 115
74944b73 116/// Load up global environment variables
f9903ed0 117
118 class object {};
119
120 session_start();
8223d271 121 if (! isset($_SESSION["SESSION"])) { $_SESSION["SESSION"] = new object; }
122 if (! isset($_SESSION["USER"])) { $_SESSION["USER"] = new object; }
123 extract($_SESSION); // Makes $SESSION and $USER available for read-only access
f9903ed0 124
9d378732 125 if (isset($FULLME)) {
126 $ME = $FULLME;
127 } else {
9fa49e22 128 $FULLME = qualified_me();
9d378732 129 $ME = strip_querystring($FULLME);
9fa49e22 130 }
f9903ed0 131
f9903ed0 132
339bb559 133/// Set language/locale of printed times. If user has chosen a language that
134/// that is different from the site language, then use the locale specified
135/// in the language file. Otherwise, if the admin hasn't specified a locale
136/// then use the one from the default language. Otherwise (and this is the
137/// majority of cases), use the stored locale specified by admin.
138
9c9f7d77 139 if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
339bb559 140 $CFG->locale = get_string("locale");
9c9f7d77 141 } else if (empty($CFG->locale)) {
339bb559 142 $CFG->locale = get_string("locale");
143 set_config("locale", $CFG->locale); // cache it to save lookups in future
144 }
145 setlocale (LC_TIME, $CFG->locale);
146 setlocale (LC_CTYPE, $CFG->locale);
147 setlocale (LC_COLLATE, $CFG->locale);
148
f9903ed0 149?>