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->id
!= SITEID
) {
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 $crumbs[] = array('name' => $strsurveys, 'link' => "index.php?id=$course->id", 'type' => 'activity');
69 $crumbs[] = array('name' => format_string($survey->name
), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
70 $crumbs[] = array('name' => $strreport, 'link' => '', 'type' => 'title');
71 $navigation = build_navigation($crumbs);
73 print_header("$course->shortname: ".format_string($survey->name
), $course->fullname
, $navigation,
75 update_module_button($cm->id
, $course->id
, $strsurvey), navmenu($course, $cm));
77 /// Check to see if groups are being used in this survey
78 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
79 $menuaction = $action == "student" ?
"students" : $action;
80 $currentgroup = setup_and_print_groups($course, $groupmode,
81 "report.php?id=$cm->id&action=$menuaction&qid=$qid");
87 $users = get_group_users($currentgroup);
89 $users = get_course_users($course->id
);
92 print_simple_box_start("center");
94 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>";
95 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>";
96 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
97 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
98 if (has_capability('mod/survey:download', $context)) {
99 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
101 if (empty($action)) {
105 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
106 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
107 if (has_capability('mod/survey:download', $context)) {
108 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
110 if (empty($action)) {
111 $action = "questions";
114 print_simple_box_end();
119 /// Print the menu across the top
121 $virtualscales = false;
126 print_heading($strsummary);
128 if (survey_count_responses($survey->id
, $currentgroup)) {
129 echo "<div class='reportsummary'><a href=\"report.php?action=scales&id=$id\">";
130 survey_print_graph("id=$id&group=$currentgroup&type=overall.png");
133 notify(get_string("nobodyyet","survey"));
138 print_heading($strscales);
140 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
141 notify(get_string("nobodyyet","survey"));
145 $questions = get_records_list("survey_questions", "id", $survey->questions
);
146 $questionorder = explode(",", $survey->questions
);
148 foreach ($questionorder as $key => $val) {
149 $question = $questions[$val];
150 if ($question->type
< 0) { // We have some virtual scales. Just show them.
151 $virtualscales = true;
156 foreach ($questionorder as $key => $val) {
157 $question = $questions[$val];
158 if ($question->multi
) {
159 if (!empty($virtualscales) && $question->type
> 0) { // Don't show non-virtual scales if virtual
162 echo "<p class=\"centerpara\"><a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
163 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
164 echo "</a></p><br />";
173 if ($qid) { // just get one multi-question
174 $questions = get_records_list("survey_questions", "id", $qid);
175 $questionorder = explode(",", $qid);
177 if ($scale = get_records("survey_questions", "multi", "$qid")) {
178 $scale = array_pop($scale);
179 print_heading("$scale->text - $strselectedquestions");
181 print_heading($strselectedquestions);
184 } else { // get all top-level questions
185 $questions = get_records_list("survey_questions", "id", $survey->questions
);
186 $questionorder = explode(",", $survey->questions
);
188 print_heading($strallquestions);
191 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
192 notify(get_string("nobodyyet","survey"));
196 foreach ($questionorder as $key => $val) {
197 $question = $questions[$val];
198 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
199 $virtualscales = true;
204 foreach ($questionorder as $key => $val) {
205 $question = $questions[$val];
207 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
210 $question->text
= get_string($question->text
, "survey");
212 if ($question->multi
) {
213 echo "<h3>$question->text:</h3>";
215 $subquestions = get_records_list("survey_questions", "id", $question->multi
);
216 $subquestionorder = explode(",", $question->multi
);
217 foreach ($subquestionorder as $key => $val) {
218 $subquestion = $subquestions[$val];
219 if ($subquestion->type
> 0) {
220 echo "<p class=\"centerpara\">";
221 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">";
222 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
226 } else if ($question->type
> 0 ) {
227 echo "<p class=\"centerpara\">";
228 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">";
229 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
234 $table->head
= array($question->text
);
235 $table->align
= array ("left");
237 $contents = '<table cellpadding="15" width="100%">';
239 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup, "sa.time ASC")) {
240 foreach ($aaa as $a) {
242 $contents .= '<td class="fullnamecell">'.fullname($a).'</td>';
243 $contents .= '<td valign="top">'.$a->answer1
.'</td>';
244 $contents .= "</tr>";
247 $contents .= "</table>";
249 $table->data
[] = array($contents);
260 if (!$question = get_record("survey_questions", "id", $qid)) {
261 error("Question doesn't exist");
263 $question->text
= get_string($question->text
, "survey");
265 $answers = explode(",", get_string($question->options
, "survey"));
267 print_heading("$strquestion: $question->text");
270 $strname = get_string("name", "survey");
271 $strtime = get_string("time", "survey");
272 $stractual = get_string("actual", "survey");
273 $strpreferred = get_string("preferred", "survey");
274 $strdateformat = get_string("strftimedatetime");
277 $table->head
= array("", $strname, $strtime, $stractual, $strpreferred);
278 $table->align
= array ("left", "left", "left", "left", "right");
279 $table->size
= array (35, "", "", "", "");
281 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup)) {
282 foreach ($aaa as $a) {
284 $answer1 = "$a->answer1 - ".$answers[$a->answer1
- 1];
289 $answer2 = "$a->answer2 - ".$answers[$a->answer2
- 1];
294 $table->data
[] = array(
295 print_user_picture($a->userid
, $course->id
, $a->picture
, false, true, true),
296 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>",
309 print_heading(get_string("analysisof", "survey", "$course->students"));
311 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
312 notify(get_string("nobodyyet","survey"));
314 survey_print_all_responses($cm->id
, $results, $course->id
);
320 if (!$user = get_record("user", "id", $student)) {
321 error("Student doesn't exist");
324 print_heading(get_string("analysisof", "survey", fullname($user)));
326 if ($notes != '' and confirm_sesskey()) {
327 if (survey_get_analysis($survey->id
, $user->id
)) {
328 if (! survey_update_analysis($survey->id
, $user->id
, $notes)) {
329 notify("An error occurred while saving your notes. Sorry.");
331 notify(get_string("savednotes", "survey"));
334 if (! survey_add_analysis($survey->id
, $user->id
, $notes)) {
335 notify("An error occurred while saving your notes. Sorry.");
337 notify(get_string("savednotes", "survey"));
342 echo "<p <p class=\"centerpara\">";
343 print_user_picture($user->id
, $course->id
, $user->picture
, true);
346 $questions = get_records_list("survey_questions", "id", $survey->questions
);
347 $questionorder = explode(",", $survey->questions
);
350 // Print overall summary
351 echo "<p <p class=\"centerpara\">>";
352 survey_print_graph("id=$id&sid=$student&type=student.png");
357 foreach ($questionorder as $key => $val) {
358 $question = $questions[$val];
359 if ($question->type
< 0) { // We have some virtual scales. Just show them.
360 $virtualscales = true;
365 foreach ($questionorder as $key => $val) {
366 $question = $questions[$val];
367 if ($question->multi
) {
368 if ($virtualscales && $question->type
> 0) { // Don't show non-virtual scales if virtual
371 echo "<p class=\"centerpara\">";
372 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
373 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png");
374 echo "</a></p><br />";
379 // Print non-scale questions
381 foreach ($questionorder as $key => $val) {
382 $question = $questions[$val];
383 if ($question->type
== 0 or $question->type
== 1) {
384 if ($answer = survey_get_user_answer($survey->id
, $question->id
, $user->id
)) {
386 $table->head
= array(get_string($question->text
, "survey"));
387 $table->align
= array ("left");
388 $table->data
[] = array(s($answer->answer1
)); // no html here, just plain text
395 if ($rs = survey_get_analysis($survey->id
, $user->id
)) {
400 echo "<hr noshade=\"noshade\" size=\"1\" />";
401 echo "<div class='studentreport'>";
402 echo "<form action=\"report.php\" method=\"post\">";
403 echo "<h3>$strnotes:</h3>";
405 echo "<textarea name=\"notes\" rows=\"10\" cols=\"60\">";
407 echo "</textarea><br />";
408 echo "<input type=\"hidden\" name=\"action\" value=\"student\" />";
409 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
410 echo "<input type=\"hidden\" name=\"student\" value=\"$student\" />";
411 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
412 echo "<input type=\"submit\" value=\"".get_string("savechanges")."\" />";
413 echo "</blockquote>";
421 print_heading($strdownload);
423 require_capability('mod/survey:download', $context);
425 echo '<p class="centerpara">'.get_string("downloadinfo", "survey").'</p>';
427 echo '<div class="reportbuttons">';
429 $options["id"] = "$cm->id";
430 $options["group"] = $currentgroup;
432 $options["type"] = "ods";
433 print_single_button("download.php", $options, get_string("downloadods"));
435 $options["type"] = "xls";
436 print_single_button("download.php", $options, get_string("downloadexcel"));
438 $options["type"] = "txt";
439 print_single_button("download.php", $options, get_string("downloadtext"));
445 print_footer($course);