3 require_once("../../config.php");
4 require_once("lib.php");
6 // Check that all the parameters have been provided.
8 require_variable($id); // Course Module ID
9 optional_variable($action, ""); // What to look at
10 optional_variable($qid, "0"); // Question id
12 if (! $cm = get_record("course_modules", "id", $id)) {
13 error("Course Module ID was incorrect");
16 if (! $course = get_record("course", "id", $cm->course
)) {
17 error("Course is misconfigured");
20 require_login($course->id
);
22 if (!isteacher($course->id
)) {
23 error("Sorry, only teachers can see this.");
26 if (! $survey = get_record("survey", "id", $cm->instance
)) {
27 error("Survey ID was incorrect");
30 if (! $template = get_record("survey", "id", $survey->template
)) {
31 error("Template ID was incorrect");
34 $showscales = ($template->name
!= 'ciqname');
37 $strreport = get_string("report", "survey");
38 $strsurvey = get_string("modulename", "survey");
39 $strsurveys = get_string("modulenameplural", "survey");
40 $strsummary = get_string("summary", "survey");
41 $strscales = get_string("scales", "survey");
42 $strquestion = get_string("question", "survey");
43 $strquestions = get_string("questions", "survey");
44 $strdownload = get_string("download", "survey");
45 $strallscales = get_string("allscales", "survey");
46 $strallquestions = get_string("allquestions", "survey");
47 $strselectedquestions = get_string("selectedquestions", "survey");
48 $strseemoredetail = get_string("seemoredetail", "survey");
49 $strnotes = get_string("notes", "survey");
51 add_to_log($course->id
, "survey", "view report", "report.php?id=$cm->id", "$survey->id", $cm->id
);
53 if ($course->category
) {
54 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
55 <a href=\"index.php?id=$course->id\">$strsurveys</a> ->
56 <a href=\"view.php?id=$cm->id\">$survey->name</a> -> ";
58 $navigation = "<a href=\"index.php?id=$course->id\">$strsurveys</a> ->
59 <a href=\"view.php?id=$cm->id\">$survey->name</a> -> ";
62 print_header("$course->shortname: $survey->name", "$course->fullname", "$navigation $strreport",
64 update_module_button($cm->id
, $course->id
, $strsurvey), navmenu($course, $cm));
66 /// Check to see if groups are being used in this survey
67 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
68 $menuaction = $action == "student" ?
"students" : $action;
69 $currentgroup = setup_and_print_groups($course, $groupmode,
70 "report.php?id=$cm->id&action=$menuaction&qid=$qid");
76 $users = get_group_users($currentgroup);
78 $users = get_course_users($course->id
);
81 print_simple_box_start("center");
83 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>";
84 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>";
85 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
86 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
87 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
92 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
93 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
94 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
96 $action = "questions";
99 print_simple_box_end();
104 /// Print the menu across the top
109 print_heading($strsummary);
111 if (survey_count_responses($survey->id
, $currentgroup)) {
112 echo "<p align=center><a href=\"report.php?action=scales&id=$id\">";
113 survey_print_graph("id=$id&group=$currentgroup&type=overall.png");
116 echo "<p align=center>".get_string("nobodyyet","survey")."</p>";
121 print_heading($strscales);
123 $questions = get_records_list("survey_questions", "id", $survey->questions
);
124 $questionorder = explode(",", $survey->questions
);
126 foreach ($questionorder as $key => $val) {
127 $question = $questions[$val];
128 if ($question->type
< 0) { // We have some virtual scales. Just show them.
129 $virtualscales = true;
134 foreach ($questionorder as $key => $val) {
135 $question = $questions[$val];
136 if ($question->multi
) {
137 if ($virtualscales && $question->type
> 0) { // Don't show non-virtual scales if virtual
140 echo "<p align=center><a title=\"$strseemoredetail\" href=report.php?action=questions&id=$id&qid=$question->multi>";
141 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
150 if ($qid) { // just get one multi-question
151 $questions = get_records_list("survey_questions", "id", $qid);
152 $questionorder = explode(",", $qid);
154 if ($scale = get_records("survey_questions", "multi", "$qid")) {
155 $scale = array_pop($scale);
156 print_heading("$scale->text - $strselectedquestions");
158 print_heading($strselectedquestions);
161 } else { // get all top-level questions
162 $questions = get_records_list("survey_questions", "id", $survey->questions
);
163 $questionorder = explode(",", $survey->questions
);
165 print_heading($strallquestions);
168 foreach ($questionorder as $key => $val) {
169 $question = $questions[$val];
170 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
171 $virtualscales = true;
176 foreach ($questionorder as $key => $val) {
177 $question = $questions[$val];
179 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
182 $question->text
= get_string($question->text
, "survey");
184 if ($question->multi
) {
185 echo "<h3>$question->text:</h3>";
187 $subquestions = get_records_list("survey_questions", "id", $question->multi
);
188 $subquestionorder = explode(",", $question->multi
);
189 foreach ($subquestionorder as $key => $val) {
190 $subquestion = $subquestions[$val];
191 if ($subquestion->type
> 0) {
192 echo "<p align=center>";
193 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">";
194 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
198 } else if ($question->type
> 0 ) {
199 echo "<p align=center>";
200 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">";
201 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
206 $table->head
= array($question->text
);
207 $table->align
= array ("left");
209 $contents = '<table cellpadding="15" width="100%">';
211 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup, "sa.time ASC")) {
212 foreach ($aaa as $a) {
214 $contents .= '<td nowrap="nowrap" width="10%" valign="top">'.fullname($a).'</td>';
215 $contents .= '<td valign="top">'.$a->answer1
.'</td>';
216 $contents .= "</tr>";
219 $contents .= "</table>";
221 $table->data
[] = array($contents);
231 if (!$question = get_record("survey_questions", "id", $qid)) {
232 error("Question doesn't exist");
234 $question->text
= get_string($question->text
, "survey");
236 $answers = explode(",", get_string($question->options
, "survey"));
238 print_heading("$strquestion: $question->text");
241 $strname = get_string("name", "survey");
242 $strtime = get_string("time", "survey");
243 $stractual = get_string("actual", "survey");
244 $strpreferred = get_string("preferred", "survey");
245 $strdateformat = get_string("strftimedatetime");
248 $table->head
= array("", $strname, $strtime, $stractual, $strpreferred);
249 $table->align
= array ("left", "left", "left", "left", "right");
250 $table->size
= array (35, "", "", "", "");
252 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup)) {
253 foreach ($aaa as $a) {
255 $answer1 = "$a->answer1 - ".$answers[$a->answer1
- 1];
260 $answer2 = "$a->answer2 - ".$answers[$a->answer2
- 1];
265 $table->data
[] = array(
266 print_user_picture($a->userid
, $course->id
, $a->picture
, false, true, true),
267 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>",
280 print_heading(get_string("analysisof", "survey", "$course->students"));
282 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
283 notify(get_string("nobodyyet","survey"));
285 survey_print_all_responses($cm->id
, $results, $course->id
);
291 if (!$user = get_record("user", "id", $student)) {
292 error("Student doesn't exist");
295 print_heading(get_string("analysisof", "survey", fullname($user)));
298 if (survey_get_analysis($survey->id
, $user->id
)) {
299 if (! survey_update_analysis($survey->id
, $user->id
, $notes)) {
300 notify("An error occurred while saving your notes. Sorry.");
302 notify(get_string("savednotes", "survey"));
305 if (! survey_add_analysis($survey->id
, $user->id
, $notes)) {
306 notify("An error occurred while saving your notes. Sorry.");
308 notify(get_string("savednotes", "survey"));
313 echo "<p align=center>";
314 print_user_picture($user->id
, $course->id
, $user->picture
, true);
317 $questions = get_records_list("survey_questions", "id", $survey->questions
);
318 $questionorder = explode(",", $survey->questions
);
321 // Print overall summary
322 echo "<p align=center>";
323 survey_print_graph("id=$id&sid=$student&type=student.png");
328 foreach ($questionorder as $key => $val) {
329 $question = $questions[$val];
330 if ($question->type
< 0) { // We have some virtual scales. Just show them.
331 $virtualscales = true;
336 foreach ($questionorder as $key => $val) {
337 $question = $questions[$val];
338 if ($question->multi
) {
339 if ($virtualscales && $question->type
> 0) { // Don't show non-virtual scales if virtual
342 echo "<p align=center>";
343 echo "<a title=\"$strseemoredetail\" href=report.php?action=questions&id=$id&qid=$question->multi>";
344 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png");
350 // Print non-scale questions
352 foreach ($questionorder as $key => $val) {
353 $question = $questions[$val];
354 if ($question->type
== 0 or $question->type
== 1) {
355 if ($answer = survey_get_user_answer($survey->id
, $question->id
, $user->id
)) {
357 $table->head
= array(get_string($question->text
, "survey"));
358 $table->align
= array ("left");
359 $table->data
[] = array("$answer->answer1");
366 if ($rs = survey_get_analysis($survey->id
, $user->id
)) {
371 echo "<hr noshade size=1>";
373 echo "<form action=report.php method=post name=form>";
374 echo "<h3>$strnotes:</h3>";
376 echo "<textarea name=notes rows=10 cols=60>";
378 echo "</textarea><br>";
379 echo "<input type=hidden name=action value=student>";
380 echo "<input type=hidden name=student value=$student>";
381 echo "<input type=hidden name=id value=$cm->id>";
382 echo "<input type=submit value=\"".get_string("savechanges")."\">";
383 echo "</blockquote>";
391 print_heading($strdownload);
393 echo '<p align="center">'.get_string("downloadinfo", "survey").'</p>';
396 $options["id"] = "$cm->id";
397 $options["type"] = "xls";
398 $options["group"] = $currentgroup;
399 print_single_button("download.php", $options, get_string("downloadexcel", "survey"));
401 $options["type"] = "txt";
402 print_single_button("download.php", $options, get_string("downloadtext", "survey"));
408 print_footer($course);