removed empty bullet point
This commit is contained in:
+111
-257
@@ -1,90 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* 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.
|
||||
* @author Martin Dougiamas
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||
* @package moodlecore
|
||||
*/
|
||||
|
||||
////// DOCUMENTATION IN PHPDOC FORMAT FOR MOODLE GLOBALS AND COMMON OBJECT TYPES /////////////
|
||||
/**
|
||||
* This global variable is read in from the 'config' table.
|
||||
*
|
||||
* Some typical settings in the $CFG global:
|
||||
* - $USER->emailstop - Does the user want email sent to them?
|
||||
* - $USER->email - The user's email address.
|
||||
* - $USER->id - The unique integer identified of this user in the 'user' table.
|
||||
* - $USER->email - The user's email address.
|
||||
* - $USER->firstname - The user's first name.
|
||||
* - $USER->lastname - The user's last name.
|
||||
* - $USER->username - The user's login username.
|
||||
* - $USER->secret - The user's ?.
|
||||
* - $USER->lang - The user's language choice.
|
||||
*
|
||||
* @global object(user) $USER
|
||||
*/
|
||||
global $USER;
|
||||
/**
|
||||
* $USER is a global instance of a typical $user record.
|
||||
*
|
||||
* Items found in the user record:
|
||||
* - $CFG->wwwroot - Path to moodle index directory in url format.
|
||||
* - $CFG->dataroot - Path to moodle index directory on server's filesystem.
|
||||
* - $CFG->libroot - Path to moodle's library folder on server's filesystem.
|
||||
*
|
||||
* @global object(cfg) $CFG
|
||||
*/
|
||||
global $CFG;
|
||||
/**
|
||||
* Definition of session type
|
||||
* @global object(session) $SESSION
|
||||
*/
|
||||
global $SESSION;
|
||||
/**
|
||||
* Definition of course type
|
||||
* @global object(course) $COURSE
|
||||
*/
|
||||
global $COURSE;
|
||||
/**
|
||||
* Definition of db type
|
||||
* @global object(db) $db
|
||||
*/
|
||||
global $db;
|
||||
/**
|
||||
* $THEME is a global that defines the site theme.
|
||||
*
|
||||
* Items found in the theme record:
|
||||
* - $THEME->cellheading - Cell colors.
|
||||
* - $THEME->cellheading2 - Alternate cell colors.
|
||||
*
|
||||
* @global object(theme) $THEME
|
||||
*/
|
||||
global $THEME;
|
||||
<?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 (!isset($CFG->wwwroot)) {
|
||||
die;
|
||||
}
|
||||
|
||||
/// Time to start counting
|
||||
init_performance_info();
|
||||
|
||||
if (!isset($CFG->enrol)) { // This is a hack to fix bug 1598
|
||||
$CFG->enrol = 'internal';
|
||||
}
|
||||
|
||||
/// 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';
|
||||
$CFG->libdir = "$CFG->dirroot/lib";
|
||||
|
||||
require_once($CFG->libdir .'/adodb/adodb.inc.php'); // Database access functions
|
||||
require_once("$CFG->libdir/adodb/adodb.inc.php"); // Database access functions
|
||||
|
||||
$db = &ADONewConnection($CFG->dbtype);
|
||||
$db = &ADONewConnection($CFG->dbtype);
|
||||
|
||||
error_reporting(0); // Hide errors
|
||||
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);
|
||||
@@ -92,30 +37,25 @@ global $THEME;
|
||||
$dbconnected = $db->Connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass,$CFG->dbname);
|
||||
}
|
||||
if (! $dbconnected) {
|
||||
// In the name of protocol correctness, monitoring and performance
|
||||
// profiling, set the appropriate error headers for machine comsumption
|
||||
if (isset($_SERVER['SERVER_PROTOCOL'])) {
|
||||
// Avoid it with cron.php. Note that we assume it's HTTP/1.x
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
|
||||
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>";
|
||||
}
|
||||
// and then for human consumption...
|
||||
echo '<html><body>';
|
||||
echo '<table align="center"><tr>';
|
||||
echo '<td style="color:#990000; text-align:center; font-size:large; border-width:1px; '.
|
||||
' border-color:#000000; border-style:solid; border-radius: 20px; border-collapse: collapse; '.
|
||||
' -moz-border-radius: 20px; padding: 15px">';
|
||||
echo '<p>Error: Database connection failed.</p>';
|
||||
echo '<p>It is possible that the database is overloaded or otherwise not running properly.</p>';
|
||||
echo '<p>The site administrator should also check that the database details have been correctly specified in config.php</p>';
|
||||
echo '</td></tr></table>';
|
||||
echo '</body></html>';
|
||||
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 = '';
|
||||
$CFG->prefix = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -126,40 +66,30 @@ global $THEME;
|
||||
}
|
||||
|
||||
|
||||
/// Load up standard libraries
|
||||
/// 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
|
||||
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
|
||||
|
||||
|
||||
/// Increase memory limits if possible
|
||||
|
||||
raise_memory_limit('64M'); // We should never NEED this much but just in case...
|
||||
@ini_set('memory_limit' , '16M');
|
||||
|
||||
|
||||
/// Load up any configuration from the config table
|
||||
|
||||
|
||||
if ($configs = get_records('config')) {
|
||||
$CFG = (array)$CFG;
|
||||
foreach ($configs as $config) {
|
||||
if (!isset($CFG[$config->name])) {
|
||||
$CFG[$config->name] = $config->value;
|
||||
} else {
|
||||
error_log("\$CFG->$config->name in config.php overrides database setting");
|
||||
}
|
||||
$CFG[$config->name] = $config->value;
|
||||
}
|
||||
|
||||
$CFG = (object)$CFG;
|
||||
unset($configs);
|
||||
unset($config);
|
||||
}
|
||||
|
||||
/// Turn on SQL logging if required
|
||||
if (!empty($CFG->logsql)) {
|
||||
$db->LogSQL();
|
||||
}
|
||||
|
||||
|
||||
/// Set error reporting back to normal
|
||||
if (empty($CFG->debug)) {
|
||||
@@ -168,11 +98,6 @@ global $THEME;
|
||||
error_reporting($CFG->debug);
|
||||
|
||||
|
||||
/// Set a default enrolment configuration (see bug 1598)
|
||||
if (!isset($CFG->enrol)) {
|
||||
$CFG->enrol = 'internal';
|
||||
}
|
||||
|
||||
/// File permissions on created directories in the $CFG->dataroot
|
||||
|
||||
if (empty($CFG->directorypermissions)) {
|
||||
@@ -180,75 +105,80 @@ global $THEME;
|
||||
}
|
||||
|
||||
/// Set up smarty template system
|
||||
//require_once($CFG->libdir .'/smarty/Smarty.class.php');
|
||||
//$smarty = new Smarty;
|
||||
//$smarty->template_dir = $CFG->dirroot .'/templates/'. $CFG->template;
|
||||
//if (!file_exists($CFG->dataroot .'/cache')) {
|
||||
// make_upload_directory('cache');
|
||||
//}
|
||||
//$smarty->compile_dir = $CFG->dataroot .'/cache';
|
||||
|
||||
/// Set up session handling
|
||||
if(empty($CFG->respectsessionsettings)) {
|
||||
if (empty($CFG->dbsessions)) { /// File-based sessions
|
||||
|
||||
// Some distros disable GC by setting probability to 0
|
||||
// overriding the PHP default of 1
|
||||
// (gc_probability is divided by gc_divisor, which defaults to 1000)
|
||||
if (ini_get('session.gc_probability') == 0) {
|
||||
ini_set('session.gc_probability', 1);
|
||||
}
|
||||
|
||||
if (!empty($CFG->sessiontimeout)) {
|
||||
ini_set('session.gc_maxlifetime', $CFG->sessiontimeout);
|
||||
}
|
||||
|
||||
if (!file_exists($CFG->dataroot .'/sessions')) {
|
||||
make_upload_directory('sessions');
|
||||
}
|
||||
ini_set('session.save_path', $CFG->dataroot .'/sessions');
|
||||
|
||||
} else { /// Database sessions
|
||||
ini_set('session.save_handler', 'user');
|
||||
|
||||
$ADODB_SESSION_DRIVER = $CFG->dbtype;
|
||||
$ADODB_SESSION_CONNECT = $CFG->dbhost;
|
||||
$ADODB_SESSION_USER = $CFG->dbuser;
|
||||
$ADODB_SESSION_PWD = $CFG->dbpass;
|
||||
$ADODB_SESSION_DB = $CFG->dbname;
|
||||
$ADODB_SESSION_TBL = $CFG->prefix.'sessions';
|
||||
|
||||
require_once($CFG->libdir. '/adodb/session/adodb-session.php');
|
||||
}
|
||||
require_once("$CFG->libdir/smarty/Smarty.class.php");
|
||||
$smarty = new Smarty;
|
||||
$smarty->template_dir = "$CFG->dirroot/templates/$CFG->template";
|
||||
if (!file_exists("$CFG->dataroot/cache")) {
|
||||
make_upload_directory('cache');
|
||||
}
|
||||
$smarty->compile_dir = "$CFG->dataroot/cache";
|
||||
|
||||
/// Set session timeouts
|
||||
if (!empty($CFG->sessiontimeout)) {
|
||||
ini_set('session.gc_maxlifetime', $CFG->sessiontimeout);
|
||||
}
|
||||
|
||||
/// Set custom session path
|
||||
if (!file_exists("$CFG->dataroot/sessions")) {
|
||||
make_upload_directory('sessions');
|
||||
}
|
||||
ini_set('session.save_path', "$CFG->dataroot/sessions");
|
||||
|
||||
/// Set sessioncookie variable if it isn't already
|
||||
if (!isset($CFG->sessioncookie)) {
|
||||
$CFG->sessioncookie = '';
|
||||
}
|
||||
|
||||
/// Configure ampersands in URLs
|
||||
|
||||
@ini_set('arg_separator.output', '&');
|
||||
|
||||
/// Location of standard files
|
||||
|
||||
$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
|
||||
$CFG->javascript = $CFG->libdir .'/javascript.php';
|
||||
$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";
|
||||
|
||||
if (empty($THEME->custompix)) {
|
||||
$CFG->pixpath = "$CFG->wwwroot/pix";
|
||||
$CFG->modpixpath = "$CFG->wwwroot/mod";
|
||||
} else {
|
||||
$CFG->pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
|
||||
$CFG->modpixpath = "$CFG->wwwroot/theme/$CFG->theme/pix/mod";
|
||||
}
|
||||
|
||||
|
||||
/// A hack to get around magic_quotes_gpc being turned off
|
||||
|
||||
if (!ini_get_bool('magic_quotes_gpc') ) {
|
||||
function addslashes_deep($value) {
|
||||
$value = is_array($value) ?
|
||||
array_map('addslashes_deep', $value) :
|
||||
addslashes($value);
|
||||
return $value;
|
||||
foreach ($_GET as $key => $var) {
|
||||
if (!is_array($var)) {
|
||||
$_GET[$key] = addslashes($var);
|
||||
} else {
|
||||
foreach ($var as $arrkey => $arrvar) {
|
||||
$var[$arrkey] = addslashes($arrvar);
|
||||
}
|
||||
$_GET[$key] = $var;
|
||||
}
|
||||
}
|
||||
foreach ($_POST as $key => $var) {
|
||||
if (!is_array($var)) {
|
||||
$_POST[$key] = addslashes($var);
|
||||
} else {
|
||||
foreach ($var as $arrkey => $arrvar) {
|
||||
$var[$arrkey] = addslashes($arrvar);
|
||||
}
|
||||
$_POST[$key] = $var;
|
||||
}
|
||||
}
|
||||
$_POST = array_map('addslashes_deep', $_POST);
|
||||
$_GET = array_map('addslashes_deep', $_GET);
|
||||
$_COOKIE = array_map('addslashes_deep', $_COOKIE);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,83 +192,50 @@ global $THEME;
|
||||
if (isset($_POST)) {
|
||||
extract($_POST, EXTR_SKIP); // Skip existing variables, ie CFG
|
||||
}
|
||||
if (isset($_SERVER)) {
|
||||
if (isset($_SERVER)) {
|
||||
extract($_SERVER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Load up global environment variables
|
||||
|
||||
class object {};
|
||||
|
||||
unset(${'MoodleSession'.$CFG->sessioncookie});
|
||||
unset($_GET['MoodleSession'.$CFG->sessioncookie]);
|
||||
unset($_POST['MoodleSession'.$CFG->sessioncookie]);
|
||||
|
||||
|
||||
if (!isset($nomoodlecookie)) {
|
||||
session_name('MoodleSession'.$CFG->sessioncookie);
|
||||
@session_start();
|
||||
if (! isset($_SESSION['SESSION'])) {
|
||||
$_SESSION['SESSION'] = new object;
|
||||
if (! isset($_SESSION['SESSION'])) {
|
||||
$_SESSION['SESSION'] = new object;
|
||||
}
|
||||
if (! isset($_SESSION['USER'])) {
|
||||
$_SESSION['USER'] = new object;
|
||||
if (! isset($_SESSION['USER'])) {
|
||||
$_SESSION['USER'] = new object;
|
||||
}
|
||||
|
||||
|
||||
$SESSION = &$_SESSION['SESSION']; // Makes them easier to reference
|
||||
$USER = &$_SESSION['USER'];
|
||||
}
|
||||
else {
|
||||
$SESSION = NULL;
|
||||
$USER = NULL;
|
||||
}
|
||||
|
||||
if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
|
||||
$FULLME = FULLME;
|
||||
$ME = FULLME;
|
||||
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
|
||||
/// 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");
|
||||
|
||||
|
||||
|
||||
/// Load up theme variables (colours etc)
|
||||
|
||||
if (!isset($CFG->themedir)) {
|
||||
$CFG->themedir = $CFG->dirroot.'/theme/';
|
||||
$CFG->themewww = $CFG->wwwroot.'/theme/';
|
||||
}
|
||||
|
||||
if (isset($_GET['theme'])) {
|
||||
if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
|
||||
if (!detect_munged_arguments($_GET['theme'], 0) and file_exists($CFG->themedir. $_GET['theme'])) {
|
||||
$SESSION->theme = $_GET['theme'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($CFG->theme)) {
|
||||
$CFG->theme = 'standard';
|
||||
}
|
||||
|
||||
theme_setup(); // Sets up theme global variables
|
||||
|
||||
|
||||
|
||||
/// 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
|
||||
/// 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
|
||||
/// 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'])) {
|
||||
if (!detect_munged_arguments($lang, 0) and file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
||||
if (!detect_munged_arguments($lang, 0) and file_exists("$CFG->dirroot/lang/$lang")) {
|
||||
$SESSION->lang = $lang;
|
||||
$SESSION->encoding = get_string('thischarset');
|
||||
}
|
||||
@@ -367,47 +264,4 @@ global $THEME;
|
||||
}
|
||||
}
|
||||
|
||||
if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
|
||||
if (empty($_SESSION['USER']->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
|
||||
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
|
||||
(strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
|
||||
if ($USER = get_user_info_from_db("username", "w3cvalidator")) {
|
||||
$USER->loggedin = true;
|
||||
$USER->site = $CFG->wwwroot;
|
||||
$USER->ignoresesskey = true;
|
||||
} else {
|
||||
$USER = guest_user();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
*** init_performance_info() {
|
||||
***
|
||||
*** Initializes our performance info early.
|
||||
***
|
||||
*** Pairs up with get_performance_info() which is actually
|
||||
*** in moodlelib.php. This function is here so that we can
|
||||
*** call it before all the libs are pulled in.
|
||||
***
|
||||
**/
|
||||
function init_performance_info() {
|
||||
|
||||
global $PERF;
|
||||
|
||||
$PERF = new Object;
|
||||
$PERF->dbqueries = 0;
|
||||
$PERF->logwrites = 0;
|
||||
if (function_exists('microtime')) {
|
||||
$PERF->starttime = microtime();
|
||||
}
|
||||
if (function_exists('memory_get_usage')) {
|
||||
$PERF->startmemory = memory_get_usage();
|
||||
}
|
||||
if (function_exists('posix_times')) {
|
||||
$PERF->startposixtimes = posix_times();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user