Initial revision
[moodle.git] / mod / choice / report.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3 require("../../config.php");
4
5 require_variable($id); // course module
6
7 if (! $cm = get_record("course_modules", "id", $id)) {
8 error("Course Module ID was incorrect");
9 }
10
11 if (! $course = get_record("course", "id", $cm->course)) {
12 error("Course module is misconfigured");
13 }
14
15 require_login($course->id);
16
17 if (!isteacher($course->id)) {
18 error("Only teachers can look at this page");
19 }
20
21 if (! $choice = get_record("choice", "id", $cm->instance)) {
22 error("Course module is incorrect");
23 }
24
25 add_to_log("View choices report", $course->id);
26
27 print_header("$course->shortname: $choice->name: Responses", "$course->fullname",
28 "<A HREF=/course/view.php?id=$course->id>$course->shortname</A> ->
29 <A HREF=index.php?id=$course->id>Choices</A> ->
30 <A HREF=view.php?id=$cm->id>$choice->name</A> -> Responses", "");
31
32
33 if (! $participants = get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
34 WHERE (s.course = '$course->id' AND s.user = u.id)
35 OR (t.course = '$course->id' AND t.user = u.id)
36 ORDER BY u.lastaccess DESC")) {
37
38 notify("No participants (strange)", "/course/view.php?id=$course->id");
39 die;
40 }
41
42 if ( $allanswers = get_records_sql("SELECT * FROM choice_answers WHERE choice='$choice->id'")) {
43 foreach ($allanswers as $aa) {
44 $answers[$aa->user] = $aa;
45 }
46
47 } else {
48 $answers = array () ;
49 }
50
51
52
53 $timenow = time();
54
55 echo "<TABLE BORDER=1 CELLSPACING=0 valign=top align=center cellpadding=10>";
56 foreach ($participants as $user) {
57 $answer = $answers[$user->id];
58
59 echo "<TR>";
60
61 echo "<TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
62 print_user_picture($user->id, $course->id, $user->picture);
63 echo "</TD>";
64
65 echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">$user->firstname $user->lastname</TD>";
66 echo "<TD><P>&nbsp;";
67 if ($answer->timemodified) {
68 echo moodledate($answer->timemodified);
69 }
70
71 echo "</P> </TD>";
72
73 echo "<TD ALIGN=CENTER BGCOLOR=\"$THEME->cellcontent\"><P>";
74 switch ($answer->answer) {
75 case 1:
76 echo "$choice->answer1";
77 break;
78 case 2:
79 echo "$choice->answer2";
80 break;
81 default:
82 echo "Undecided";
83 break;
84
85 }
86 echo "</P></TD></TR>";
87 }
88 echo "</TABLE>";
89
90 print_footer($course);
91
92
93?>
94