Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / forum / report.php
blobede8b138f83497d4a0241237a9b868ea40b0951b
1 <?php // $Id$
3 // For a given post, shows a report of all the ratings it has
5 require_once("../../config.php");
6 require_once("lib.php");
8 $id = required_param('id', PARAM_INT);
9 $sort = optional_param('sort', '', PARAM_ALPHA);
11 if (! $post = get_record('forum_posts', 'id', $id)) {
12 error("Post ID was incorrect");
15 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion)) {
16 error("Discussion ID was incorrect");
19 if (! $forum = get_record('forum', 'id', $discussion->forum)) {
20 error("Forum ID was incorrect");
23 if (! $course = get_record('course', 'id', $forum->course)) {
24 error("Course ID was incorrect");
27 if (! $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
28 error("Course Module ID was incorrect");
31 require_login($course, false, $cm);
32 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
34 if (!$forum->assessed) {
35 error("This activity does not use ratings");
38 if (!has_capability('mod/forum:viewrating', $context)) {
39 error("You do not have the capability to view post ratings");
41 if (!has_capability('mod/forum:viewanyrating', $context) and $USER->id != $post->userid) {
42 error("You can only look at results for posts that you made");
45 switch ($sort) {
46 case 'firstname': $sqlsort = "u.firstname ASC"; break;
47 case 'rating': $sqlsort = "r.rating ASC"; break;
48 default: $sqlsort = "r.time ASC";
51 $scalemenu = make_grades_menu($forum->scale);
53 $strratings = get_string('ratings', 'forum');
54 $strrating = get_string('rating', 'forum');
55 $strname = get_string('name');
56 $strtime = get_string('time');
58 print_header("$strratings: ".format_string($post->subject));
60 if (!$ratings = forum_get_ratings($post->id, $sqlsort)) {
61 error("No ratings for this post: \"".format_string($post->subject)."\"");
63 } else {
64 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
65 echo "<tr>";
66 echo "<th class=\"header\" scope=\"col\">&nbsp;</th>";
67 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$post->id&amp;sort=firstname\">$strname</a></th>";
68 echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$post->id&amp;sort=rating\">$strrating</a></th>";
69 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$post->id&amp;sort=time\">$strtime</a></th>";
70 echo "</tr>";
71 foreach ($ratings as $rating) {
72 echo '<tr class="forumpostheader">';
73 echo "<td>";
74 print_user_picture($rating->id, $forum->course, $rating->picture);
75 echo '</td><td>'.fullname($rating).'</td>';
76 echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating]."</td>";
77 echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->time)."</td>";
78 echo "</tr>\n";
80 echo "</table>";
81 echo "<br />";
84 close_window_button();
85 print_footer('none');