moodle/mod/quiz/attempt.php
tjhunt d4a03c00ea themes & blocks - MDL-19077 & MDL-19010 blocks are now printed by the theme
The code to print blocks in now in theme layout.php files. (Or in
moodle_core_renderer::handle_legacy_theme)

Code for printing blocks everywhere else has been stripped out.
(Total diffstat 1225 insertions, 2019 deletions)

The way the HTML for a block instance is generated has been cleaned
up a lot. Now, the block_instance generates a block_contents
object which gives a structured representation of the block,
and then $OUTPUT->block builds all the HTML from that.

How theme config.php files specify the layout template and block
regions by page general type has been changed to be even more flexible.

Further refinement for how the theme and block code gets initialised.

Ability for scrits to add 'pretend blocks' to the page. That is,
things that look like blocks, but are not normal block_instances.
(Like the add a new block UI.)

Things that are still broken:
 * some pages in lesson, quiz and resource. I'm working on it.
 * lots of developer debug notices pointing out things that
   need to be updated.
2009-07-09 07:35:03 +00:00

175 lines
7.0 KiB
PHP

<?php // $Id$
/**
* 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
*/
require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
/// Look for old-style URLs, such as may be in the logs, and redirect them to startattemtp.php
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());
}
/// Get submitted parameters.
$attemptid = required_param('attempt', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
/// Check that this attempt belongs to this user.
if ($attemptobj->get_userid() != $USER->id) {
redirect($attemptobj->review_url(0, $page));
}
/// Check capabilites.
if ($attemptobj->is_preview_user()) {
} else {
$attemptobj->require_capability('mod/quiz:attempt');
}
/// 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());
/// 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());
/// Get the list of questions needed by this page.
$questionids = $attemptobj->get_question_ids($page);
/// Check.
if (empty($questionids)) {
quiz_error($quiz, 'noquestionsfound');
}
/// Load those questions and the associated states.
$attemptobj->load_questions($questionids);
$attemptobj->load_question_states($questionids);
/// Print the quiz page ////////////////////////////////////////////////////////
// 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);
// Print the page header
$PAGE->requires->yui_lib('event');
$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);
} else {
print_header_simple(format_string($attemptobj->get_quiz_name()), '', $attemptobj->navigation($title),
'', $headtags, true, $attemptobj->update_module_button());
}
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
if ($attemptobj->is_preview_user()) {
/// Show the tab bar.
$currenttab = 'preview';
include('tabs.php');
/// Heading and tab bar.
print_heading(get_string('previewquiz', 'quiz', format_string($quiz->name)));
$attemptobj->print_restart_preview_button();
/// Inform teachers of any restrictions that would apply to students at this point.
if ($messages) {
print_box_start('quizaccessnotices');
print_heading(get_string('accessnoticesheader', 'quiz'), '', 3);
$accessmanager->print_messages($messages);
print_box_end();
}
} else {
/// Just a heading.
if ($attemptobj->get_num_attempts_allowed() != 1) {
print_heading(format_string($attemptobj->get_quiz_name()).' - '.$title);
} else {
print_heading(format_string($attemptobj->get_quiz_name()));
}
}
// Start the form
echo '<form id="responseform" method="post" action="', $attemptobj->processattempt_url(),
'" enctype="multipart/form-data" accept-charset="utf-8">', "\n";
// 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.
echo $PAGE->requires->yui_lib('event')->asap();
echo $PAGE->requires->js('mod/quiz/quiz.js')->asap();
echo $PAGE->requires->js_function_call('init_quiz_form')->asap();
echo '<div>';
/// Print all the questions
foreach ($attemptobj->get_question_ids($page) as $id) {
$attemptobj->print_question($id, false, $attemptobj->attempt_url($id, $page));
}
/// Print a link to the next page.
echo '<div class="submitbtns">';
if ($attemptobj->is_last_page($page)) {
$nextpage = -1;
$nextpageforie = 'gotosummary';
} else {
$nextpage = $page + 1;
$nextpageforie = 'gotopage' . $nextpage;
}
echo '<input type="submit" name="' . $nextpageforie . '" value="' . get_string('next') . '" />';
echo "</div>";
// Some hidden fields to trach what is going on.
echo '<input type="hidden" name="attempt" value="' . $attemptobj->get_attemptid() . '" />';
echo '<input type="hidden" name="nextpage" value="' . $nextpage . '" />';
echo '<input type="hidden" name="timeup" id="timeup" value="0" />';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
// Add a hidden field with questionids. Do this at the end of the form, so
// if you navigate before the form has finished loading, it does not wipe all
// the student's answers.
echo '<input type="hidden" name="questionids" value="' .
implode(',', $attemptobj->get_question_ids($page)) . "\" />\n";
// Finish the form
echo '</div>';
echo "</form>\n";
// Finish the page
$accessmanager->show_attempt_timer_if_needed($attemptobj->get_attempt(), time());
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
print_footer('empty');
} else {
print_footer($attemptobj->get_course());
}
?>