mirror of
https://github.com/moodle/moodle.git
synced 2025-02-02 06:10:08 +01:00
8223d27193
servers that have register_globals turned off (this is the default setting on newer version of PHP). In fact it's partly a hack that globalises all GET, POST, FILES AND COOKIE variables. Unfortunately though the SESSION and USER global session variables are only available as $_SESSION["USER"] and $_SESSION["SESSION"], which is cumbersome to use. So, for every request I now make a copy of these two session variables into $USER and $SESSION. Whenever I update them thoughout Moodle I now have to call save_session("USER") which copies them back to the session variable. This seems to be working well now. Because I'm using $_SESSION etc now this will raise the required minimum version of PHP to 4.1.0
50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?PHP // $Id$
|
|
|
|
// Collect ratings, store them, then return to where we came from
|
|
|
|
|
|
require("../../config.php");
|
|
require("lib.php");
|
|
|
|
if (isguest()) {
|
|
error("Guests are not allowed to rate posts.", $HTTP_REFERER);
|
|
}
|
|
|
|
require_variable($id); // The course these ratings are part of
|
|
|
|
if (! $course = get_record("course", "id", $id)) {
|
|
error("Course ID was incorrect");
|
|
}
|
|
|
|
require_login($course->id);
|
|
|
|
if (isset($HTTP_POST_VARS)) { // form submitted
|
|
|
|
foreach ($HTTP_POST_VARS as $post => $rating) {
|
|
if ($post == "id") {
|
|
continue;
|
|
}
|
|
if ($rating) {
|
|
if ($check = get_record_sql("SELECT COUNT(*) as count FROM forum_ratings
|
|
WHERE user='$USER->id' AND post='$post'")){
|
|
if ($check->count == 0) {
|
|
$timenow = time();
|
|
if (!$rs = $db->Execute("INSERT DELAYED INTO forum_ratings
|
|
SET user='$USER->id', post='$post', time='$timenow', rating='$rating'")){
|
|
error("Could not insert a new rating ($post = $rating)");
|
|
}
|
|
|
|
} else {
|
|
error("You've rated this question before ($post)");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
redirect($HTTP_REFERER, "Ratings saved");
|
|
|
|
} else {
|
|
error("This page was not accessed correctly");
|
|
}
|
|
|
|
?>
|