MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / data / report.php
blobfafbc549e2cb775eab76d10997d653beeda58f83
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 (!$record = get_record('data_records', 'id', $id)) {
12 error("Record ID is incorrect");
15 if (!$data = get_record('data', 'id', $record->dataid)) {
16 error("Data ID is incorrect");
19 if (!$course = get_record('course', 'id', $data->course)) {
20 error("Course is misconfigured");
23 if (!$cm = get_coursemodule_from_instance('data', $data->id, $course->id)) {
24 error("Course Module ID was incorrect");
27 require_login($course->id, false, $cm);
28 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
30 if (!$data->assessed) {
31 error("This activity does not use ratings");
34 if (!data_isowner($record->id) and !has_capability('mod/data:viewrating', $context) and !has_capability('mod/data:rate', $context)) {
35 error("You can not view ratings");
38 switch ($sort) {
39 case 'firstname': $sqlsort = "u.firstname ASC"; break;
40 case 'rating': $sqlsort = "r.rating ASC"; break;
41 default: $sqlsort = "r.id ASC";
44 $scalemenu = make_grades_menu($data->scale);
46 $strratings = get_string('ratings', 'data');
47 $strrating = get_string('rating', 'data');
48 $strname = get_string('name');
50 print_header($strratings);
52 if (!$ratings = data_get_ratings($record->id, $sqlsort)) {
53 error("No ratings for this record!");
55 } else {
56 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
57 echo "<tr>";
58 echo "<th class=\"header\" scope=\"col\">&nbsp;</th>";
59 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$record->id&amp;sort=firstname\">$strname</a></th>";
60 echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$id&amp;sort=rating\">$strrating</a></th>";
61 echo "</tr>";
62 foreach ($ratings as $rating) {
63 if (has_capability('mod/data:manageentries', $context)) {
64 echo '<tr class="forumpostheadertopic">';
65 } else {
66 echo '<tr class="forumpostheader">';
68 echo '<td class="picture">';
69 print_user_picture($rating->id, $data->course, $rating->picture, false, false, true);
70 echo '</td>';
71 echo '<td class="author"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$rating->id.'&amp;course='.$data->course.'">'.fullname($rating).'</a></td>';
72 echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating].'</td>';
73 echo "</tr>\n";
75 echo "</table>";
76 echo "<br />";
79 close_window_button();
80 print_footer('none');