Much longer images for long tabs .... hope this doesn't slow them
[moodle.git] / mod / choice / report.php
CommitLineData
1c61c8d6 1<?php // $Id$
f9903ed0 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
ec81373f 16 require_login($course->id, false, $cm);
f9903ed0 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
c61d50b8 32 print_header_simple(format_string($choice->name).": $strresponses", "",
1ff45e74 33 "<a href=\"index.php?id=$course->id\">$strchoices</a> ->
c61d50b8 34 <a href=\"view.php?id=$cm->id\">".format_string($choice->name,true)."</a> -> $strresponses", "");
f9903ed0 35
b6ee2d82 36/// Check to see if groups are being used in this choice
37 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
38 $currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id");
39 } else {
40 $currentgroup = false;
41 }
42
43 if ($currentgroup) {
a12f686b 44 $users = get_group_users($currentgroup, "u.firstname ASC");
b6ee2d82 45 } else {
46 $users = get_course_users($course->id, "u.firstname ASC");
47 }
f9903ed0 48
b6ee2d82 49 if (!$users) {
50 print_heading(get_string("nousersyet"));
51 print_footer($course);
52 exit;
f9903ed0 53 }
54
6fd87e3b 55 if ( $allresponses = get_records("choice_responses", "choice", $choice->id)) {
56 foreach ($allresponses as $aa) {
ebc3bd2b 57 $answers[$aa->userid] = $aa;
f9903ed0 58 }
f9903ed0 59 } else {
60 $answers = array () ;
61 }
f9903ed0 62
63 $timenow = time();
64
ec81373f 65 foreach ($choice->answer as $key => $answer) {
cd3fccff 66 $useranswer[$key] = array();
66062dd3 67 }
da664183 68 foreach ($users as $user) {
dcde9f02 69 if (!empty($answers[$user->id])) {
70 $answer = $answers[$user->id];
71 } else {
6fd87e3b 72 $answer->answerid = 0;
dcde9f02 73 }
6fd87e3b 74 $useranswer[(int)$answer->answerid][] = $user;
da664183 75 }
ec81373f 76 foreach ($choice->answer as $key => $answer) {
cd3fccff 77 if (!$choice->answer[$key]) {
78 unset($useranswer[$key]); // Throw away any data that doesn't apply
79 }
80 }
da664183 81 ksort($useranswer);
f9903ed0 82
da664183 83 $tablewidth = (int) (100.0 / count($useranswer));
f9903ed0 84
8b50d2a7 85 echo "<table cellpadding=\"5\" cellspacing=\"10\" align=\"center\">";
86 echo "<tr>";
da664183 87 foreach ($useranswer as $key => $answer) {
a9d5f810 88 echo "<th class=\"col$key\" width=\"$tablewidth%\">";
c61d50b8 89 echo format_string(choice_get_answer($choice, $key));
8b50d2a7 90 echo "</th>";
da664183 91 }
8b50d2a7 92 echo "</tr><tr>";
f9903ed0 93
da664183 94 foreach ($useranswer as $key => $answer) {
a9d5f810 95 echo "<td class=\"col$key\" width=\"$tablewidth%\" valign=\"top\" nowrap=\"nowrap\">";
f9903ed0 96
8b50d2a7 97 echo "<table width=\"100%\">";
da664183 98 foreach ($answer as $user) {
d526e68e 99 echo "<tr><td width=\"10\" nowrap=\"nowrap\">";
da664183 100 print_user_picture($user->id, $course->id, $user->picture);
d526e68e 101 echo "</td><td width=\"100%\" nowrap=\"nowrap\">";
b3679ca4 102 echo "<p>".fullname($user, true)."</p>";
8b50d2a7 103 echo "</td></tr>";
da664183 104 }
d526e68e 105 echo "<tr><td colspan=\"2\">&nbsp;</td></tr>"; /// need to have at least one row within table tags
8b50d2a7 106 echo "</table>";
da664183 107
8b50d2a7 108 echo "</td>";
f9903ed0 109 }
8b50d2a7 110 echo "</tr></table>";
f9903ed0 111
112 print_footer($course);
113
ec81373f 114
f9903ed0 115?>
116