2004-09-12 17:34:35 +00:00
|
|
|
<?php // $Id$
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2003-07-24 05:18:00 +00:00
|
|
|
// This script uses installed report plugins to print quiz reports
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
2005-01-08 20:06:00 +00:00
|
|
|
require_once("locallib.php");
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2005-07-05 15:00:34 +00:00
|
|
|
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or
|
|
|
|
$q = optional_param('q',0,PARAM_INT); // quiz ID
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2005-07-05 15:00:34 +00:00
|
|
|
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode
|
2002-10-21 15:00:51 +00:00
|
|
|
|
2002-10-13 13:51:56 +00:00
|
|
|
if ($id) {
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('quiz', $id)) {
|
2005-06-04 09:58:35 +00:00
|
|
|
error("There is no coursemodule with id $id");
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2002-10-13 13:51:56 +00:00
|
|
|
if (! $course = get_record("course", "id", $cm->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2002-10-13 13:51:56 +00:00
|
|
|
if (! $quiz = get_record("quiz", "id", $cm->instance)) {
|
2005-06-04 09:58:35 +00:00
|
|
|
error("The quiz with id $cm->instance corresponding to this coursemodule $id is missing");
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (! $quiz = get_record("quiz", "id", $q)) {
|
2005-06-04 09:58:35 +00:00
|
|
|
error("There is no quiz with id $q");
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $quiz->course)) {
|
2005-06-04 09:58:35 +00:00
|
|
|
error("The course with id $quiz->course that the quiz with id $q belongs to is missing");
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
|
2005-06-04 09:58:35 +00:00
|
|
|
error("The course module for the quiz with id $q is missing");
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
require_login($course->id, false);
|
2006-08-22 09:04:23 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-08-25 11:23:00 +00:00
|
|
|
require_capability('mod/quiz:viewreports', $context);
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
// if no questions have been set up yet redirect to edit.php
|
2006-08-22 09:04:23 +00:00
|
|
|
if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
|
2007-08-14 02:50:56 +00:00
|
|
|
redirect('edit.php?cmid='.$cm->id);
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
2002-10-22 04:25:58 +00:00
|
|
|
|
2007-08-14 02:50:56 +00:00
|
|
|
// Upgrade any attempts that have not yet been upgraded to the
|
2005-05-23 20:52:55 +00:00
|
|
|
// Moodle 1.5 model (they will not yet have the timestamp set)
|
|
|
|
if ($attempts = get_records_sql("SELECT a.*".
|
2006-02-28 09:26:00 +00:00
|
|
|
" FROM {$CFG->prefix}quiz_attempts a, {$CFG->prefix}question_states s".
|
2005-07-02 18:14:51 +00:00
|
|
|
" WHERE a.quiz = '$quiz->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) {
|
2005-05-23 20:52:55 +00:00
|
|
|
foreach ($attempts as $attempt) {
|
|
|
|
quiz_upgrade_states($attempt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id", "$cm->id");
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2003-07-24 05:18:00 +00:00
|
|
|
/// Open the selected quiz report and display it
|
2002-10-22 06:52:23 +00:00
|
|
|
|
2006-03-04 12:37:29 +00:00
|
|
|
$mode = clean_param($mode, PARAM_SAFEDIR);
|
2004-09-29 07:02:22 +00:00
|
|
|
|
2003-07-24 05:18:00 +00:00
|
|
|
if (! is_readable("report/$mode/report.php")) {
|
2006-03-04 12:37:29 +00:00
|
|
|
error("Report not known ($mode)");
|
2002-10-22 06:52:23 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 05:18:00 +00:00
|
|
|
include("report/default.php"); // Parent class
|
|
|
|
include("report/$mode/report.php");
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2003-07-24 05:18:00 +00:00
|
|
|
$report = new quiz_report();
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2003-07-28 02:04:58 +00:00
|
|
|
if (! $report->display($quiz, $cm, $course)) { // Run the report!
|
2003-07-24 05:18:00 +00:00
|
|
|
error("Error occurred during pre-processing!");
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
/// Print footer
|
2003-07-28 02:04:58 +00:00
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
print_footer($course);
|
2002-10-13 13:51:56 +00:00
|
|
|
|
|
|
|
?>
|