Changes to how functions are called from modules - much cleaner now
[moodle.git] / mod / survey / lib.php
CommitLineData
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
17function survey_already_done($survey, $user) {
18 return record_exists_sql("SELECT * FROM survey_answers WHERE survey='$survey' AND user='$user'");
19}
20
21function 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
38function 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 52function 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
71function 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
80function 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
89function 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
101function update_survey_analysis($survey, $user, $notes) {
102 global $db;
103
104 return $db->Execute("UPDATE survey_analysis SET notes='$notes' WHERE survey='$survey' and user='$user'");
105}
106
107function add_survey_analysis($survey, $user, $notes) {
108 global $db;
109
110 return $db->Execute("INSERT INTO survey_analysis SET notes='$notes', survey='$survey', user='$user'");
111}
112
113
114
115?>