f9903ed0 |
1 | <?PHP // $Id$ |
2 | |
3 | // Graph size |
4 | $GHEIGHT = 500; |
07cb9964 |
5 | $GWIDTH = 900; |
f9903ed0 |
6 | |
7 | $QTYPE = array ( |
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 | |
21 | function get_survey_status($survey) { |
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 | |
38 | function get_responses_for_survey($surveyid) { |
39 | global $db; |
40 | |
41 | if ($aa = $db->Execute("SELECT user FROM survey_answers WHERE survey = $surveyid GROUP BY user")) { |
42 | if ($aa) { |
43 | return $aa->RowCount(); |
44 | } else { |
45 | return -1; |
46 | } |
47 | } else { |
48 | return -1; |
49 | } |
50 | } |
51 | |
b416a1c3 |
52 | function print_all_responses($survey, $results) { |
53 | |
54 | global $THEME; |
55 | |
56 | echo "<TABLE CELLPADDING=5 CELLSPACING=2 ALIGN=CENTER>"; |
57 | echo "<TR><TD>Name<TD>Time<TD>Answered</TR>"; |
58 | |
59 | foreach ($results as $a) { |
60 | |
61 | echo "<TR>"; |
62 | echo "<TD><A HREF=\"report.php?action=student&student=$a->id&id=$survey\">$a->firstname $a->lastname</A></TD>"; |
7a302afc |
63 | echo "<TD>".userdate($a->time, "%e %B %Y, %I:%M %p")."</TD>"; |
b416a1c3 |
64 | echo "<TD align=right>$a->numanswers</TD>"; |
65 | echo "</TR>"; |
66 | } |
67 | echo "</TABLE>"; |
68 | } |
69 | |
70 | |
71 | function get_survey_responses($survey) { |
72 | return get_records_sql("SELECT a.time as time, count(*) as numanswers, u.* |
73 | FROM survey_answers AS a, user AS u |
74 | WHERE a.answer1 <> '0' AND a.answer2 <> '0' |
75 | AND a.survey = $survey |
76 | AND a.user = u.id |
77 | GROUP BY a.user ORDER BY a.time ASC"); |
78 | } |
79 | |
80 | function count_completed_surveys($survey) { |
81 | if ($responses = get_survey_responses($survey)) { |
82 | return count($responses); |
83 | } else { |
84 | return 0; |
85 | } |
86 | } |
87 | |
f9903ed0 |
88 | |
89 | function get_template_name($templateid) { |
90 | global $db; |
91 | |
92 | if ($templateid) { |
93 | if ($ss = $db->Execute("SELECT name FROM surveys WHERE id = $templateid")) { |
94 | return $ss->fields["name"]; |
95 | } |
96 | } else { |
97 | return ""; |
98 | } |
99 | } |
100 | |
0d22e7cc |
101 | |
f9903ed0 |
102 | function update_survey_analysis($survey, $user, $notes) { |
103 | global $db; |
104 | |
105 | return $db->Execute("UPDATE survey_analysis SET notes='$notes' WHERE survey='$survey' and user='$user'"); |
106 | } |
107 | |
0d22e7cc |
108 | |
f9903ed0 |
109 | function add_survey_analysis($survey, $user, $notes) { |
110 | global $db; |
111 | |
112 | return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'"); |
113 | } |
114 | |
115 | |
0d22e7cc |
116 | function survey_user_summary($course, $user, $mod, $survey) { |
117 | global $CFG; |
118 | } |
119 | |
120 | |
121 | function survey_user_outline($course, $user, $mod, $survey) { |
122 | if ($answers = get_records_sql("SELECT * FROM survey_answers WHERE survey='$survey->id' AND user='$user->id'")) { |
123 | |
124 | $lastanswer = array_pop($answers); |
125 | |
126 | $result->info = "Done"; |
127 | $result->time = $lastanswer->time; |
128 | return $result; |
0d22e7cc |
129 | } |
130 | return NULL; |
131 | } |
132 | |
133 | |
134 | function survey_user_complete($course, $user, $mod, $survey) { |
3f4deb2b |
135 | global $CFG; |
0d22e7cc |
136 | |
137 | if (survey_already_done($survey->id, $user->id)) { |
138 | echo "<IMG SRC=\"$CFG->wwwroot/mod/survey/graph.php?id=$mod->id&sid=$user->id&type=student.png\">"; |
139 | } else { |
140 | echo "Not done yet"; |
141 | } |
142 | } |
f9903ed0 |
143 | |
144 | ?> |