|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 require_once(dirname(__FILE__) . '/../../config.php'); 00028 require_once($CFG->dirroot . '/mod/quiz/locallib.php'); 00029 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); 00030 require_once($CFG->dirroot . '/mod/quiz/report/default.php'); 00031 00032 $id = optional_param('id', 0, PARAM_INT); 00033 $q = optional_param('q', 0, PARAM_INT); 00034 $mode = optional_param('mode', '', PARAM_ALPHA); 00035 00036 if ($id) { 00037 if (!$cm = get_coursemodule_from_id('quiz', $id)) { 00038 print_error('invalidcoursemodule'); 00039 } 00040 if (!$course = $DB->get_record('course', array('id' => $cm->course))) { 00041 print_error('coursemisconf'); 00042 } 00043 if (!$quiz = $DB->get_record('quiz', array('id' => $cm->instance))) { 00044 print_error('invalidcoursemodule'); 00045 } 00046 00047 } else { 00048 if (!$quiz = $DB->get_record('quiz', array('id' => $q))) { 00049 print_error('invalidquizid', 'quiz'); 00050 } 00051 if (!$course = $DB->get_record('course', array('id' => $quiz->course))) { 00052 print_error('invalidcourseid'); 00053 } 00054 if (!$cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) { 00055 print_error('invalidcoursemodule'); 00056 } 00057 } 00058 00059 $url = new moodle_url('/mod/quiz/report.php', array('id' => $cm->id)); 00060 if ($mode !== '') { 00061 $url->param('mode', $mode); 00062 } 00063 $PAGE->set_url($url); 00064 00065 require_login($course, false, $cm); 00066 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 00067 $PAGE->set_pagelayout('report'); 00068 00069 $reportlist = quiz_report_list($context); 00070 if (empty($reportlist)) { 00071 print_error('erroraccessingreport', 'quiz'); 00072 } 00073 00074 // Validate the requested report name. 00075 if ($mode == '') { 00076 // Default to first accessible report and redirect. 00077 $url->param('mode', reset($reportlist)); 00078 redirect($url); 00079 } else if (!in_array($mode, $reportlist)) { 00080 print_error('erroraccessingreport', 'quiz'); 00081 } 00082 if (!is_readable("report/$mode/report.php")) { 00083 print_error('reportnotfound', 'quiz', '', $mode); 00084 } 00085 00086 add_to_log($course->id, 'quiz', 'report', 'report.php?id=' . $cm->id . '&mode=' . $mode, 00087 $quiz->id, $cm->id); 00088 00089 // Open the selected quiz report and display it 00090 $file = $CFG->dirroot . '/mod/quiz/report/' . $mode . '/report.php'; 00091 if (is_readable($file)) { 00092 include_once($file); 00093 } 00094 $reportclassname = 'quiz_' . $mode . '_report'; 00095 if (!class_exists($reportclassname)) { 00096 print_error('preprocesserror', 'quiz'); 00097 } 00098 00099 $report = new $reportclassname(); 00100 $report->display($quiz, $cm, $course); 00101 00102 // Print footer 00103 echo $OUTPUT->footer();