f9903ed0 |
1 | <?PHP // $Id$ |
2 | |
3 | // Graph size |
551b0b98 |
4 | $SURVEY_GHEIGHT = 500; |
5 | $SURVEY_GWIDTH = 900; |
f9903ed0 |
6 | |
551b0b98 |
7 | $SURVEY_QTYPE = array ( |
f9903ed0 |
8 | "-3" => "Virtual Actual and Preferred", |
9 | "-2" => "Virtual Preferred", |
10 | "-1" => "Virtual Actual", |
11 | "0" => "Text", |
12 | "1" => "Actual", |
13 | "2" => "Preferred", |
14 | "3" => "Actual and Preferred", |
15 | ); |
16 | |
17 | function survey_already_done($survey, $user) { |
18 | return record_exists_sql("SELECT * FROM survey_answers WHERE survey='$survey' AND user='$user'"); |
19 | } |
20 | |
551b0b98 |
21 | function survey_get_status($survey) { |
f9903ed0 |
22 | |
23 | $timenow = time(); |
24 | if ($survey->locked) { |
25 | if (($survey->timeopen <= $timenow) && ($timenow <= $survey->timeclose)) { |
26 | return "released"; |
27 | } else if ($survey->timenow >= $survey->timeclose) { |
28 | return "finished"; |
29 | } else { |
30 | return "error"; |
31 | } |
32 | } else { |
33 | return "editing"; |
34 | } |
35 | |
36 | } |
37 | |
551b0b98 |
38 | function survey_get_responses($survey) { |
39 | return get_records_sql("SELECT a.time as time, count(*) as numanswers, u.* |
40 | FROM survey_answers AS a, user AS u |
41 | WHERE a.answer1 <> '0' AND a.answer2 <> '0' |
42 | AND a.survey = $survey |
43 | AND a.user = u.id |
44 | GROUP BY a.user ORDER BY a.time ASC"); |
45 | } |
f9903ed0 |
46 | |
362f9c9c |
47 | function survey_count_responses($survey) { |
551b0b98 |
48 | if ($responses = survey_get_responses($survey)) { |
49 | return count($responses); |
50 | } else { |
51 | return 0; |
52 | } |
f9903ed0 |
53 | } |
54 | |
b416a1c3 |
55 | |
551b0b98 |
56 | function survey_print_all_responses($survey, $results) { |
b416a1c3 |
57 | global $THEME; |
58 | |
59 | echo "<TABLE CELLPADDING=5 CELLSPACING=2 ALIGN=CENTER>"; |
60 | echo "<TR><TD>Name<TD>Time<TD>Answered</TR>"; |
61 | |
62 | foreach ($results as $a) { |
63 | |
64 | echo "<TR>"; |
65 | echo "<TD><A HREF=\"report.php?action=student&student=$a->id&id=$survey\">$a->firstname $a->lastname</A></TD>"; |
7a302afc |
66 | echo "<TD>".userdate($a->time, "%e %B %Y, %I:%M %p")."</TD>"; |
b416a1c3 |
67 | echo "<TD align=right>$a->numanswers</TD>"; |
68 | echo "</TR>"; |
69 | } |
70 | echo "</TABLE>"; |
71 | } |
72 | |
b416a1c3 |
73 | |
551b0b98 |
74 | function survey_get_template_name($templateid) { |
f9903ed0 |
75 | global $db; |
76 | |
77 | if ($templateid) { |
78 | if ($ss = $db->Execute("SELECT name FROM surveys WHERE id = $templateid")) { |
79 | return $ss->fields["name"]; |
80 | } |
81 | } else { |
82 | return ""; |
83 | } |
84 | } |
85 | |
0d22e7cc |
86 | |
551b0b98 |
87 | function survey_get_analysis($survey, $user) { |
88 | global $db; |
89 | |
90 | return get_record_sql("SELECT notes from survey_analysis WHERE survey='$survey' and user='$user'"); |
91 | } |
92 | |
93 | function survey_update_analysis($survey, $user, $notes) { |
f9903ed0 |
94 | global $db; |
95 | |
96 | return $db->Execute("UPDATE survey_analysis SET notes='$notes' WHERE survey='$survey' and user='$user'"); |
97 | } |
98 | |
0d22e7cc |
99 | |
551b0b98 |
100 | function survey_add_analysis($survey, $user, $notes) { |
f9903ed0 |
101 | global $db; |
102 | |
103 | return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'"); |
104 | } |
105 | |
106 | |
0d22e7cc |
107 | function survey_user_summary($course, $user, $mod, $survey) { |
108 | global $CFG; |
109 | } |
110 | |
111 | |
112 | function survey_user_outline($course, $user, $mod, $survey) { |
113 | if ($answers = get_records_sql("SELECT * FROM survey_answers WHERE survey='$survey->id' AND user='$user->id'")) { |
114 | |
115 | $lastanswer = array_pop($answers); |
116 | |
117 | $result->info = "Done"; |
118 | $result->time = $lastanswer->time; |
119 | return $result; |
0d22e7cc |
120 | } |
121 | return NULL; |
122 | } |
123 | |
124 | |
125 | function survey_user_complete($course, $user, $mod, $survey) { |
3f4deb2b |
126 | global $CFG; |
0d22e7cc |
127 | |
128 | if (survey_already_done($survey->id, $user->id)) { |
129 | echo "<IMG SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$mod->id&sid=$user->id&type=student.png\">"; |
130 | } else { |
131 | echo "Not done yet"; |
132 | } |
133 | } |
f9903ed0 |
134 | |
135 | ?> |