Tip over 'Edit profile' is the user's name
[moodle.git] / mod / choice / report.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3 require("../../config.php");
c4016bc1 4 require("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
22 if (! $choice = get_record("choice", "id", $cm->instance)) {
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",
f9903ed0 33 "<A HREF=/course/view.php?id=$course->id>$course->shortname</A> ->
c4016bc1 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
66062dd3 38 if (! $users = get_course_users($course->id, "u.firstname ASC")) {
da664183 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) {
44 $answers[$aa->user] = $aa;
45 }
46
47 } else {
48 $answers = array () ;
49 }
f9903ed0 50
51 $timenow = time();
52
66062dd3 53 for ($i=0; $i<=2; $i++) { // number of choices (presently hardcoded)
54 $useranswer[$i] = array();
55 }
56
da664183 57 foreach ($users as $user) {
f9903ed0 58 $answer = $answers[$user->id];
da664183 59 $useranswer[(int)$answer->answer][] = $user;
60 }
61 ksort($useranswer);
f9903ed0 62
da664183 63 $tablewidth = (int) (100.0 / count($useranswer));
f9903ed0 64
da664183 65 echo "<TABLE CELLPADDING=5 CELLSPACING=10 ALIGN=CENTER>";
66 echo "<TR>";
67 foreach ($useranswer as $key => $answer) {
68 if ($key) {
69 echo "<TH WIDTH=\"$tablewidth%\">";
70 } else {
71 echo "<TH BGCOLOR=\"$THEME->body\" WIDTH=\"$tablewidth%\">";
72 }
73 echo choice_get_answer($choice, $key);
74 echo "</TH>";
75 }
76 echo "</TR><TR>";
f9903ed0 77
da664183 78 foreach ($useranswer as $key => $answer) {
79 if ($key) {
80 echo "<TD WIDTH=\"$tablewidth%\" VALIGN=TOP NOWRAP BGCOLOR=\"$THEME->cellcontent\">";
81 } else {
82 echo "<TD WIDTH=\"$tablewidth%\" VALIGN=TOP NOWRAP BGCOLOR=\"$THEME->body\">";
83 }
f9903ed0 84
da664183 85 echo "<TABLE WIDTH=100%>";
86 foreach ($answer as $user) {
87 echo "<TR><TD WIDTH=10 NOWRAP>";
88 print_user_picture($user->id, $course->id, $user->picture);
89 echo "</TD><TD WIDTH=100% NOWRAP>";
90 echo "<P>$user->firstname $user->lastname</P>";
91 echo "</TD></TR>";
92 }
93 echo "</TABLE>";
94
95 echo "</TD>";
f9903ed0 96 }
da664183 97 echo "</TR></TABLE>";
f9903ed0 98
99 print_footer($course);
100
101
102?>
103