MDL-13678 "Change default number of rows per page on quiz reports" Made a new constan...
[moodle.git] / mod / quiz / report.php
CommitLineData
d1290cec 1<?php // $Id$
579ddad5 2
29d5d0b4 3// This script uses installed report plugins to print quiz reports
579ddad5 4
f33c438e 5 require_once('../../config.php');
6 require_once($CFG->dirroot.'/mod/quiz/locallib.php');
7 require_once($CFG->dirroot.'/mod/quiz/report/reportlib.php');
579ddad5 8
5a90586d 9 $id = optional_param('id',0,PARAM_INT); // Course Module ID, or
10 $q = optional_param('q',0,PARAM_INT); // quiz ID
579ddad5 11
5a90586d 12 $mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode
e1c91df0 13
579ddad5 14 if ($id) {
f9d5371b 15 if (! $cm = get_coursemodule_from_id('quiz', $id)) {
5a2a5331 16 print_error("There is no coursemodule with id $id");
579ddad5 17 }
ec81373f 18
579ddad5 19 if (! $course = get_record("course", "id", $cm->course)) {
5a2a5331 20 print_error("Course is misconfigured");
579ddad5 21 }
ec81373f 22
579ddad5 23 if (! $quiz = get_record("quiz", "id", $cm->instance)) {
5a2a5331 24 print_error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
579ddad5 25 }
26
27 } else {
28 if (! $quiz = get_record("quiz", "id", $q)) {
5a2a5331 29 print_error("There is no quiz with id $q");
579ddad5 30 }
31 if (! $course = get_record("course", "id", $quiz->course)) {
5a2a5331 32 print_error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
579ddad5 33 }
34 if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
5a2a5331 35 print_error("The course module for the quiz with id $q is missing");
579ddad5 36 }
37 }
38
bb5b7224 39 require_login($course, false, $cm);
5cf38a57 40 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
64d80923 41 require_capability('mod/quiz:viewreports', $context);
579ddad5 42
ee1fb969 43 // if no questions have been set up yet redirect to edit.php
5cf38a57 44 if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
9f877cb0 45 redirect('edit.php?cmid='.$cm->id);
ee1fb969 46 }
6d86b5dc 47
9f877cb0 48 // Upgrade any attempts that have not yet been upgraded to the
b3ccc054 49 // Moodle 1.5 model (they will not yet have the timestamp set)
50 if ($attempts = get_records_sql("SELECT a.*".
4f48fb42 51 " FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}question_states s".
d115d8c7 52 " WHERE a.quiz = '$quiz->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) {
b3ccc054 53 foreach ($attempts as $attempt) {
54 quiz_upgrade_states($attempt);
55 }
56 }
57
ee1fb969 58 add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id", "$cm->id");
ec81373f 59
29d5d0b4 60/// Open the selected quiz report and display it
e331eb06 61
1b1d3422 62 $mode = clean_param($mode, PARAM_SAFEDIR);
de9bc13e 63
29d5d0b4 64 if (! is_readable("report/$mode/report.php")) {
5a2a5331 65 print_error("Report not known ($mode)");
e331eb06 66 }
67
29d5d0b4 68 include("report/default.php"); // Parent class
69 include("report/$mode/report.php");
579ddad5 70
29d5d0b4 71 $report = new quiz_report();
579ddad5 72
8b0ef9b0 73 if (! $report->display($quiz, $cm, $course)) { // Run the report!
5a2a5331 74 print_error("Error occurred during pre-processing!");
579ddad5 75 }
76
ee1fb969 77/// Print footer
8b0ef9b0 78
ee1fb969 79 print_footer($course);
579ddad5 80
81?>