2002-07-31 14:19:35 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
// Collect ratings, store them, then return to where we came from
|
|
|
|
|
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if (isguest()) {
|
2003-01-05 06:45:20 +00:00
|
|
|
error("Guests are not allowed to rate posts.", $_SERVER["HTTP_REFERER"]);
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
if ($data = data_submitted("$CFG->wwwroot/mod/forum/discuss.php")) { // form submitted
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2003-01-05 06:45:20 +00:00
|
|
|
foreach ($data as $post => $rating) {
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($post == "id") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($rating) {
|
2002-12-23 09:39:26 +00:00
|
|
|
if (record_exists("forum_ratings", "userid", $USER->id, "post", $post)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
error("You've rated this question before ($post)");
|
|
|
|
} else {
|
|
|
|
unset($newrating);
|
2002-12-23 09:39:26 +00:00
|
|
|
$newrating->userid = $USER->id;
|
2002-12-20 14:44:14 +00:00
|
|
|
$newrating->time = time();
|
|
|
|
$newrating->post = $post;
|
|
|
|
$newrating->rating = $rating;
|
|
|
|
|
|
|
|
if (! insert_record("forum_ratings", $newrating)) {
|
|
|
|
error("Could not insert a new rating ($post = $rating)");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-01-05 06:45:20 +00:00
|
|
|
redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "forum"));
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
error("This page was not accessed correctly");
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|