From 607809b3bafb9e49c6d8e5107c8a794fe6fb8ea5 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 5 Jan 2003 06:45:20 +0000 Subject: [PATCH] OK a number of small changes here. Firstly, I'm replacing all use of old-style global variables like $HTTY_REFERER with their new-style equivalent $_SERVER["HTTP_REFERER"] Also using $_POST instead $HTTP_POST_VARS etc Secondly, if gdversion == 0 (ie GD is not installed) then: - users are not even allowed to upload new images - graphs now just print a message instead of failing. this allows Moodle to still be used even if GD is not present --- admin/lang.php | 4 +-- course/lib.php | 6 +++- course/loginas.php | 2 +- course/mod.php | 8 +++--- files/index.php | 6 ++-- lang/en/forum.php | 1 + lang/en/moodle.php | 1 + lib/moodlelib.php | 13 ++++----- lib/weblib.php | 62 +++++++++++++++++++--------------------- login/index.php | 2 +- mod/forum/lib.php | 6 ++-- mod/forum/post.php | 6 ++-- mod/forum/rate.php | 8 +++--- mod/forum/subscribe.php | 6 ++-- mod/journal/edit.php | 2 +- mod/quiz/edit.php | 6 ++-- mod/resource/details.php | 4 +-- mod/survey/details.php | 2 +- mod/survey/lib.php | 14 ++++++++- mod/survey/report.php | 30 ++++++++++++------- mod/survey/save.php | 8 +++--- mod/survey/view.php | 2 +- user/edit.html | 5 ++++ user/edit.php | 4 +-- user/lib.php | 34 ++++++++++++++++++++-- 25 files changed, 147 insertions(+), 95 deletions(-) diff --git a/admin/lang.php b/admin/lang.php index 6fe4da5f2b3..2c3b5c66c2a 100644 --- a/admin/lang.php +++ b/admin/lang.php @@ -130,8 +130,8 @@ } else if ($mode == "compare") { - if (isset($HTTP_POST_VARS['file'])){ // Save a file - $newstrings = $HTTP_POST_VARS; + if (isset($_POST['file'])){ // Save a file + $newstrings = $_POST; $file = $newstrings['file']; unset($newstrings['file']); if (lang_save_file($langdir, $file, $newstrings)) { diff --git a/course/lib.php b/course/lib.php index 9233040195b..7b447c4fc58 100644 --- a/course/lib.php +++ b/course/lib.php @@ -756,7 +756,11 @@ function print_course_categories($categories, $selected="none", $width=180) { function print_log_graph($course, $userid=0, $type="course.png", $date=0) { global $CFG; - echo "wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">"; + if (empty($CFG->gdversion)) { + echo "(".get_string("gdneed").")"; + } else { + echo "wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">"; + } } diff --git a/course/loginas.php b/course/loginas.php index 311c04dd4e0..134bafa8524 100644 --- a/course/loginas.php +++ b/course/loginas.php @@ -19,7 +19,7 @@ $USER->loggedin = true; $USER->site = $CFG->wwwroot; save_session("USER"); - redirect($HTTP_REFERER); + redirect($_SERVER["HTTP_REFERER"]); exit; } diff --git a/course/mod.php b/course/mod.php index 04456185c14..3263ecb6da5 100644 --- a/course/mod.php +++ b/course/mod.php @@ -17,14 +17,14 @@ } - if (isset($course) && isset($HTTP_POST_VARS)) { // add or update form submitted + if (isset($_POST["course"])) { // add or update form submitted if (isset($SESSION->modform)) { // Variables are stored in the session $mod = $SESSION->modform; unset($SESSION->modform); save_session("SESSION"); } else { - $mod = (object)$HTTP_POST_VARS; + $mod = (object)$_POST; } require_login($mod->course); @@ -118,7 +118,7 @@ error("Could not cache module information!"); } - redirect($HTTP_REFERER); + redirect($_SERVER["HTTP_REFERER"]); exit; } else if (isset($delete)) { // value = course module @@ -218,7 +218,7 @@ } else if (isset($add)) { if (!$add) { - redirect($HTTP_REFERER); + redirect($_SERVER["HTTP_REFERER"]); die; } diff --git a/files/index.php b/files/index.php index 9c2ddd97358..11fc1d8af67 100644 --- a/files/index.php +++ b/files/index.php @@ -163,7 +163,7 @@ } else { html_header($course, $wdir); - if (setfilelist($HTTP_POST_VARS)) { + if (setfilelist($_POST)) { echo "

You are about to delete:

"; print_simple_box_start("center"); printfilelist($USER->filelist); @@ -181,7 +181,7 @@ case "move": html_header($course, $wdir); - if ($count = setfilelist($HTTP_POST_VARS)) { + if ($count = setfilelist($_POST)) { $USER->fileop = $action; $USER->filesource = $wdir; save_session("USER"); @@ -348,7 +348,7 @@ } else { html_header($course, $wdir, "form.name"); - if (setfilelist($HTTP_POST_VARS)) { + if (setfilelist($_POST)) { echo "

You are about create a zip file containing:

