2009-10-16 03:20:38 +00:00
|
|
|
<?php
|
2011-02-08 15:02:23 +00:00
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
/**
|
|
|
|
* This page prints a summary of a quiz attempt before it is submitted.
|
|
|
|
*
|
2011-02-21 16:13:25 +00:00
|
|
|
* @package mod
|
2011-02-08 15:02:23 +00:00
|
|
|
* @subpackage quiz
|
2011-02-21 16:13:25 +00:00
|
|
|
* @copyright 2009 The Open University
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2008-06-27 18:04:48 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-21 16:13:25 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../../config.php');
|
|
|
|
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
2008-06-27 18:04:48 +00:00
|
|
|
|
|
|
|
$attemptid = required_param('attempt', PARAM_INT); // The attempt to summarise.
|
2009-10-16 03:20:38 +00:00
|
|
|
|
2010-08-04 16:31:54 +00:00
|
|
|
$PAGE->set_url('/mod/quiz/summary.php', array('attempt' => $attemptid));
|
2009-10-16 03:20:38 +00:00
|
|
|
|
2010-03-08 16:01:38 +00:00
|
|
|
$attemptobj = quiz_attempt::create($attemptid);
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Check login.
|
2010-05-21 03:15:48 +00:00
|
|
|
require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// If this is not our own attempt, display an error.
|
2008-06-27 18:04:48 +00:00
|
|
|
if ($attemptobj->get_userid() != $USER->id) {
|
|
|
|
print_error('notyourattempt', 'quiz', $attemptobj->view_url());
|
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Check capabilites.
|
|
|
|
if (!$attemptobj->is_preview_user()) {
|
|
|
|
$attemptobj->require_capability('mod/quiz:attempt');
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the attempt is already closed, redirect them to the review page.
|
2008-06-27 18:04:48 +00:00
|
|
|
if ($attemptobj->is_finished()) {
|
|
|
|
redirect($attemptobj->review_url());
|
|
|
|
}
|
|
|
|
|
2010-08-04 16:31:54 +00:00
|
|
|
if ($attemptobj->is_preview_user()) {
|
2010-08-06 05:49:47 +00:00
|
|
|
navigation_node::override_active_url($attemptobj->start_attempt_url());
|
2010-08-04 16:31:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Check access.
|
2008-06-27 18:04:48 +00:00
|
|
|
$accessmanager = $attemptobj->get_access_manager(time());
|
|
|
|
$messages = $accessmanager->prevent_access();
|
2008-06-30 16:56:49 +00:00
|
|
|
if (!$attemptobj->is_preview_user() && $messages) {
|
2008-06-27 18:04:48 +00:00
|
|
|
print_error('attempterror', 'quiz', $attemptobj->view_url(),
|
|
|
|
$accessmanager->print_messages($messages, true));
|
|
|
|
}
|
2008-06-30 16:56:49 +00:00
|
|
|
$accessmanager->do_password_check($attemptobj->is_preview_user());
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
$displayoptions = $attemptobj->get_display_options(false);
|
|
|
|
|
|
|
|
// Log this page view.
|
2008-06-27 18:04:48 +00:00
|
|
|
add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(),
|
|
|
|
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Print the page header
|
2010-05-21 03:15:48 +00:00
|
|
|
if (empty($attemptobj->get_quiz()->showblocks)) {
|
|
|
|
$PAGE->blocks->show_only_fake_blocks();
|
|
|
|
}
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
$title = get_string('summaryofattempt', 'quiz');
|
2008-06-30 16:56:49 +00:00
|
|
|
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
|
2008-07-08 16:33:47 +00:00
|
|
|
$accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
|
|
|
|
format_string($attemptobj->get_quiz_name()), '');
|
2009-09-30 10:57:57 +00:00
|
|
|
} elseif ($accessmanager->safebrowser_required($attemptobj->is_preview_user())) {
|
2009-10-16 03:20:38 +00:00
|
|
|
$PAGE->set_title($attemptobj->get_course()->shortname . ': '.format_string($attemptobj->get_quiz_name()));
|
2010-05-21 03:15:48 +00:00
|
|
|
$PAGE->set_heading($attemptobj->get_course()->fullname);
|
2009-10-16 03:20:38 +00:00
|
|
|
$PAGE->set_cacheable(false);
|
|
|
|
echo $OUTPUT->header();
|
2008-06-27 18:04:48 +00:00
|
|
|
} else {
|
2011-02-08 15:02:23 +00:00
|
|
|
$PAGE->navbar->add($title);
|
2009-09-08 01:57:28 +00:00
|
|
|
$PAGE->set_title(format_string($attemptobj->get_quiz_name()));
|
2010-05-21 03:15:48 +00:00
|
|
|
$PAGE->set_heading($attemptobj->get_course()->fullname);
|
2009-09-08 01:57:28 +00:00
|
|
|
echo $OUTPUT->header();
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Print heading.
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(format_string($attemptobj->get_quiz_name()));
|
2008-06-30 16:56:49 +00:00
|
|
|
if ($attemptobj->is_preview_user()) {
|
2008-07-08 16:33:47 +00:00
|
|
|
$attemptobj->print_restart_preview_button();
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading($title);
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Prepare the summary table header
|
2009-08-20 08:45:47 +00:00
|
|
|
$table = new html_table();
|
2010-03-20 22:15:54 +00:00
|
|
|
$table->attributes['class'] = 'generaltable quizsummaryofattempt boxaligncenter';
|
2008-06-27 18:04:48 +00:00
|
|
|
$table->head = array(get_string('question', 'quiz'), get_string('status', 'quiz'));
|
|
|
|
$table->align = array('left', 'left');
|
|
|
|
$table->size = array('', '');
|
2011-02-08 15:02:23 +00:00
|
|
|
$markscolumn = $displayoptions->marks;
|
|
|
|
if ($markscolumn) {
|
2008-06-27 18:04:48 +00:00
|
|
|
$table->head[] = get_string('marks', 'quiz');
|
|
|
|
$table->align[] = 'left';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
|
|
|
$table->data = array();
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Get the summary info for each question.
|
|
|
|
$slots = $attemptobj->get_slots();
|
|
|
|
foreach ($slots as $slot) {
|
|
|
|
if (!$attemptobj->is_real_question($slot)) {
|
2008-07-10 17:23:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-29 11:40:58 +00:00
|
|
|
$flag = '';
|
2011-02-08 15:02:23 +00:00
|
|
|
if ($attemptobj->is_question_flagged($slot)) {
|
2009-12-16 21:50:45 +00:00
|
|
|
$flag = ' <img src="' . $OUTPUT->pix_url('i/flagged') . '" alt="' .
|
2008-08-29 11:40:58 +00:00
|
|
|
get_string('flagged', 'question') . '" class="questionflag" />';
|
|
|
|
}
|
2011-02-11 17:36:30 +00:00
|
|
|
$row = array('<a href="' . $attemptobj->attempt_url($slot) . '">' .
|
2011-02-08 15:02:23 +00:00
|
|
|
$attemptobj->get_question_number($slot) . $flag . '</a>',
|
|
|
|
$attemptobj->get_question_status($slot, $displayoptions->correctness));
|
|
|
|
if ($markscolumn) {
|
2011-02-09 16:56:44 +00:00
|
|
|
$row[] = $attemptobj->get_question_mark($slot);
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
$table->data[] = $row;
|
|
|
|
}
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Print the summary table.
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// countdown timer
|
2009-03-11 07:10:57 +00:00
|
|
|
echo $attemptobj->get_timer_html();
|
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Finish attempt button.
|
2009-08-20 08:45:47 +00:00
|
|
|
echo $OUTPUT->container_start('submitbtns mdl-align');
|
2008-06-27 18:04:48 +00:00
|
|
|
$options = array(
|
2008-07-15 16:46:24 +00:00
|
|
|
'attempt' => $attemptobj->get_attemptid(),
|
2008-06-27 18:04:48 +00:00
|
|
|
'finishattempt' => 1,
|
|
|
|
'timeup' => 0,
|
2011-02-08 15:02:23 +00:00
|
|
|
'slots' => '',
|
2008-07-15 16:46:24 +00:00
|
|
|
'sesskey' => sesskey(),
|
2008-06-27 18:04:48 +00:00
|
|
|
);
|
2009-08-20 08:45:47 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
$button = new single_button(
|
|
|
|
new moodle_url($attemptobj->processattempt_url(), $options),
|
|
|
|
get_string('submitallandfinish', 'quiz'));
|
2010-01-14 19:18:04 +00:00
|
|
|
$button->id = 'responseform';
|
|
|
|
$button->add_confirm_action(get_string('confirmclose', 'quiz'));
|
2009-08-20 08:45:47 +00:00
|
|
|
|
2010-07-28 15:04:26 +00:00
|
|
|
echo $OUTPUT->container_start('controls');
|
2010-01-14 19:18:04 +00:00
|
|
|
echo $OUTPUT->render($button);
|
2009-08-20 08:45:47 +00:00
|
|
|
echo $OUTPUT->container_end();
|
2010-07-28 15:04:26 +00:00
|
|
|
echo $OUTPUT->container_end();
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2011-02-08 15:02:23 +00:00
|
|
|
// Finish the page
|
2008-06-27 18:04:48 +00:00
|
|
|
$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
|
2009-08-06 14:13:48 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-06-27 18:04:48 +00:00
|
|
|
|