[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This file is responsible for producing the survey reports 20 * 21 * @package mod_survey 22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once("../../config.php"); 27 require_once ("lib.php"); 28 29 // Check that all the parameters have been provided. 30 31 $id = required_param('id', PARAM_INT); // Course Module ID 32 $action = optional_param('action', '', PARAM_ALPHA); // What to look at 33 $qid = optional_param('qid', 0, PARAM_RAW); // Question IDs comma-separated list 34 $student = optional_param('student', 0, PARAM_INT); // Student ID 35 $notes = optional_param('notes', '', PARAM_RAW); // Save teachers notes 36 37 $qids = explode(',', $qid); 38 $qids = clean_param_array($qids, PARAM_INT); 39 $qid = implode (',', $qids); 40 41 if (! $cm = get_coursemodule_from_id('survey', $id)) { 42 print_error('invalidcoursemodule'); 43 } 44 45 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { 46 print_error('coursemisconf'); 47 } 48 49 $url = new moodle_url('/mod/survey/report.php', array('id'=>$id)); 50 if ($action !== '') { 51 $url->param('action', $action); 52 } 53 if ($qid !== 0) { 54 $url->param('qid', $qid); 55 } 56 if ($student !== 0) { 57 $url->param('student', $student); 58 } 59 if ($notes !== '') { 60 $url->param('notes', $notes); 61 } 62 $PAGE->set_url($url); 63 64 require_login($course, false, $cm); 65 66 $context = context_module::instance($cm->id); 67 68 require_capability('mod/survey:readresponses', $context); 69 70 if (! $survey = $DB->get_record("survey", array("id"=>$cm->instance))) { 71 print_error('invalidsurveyid', 'survey'); 72 } 73 74 if (! $template = $DB->get_record("survey", array("id"=>$survey->template))) { 75 print_error('invalidtmptid', 'survey'); 76 } 77 78 $showscales = ($template->name != 'ciqname'); 79 80 81 $strreport = get_string("report", "survey"); 82 $strsurvey = get_string("modulename", "survey"); 83 $strsurveys = get_string("modulenameplural", "survey"); 84 $strsummary = get_string("summary", "survey"); 85 $strscales = get_string("scales", "survey"); 86 $strquestion = get_string("question", "survey"); 87 $strquestions = get_string("questions", "survey"); 88 $strdownload = get_string("download", "survey"); 89 $strallscales = get_string("allscales", "survey"); 90 $strallquestions = get_string("allquestions", "survey"); 91 $strselectedquestions = get_string("selectedquestions", "survey"); 92 $strseemoredetail = get_string("seemoredetail", "survey"); 93 $strnotes = get_string("notes", "survey"); 94 95 switch ($action) { 96 case 'download': 97 $PAGE->navbar->add(get_string('downloadresults', 'survey')); 98 break; 99 case 'summary': 100 case 'scales': 101 case 'questions': 102 $PAGE->navbar->add($strreport); 103 $PAGE->navbar->add(${'str'.$action}); 104 break; 105 case 'students': 106 $PAGE->navbar->add($strreport); 107 $PAGE->navbar->add(get_string('participants')); 108 break; 109 case '': 110 $PAGE->navbar->add($strreport); 111 $PAGE->navbar->add($strsummary); 112 break; 113 default: 114 $PAGE->navbar->add($strreport); 115 break; 116 } 117 118 $PAGE->set_title("$course->shortname: ".format_string($survey->name)); 119 $PAGE->set_heading($course->fullname); 120 echo $OUTPUT->header(); 121 echo $OUTPUT->heading($survey->name); 122 123 /// Check to see if groups are being used in this survey 124 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used 125 $menuaction = $action == "student" ? "students" : $action; 126 $currentgroup = groups_get_activity_group($cm, true); 127 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/survey/report.php?id=$cm->id&action=$menuaction&qid=$qid"); 128 } else { 129 $currentgroup = 0; 130 } 131 132 $params = array( 133 'objectid' => $survey->id, 134 'context' => $context, 135 'courseid' => $course->id, 136 'relateduserid' => $student, 137 'other' => array('action' => $action, 'groupid' => $currentgroup) 138 ); 139 $event = \mod_survey\event\report_viewed::create($params); 140 $event->trigger(); 141 142 if ($currentgroup) { 143 $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $currentgroup, null, false); 144 } else if (!empty($cm->groupingid)) { 145 $groups = groups_get_all_groups($courseid, 0, $cm->groupingid); 146 $groups = array_keys($groups); 147 $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', $groups, null, false); 148 } else { 149 $users = get_users_by_capability($context, 'mod/survey:participate', '', '', '', '', '', null, false); 150 $group = false; 151 } 152 153 $groupingid = $cm->groupingid; 154 155 echo $OUTPUT->box_start("generalbox boxaligncenter"); 156 if ($showscales) { 157 echo "<a href=\"report.php?action=summary&id=$id\">$strsummary</a>"; 158 echo " <a href=\"report.php?action=scales&id=$id\">$strscales</a>"; 159 echo " <a href=\"report.php?action=questions&id=$id\">$strquestions</a>"; 160 echo " <a href=\"report.php?action=students&id=$id\">".get_string('participants')."</a>"; 161 if (has_capability('mod/survey:download', $context)) { 162 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>"; 163 } 164 if (empty($action)) { 165 $action = "summary"; 166 } 167 } else { 168 echo "<a href=\"report.php?action=questions&id=$id\">$strquestions</a>"; 169 echo " <a href=\"report.php?action=students&id=$id\">".get_string('participants')."</a>"; 170 if (has_capability('mod/survey:download', $context)) { 171 echo " <a href=\"report.php?action=download&id=$id\">$strdownload</a>"; 172 } 173 if (empty($action)) { 174 $action = "questions"; 175 } 176 } 177 echo $OUTPUT->box_end(); 178 179 echo $OUTPUT->spacer(array('height'=>30, 'width'=>30, 'br'=>true)); // should be done with CSS instead 180 181 182 /// Print the menu across the top 183 184 $virtualscales = false; 185 186 switch ($action) { 187 188 case "summary": 189 echo $OUTPUT->heading($strsummary, 3); 190 191 if (survey_count_responses($survey->id, $currentgroup, $groupingid)) { 192 echo "<div class='reportsummary'><a href=\"report.php?action=scales&id=$id\">"; 193 survey_print_graph("id=$id&group=$currentgroup&type=overall.png"); 194 echo "</a></div>"; 195 } else { 196 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 197 } 198 break; 199 200 case "scales": 201 echo $OUTPUT->heading($strscales, 3); 202 203 if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) { 204 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 205 206 } else { 207 208 $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); 209 $questionorder = explode(",", $survey->questions); 210 211 foreach ($questionorder as $key => $val) { 212 $question = $questions[$val]; 213 if ($question->type < 0) { // We have some virtual scales. Just show them. 214 $virtualscales = true; 215 break; 216 } 217 } 218 219 foreach ($questionorder as $key => $val) { 220 $question = $questions[$val]; 221 if ($question->multi) { 222 if (!empty($virtualscales) && $question->type > 0) { // Don't show non-virtual scales if virtual 223 continue; 224 } 225 echo "<p class=\"centerpara\"><a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">"; 226 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=multiquestion.png"); 227 echo "</a></p><br />"; 228 } 229 } 230 } 231 232 break; 233 234 case "questions": 235 236 if ($qid) { // just get one multi-question 237 $questions = $DB->get_records_select("survey_questions", "id in ($qid)"); 238 $questionorder = explode(",", $qid); 239 240 if ($scale = $DB->get_records("survey_questions", array("multi"=>$qid))) { 241 $scale = array_pop($scale); 242 echo $OUTPUT->heading("$scale->text - $strselectedquestions", 3); 243 } else { 244 echo $OUTPUT->heading($strselectedquestions, 3); 245 } 246 247 } else { // get all top-level questions 248 $questions = $DB->get_records_list("survey_questions", "id", explode(',',$survey->questions)); 249 $questionorder = explode(",", $survey->questions); 250 251 echo $OUTPUT->heading($strallquestions, 3); 252 } 253 254 if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) { 255 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 256 257 } else { 258 259 foreach ($questionorder as $key => $val) { 260 $question = $questions[$val]; 261 if ($question->type < 0) { // We have some virtual scales. DON'T show them. 262 $virtualscales = true; 263 break; 264 } 265 } 266 267 foreach ($questionorder as $key => $val) { 268 $question = $questions[$val]; 269 270 if ($question->type < 0) { // We have some virtual scales. DON'T show them. 271 continue; 272 } 273 $question->text = get_string($question->text, "survey"); 274 275 if ($question->multi) { 276 echo $OUTPUT->heading($question->text . ':', 4); 277 278 $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi)); 279 $subquestionorder = explode(",", $question->multi); 280 foreach ($subquestionorder as $key => $val) { 281 $subquestion = $subquestions[$val]; 282 if ($subquestion->type > 0) { 283 echo "<p class=\"centerpara\">"; 284 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$subquestion->id\">"; 285 survey_print_graph("id=$id&qid=$subquestion->id&group=$currentgroup&type=question.png"); 286 echo "</a></p>"; 287 } 288 } 289 } else if ($question->type > 0 ) { 290 echo "<p class=\"centerpara\">"; 291 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=question&id=$id&qid=$question->id\">"; 292 survey_print_graph("id=$id&qid=$question->id&group=$currentgroup&type=question.png"); 293 echo "</a></p>"; 294 295 } else { 296 $table = new html_table(); 297 $table->head = array($question->text); 298 $table->align = array ("left"); 299 300 $contents = '<table cellpadding="15" width="100%">'; 301 302 if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup, "sa.time ASC")) { 303 foreach ($aaa as $a) { 304 $contents .= "<tr>"; 305 $contents .= '<td class="fullnamecell">'.fullname($a).'</td>'; 306 $contents .= '<td valign="top">'.$a->answer1.'</td>'; 307 $contents .= "</tr>"; 308 } 309 } 310 $contents .= "</table>"; 311 312 $table->data[] = array($contents); 313 314 echo html_writer::table($table); 315 316 echo $OUTPUT->spacer(array('height'=>30)); // should be done with CSS instead 317 } 318 } 319 } 320 321 break; 322 323 case "question": 324 if (!$question = $DB->get_record("survey_questions", array("id"=>$qid))) { 325 print_error('cannotfindquestion', 'survey'); 326 } 327 $question->text = get_string($question->text, "survey"); 328 329 $answers = explode(",", get_string($question->options, "survey")); 330 331 echo $OUTPUT->heading("$strquestion: $question->text", 3); 332 333 334 $strname = get_string("name", "survey"); 335 $strtime = get_string("time", "survey"); 336 $stractual = get_string("actual", "survey"); 337 $strpreferred = get_string("preferred", "survey"); 338 $strdateformat = get_string("strftimedatetime"); 339 340 $table = new html_table(); 341 $table->head = array("", $strname, $strtime, $stractual, $strpreferred); 342 $table->align = array ("left", "left", "left", "left", "right"); 343 $table->size = array (35, "", "", "", ""); 344 345 if ($aaa = survey_get_user_answers($survey->id, $question->id, $currentgroup)) { 346 foreach ($aaa as $a) { 347 if ($a->answer1) { 348 $answer1 = "$a->answer1 - ".$answers[$a->answer1 - 1]; 349 } else { 350 $answer1 = " "; 351 } 352 if ($a->answer2) { 353 $answer2 = "$a->answer2 - ".$answers[$a->answer2 - 1]; 354 } else { 355 $answer2 = " "; 356 } 357 $table->data[] = array( 358 $OUTPUT->user_picture($a, array('courseid'=>$course->id)), 359 "<a href=\"report.php?id=$id&action=student&student=$a->userid\">".fullname($a)."</a>", 360 userdate($a->time), 361 $answer1, $answer2); 362 363 } 364 } 365 366 echo html_writer::table($table); 367 368 break; 369 370 case "students": 371 372 echo $OUTPUT->heading(get_string("analysisof", "survey", get_string('participants')), 3); 373 374 if (! $results = survey_get_responses($survey->id, $currentgroup, $groupingid) ) { 375 echo $OUTPUT->notification(get_string("nobodyyet","survey")); 376 } else { 377 survey_print_all_responses($cm->id, $results, $course->id); 378 } 379 380 break; 381 382 case "student": 383 if (!$user = $DB->get_record("user", array("id"=>$student))) { 384 print_error('invaliduserid'); 385 } 386 387 echo $OUTPUT->heading(get_string("analysisof", "survey", fullname($user)), 3); 388 389 if ($notes != '' and confirm_sesskey()) { 390 if (survey_get_analysis($survey->id, $user->id)) { 391 if (! survey_update_analysis($survey->id, $user->id, $notes)) { 392 echo $OUTPUT->notification("An error occurred while saving your notes. Sorry."); 393 } else { 394 echo $OUTPUT->notification(get_string("savednotes", "survey")); 395 } 396 } else { 397 if (! survey_add_analysis($survey->id, $user->id, $notes)) { 398 echo $OUTPUT->notification("An error occurred while saving your notes. Sorry."); 399 } else { 400 echo $OUTPUT->notification(get_string("savednotes", "survey")); 401 } 402 } 403 } 404 405 echo "<p <p class=\"centerpara\">"; 406 echo $OUTPUT->user_picture($user, array('courseid'=>$course->id)); 407 echo "</p>"; 408 409 $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions)); 410 $questionorder = explode(",", $survey->questions); 411 412 if ($showscales) { 413 // Print overall summary 414 echo "<p <p class=\"centerpara\">>"; 415 survey_print_graph("id=$id&sid=$student&type=student.png"); 416 echo "</p>"; 417 418 // Print scales 419 420 foreach ($questionorder as $key => $val) { 421 $question = $questions[$val]; 422 if ($question->type < 0) { // We have some virtual scales. Just show them. 423 $virtualscales = true; 424 break; 425 } 426 } 427 428 foreach ($questionorder as $key => $val) { 429 $question = $questions[$val]; 430 if ($question->multi) { 431 if ($virtualscales && $question->type > 0) { // Don't show non-virtual scales if virtual 432 continue; 433 } 434 echo "<p class=\"centerpara\">"; 435 echo "<a title=\"$strseemoredetail\" href=\"report.php?action=questions&id=$id&qid=$question->multi\">"; 436 survey_print_graph("id=$id&qid=$question->id&sid=$student&type=studentmultiquestion.png"); 437 echo "</a></p><br />"; 438 } 439 } 440 } 441 442 // Print non-scale questions 443 444 foreach ($questionorder as $key => $val) { 445 $question = $questions[$val]; 446 if ($question->type == 0 or $question->type == 1) { 447 if ($answer = survey_get_user_answer($survey->id, $question->id, $user->id)) { 448 $table = new html_table(); 449 $table->head = array(get_string($question->text, "survey")); 450 $table->align = array ("left"); 451 $table->data[] = array(s($answer->answer1)); // no html here, just plain text 452 echo html_writer::table($table); 453 echo $OUTPUT->spacer(array('height'=>30)); 454 } 455 } 456 } 457 458 if ($rs = survey_get_analysis($survey->id, $user->id)) { 459 $notes = $rs->notes; 460 } else { 461 $notes = ""; 462 } 463 echo "<hr noshade=\"noshade\" size=\"1\" />"; 464 echo "<div class='studentreport'>"; 465 echo "<form action=\"report.php\" method=\"post\">"; 466 echo "<h3>$strnotes:</h3>"; 467 echo "<blockquote>"; 468 echo "<textarea name=\"notes\" rows=\"10\" cols=\"60\">"; 469 p($notes); 470 echo "</textarea><br />"; 471 echo "<input type=\"hidden\" name=\"action\" value=\"student\" />"; 472 echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />"; 473 echo "<input type=\"hidden\" name=\"student\" value=\"$student\" />"; 474 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />"; 475 echo "<input type=\"submit\" value=\"".get_string("savechanges")."\" />"; 476 echo "</blockquote>"; 477 echo "</form>"; 478 echo "</div>"; 479 480 481 break; 482 483 case "download": 484 echo $OUTPUT->heading($strdownload, 3); 485 486 require_capability('mod/survey:download', $context); 487 488 $numusers = survey_count_responses($survey->id, $currentgroup, $groupingid); 489 if ($numusers > 0) { 490 echo html_writer::tag('p', get_string("downloadinfo", "survey"), array('class' => 'centerpara')); 491 492 echo $OUTPUT->container_start('reportbuttons'); 493 $options = array(); 494 $options["id"] = "$cm->id"; 495 $options["group"] = $currentgroup; 496 497 $options["type"] = "ods"; 498 echo $OUTPUT->single_button(new moodle_url("download.php", $options), get_string("downloadods")); 499 500 $options["type"] = "xls"; 501 echo $OUTPUT->single_button(new moodle_url("download.php", $options), get_string("downloadexcel")); 502 503 $options["type"] = "txt"; 504 echo $OUTPUT->single_button(new moodle_url("download.php", $options), get_string("downloadtext")); 505 echo $OUTPUT->container_end(); 506 507 } else { 508 echo html_writer::tag('p', get_string("nobodyyet", "survey"), array('class' => 'centerpara')); 509 } 510 511 break; 512 513 } 514 echo $OUTPUT->footer(); 515
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |