Merged from HEAD
[moodle.git] / mod / quiz / report.php
blob90b4c0708609473ed487eb4c7447c46108927f2d
1 <?php // $Id$
3 // This script uses installed report plugins to print quiz reports
5 require_once("../../config.php");
6 require_once("locallib.php");
8 optional_variable($id); // Course Module ID, or
9 optional_variable($q); // quiz ID
11 optional_variable($mode, "overview"); // Report mode
13 if ($id) {
14 if (! $cm = get_record("course_modules", "id", $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");
26 } else {
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);
40 if (!isteacher($course->id)) {
41 error("You are not allowed to use this script");
44 // if no questions have been set up yet redirect to edit.php
45 if (!$quiz->questions and isteacheredit($course->id)) {
46 redirect('edit.php?quizid='.$quiz->id);
49 // Upgrade any attempts that have not yet been upgraded to the
50 // Moodle 1.5 model (they will not yet have the timestamp set)
51 if ($attempts = get_records_sql("SELECT a.*".
52 " FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}quiz_states s".
53 " WHERE a.quiz = '$quiz->id' AND s.attempt = a.id AND s.timestamp = 0")) {
54 foreach ($attempts as $attempt) {
55 quiz_upgrade_states($attempt);
59 add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id", "$cm->id");
61 /// Open the selected quiz report and display it
63 $mode = clean_filename($mode);
65 if (! is_readable("report/$mode/report.php")) {
66 error("Report not known (".clean_text($mode).")");
69 include("report/default.php"); // Parent class
70 include("report/$mode/report.php");
72 $report = new quiz_report();
74 if (! $report->display($quiz, $cm, $course)) { // Run the report!
75 error("Error occurred during pre-processing!");
78 /// Print footer
80 print_footer($course);