forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
213 lines (165 loc) · 7.12 KB
/
setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?PHP // $Id$
//
// setup.php
//
// Sets up sessions, connects to databases and so on
//
// Normally this is only called by the main config.php file
//
// Normally this file does not need to be edited.
//
//////////////////////////////////////////////////////////////
/// If there are any errors in the standard libraries we want to know!
error_reporting(E_ALL);
/// Connect to the database using adodb
$CFG->libdir = "$CFG->dirroot/lib";
require_once("$CFG->libdir/adodb/adodb.inc.php"); // Database access functions
$db = &ADONewConnection($CFG->dbtype);
error_reporting(0); // Hide errors
if (!isset($CFG->dbpersist) or !empty($CFG->dbpersist)) { // Use persistent connection (default)
$dbconnected = $db->PConnect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
} else { // Use single connection
$dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
}
if (! $dbconnected) {
echo "<font color=\"#990000\">";
echo "<p>Error: Moodle could not connect to the database.</p>";
echo "<p>It's possible the database itself is just not working at the moment.</p>";
echo "<p>The admin should
also check that the database details have been correctly specified in config.php</p>";
echo "<p>Database host: $CFG->dbhost<br />";
echo "Database name: $CFG->dbname<br />";
echo "Database user: $CFG->dbuser<br />";
if (!isset($CFG->dbpersist)) {
echo "<p>The admin should also try setting this in config.php: $"."CFG->dbpersist = false; </p>";
}
echo "</font>";
die;
}
error_reporting(E_ALL); // Show errors from now on.
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
$CFG->prefix = "";
}
/// Define admin directory
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
$CFG->admin = "admin"; // This is relative to the wwwroot and dirroot
}
/// Load up standard libraries
require_once("$CFG->libdir/weblib.php"); // Functions for producing HTML
require_once("$CFG->libdir/datalib.php"); // Functions for accessing databases
require_once("$CFG->libdir/moodlelib.php"); // Other general-purpose functions
/// Load up any configuration from the config table
if ($configs = get_records("config")) {
$CFG = (array)$CFG;
foreach ($configs as $config) {
$CFG[$config->name] = $config->value;
}
$CFG = (object)$CFG;
unset($configs);
unset($config);
}
/// Set error reporting back to normal
if (empty($CFG->debug)) {
$CFG->debug = 7;
}
error_reporting($CFG->debug);
/// File permissions on created directories in the $CFG->dataroot
if (empty($CFG->directorypermissions)) {
$CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
}
/// Set session timeouts
if (!empty($CFG->sessiontimeout)) {
ini_set("session.gc_maxlifetime", $CFG->sessiontimeout);
}
/// Location of standard files
$CFG->wordlist = "$CFG->libdir/wordlist.txt";
$CFG->javascript = "$CFG->libdir/javascript.php";
$CFG->moddata = "moddata";
/// Load up theme variables (colours etc)
if (!isset($CFG->theme)) {
$CFG->theme = "standard";
}
include("$CFG->dirroot/theme/$CFG->theme/config.php");
$CFG->stylesheet = "$CFG->wwwroot/theme/$CFG->theme/styles.php";
$CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
$CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
/// Reference code to remove magic quotes from everything ... just in case.
/// If you have problems with slashes everywhere then you might want to
/// uncomment this code. It will not be necessary on 99.9% of PHP servers.
/// Got this from http://www.php.net/manual/en/configuration.php
// if (ini_get_bool("magic_quotes_gpc") ) {
// foreach ($GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"] as $key => $value) {
// if (!is_array($value)) { // Simple value
// $newval = stripslashes($value);
// $GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"][$key] = $newval;
// if (ini_get_bool("register_globals")) {
// $GLOBALS[$key] = $newval;
// }
// } else { // Array
// foreach ($value as $k => $v) {
// $newval = stripslashes($v);
// $GLOBALS["HTTP_".$GLOBALS["REQUEST_METHOD"]."_VARS"][$key][$k] = $newval;
// if (ini_get_bool("register_globals")) {
// $GLOBALS[$key][$k] = $newval;
// }
// }
// }
// }
// }
/// The following is a hack to get around the problem of PHP installations
/// that have "register_globals" turned off (default since PHP 4.1.0).
/// Eventually I'll go through and upgrade all the code to make this unnecessary
if (isset($_GET)) {
extract($_GET, EXTR_SKIP); // Skip existing variables, ie CFG
}
if (isset($_POST)) {
extract($_POST, EXTR_SKIP); // Skip existing variables, ie CFG
}
if (isset($_SERVER)) {
extract($_SERVER);
}
/// Load up global environment variables
class object {};
session_name('MoodleSession');
@session_start();
if (! isset($_SESSION['SESSION'])) {
$_SESSION['SESSION'] = new object;
}
if (! isset($_SESSION['USER'])) {
$_SESSION['USER'] = new object;
}
$SESSION = &$_SESSION['SESSION']; // Makes them easier to reference
$USER = &$_SESSION['USER'];
if (isset($FULLME)) {
$ME = $FULLME;
} else {
$FULLME = qualified_me();
$ME = strip_querystring($FULLME);
}
/// In VERY rare cases old PHP server bugs (it has been found on PHP 4.1.2 running
/// as a CGI under IIS on Windows) may require that you uncomment the following:
// session_register("USER");
// session_register("SESSION");
/// Set language/locale of printed times. If user has chosen a language that
/// that is different from the site language, then use the locale specified
/// in the language file. Otherwise, if the admin hasn't specified a locale
/// then use the one from the default language. Otherwise (and this is the
/// majority of cases), use the stored locale specified by admin.
if (isset($_GET['lang'])) {
$SESSION->lang = $lang;
}
if (empty($CFG->lang)) {
$CFG->lang = "en";
}
if (!empty($SESSION->lang) and ($SESSION->lang != $CFG->lang) ) {
$CFG->locale = get_string("locale");
} else if (!empty($USER->lang) and ($USER->lang != $CFG->lang) ) {
$CFG->locale = get_string("locale");
} else if (empty($CFG->locale)) {
$CFG->locale = get_string("locale");
set_config("locale", $CFG->locale); // cache it to save lookups in future
}
setlocale (LC_TIME, $CFG->locale);
setlocale (LC_CTYPE, $CFG->locale);
setlocale (LC_COLLATE, $CFG->locale);
?>