Moodle release 1.9.16
[moodle.git] / mod / quiz / report.php
blob62ec3a9a795771fb1caefc0d98792231fb3f2713
1 <?php // $Id$
3 // This script uses installed report plugins to print quiz reports
5 require_once('../../config.php');
6 require_once($CFG->dirroot.'/mod/quiz/locallib.php');
7 require_once($CFG->dirroot.'/mod/quiz/report/reportlib.php');
9 $id = optional_param('id',0,PARAM_INT); // Course Module ID, or
10 $q = optional_param('q',0,PARAM_INT); // quiz ID
12 $mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode
14 if ($id) {
15 if (! $cm = get_coursemodule_from_id('quiz', $id)) {
16 error("There is no coursemodule with id $id");
19 if (! $course = get_record("course", "id", $cm->course)) {
20 error("Course is misconfigured");
23 if (! $quiz = get_record("quiz", "id", $cm->instance)) {
24 error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
27 } else {
28 if (! $quiz = get_record("quiz", "id", $q)) {
29 error("There is no quiz with id $q");
31 if (! $course = get_record("course", "id", $quiz->course)) {
32 error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
34 if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
35 error("The course module for the quiz with id $q is missing");
39 require_login($course, false, $cm);
40 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
41 require_capability('mod/quiz:viewreports', $context);
43 // if no questions have been set up yet redirect to edit.php
44 if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
45 redirect('edit.php?cmid='.$cm->id);
48 // Upgrade any attempts that have not yet been upgraded to the
49 // Moodle 1.5 model (they will not yet have the timestamp set)
50 if ($attempts = get_records_sql("SELECT a.*".
51 " FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}question_states s".
52 " WHERE a.quiz = '$quiz->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) {
53 foreach ($attempts as $attempt) {
54 quiz_upgrade_states($attempt);
58 add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id", "$cm->id");
60 /// Open the selected quiz report and display it
62 $mode = clean_param($mode, PARAM_SAFEDIR);
64 if (! is_readable("report/$mode/report.php")) {
65 error("Report not known ($mode)");
68 include("report/default.php"); // Parent class
69 include("report/$mode/report.php");
71 $report = new quiz_report();
73 if (! $report->display($quiz, $cm, $course)) { // Run the report!
74 error("Error occurred during pre-processing!");
77 /// Print footer
79 print_footer($course);