Browse files

MDL-17365 forum rate - validate rating against scale values. Backport…

…ed from 18_STABLE
  • Loading branch information...
1 parent 035699d commit 2f33962df9b92385ac48a3561a5fcbebaac39715 stronk7 committed Jan 27, 2009
Showing with 13 additions and 0 deletions.
  1. +1 −0 lang/en_utf8/forum.php
  2. +12 −0 mod/forum/rate.php
View
1 lang/en_utf8/forum.php
@@ -108,6 +108,7 @@
$string['intronews'] = 'General news and announcements';
$string['introsocial'] = 'An open forum for chatting about anything you want to';
$string['introteacher'] = 'A forum for teacher-only notes and discussion';
+$string['invalidrate'] = 'Invalid rate ($a)';
$string['lastpost'] = 'Last post';
$string['learningforums'] = 'Learning forums';
$string['mailnow'] = 'Mail now';
View
12 mod/forum/rate.php
@@ -13,6 +13,10 @@
if (! $cm = get_coursemodule_from_instance('forum', $forumid, $id)) {
error('Course Module ID was incorrect');
}
+
+ if (!$forum = get_record('forum', 'id', $forumid)) {
+ error("Forum ID was incorrect");
+ }
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -39,6 +43,9 @@
$lastpostid = 0;
+ /// Calculate scale values
+ $scale_values = make_grades_menu($forum->scale);
+
foreach ((array)$data as $postid => $rating) {
if ($postid == "id") {
continue;
@@ -47,6 +54,11 @@
$postid = (int)$postid;
$lastpostid = $postid;
+ /// Check rate is valid for for that forum scale values
+ if (!array_key_exists($rating, $scale_values) && $rating != FORUM_UNSET_POST_RATING) {
+ print_error('invalidrate', 'forum', '', $rating);
+ }
+
if ($rating == FORUM_UNSET_POST_RATING) {
delete_records('forum_ratings', 'post', $postid, 'userid', $USER->id);

0 comments on commit 2f33962

Please sign in to comment.