"; print_simple_box_start("center"); printfilelist($USER->filelist); diff --git a/lang/en/forum.php b/lang/en/forum.php index 3337193aedc..9109b6bd9e0 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -81,6 +81,7 @@ $string['postupdated'] = "Your post was updated"; $string['processingpost'] = "Processing post \$a"; $string['rate'] = "Rate"; $string['ratings'] = "Ratings"; +$string['ratingssaved'] = "Ratings saved"; $string['readtherest'] = "Read the rest of this topic"; $string['re'] = "Re:"; // Put in front of subjects that are replies to another post $string['repliesmany'] = "\$a replies so far"; diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 34312d1b753..8ae84f7f981 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -192,6 +192,7 @@ $string['fullname'] = "Full name"; $string['fullsitename'] = "Full site name"; $string['gd1'] = "GD 1.x is installed"; $string['gd2'] = "GD 2.x is installed"; +$string['gdneed'] = "GD must be installed to see this graph"; $string['gdnot'] = "GD is not installed"; $string['gpl'] = "Copyright (C) 2001-2002 Martin Dougiamas (http://dougiamas.com) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 20636f5f95d..69290538c05 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -254,12 +254,12 @@ function require_login($courseid=0) { /// whether they are "logged in" or allowed to be in a particular course. /// If not, then it redirects them to the site login or course enrolment. - global $CFG, $SESSION, $USER, $FULLME, $HTTP_REFERER, $PHPSESSID; + global $CFG, $SESSION, $USER, $FULLME, $PHPSESSID; // First check that the user is logged in to the site. if (! (isset($USER->loggedin) and $USER->confirmed and ($USER->site == $CFG->wwwroot)) ) { // They're not $SESSION->wantsurl = $FULLME; - $SESSION->fromurl = $HTTP_REFERER; + $SESSION->fromurl = $_SERVER["HTTP_REFERER"]; save_session("SESSION"); $USER = NULL; save_session("USER"); @@ -458,9 +458,7 @@ function get_moodle_cookie() { $cookiename = "MOODLEID{$CFG->prefix}"; - global $$cookiename; - - return rc4decrypt($$cookiename); + return rc4decrypt($_COOKIE[$cookiename]); } @@ -1124,12 +1122,11 @@ function check_php_version($version="4.1.0") { function check_browser_version($brand="MSIE", $version=5.5) { /// Checks to see if is a browser matches the specified /// brand and is equal or better version. - global $HTTP_USER_AGENT; - if (!$HTTP_USER_AGENT) { + if (empty($_SERVER["HTTP_USER_AGENT"])) { return false; } - $string = explode(";", $HTTP_USER_AGENT); + $string = explode(";", $_SERVER["HTTP_USER_AGENT"]); if (!isset($string[1])) { return false; } diff --git a/lib/weblib.php b/lib/weblib.php index 69f1dfaac32..8d9c91b9566 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -120,9 +120,7 @@ function strip_querystring($url) { function get_referer() { /// returns the URL of the HTTP_REFERER, less the querystring portion - global $HTTP_REFERER; - - return strip_querystring(nvl($HTTP_REFERER)); + return strip_querystring(nvl($_SERVER["HTTP_REFERER"])); } @@ -132,16 +130,14 @@ function me() { /// return different things depending on a lot of things like your OS, Web /// server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.) - global $REQUEST_URI, $PATH_INFO, $PHP_SELF; + if (!empty($_SERVER["REQUEST_URI"])) { + return $_SERVER["REQUEST_URI"]; - if ($REQUEST_URI) { - return $REQUEST_URI; + } else if (!empty($_SERVER["PATH_INFO"])) { + return $_SERVER["PATH_INFO"]; - } else if ($PATH_INFO) { - return $PATH_INFO; - - } else if ($PHP_SELF) { - return $PHP_SELF; + } else if (!empty($_SERVER["PHP_SELF"])) { + return $_SERVER["PHP_SELF"]; } else { notify("Error: Could not find any of these web server variables: \$REQUEST_URI, \$PATH_INFO or \$PHP_SELF"); @@ -152,14 +148,12 @@ function me() { function qualified_me() { /// like me() but returns a full URL - global $HTTPS, $HTTP_HOST; - - if (!$HTTP_HOST) { + if (empty($_SERVER["HTTP_HOST"])) { notify("Error: could not find web server variable: \$HTTP_HOST"); } - $protocol = (isset($HTTPS) && $HTTPS == "on") ? "https://" : "http://"; - $url_prefix = "$protocol$HTTP_HOST"; + $protocol = (isset($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == "on") ? "https://" : "http://"; + $url_prefix = "$protocol".$_SERVER["HTTP_HOST"]; return $url_prefix . me(); } @@ -182,18 +176,19 @@ function match_referer($good_referer = "") { function data_submitted($url="") { /// Used on most forms in Moodle to check for data /// Returns the data as an object, if it's found. +/// This object can be used in foreach loops without +/// casting because it's cast to (array) automatically /// /// Checks that submitted POST data exists, and also /// checks the referer against the given url (it uses /// the current page if none was specified. - global $HTTP_POST_VARS, $CFG; - - if (empty($HTTP_POST_VARS)) { + if (empty($_POST)) { return false; + } else { if (match_referer($url)) { - return (object)$HTTP_POST_VARS; + return (object)$_POST; } else { if ($CFG->debug > 10) { notice("The form did not come from this page! (referer = ".get_referer().")"); @@ -306,15 +301,17 @@ function choose_from_menu ($options, $name, $selected="", $nothing="choose", $sc } $output .= ">$nothing\n"; } - foreach ($options as $value => $label) { - $output .= "