]> git.mjollnir.org Git - moodle.git/commitdiff
Most of the time, don't rely on HTTP_REFERER
authormoodler <moodler>
Mon, 22 Mar 2004 05:59:43 +0000 (05:59 +0000)
committermoodler <moodler>
Mon, 22 Mar 2004 05:59:43 +0000 (05:59 +0000)
mod/forum/rate.php

index e91c43ec30380279232c7f97185b53411bcb81da..902c5252840475c7b2573e017ffa1695b4af7423 100644 (file)
 
     if ($data = data_submitted("$CFG->wwwroot/mod/forum/discuss.php")) {    // form submitted
 
-        foreach ($data as $post => $rating) {
-            if ($post == "id") {
+        foreach ($data as $postid => $rating) {
+            if ($postid == "id") {
                 continue;
             }
-            if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $post)) {
+            if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $postid)) {
                 if ($rating != $oldrating->rating) {
                     $oldrating->rating = $rating;
                     $oldrating->time = time();
                     if (! update_record("forum_ratings", $oldrating)) {
-                        error("Could not update an old rating ($post = $rating)");
+                        error("Could not update an old rating ($postid = $rating)");
                     }
                 }
             } else if ($rating) {
                 unset($newrating);
                 $newrating->userid = $USER->id;
                 $newrating->time = time();
-                $newrating->post = $post;
+                $newrating->post = $postid;
                 $newrating->rating = $rating;
 
                 if (! insert_record("forum_ratings", $newrating)) {
-                    error("Could not insert a new rating ($post = $rating)");
+                    error("Could not insert a new rating ($postid = $rating)");
                 }
             }
         }
-        redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "forum"));
+        if ($post = get_record('forum_posts', 'id', $postid)) {
+            redirect("$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion", get_string("ratingssaved", "forum"));
+        } else {
+            redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "forum"));
+        }
 
     } else {
         error("This page was not accessed correctly");