3 require_once("../../config.php");
4 require_once("lib.php");
6 // Check that all the parameters have been provided.
8 $id = required_param('id', PARAM_INT
); // Course Module ID
9 $action = optional_param('action', '', PARAM_ALPHA
); // What to look at
10 $qid = optional_param('qid', 0, PARAM_RAW
); // Question IDs comma-separated list
11 $student = optional_param('student', 0, PARAM_INT
); // Student ID
12 $notes = optional_param('notes', '', PARAM_RAW
); // Save teachers notes
14 $qids = explode(',', $qid);
15 $qids = clean_param($qids, PARAM_INT
);
16 $qid = implode (',', $qids);
18 if (! $cm = get_coursemodule_from_id('survey', $id)) {
19 error("Course Module ID was incorrect");
22 if (! $course = get_record("course", "id", $cm->course
)) {
23 error("Course is misconfigured");
26 require_login($course->id
, false);
28 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
30 require_capability('mod/survey:readresponses', $context);
32 if (! $survey = get_record("survey", "id", $cm->instance
)) {
33 error("Survey ID was incorrect");
36 if (! $template = get_record("survey", "id", $survey->template
)) {
37 error("Template ID was incorrect");
40 $showscales = ($template->name
!= 'ciqname');
43 $strreport = get_string("report", "survey");
44 $strsurvey = get_string("modulename", "survey");
45 $strsurveys = get_string("modulenameplural", "survey");
46 $strsummary = get_string("summary", "survey");
47 $strscales = get_string("scales", "survey");
48 $strquestion = get_string("question", "survey");
49 $strquestions = get_string("questions", "survey");
50 $strdownload = get_string("download", "survey");
51 $strallscales = get_string("allscales", "survey");
52 $strallquestions = get_string("allquestions", "survey");
53 $strselectedquestions = get_string("selectedquestions", "survey");
54 $strseemoredetail = get_string("seemoredetail", "survey");
55 $strnotes = get_string("notes", "survey");
57 add_to_log($course->id
, "survey", "view report", "report.php?id=$cm->id", "$survey->id", $cm->id
);
59 if ($course->category
) {
60 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
61 <a href=\"index.php?id=$course->id\">$strsurveys</a> ->
62 <a href=\"view.php?id=$cm->id\">".format_string($survey->name
,true)."</a> -> ";
64 $navigation = "<a href=\"index.php?id=$course->id\">$strsurveys</a> ->
65 <a href=\"view.php?id=$cm->id\">".format_string($survey->name
,true)."</a> -> ";
68 print_header("$course->shortname: ".format_string($survey->name
), "$course->fullname", "$navigation $strreport",
70 update_module_button($cm->id
, $course->id
, $strsurvey), navmenu($course, $cm));
72 /// Check to see if groups are being used in this survey
73 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
74 $menuaction = $action == "student" ?
"students" : $action;
75 $currentgroup = setup_and_print_groups($course, $groupmode,
76 "report.php?id=$cm->id&action=$menuaction&qid=$qid");
82 $users = get_group_users($currentgroup);
84 $users = get_course_users($course->id
);
87 print_simple_box_start("center");
89 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>";
90 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>";
91 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
92 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
93 if (has_capability('mod/survey:download', $context)) {
94 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
100 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
101 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
102 if (has_capability('mod/survey:download', $context)) {
103 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
105 if (empty($action)) {
106 $action = "questions";
109 print_simple_box_end();
114 /// Print the menu across the top
116 $virtualscales = false;
121 print_heading($strsummary);
123 if (survey_count_responses($survey->id
, $currentgroup)) {
124 echo "<center><a href=\"report.php?action=scales&id=$id\">";
125 survey_print_graph("id=$id&group=$currentgroup&type=overall.png");
126 echo "</a></center>";
128 notify(get_string("nobodyyet","survey"));
133 print_heading($strscales);
135 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
136 notify(get_string("nobodyyet","survey"));
140 $questions = get_records_list("survey_questions", "id", $survey->questions
);
141 $questionorder = explode(",", $survey->questions
);
143 foreach ($questionorder as $key => $val) {
144 $question = $questions[$val];
145 if ($question->type
< 0) { // We have some virtual scales. Just show them.
146 $virtualscales = true;
151 foreach ($questionorder as $key => $val) {
152 $question = $questions[$val];
153 if ($question->multi
) {
154 if (!empty($virtualscales) && $question->type
> 0) { // Don't show non-virtual scales if virtual
157 echo "<p align=\"center\"><a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
158 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
159 echo "</a></p><br />";
168 if ($qid) { // just get one multi-question
169 $questions = get_records_list("survey_questions", "id", $qid);
170 $questionorder = explode(",", $qid);
172 if ($scale = get_records("survey_questions", "multi", "$qid")) {
173 $scale = array_pop($scale);
174 print_heading("$scale->text - $strselectedquestions");
176 print_heading($strselectedquestions);
179 } else { // get all top-level questions
180 $questions = get_records_list("survey_questions", "id", $survey->questions
);
181 $questionorder = explode(",", $survey->questions
);
183 print_heading($strallquestions);
186 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
187 notify(get_string("nobodyyet","survey"));
191 foreach ($questionorder as $key => $val) {
192 $question = $questions[$val];
193 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
194 $virtualscales = true;
199 foreach ($questionorder as $key => $val) {
200 $question = $questions[$val];
202 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
205 $question->text
= get_string($question->text
, "survey");
207 if ($question->multi
) {
208 echo "<h3>$question->text:</h3>";
210 $subquestions = get_records_list("survey_questions", "id", $question->multi
);
211 $subquestionorder = explode(",", $question->multi
);
212 foreach ($subquestionorder as $key => $val) {
213 $subquestion = $subquestions[$val];
214 if ($subquestion->type
> 0) {
215 echo "<p align=\"center\">";
216 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">";
217 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
221 } else if ($question->type
> 0 ) {
222 echo "<p align=\"center\">";
223 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">";
224 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
229 $table->head
= array($question->text
);
230 $table->align
= array ("left");
232 $contents = '<table cellpadding="15" width="100%">';
234 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup, "sa.time ASC")) {
235 foreach ($aaa as $a) {
237 $contents .= '<td nowrap="nowrap" width="10%" valign="top">'.fullname($a).'</td>';
238 $contents .= '<td valign="top">'.$a->answer1
.'</td>';
239 $contents .= "</tr>";
242 $contents .= "</table>";
244 $table->data
[] = array($contents);
255 if (!$question = get_record("survey_questions", "id", $qid)) {
256 error("Question doesn't exist");
258 $question->text
= get_string($question->text
, "survey");
260 $answers = explode(",", get_string($question->options
, "survey"));
262 print_heading("$strquestion: $question->text");
265 $strname = get_string("name", "survey");
266 $strtime = get_string("time", "survey");
267 $stractual = get_string("actual", "survey");
268 $strpreferred = get_string("preferred", "survey");
269 $strdateformat = get_string("strftimedatetime");
272 $table->head
= array("", $strname, $strtime, $stractual, $strpreferred);
273 $table->align
= array ("left", "left", "left", "left", "right");
274 $table->size
= array (35, "", "", "", "");
276 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup)) {
277 foreach ($aaa as $a) {
279 $answer1 = "$a->answer1 - ".$answers[$a->answer1
- 1];
284 $answer2 = "$a->answer2 - ".$answers[$a->answer2
- 1];
289 $table->data
[] = array(
290 print_user_picture($a->userid
, $course->id
, $a->picture
, false, true, true),
291 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>",
304 print_heading(get_string("analysisof", "survey", "$course->students"));
306 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
307 notify(get_string("nobodyyet","survey"));
309 survey_print_all_responses($cm->id
, $results, $course->id
);
315 if (!$user = get_record("user", "id", $student)) {
316 error("Student doesn't exist");
319 print_heading(get_string("analysisof", "survey", fullname($user)));
321 if ($notes != '' and confirm_sesskey()) {
322 if (survey_get_analysis($survey->id
, $user->id
)) {
323 if (! survey_update_analysis($survey->id
, $user->id
, $notes)) {
324 notify("An error occurred while saving your notes. Sorry.");
326 notify(get_string("savednotes", "survey"));
329 if (! survey_add_analysis($survey->id
, $user->id
, $notes)) {
330 notify("An error occurred while saving your notes. Sorry.");
332 notify(get_string("savednotes", "survey"));
337 echo "<p align=\"center\">";
338 print_user_picture($user->id
, $course->id
, $user->picture
, true);
341 $questions = get_records_list("survey_questions", "id", $survey->questions
);
342 $questionorder = explode(",", $survey->questions
);
345 // Print overall summary
346 echo "<p align=\"center\">";
347 survey_print_graph("id=$id&sid=$student&type=student.png");
352 foreach ($questionorder as $key => $val) {
353 $question = $questions[$val];
354 if ($question->type
< 0) { // We have some virtual scales. Just show them.
355 $virtualscales = true;
360 foreach ($questionorder as $key => $val) {
361 $question = $questions[$val];
362 if ($question->multi
) {
363 if ($virtualscales && $question->type
> 0) { // Don't show non-virtual scales if virtual
366 echo "<p align=\"center\">";
367 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
368 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png");
369 echo "</a></p><br />";
374 // Print non-scale questions
376 foreach ($questionorder as $key => $val) {
377 $question = $questions[$val];
378 if ($question->type
== 0 or $question->type
== 1) {
379 if ($answer = survey_get_user_answer($survey->id
, $question->id
, $user->id
)) {
381 $table->head
= array(get_string($question->text
, "survey"));
382 $table->align
= array ("left");
383 $table->data
[] = array(s($answer->answer1
)); // no html here, just plain text
390 if ($rs = survey_get_analysis($survey->id
, $user->id
)) {
395 echo "<hr noshade=\"noshade\" size=\"1\" />";
397 echo "<form action=\"report.php\" method=\"post\" name=\"form\">";
398 echo "<h3>$strnotes:</h3>";
400 echo "<textarea name=\"notes\" rows=\"10\" cols=\"60\">";
402 echo "</textarea><br />";
403 echo "<input type=\"hidden\" name=\"action\" value=\"student\" />";
404 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
405 echo "<input type=\"hidden\" name=\"student\" value=\"$student\" />";
406 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
407 echo "<input type=\"submit\" value=\"".get_string("savechanges")."\" />";
408 echo "</blockquote>";
416 print_heading($strdownload);
418 require_capability('mod/survey:download', $context);
420 echo '<p align="center">'.get_string("downloadinfo", "survey").'</p>';
423 $options["id"] = "$cm->id";
424 $options["type"] = "xls";
425 $options["group"] = $currentgroup;
426 print_single_button("download.php", $options, get_string("downloadexcel", "survey"));
428 $options["type"] = "txt";
429 print_single_button("download.php", $options, get_string("downloadtext", "survey"));
435 print_footer($course);