id); if ($data = data_submitted("$CFG->wwwroot/mod/forum/discuss.php")) { // form submitted foreach ($data as $post => $rating) { if ($post == "id") { continue; } if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $post)) { 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)"); } } } else if ($rating) { unset($newrating); $newrating->userid = $USER->id; $newrating->time = time(); $newrating->post = $post; $newrating->rating = $rating; if (! insert_record("forum_ratings", $newrating)) { error("Could not insert a new rating ($post = $rating)"); } } } redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "forum")); } else { error("This page was not accessed correctly"); } ?>