2005-05-06 06:24:04 +00:00
|
|
|
<?php // $Id$
|
|
|
|
/**
|
|
|
|
* This page prints a review of a particular question attempt
|
|
|
|
*
|
|
|
|
* @version $Id$
|
|
|
|
* @author Martin Dougiamas and many others. This has recently been completely
|
|
|
|
* rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of
|
|
|
|
* the Serving Mathematics project
|
|
|
|
* {@link http://maths.york.ac.uk/serving_maths}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package quiz
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('locallib.php');
|
|
|
|
|
|
|
|
// Either stateid or (attemptid AND questionid) must be given
|
|
|
|
$stateid = optional_param('state', 0, PARAM_INT); // state id
|
|
|
|
$attemptid = optional_param('attempt', 0, PARAM_INT); // attempt id
|
|
|
|
$questionid = optional_param('question', 0, PARAM_INT); // attempt id
|
2005-06-05 20:51:15 +00:00
|
|
|
$number = optional_param('number', 0, PARAM_INT); // question number
|
2005-05-06 06:24:04 +00:00
|
|
|
|
|
|
|
if ($stateid) {
|
|
|
|
if (! $state = get_record('quiz_states', 'id', $stateid)) {
|
|
|
|
error('Invalid state id');
|
|
|
|
}
|
|
|
|
if (! $attempt = get_record('quiz_attempts', 'id', $state->attempt)) {
|
|
|
|
error('No such attempt ID exists');
|
|
|
|
}
|
|
|
|
} elseif ($attemptid) {
|
|
|
|
if (! $attempt = get_record('quiz_attempts', 'id', $attemptid)) {
|
|
|
|
error('No such attempt ID exists');
|
|
|
|
}
|
2006-02-15 08:38:41 +00:00
|
|
|
if (! $neweststateid = get_field('question_sessions', 'newest', 'attemptid', $attempt->uniqueid, 'questionid', $questionid)) {
|
2005-05-06 06:24:04 +00:00
|
|
|
// newest_state not set, probably because this is an old attempt from the old quiz module code
|
2005-07-02 18:14:51 +00:00
|
|
|
if (! $state = get_record('quiz_states', 'question', $questionid, 'attempt', $attempt->uniqueid)) {
|
2005-05-06 06:24:04 +00:00
|
|
|
error('Invalid question id');
|
|
|
|
}
|
|
|
|
} else {
|
2005-06-04 09:58:35 +00:00
|
|
|
if (! $state = get_record('quiz_states', 'id', $neweststateid)) {
|
2005-05-06 06:24:04 +00:00
|
|
|
error('Invalid state id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error('Parameter missing');
|
|
|
|
}
|
|
|
|
if (! $question = get_record('quiz_questions', 'id', $state->question)) {
|
|
|
|
error('Question for this state is missing');
|
|
|
|
}
|
|
|
|
if (! $quiz = get_record('quiz', 'id', $attempt->quiz)) {
|
|
|
|
error('Course module is incorrect');
|
|
|
|
}
|
|
|
|
if (! $course = get_record('course', 'id', $quiz->course)) {
|
|
|
|
error('Course is misconfigured');
|
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id)) {
|
|
|
|
error('Course Module ID was incorrect');
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id, false, $cm);
|
|
|
|
$isteacher = isteacher($course->id);
|
|
|
|
|
|
|
|
if (!$isteacher) {
|
|
|
|
if (!$attempt->timefinish) {
|
|
|
|
redirect('attempt.php?q='.$quiz->id);
|
|
|
|
}
|
|
|
|
// If not even responses are to be shown in review then we
|
|
|
|
// don't allow any review
|
|
|
|
if (!($quiz->review & QUIZ_REVIEW_RESPONSES)) {
|
|
|
|
error(get_string("noreview", "quiz"));
|
|
|
|
}
|
|
|
|
if ((time() - $attempt->timefinish) > 120) { // always allow review right after attempt
|
2005-07-07 17:16:56 +00:00
|
|
|
if (!$quiz->timeclose or time() < $quiz->timeclose and !($quiz->review & QUIZ_REVIEW_OPEN)) {
|
2005-05-06 06:24:04 +00:00
|
|
|
error(get_string("noreviewuntil", "quiz", userdate($quiz->timeclose)));
|
|
|
|
}
|
2005-07-07 17:16:56 +00:00
|
|
|
if ($quiz->timeclose and time() >= $quiz->timeclose and !($quiz->review & QUIZ_REVIEW_CLOSED)) {
|
2005-05-06 06:24:04 +00:00
|
|
|
error(get_string("noreview", "quiz"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($attempt->userid != $USER->id) {
|
|
|
|
error('This is not your attempt!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//add_to_log($course->id, 'quiz', 'review', "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", "$cm->id");
|
|
|
|
|
|
|
|
/// Print the page header
|
|
|
|
|
|
|
|
$strquizzes = get_string('modulenameplural', 'quiz');
|
|
|
|
$strreviewquestion = get_string('reviewquestion', 'quiz');
|
|
|
|
|
|
|
|
print_header();
|
|
|
|
|
|
|
|
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
|
|
|
|
|
|
|
/// Print heading
|
2005-06-04 09:58:35 +00:00
|
|
|
print_heading(format_string($question->name));
|
2005-05-06 06:24:04 +00:00
|
|
|
|
|
|
|
$instance = get_record('quiz_question_instances', 'quiz', $quiz->id, 'question', $question->id);
|
|
|
|
$question->instance = $instance->id;
|
|
|
|
$question->maxgrade = $instance->grade;
|
|
|
|
$question->name_prefix = 'r';
|
|
|
|
$QUIZ_QTYPES[$question->qtype]->get_question_options($question);
|
|
|
|
|
|
|
|
quiz_restore_state($question, $state);
|
|
|
|
$state->last_graded = $state;
|
|
|
|
|
|
|
|
$options = quiz_get_reviewoptions($quiz, $attempt, $isteacher);
|
|
|
|
$options->validation = ($state->event == QUIZ_EVENTVALIDATE);
|
|
|
|
$options->history = 'all';
|
|
|
|
|
2005-06-04 09:58:35 +00:00
|
|
|
/// Print infobox
|
|
|
|
$table->align = array("right", "left");
|
|
|
|
if ($attempt->userid <> $USER->id) {
|
|
|
|
// Print user picture and name
|
|
|
|
$student = get_record('user', 'id', $attempt->userid);
|
|
|
|
$picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
|
|
|
|
$table->data[] = array($picture, fullname($student, true));
|
|
|
|
}
|
|
|
|
// print quiz name
|
|
|
|
$table->data[] = array(get_string('modulename', 'quiz').':', format_string($quiz->name));
|
|
|
|
if ($isteacher and count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) {
|
|
|
|
// print list of attempts
|
|
|
|
$attemptlist = '';
|
|
|
|
foreach ($attempts as $at) {
|
|
|
|
$attemptlist .= ($at->id == $attempt->id)
|
|
|
|
? '<b>'.$at->attempt.'</b>, '
|
|
|
|
: '<a href="reviewquestion.php?attempt='.$at->id.'&question='.$question->id.'&number='.$number.'">'.$at->attempt.'</a>, ';
|
|
|
|
}
|
|
|
|
$table->data[] = array(get_string('attempts', 'quiz').':', trim($attemptlist, ' ,'));
|
|
|
|
}
|
|
|
|
if ($state->timestamp) {
|
|
|
|
// print time stamp
|
|
|
|
$table->data[] = array(get_string("completedon", "quiz").':', userdate($state->timestamp));
|
|
|
|
}
|
|
|
|
// Print info box unless it is empty
|
|
|
|
if ($table->data) {
|
|
|
|
print_table($table);
|
|
|
|
}
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
quiz_print_quiz_question($question, $state, $number, $quiz, $options);
|
|
|
|
|
|
|
|
print_footer();
|
|
|
|
|
|
|
|
?>
|