3 // This script uses installed report plugins to print quiz reports
5 require_once("../../config.php");
6 require_once("locallib.php");
8 $id = optional_param('id',0,PARAM_INT
); // Course Module ID, or
9 $q = optional_param('q',0,PARAM_INT
); // quiz ID
11 $mode = optional_param('mode', 'overview', PARAM_ALPHA
); // Report mode
14 if (! $cm = get_coursemodule_from_id('quiz', $id)) {
15 error("There is no coursemodule with id $id");
18 if (! $course = get_record("course", "id", $cm->course
)) {
19 error("Course is misconfigured");
22 if (! $quiz = get_record("quiz", "id", $cm->instance
)) {
23 error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
27 if (! $quiz = get_record("quiz", "id", $q)) {
28 error("There is no quiz with id $q");
30 if (! $course = get_record("course", "id", $quiz->course
)) {
31 error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
33 if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id
, $course->id
)) {
34 error("The course module for the quiz with id $q is missing");
38 require_login($course->id
, false);
39 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
40 require_capability('mod/quiz:viewreports', $context);
42 // if no questions have been set up yet redirect to edit.php
43 if (!$quiz->questions
and has_capability('mod/quiz:manage', $context)) {
44 redirect('edit.php?quizid='.$quiz->id
);
47 // Upgrade any attempts that have not yet been upgraded to the
48 // Moodle 1.5 model (they will not yet have the timestamp set)
49 if ($attempts = get_records_sql("SELECT a.*".
50 " FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}question_states s".
51 " WHERE a.quiz = '$quiz->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) {
52 foreach ($attempts as $attempt) {
53 quiz_upgrade_states($attempt);
57 add_to_log($course->id
, "quiz", "report", "report.php?id=$cm->id", "$quiz->id", "$cm->id");
59 /// Open the selected quiz report and display it
61 $mode = clean_param($mode, PARAM_SAFEDIR
);
63 if (! is_readable("report/$mode/report.php")) {
64 error("Report not known ($mode)");
67 include("report/default.php"); // Parent class
68 include("report/$mode/report.php");
70 $report = new quiz_report();
72 if (! $report->display($quiz, $cm, $course)) { // Run the report!
73 error("Error occurred during pre-processing!");
78 print_footer($course);