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, $cm);
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 $navigation = build_navigation($strreport, $cm);
69 print_header("$course->shortname: ".format_string($survey->name
), $course->fullname
, $navigation,
71 update_module_button($cm->id
, $course->id
, $strsurvey), navmenu($course, $cm));
73 /// Check to see if groups are being used in this survey
74 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
75 $menuaction = $action == "student" ?
"students" : $action;
76 $currentgroup = groups_get_activity_group($cm, true);
77 groups_print_activity_menu($cm, $CFG->wwwroot
. "/mod/survey/report.php?id=$cm->id&action=$menuaction&qid=$qid");
83 $users = groups_get_members($currentgroup);
84 } else if (!empty($CFG->enablegroupings
) && !empty($cm->groupingid
)) {
85 $users = groups_get_grouping_members($cm->groupingid
);
87 $users = get_course_users($course->id
);
89 $groupingid = $cm->groupingid
;
91 print_simple_box_start("center");
93 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>";
94 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>";
95 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
96 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
97 if (has_capability('mod/survey:download', $context)) {
98 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
100 if (empty($action)) {
104 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>";
105 echo " <a href=\"report.php?action=students&id=$id\">$course->students</a>";
106 if (has_capability('mod/survey:download', $context)) {
107 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>";
109 if (empty($action)) {
110 $action = "questions";
113 print_simple_box_end();
118 /// Print the menu across the top
120 $virtualscales = false;
125 print_heading($strsummary);
127 if (survey_count_responses($survey->id
, $currentgroup, $groupingid)) {
128 echo "<div class='reportsummary'><a href=\"report.php?action=scales&id=$id\">";
129 survey_print_graph("id=$id&group=$currentgroup&type=overall.png");
132 notify(get_string("nobodyyet","survey"));
137 print_heading($strscales);
139 if (! $results = survey_get_responses($survey->id
, $currentgroup, $groupingid) ) {
140 notify(get_string("nobodyyet","survey"));
144 $questions = get_records_list("survey_questions", "id", $survey->questions
);
145 $questionorder = explode(",", $survey->questions
);
147 foreach ($questionorder as $key => $val) {
148 $question = $questions[$val];
149 if ($question->type
< 0) { // We have some virtual scales. Just show them.
150 $virtualscales = true;
155 foreach ($questionorder as $key => $val) {
156 $question = $questions[$val];
157 if ($question->multi
) {
158 if (!empty($virtualscales) && $question->type
> 0) { // Don't show non-virtual scales if virtual
161 echo "<p class=\"centerpara\"><a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
162 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png");
163 echo "</a></p><br />";
172 if ($qid) { // just get one multi-question
173 $questions = get_records_list("survey_questions", "id", $qid);
174 $questionorder = explode(",", $qid);
176 if ($scale = get_records("survey_questions", "multi", "$qid")) {
177 $scale = array_pop($scale);
178 print_heading("$scale->text - $strselectedquestions");
180 print_heading($strselectedquestions);
183 } else { // get all top-level questions
184 $questions = get_records_list("survey_questions", "id", $survey->questions
);
185 $questionorder = explode(",", $survey->questions
);
187 print_heading($strallquestions);
190 if (! $results = survey_get_responses($survey->id
, $currentgroup, $groupingid) ) {
191 notify(get_string("nobodyyet","survey"));
195 foreach ($questionorder as $key => $val) {
196 $question = $questions[$val];
197 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
198 $virtualscales = true;
203 foreach ($questionorder as $key => $val) {
204 $question = $questions[$val];
206 if ($question->type
< 0) { // We have some virtual scales. DON'T show them.
209 $question->text
= get_string($question->text
, "survey");
211 if ($question->multi
) {
212 echo "<h3>$question->text:</h3>";
214 $subquestions = get_records_list("survey_questions", "id", $question->multi
);
215 $subquestionorder = explode(",", $question->multi
);
216 foreach ($subquestionorder as $key => $val) {
217 $subquestion = $subquestions[$val];
218 if ($subquestion->type
> 0) {
219 echo "<p class=\"centerpara\">";
220 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">";
221 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png");
225 } else if ($question->type
> 0 ) {
226 echo "<p class=\"centerpara\">";
227 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">";
228 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png");
233 $table->head
= array($question->text
);
234 $table->align
= array ("left");
236 $contents = '<table cellpadding="15" width="100%">';
238 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup, "sa.time ASC")) {
239 foreach ($aaa as $a) {
241 $contents .= '<td class="fullnamecell">'.fullname($a).'</td>';
242 $contents .= '<td valign="top">'.$a->answer1
.'</td>';
243 $contents .= "</tr>";
246 $contents .= "</table>";
248 $table->data
[] = array($contents);
259 if (!$question = get_record("survey_questions", "id", $qid)) {
260 error("Question doesn't exist");
262 $question->text
= get_string($question->text
, "survey");
264 $answers = explode(",", get_string($question->options
, "survey"));
266 print_heading("$strquestion: $question->text");
269 $strname = get_string("name", "survey");
270 $strtime = get_string("time", "survey");
271 $stractual = get_string("actual", "survey");
272 $strpreferred = get_string("preferred", "survey");
273 $strdateformat = get_string("strftimedatetime");
276 $table->head
= array("", $strname, $strtime, $stractual, $strpreferred);
277 $table->align
= array ("left", "left", "left", "left", "right");
278 $table->size
= array (35, "", "", "", "");
280 if ($aaa = survey_get_user_answers($survey->id
, $question->id
, $currentgroup)) {
281 foreach ($aaa as $a) {
283 $answer1 = "$a->answer1 - ".$answers[$a->answer1
- 1];
288 $answer2 = "$a->answer2 - ".$answers[$a->answer2
- 1];
293 $table->data
[] = array(
294 print_user_picture($a->userid
, $course->id
, $a->picture
, false, true, true),
295 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>",
308 print_heading(get_string("analysisof", "survey", "$course->students"));
310 if (! $results = survey_get_responses($survey->id
, $currentgroup, $groupingid) ) {
311 notify(get_string("nobodyyet","survey"));
313 survey_print_all_responses($cm->id
, $results, $course->id
);
319 if (!$user = get_record("user", "id", $student)) {
320 error("Student doesn't exist");
323 print_heading(get_string("analysisof", "survey", fullname($user)));
325 if ($notes != '' and confirm_sesskey()) {
326 if (survey_get_analysis($survey->id
, $user->id
)) {
327 if (! survey_update_analysis($survey->id
, $user->id
, $notes)) {
328 notify("An error occurred while saving your notes. Sorry.");
330 notify(get_string("savednotes", "survey"));
333 if (! survey_add_analysis($survey->id
, $user->id
, $notes)) {
334 notify("An error occurred while saving your notes. Sorry.");
336 notify(get_string("savednotes", "survey"));
341 echo "<p <p class=\"centerpara\">";
342 print_user_picture($user->id
, $course->id
, $user->picture
, true);
345 $questions = get_records_list("survey_questions", "id", $survey->questions
);
346 $questionorder = explode(",", $survey->questions
);
349 // Print overall summary
350 echo "<p <p class=\"centerpara\">>";
351 survey_print_graph("id=$id&sid=$student&type=student.png");
356 foreach ($questionorder as $key => $val) {
357 $question = $questions[$val];
358 if ($question->type
< 0) { // We have some virtual scales. Just show them.
359 $virtualscales = true;
364 foreach ($questionorder as $key => $val) {
365 $question = $questions[$val];
366 if ($question->multi
) {
367 if ($virtualscales && $question->type
> 0) { // Don't show non-virtual scales if virtual
370 echo "<p class=\"centerpara\">";
371 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">";
372 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png");
373 echo "</a></p><br />";
378 // Print non-scale questions
380 foreach ($questionorder as $key => $val) {
381 $question = $questions[$val];
382 if ($question->type
== 0 or $question->type
== 1) {
383 if ($answer = survey_get_user_answer($survey->id
, $question->id
, $user->id
)) {
385 $table->head
= array(get_string($question->text
, "survey"));
386 $table->align
= array ("left");
387 $table->data
[] = array(s($answer->answer1
)); // no html here, just plain text
394 if ($rs = survey_get_analysis($survey->id
, $user->id
)) {
399 echo "<hr noshade=\"noshade\" size=\"1\" />";
400 echo "<div class='studentreport'>";
401 echo "<form action=\"report.php\" method=\"post\">";
402 echo "<h3>$strnotes:</h3>";
404 echo "<textarea name=\"notes\" rows=\"10\" cols=\"60\">";
406 echo "</textarea><br />";
407 echo "<input type=\"hidden\" name=\"action\" value=\"student\" />";
408 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
409 echo "<input type=\"hidden\" name=\"student\" value=\"$student\" />";
410 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
411 echo "<input type=\"submit\" value=\"".get_string("savechanges")."\" />";
412 echo "</blockquote>";
420 print_heading($strdownload);
422 require_capability('mod/survey:download', $context);
424 echo '<p class="centerpara">'.get_string("downloadinfo", "survey").'</p>';
426 echo '<div class="reportbuttons">';
428 $options["id"] = "$cm->id";
429 $options["group"] = $currentgroup;
431 $options["type"] = "ods";
432 print_single_button("download.php", $options, get_string("downloadods"));
434 $options["type"] = "xls";
435 print_single_button("download.php", $options, get_string("downloadexcel"));
437 $options["type"] = "txt";
438 print_single_button("download.php", $options, get_string("downloadtext"));
444 print_footer($course);