When searching for resources, use button instead of link.
[moodle.git] / mod / choice / report.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
f9903ed0 5
6 require_variable($id); // course module
7
8 if (! $cm = get_record("course_modules", "id", $id)) {
9 error("Course Module ID was incorrect");
10 }
11
12 if (! $course = get_record("course", "id", $cm->course)) {
13 error("Course module is misconfigured");
14 }
15
16 require_login($course->id);
17
18 if (!isteacher($course->id)) {
19 error("Only teachers can look at this page");
20 }
21
cd3fccff 22 if (!$choice = choice_get_choice($cm->instance)) {
f9903ed0 23 error("Course module is incorrect");
24 }
25
c4016bc1 26 $strchoice = get_string("modulename", "choice");
27 $strchoices = get_string("modulenameplural", "choice");
28 $strresponses = get_string("responses", "choice");
29
5eb45fa0 30 add_to_log($course->id, "choice", "report", "report.php?id=$cm->id", "$choice->id");
f9903ed0 31
c4016bc1 32 print_header("$course->shortname: $choice->name: $strresponses", "$course->fullname",
8b50d2a7 33 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
34 <a href=\"index.php?id=$course->id\">$strchoices</a> ->
35 <a href=\"view.php?id=$cm->id\">$choice->name</a> -> $strresponses", "");
f9903ed0 36
37
353d0338 38 if (! $users = get_course_users($course->id, "u.firstname ASC")) {
39 error("No users found (very strange)");
f9903ed0 40 }
41
da664183 42 if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) {
f9903ed0 43 foreach ($allanswers as $aa) {
ebc3bd2b 44 $answers[$aa->userid] = $aa;
f9903ed0 45 }
f9903ed0 46 } else {
47 $answers = array () ;
48 }
f9903ed0 49
50 $timenow = time();
51
cd3fccff 52 foreach ($choice->answer as $key => $answer) {
53 $useranswer[$key] = array();
66062dd3 54 }
da664183 55 foreach ($users as $user) {
dcde9f02 56 if (!empty($answers[$user->id])) {
57 $answer = $answers[$user->id];
58 } else {
59 $answer->answer = 0;
60 }
da664183 61 $useranswer[(int)$answer->answer][] = $user;
62 }
cd3fccff 63 foreach ($choice->answer as $key => $answer) {
64 if (!$choice->answer[$key]) {
65 unset($useranswer[$key]); // Throw away any data that doesn't apply
66 }
67 }
da664183 68 ksort($useranswer);
f9903ed0 69
da664183 70 $tablewidth = (int) (100.0 / count($useranswer));
f9903ed0 71
8b50d2a7 72 echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\">";
73 echo "<tr>";
da664183 74 foreach ($useranswer as $key => $answer) {
75 if ($key) {
8b50d2a7 76 echo "<th width=\"$tablewidth%\">";
da664183 77 } else {
51600d9d 78 echo "<th bgcolor=\"$THEME->body\" width=\"$tablewidth%\">";
da664183 79 }
80 echo choice_get_answer($choice, $key);
8b50d2a7 81 echo "</th>";
da664183 82 }
8b50d2a7 83 echo "</tr><tr>";
f9903ed0 84
da664183 85 foreach ($useranswer as $key => $answer) {
86 if ($key) {
51600d9d 87 echo "<td width=\"$tablewidth%\" valign=top nowrap bgcolor=\"$THEME->cellcontent\">";
da664183 88 } else {
51600d9d 89 echo "<td width=\"$tablewidth%\" valign=top nowrap bgcolor=\"$THEME->body\">";
da664183 90 }
f9903ed0 91
8b50d2a7 92 echo "<table width=\"100%\">";
da664183 93 foreach ($answer as $user) {
8b50d2a7 94 echo "<tr><td width=\"10\" nowrap>";
da664183 95 print_user_picture($user->id, $course->id, $user->picture);
8b50d2a7 96 echo "</td><td width=\"100%\" nowrap>";
b3679ca4 97 echo "<p>".fullname($user, true)."</p>";
8b50d2a7 98 echo "</td></tr>";
da664183 99 }
8b50d2a7 100 echo "</table>";
da664183 101
8b50d2a7 102 echo "</td>";
f9903ed0 103 }
8b50d2a7 104 echo "</tr></table>";
f9903ed0 105
106 print_footer($course);
107
108
109?>
110