2009-11-04 11:58:30 +00:00
|
|
|
<?php
|
2005-05-06 06:24:04 +00:00
|
|
|
/**
|
2007-11-07 12:35:33 +00:00
|
|
|
* This page prints a particular instance of quiz
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2002-10-06 03:24:56 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../../config.php');
|
2008-03-07 12:33:07 +00:00
|
|
|
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
2002-10-06 03:24:56 +00:00
|
|
|
|
2009-08-10 05:00:41 +00:00
|
|
|
/// Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php
|
2008-07-09 17:00:26 +00:00
|
|
|
if ($id = optional_param('id', 0, PARAM_INTEGER)) {
|
|
|
|
redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $id . '&sesskey=' . sesskey());
|
|
|
|
} else if ($qid = optional_param('q', 0, PARAM_INTEGER)) {
|
|
|
|
if (!$cm = get_coursemodule_from_instance('quiz', $qid)) {
|
|
|
|
print_error('invalidquizid', 'quiz');
|
|
|
|
}
|
|
|
|
redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $cm->id . '&sesskey=' . sesskey());
|
|
|
|
}
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Get submitted parameters.
|
2008-07-08 16:33:47 +00:00
|
|
|
$attemptid = required_param('attempt', PARAM_INT);
|
2005-05-06 06:24:04 +00:00
|
|
|
$page = optional_param('page', 0, PARAM_INT);
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/quiz/attempt.php', array('attempt'=>$attemptid));
|
2009-09-16 05:15:22 +00:00
|
|
|
if ($page !== 0) {
|
|
|
|
$url->param('page', $page);
|
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
$attemptobj = new quiz_attempt($attemptid);
|
2002-10-06 03:24:56 +00:00
|
|
|
|
2008-07-08 17:45:32 +00:00
|
|
|
/// Check login.
|
2008-07-08 16:33:47 +00:00
|
|
|
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
|
2007-09-20 15:14:24 +00:00
|
|
|
|
2008-07-10 17:23:56 +00:00
|
|
|
/// Check that this attempt belongs to this user.
|
|
|
|
if ($attemptobj->get_userid() != $USER->id) {
|
2009-07-22 09:49:48 +00:00
|
|
|
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
|
|
|
|
redirect($attemptobj->review_url(0, $page));
|
|
|
|
} else {
|
|
|
|
quiz_error($attemptobj->get_quiz(), 'notyourattempt');
|
|
|
|
}
|
2008-07-10 17:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Check capabilites.
|
2008-07-10 17:23:56 +00:00
|
|
|
if ($attemptobj->is_preview_user()) {
|
|
|
|
} else {
|
|
|
|
$attemptobj->require_capability('mod/quiz:attempt');
|
2002-10-16 09:35:04 +00:00
|
|
|
}
|
2008-03-07 12:33:07 +00:00
|
|
|
|
2008-07-15 16:46:24 +00:00
|
|
|
/// If the attempt is already closed, send them to the review page.
|
|
|
|
if ($attemptobj->is_finished()) {
|
|
|
|
redirect($attemptobj->review_url(0, $page));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check the access rules.
|
|
|
|
$accessmanager = $attemptobj->get_access_manager(time());
|
|
|
|
$messages = $accessmanager->prevent_access();
|
|
|
|
if (!$attemptobj->is_preview_user() && $messages) {
|
|
|
|
print_error('attempterror', 'quiz', $quizobj->view_url(),
|
|
|
|
$accessmanager->print_messages($messages, true));
|
|
|
|
}
|
|
|
|
$accessmanager->do_password_check($attemptobj->is_preview_user());
|
|
|
|
|
2009-03-23 01:59:30 +00:00
|
|
|
/// This action used to be 'continue attempt' but the database field has only 15 characters.
|
|
|
|
add_to_log($attemptobj->get_courseid(), 'quiz', 'continue attemp',
|
|
|
|
'review.php?attempt=' . $attemptobj->get_attemptid(),
|
|
|
|
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
2005-01-02 07:15:19 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Get the list of questions needed by this page.
|
2008-07-15 16:46:24 +00:00
|
|
|
$questionids = $attemptobj->get_question_ids($page);
|
2005-06-04 09:58:35 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/// Check.
|
|
|
|
if (empty($questionids)) {
|
2008-03-07 12:33:07 +00:00
|
|
|
quiz_error($quiz, 'noquestionsfound');
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
2002-10-06 03:24:56 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/// Load those questions and the associated states.
|
|
|
|
$attemptobj->load_questions($questionids);
|
|
|
|
$attemptobj->load_question_states($questionids);
|
2003-07-24 02:04:22 +00:00
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
/// Print the quiz page ////////////////////////////////////////////////////////
|
2009-09-17 07:46:20 +00:00
|
|
|
$PAGE->requires->js('lib/overlib/overlib.js')->in_head();
|
|
|
|
$PAGE->requires->js('lib/overlib/overlib_cssstyle.js')->in_head();
|
2002-10-13 07:17:48 +00:00
|
|
|
|
2009-07-09 07:35:03 +00:00
|
|
|
// Arrange for the navigation to be displayed.
|
|
|
|
$navbc = $attemptobj->get_navigation_panel('quiz_attempt_nav_panel', $page);
|
|
|
|
$firstregion = reset($PAGE->blocks->get_regions());
|
|
|
|
$PAGE->blocks->add_pretend_block($navbc, $firstregion);
|
|
|
|
|
2007-04-10 14:27:56 +00:00
|
|
|
// Print the page header
|
2008-07-08 16:33:47 +00:00
|
|
|
$title = get_string('attempt', 'quiz', $attemptobj->get_attempt_number());
|
|
|
|
$headtags = $attemptobj->get_html_head_contributions($page);
|
|
|
|
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
|
|
|
|
$accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
|
|
|
|
format_string($attemptobj->get_quiz_name()), $headtags);
|
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()));
|
|
|
|
$PAGE->set_cacheable(false);
|
|
|
|
echo $OUTPUT->header();
|
2007-04-10 14:27:56 +00:00
|
|
|
} else {
|
2009-09-08 01:57:28 +00:00
|
|
|
$PAGE->set_title(format_string($attemptobj->get_quiz_name()));
|
|
|
|
echo $OUTPUT->header();
|
2007-04-10 14:27:56 +00:00
|
|
|
}
|
|
|
|
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
if ($attemptobj->is_preview_user()) {
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Show the tab bar.
|
2007-04-10 14:27:56 +00:00
|
|
|
$currenttab = 'preview';
|
|
|
|
include('tabs.php');
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Heading and tab bar.
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(get_string('previewquiz', 'quiz', format_string($quiz->name)));
|
2008-07-08 16:33:47 +00:00
|
|
|
$attemptobj->print_restart_preview_button();
|
2008-03-07 12:33:07 +00:00
|
|
|
|
|
|
|
/// Inform teachers of any restrictions that would apply to students at this point.
|
|
|
|
if ($messages) {
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_start('quizaccessnotices');
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(get_string('accessnoticesheader', 'quiz'), 3);
|
2008-03-07 12:33:07 +00:00
|
|
|
$accessmanager->print_messages($messages);
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2007-12-11 15:04:31 +00:00
|
|
|
}
|
2004-08-23 12:35:13 +00:00
|
|
|
}
|
2002-10-13 07:17:48 +00:00
|
|
|
|
2007-04-25 15:45:24 +00:00
|
|
|
// Start the form
|
2009-07-22 09:49:48 +00:00
|
|
|
echo '<form id="responseform" method="post" action="', s($attemptobj->processattempt_url()),
|
2009-02-17 07:21:56 +00:00
|
|
|
'" enctype="multipart/form-data" accept-charset="utf-8">', "\n";
|
ajaxlib/require_js: MDL-16693 $PAGE->requires->... deprecates require_js etc.
There is a new implementation of require_js in lib/deprecatedlib.php,
based on $PAGE->requires.
There were a few other recently introduced functions in lib/weblib.php,
namely print_js_call, print_delayed_js_call, print_js_config and
standard_js_config. These have been removed, since they were never in
a stable branch, and all the places that used them have been changed
to use the newer $PAGE->requires->... methods.
get_require_js_code is also gone, and the evil places that were calling
it, even though it is an internal function, have been fixed.
Also, I made some minor improvements to the code I committed yesterday
for MDL-16695.
All that remains is to update all the places in core code that are
still using require_js.
(This commit also fixes the problem where the admin tree would not
start with the right categories expanded.)
2009-06-12 12:13:07 +00:00
|
|
|
|
|
|
|
// A quiz page with a lot of questions can take a long time to load, and we
|
|
|
|
// want the protection afforded by init_quiz_form immediately, so include the
|
|
|
|
// JS now.
|
2009-07-23 09:20:33 +00:00
|
|
|
echo $PAGE->requires->js_function_call('init_quiz_form')->now();
|
2007-02-28 04:58:48 +00:00
|
|
|
echo '<div>';
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2002-10-13 07:17:48 +00:00
|
|
|
/// Print all the questions
|
2008-07-08 16:33:47 +00:00
|
|
|
foreach ($attemptobj->get_question_ids($page) as $id) {
|
2008-12-10 06:26:47 +00:00
|
|
|
$attemptobj->print_question($id, false, $attemptobj->attempt_url($id, $page));
|
2003-08-03 23:00:45 +00:00
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/// Print a link to the next page.
|
2008-07-11 17:03:43 +00:00
|
|
|
echo '<div class="submitbtns">';
|
2008-07-08 16:33:47 +00:00
|
|
|
if ($attemptobj->is_last_page($page)) {
|
2008-07-15 16:46:24 +00:00
|
|
|
$nextpage = -1;
|
2008-07-08 16:33:47 +00:00
|
|
|
} else {
|
2008-07-15 16:46:24 +00:00
|
|
|
$nextpage = $page + 1;
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
2009-07-23 09:20:33 +00:00
|
|
|
echo '<input type="submit" value="' . get_string('next') . '" />';
|
2006-04-07 16:17:17 +00:00
|
|
|
echo "</div>";
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2008-07-15 16:46:24 +00:00
|
|
|
// Some hidden fields to trach what is going on.
|
|
|
|
echo '<input type="hidden" name="attempt" value="' . $attemptobj->get_attemptid() . '" />';
|
2009-07-23 09:20:33 +00:00
|
|
|
echo '<input type="hidden" name="nextpage" id="nextpagehiddeninput" value="' . $nextpage . '" />';
|
2007-07-26 12:04:34 +00:00
|
|
|
echo '<input type="hidden" name="timeup" id="timeup" value="0" />';
|
2008-07-15 16:46:24 +00:00
|
|
|
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
|
2007-09-26 18:15:31 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
// Add a hidden field with questionids. Do this at the end of the form, so
|
2007-09-26 18:15:31 +00:00
|
|
|
// if you navigate before the form has finished loading, it does not wipe all
|
|
|
|
// the student's answers.
|
2008-07-08 16:33:47 +00:00
|
|
|
echo '<input type="hidden" name="questionids" value="' .
|
|
|
|
implode(',', $attemptobj->get_question_ids($page)) . "\" />\n";
|
2007-09-26 18:15:31 +00:00
|
|
|
|
2008-08-15 11:13:54 +00:00
|
|
|
// Finish the form
|
|
|
|
echo '</div>';
|
|
|
|
echo "</form>\n";
|
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
// Finish the page
|
2008-07-08 16:33:47 +00:00
|
|
|
$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
|
2009-08-06 14:13:48 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-11-04 11:58:30 +00:00
|
|
|
|