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
|
|
|
|
2008-05-01 07:08:28 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
require_once($CFG->dirroot.'/mod/quiz/locallib.php');
|
|
|
|
require_once($CFG->dirroot.'/mod/quiz/report/reportlib.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
|
|
|
|
2008-11-25 12:11:27 +00:00
|
|
|
$mode = optional_param('mode', '', 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)) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('coursemisconf');
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
2005-02-16 10:40:48 +00:00
|
|
|
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $quiz = $DB->get_record('quiz', array('id' => $q))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidquizid', 'quiz');
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcourseid');
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-10-13 13:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 12:11:27 +00:00
|
|
|
|
2007-08-17 12:49:28 +00:00
|
|
|
require_login($course, false, $cm);
|
2006-08-22 09:04:23 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2008-11-25 12:11:27 +00:00
|
|
|
|
|
|
|
$reportlist = quiz_report_list($context);
|
|
|
|
if (count($reportlist)==0){
|
|
|
|
print_error('erroraccessingreport', 'quiz');
|
|
|
|
}
|
|
|
|
if ($mode == ''){
|
|
|
|
$mode = reset($reportlist);//first element in array
|
|
|
|
} elseif (!in_array($mode, $reportlist)){
|
|
|
|
print_error('erroraccessingreport', 'quiz');
|
|
|
|
}
|
|
|
|
|
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)
|
2008-06-09 10:00:35 +00:00
|
|
|
if ($attempts = $DB->get_records_sql("SELECT a.*".
|
|
|
|
" FROM {quiz_attempts} a, {question_states} s".
|
|
|
|
" WHERE a.quiz = ? AND s.attempt = a.uniqueid AND s.timestamp = 0", array($quiz->id))) {
|
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
|
|
|
|
2003-07-24 05:18:00 +00:00
|
|
|
if (! is_readable("report/$mode/report.php")) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('reportnotfound', 'quiz', '', $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
|
|
|
|
2008-06-24 08:59:29 +00:00
|
|
|
$reportclassname = "quiz_{$mode}_report";
|
|
|
|
$report = new $reportclassname();
|
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!
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error("preprocesserror", 'quiz');
|
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
|
|
|
|
|
|
|
?>
|