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()); /// Log continuation of the attempt, but only if some time has passed. if ((time() - $attemptobj->get_attempt()->timemodified) > QUIZ_CONTINUE_ATTEMPT_LOG_INTERVAL) { /// 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 //////////////////////////////////////////////////////// // Print the page header require_js($CFG->wwwroot . '/mod/quiz/quiz.js'); $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 '
'; // 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 '\n"; // End middle column. print_container_end(); echo ''; echo ''; echo ''; // 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()); } ?>