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> -> ";
69 $navlinks[] = array('name' => $strsurveys, 'link' => "index.php?id=$course->id", 'type' => 'activity');
70 $navlinks[] = array('name' => format_string($survey->name
), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
71 $navlinks[] = array('name' => $strreport, 'link' => '', 'type' => 'title');
72 $navigation = build_navigation($navlinks);
74 print_header("$course->shortname: ".format_string($survey->name
), $course->fullname
, $navigation,
76 update_module_button($cm->id
, $course->id
, $strsurvey), navmenu($course, $cm));
78 /// Check to see if groups are being used in this survey
79 if ($groupmode = groupmode($course, $cm)) { // Groups are being used
80 $menuaction = $action == "student" ?
"students" : $action;
81 $currentgroup = setup_and_print_groups($course, $groupmode,
82 "report.php?id=$cm->id&action=$menuaction&qid=$qid");
88 $users = get_group_users($currentgroup);
90 $users = get_course_users($course->id
);
93 print_simple_box_start("center");
95 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>";
96 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>";
97 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
98 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
99 if (has_capability('mod/survey:download', $context)) {
100 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
102 if (empty($action)) {
106 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
107 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
108 if (has_capability('mod/survey:download', $context)) {
109 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
111 if (empty($action)) {
112 $action = "questions";
115 print_simple_box_end();
120 /// Print the menu across the top
122 $virtualscales = false;
127 print_heading($strsummary);
129 if (survey_count_responses($survey->id
, $currentgroup)) {
130 echo "<div class='reportsummary'><a href=\"report.php?action=scales&id=$id\">";
131 survey_print_graph("id=$id&group=$currentgroup&type=overall.png");
134 notify(get_string("nobodyyet","survey"));
139 print_heading($strscales);
141 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
142 notify(get_string("nobodyyet","survey"));
146 $questions = get_records_list("survey_questions", "id", $survey->questions
);
147 $questionorder = explode(",", $survey->questions
);
149 foreach ($questionorder as $key => $val) {
150 $question = $questions[$val];
151 if ($question->type
< 0) { // We have some virtual scales. Just show them.
152 $virtualscales = true;
157 foreach ($questionorder as $key => $val) {
158 $question = $questions[$val];
159 if ($question->multi
) {
160 if (!empty($virtualscales) && $question->type
> 0) { // Don't show non-virtual scales if virtual
163 echo "<p class=\"centerpara\"><a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
164 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
165 echo "</a></p><br />";
174 if ($qid) { // just get one multi-question
175 $questions = get_records_list("survey_questions", "id", $qid);
176 $questionorder = explode(",", $qid);
178 if ($scale = get_records("survey_questions", "multi", "$qid")) {
179 $scale = array_pop($scale);
180 print_heading("$scale->text - $strselectedquestions");
182 print_heading($strselectedquestions);
185 } else { // get all top-level questions
186 $questions = get_records_list("survey_questions", "id", $survey->questions
);
187 $questionorder = explode(",", $survey->questions
);
189 print_heading($strallquestions);
192 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
193 notify(get_string("nobodyyet","survey"));
197 foreach ($questionorder as $key => $val) {
198 $question = $questions[$val];
199 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
200 $virtualscales = true;
205 foreach ($questionorder as $key => $val) {
206 $question = $questions[$val];
208 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
211 $question->text
= get_string($question->text
, "survey");
213 if ($question->multi
) {
214 echo "<h3>$question->text:</h3>";
216 $subquestions = get_records_list("survey_questions", "id", $question->multi
);
217 $subquestionorder = explode(",", $question->multi
);
218 foreach ($subquestionorder as $key => $val) {
219 $subquestion = $subquestions[$val];
220 if ($subquestion->type
> 0) {
221 echo "<p class=\"centerpara\">";
222 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">";
223 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
227 } else if ($question->type
> 0 ) {
228 echo "<p class=\"centerpara\">";
229 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">";
230 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
235 $table->head
= array($question->text
);
236 $table->align
= array ("left");
238 $contents = '<table cellpadding="15" width="100%">';
240 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup, "sa.time ASC")) {
241 foreach ($aaa as $a) {
243 $contents .= '<td class="fullnamecell">'.fullname($a).'</td>';
244 $contents .= '<td valign="top">'.$a->answer1
.'</td>';
245 $contents .= "</tr>";
248 $contents .= "</table>";
250 $table->data
[] = array($contents);
261 if (!$question = get_record("survey_questions", "id", $qid)) {
262 error("Question doesn't exist");
264 $question->text
= get_string($question->text
, "survey");
266 $answers = explode(",", get_string($question->options
, "survey"));
268 print_heading("$strquestion: $question->text");
271 $strname = get_string("name", "survey");
272 $strtime = get_string("time", "survey");
273 $stractual = get_string("actual", "survey");
274 $strpreferred = get_string("preferred", "survey");
275 $strdateformat = get_string("strftimedatetime");
278 $table->head
= array("", $strname, $strtime, $stractual, $strpreferred);
279 $table->align
= array ("left", "left", "left", "left", "right");
280 $table->size
= array (35, "", "", "", "");
282 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup)) {
283 foreach ($aaa as $a) {
285 $answer1 = "$a->answer1 - ".$answers[$a->answer1
- 1];
290 $answer2 = "$a->answer2 - ".$answers[$a->answer2
- 1];
295 $table->data
[] = array(
296 print_user_picture($a->userid
, $course->id
, $a->picture
, false, true, true),
297 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>",
310 print_heading(get_string("analysisof", "survey", "$course->students"));
312 if (! $results = survey_get_responses($survey->id
, $currentgroup) ) {
313 notify(get_string("nobodyyet","survey"));
315 survey_print_all_responses($cm->id
, $results, $course->id
);
321 if (!$user = get_record("user", "id", $student)) {
322 error("Student doesn't exist");
325 print_heading(get_string("analysisof", "survey", fullname($user)));
327 if ($notes != '' and confirm_sesskey()) {
328 if (survey_get_analysis($survey->id
, $user->id
)) {
329 if (! survey_update_analysis($survey->id
, $user->id
, $notes)) {
330 notify("An error occurred while saving your notes. Sorry.");
332 notify(get_string("savednotes", "survey"));
335 if (! survey_add_analysis($survey->id
, $user->id
, $notes)) {
336 notify("An error occurred while saving your notes. Sorry.");
338 notify(get_string("savednotes", "survey"));
343 echo "<p <p class=\"centerpara\">";
344 print_user_picture($user->id
, $course->id
, $user->picture
, true);
347 $questions = get_records_list("survey_questions", "id", $survey->questions
);
348 $questionorder = explode(",", $survey->questions
);
351 // Print overall summary
352 echo "<p <p class=\"centerpara\">>";
353 survey_print_graph("id=$id&sid=$student&type=student.png");
358 foreach ($questionorder as $key => $val) {
359 $question = $questions[$val];
360 if ($question->type
< 0) { // We have some virtual scales. Just show them.
361 $virtualscales = true;
366 foreach ($questionorder as $key => $val) {
367 $question = $questions[$val];
368 if ($question->multi
) {
369 if ($virtualscales && $question->type
> 0) { // Don't show non-virtual scales if virtual
372 echo "<p class=\"centerpara\">";
373 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
374 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png");
375 echo "</a></p><br />";
380 // Print non-scale questions
382 foreach ($questionorder as $key => $val) {
383 $question = $questions[$val];
384 if ($question->type
== 0 or $question->type
== 1) {
385 if ($answer = survey_get_user_answer($survey->id
, $question->id
, $user->id
)) {
387 $table->head
= array(get_string($question->text
, "survey"));
388 $table->align
= array ("left");
389 $table->data
[] = array(s($answer->answer1
)); // no html here, just plain text
396 if ($rs = survey_get_analysis($survey->id
, $user->id
)) {
401 echo "<hr noshade=\"noshade\" size=\"1\" />";
402 echo "<div class='studentreport'>";
403 echo "<form action=\"report.php\" method=\"post\">";
404 echo "<h3>$strnotes:</h3>";
406 echo "<textarea name=\"notes\" rows=\"10\" cols=\"60\">";
408 echo "</textarea><br />";
409 echo "<input type=\"hidden\" name=\"action\" value=\"student\" />";
410 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
411 echo "<input type=\"hidden\" name=\"student\" value=\"$student\" />";
412 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
413 echo "<input type=\"submit\" value=\"".get_string("savechanges")."\" />";
414 echo "</blockquote>";
422 print_heading($strdownload);
424 require_capability('mod/survey:download', $context);
426 echo '<p class="centerpara">'.get_string("downloadinfo", "survey").'</p>';
428 echo '<div class="reportbuttons">';
430 $options["id"] = "$cm->id";
431 $options["group"] = $currentgroup;
433 $options["type"] = "ods";
434 print_single_button("download.php", $options, get_string("downloadods"));
436 $options["type"] = "xls";
437 print_single_button("download.php", $options, get_string("downloadexcel"));
439 $options["type"] = "txt";
440 print_single_button("download.php", $options, get_string("downloadtext"));
446 print_footer($course);