public function setup_attempt_page($page) { $page->set_popup_notification_allowed(false); // Prevent message notifications. $page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title); $page->set_cacheable(false); $page->set_pagelayout('popup'); if ($this->quizobj->is_preview_user()) { return; } $page->add_body_class('quiz-secure-window'); $page->requires->js_init_call('M.mod_quiz.secure_window.init', null, false, quiz_get_js_module()); }
/** * Generates the view attempt button * * @param int $course The course ID * @param array $quiz Array containging quiz date * @param int $cm The Course Module ID * @param int $context The page Context ID * @param mod_quiz_view_object $viewobj * @param string $buttontext */ public function start_attempt_button($buttontext, moodle_url $url, $startattemptwarning, $popuprequired, $popupoptions) { $button = new single_button($url, $buttontext); $button->class .= ' quizstartbuttondiv'; $warning = ''; if ($popuprequired) { $this->page->requires->js_module(quiz_get_js_module()); $this->page->requires->js('/mod/quiz/module.js'); $popupaction = new popup_action('click', $url, 'quizpopup', $popupoptions); $button->class .= ' quizsecuremoderequired'; $button->add_action(new component_action('click', 'M.mod_quiz.secure_window.start_attempt_action', array( 'url' => $url->out(false), 'windowname' => 'quizpopup', 'options' => $popupaction->get_js_options(), 'fullscreen' => true, 'startattemptwarning' => $startattemptwarning, ))); $warning = html_writer::tag('noscript', $this->heading(get_string('noscript', 'quiz'))); } else if ($startattemptwarning) { $button->add_action(new confirm_action($startattemptwarning, null, get_string('startattempt', 'quiz'))); } return $this->render($button) . $warning; }
/// Summary table end ============================================================================== /// Form for saving flags if necessary. if ($options->flags == QUESTION_FLAGSEDITABLE) { echo '<form action="' . s($attemptobj->review_url(0, $page, $showall)) . '" method="post" class="questionflagsaveform"><div>'; echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; } /// Print all the questions. if ($showall) { $thispage = 'all'; $lastpage = true; } else { $thispage = $page; $lastpage = $attemptobj->is_last_page($page); } foreach ($attemptobj->get_question_ids($thispage) as $id) { $attemptobj->print_question($id, true, $attemptobj->review_url($id, $page, $showall)); } /// Close form if we opened it. if ($options->flags == QUESTION_FLAGSEDITABLE) { echo '<div class="submitbtns">' . "\n" . '<input type="submit" class="questionflagsavebutton" name="savingflags" value="' . get_string('saveflags', 'question') . '" />' . "</div>\n" . "\n</div></form>\n"; $PAGE->requires->js_init_call('M.mod_quiz.init_review_form', null, false, quiz_get_js_module()); } /// Print a link to the next page. echo '<div class="submitbtns">'; if ($lastpage) { $accessmanager->print_finish_review_link($attemptobj->is_preview_user()); } else { echo link_arrow_right(get_string('next'), s($attemptobj->review_url(0, $page + 1))); } echo "</div>"; echo $OUTPUT->footer();
// Print the comment form. echo '<form method="post" class="mform" id="manualgradingform" action="' . $CFG->wwwroot . '/mod/quiz/comment.php">'; echo $attemptobj->render_question_for_commenting($slot); ?> <div> <input type="hidden" name="attempt" value="<?php echo $attemptobj->get_attemptid(); ?>" /> <input type="hidden" name="slot" value="<?php echo $slot; ?>" /> <input type="hidden" name="slots" value="<?php echo $slot; ?>" /> <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" /> </div> <fieldset class="hidden"> <div> <div class="fitem"> <div class="fitemtitle"> <div class="fgrouplabel"><label> </label></div> </div> <fieldset class="felement fgroup"> <input id="id_submitbutton" type="submit" name="submit" value="<?php print_string('save', 'quiz'); ?>"/> </fieldset> </div> </div> </fieldset> <?php echo '</form>'; $PAGE->requires->js_init_call('M.mod_quiz.init_comment_popup', null, false, quiz_get_js_module()); // End of the page. echo $OUTPUT->footer();
$accessmanager = $attemptobj->get_access_manager(time()); $accessmanager->setup_attempt_page($PAGE); // Complete masquerading as the mod-quiz-attempt page. Must be done after setup_attempt_page. $PAGE->set_pagetype('mod-quiz-attempt'); // Get the renderer. $output = $PAGE->get_renderer('mod_quiz'); $messages = $accessmanager->prevent_access(); if (!$attemptobj->is_preview_user() && $messages) { print_error('attempterror', 'quiz', $attemptobj->view_url(), $output->access_messages($messages)); } if ($accessmanager->is_preflight_check_required($attemptobj->get_attemptid())) { redirect($attemptobj->start_attempt_url(null, $page)); } // Initialise the JavaScript. question_engine::initialise_js(); $PAGE->requires->js_module(quiz_get_js_module()); $autosaveperiod = get_config('quiz', 'autosaveperiod'); if (!$autosaveperiod) { // Offline mode only works with autosave, so if it is off for normal quizzes, // use a sensible default. $autosaveperiod = 60; } $PAGE->requires->yui_module('moodle-quizaccess_offlinemode-autosave', 'M.quizaccess_offlinemode.autosave.init', array($autosaveperiod)); $PAGE->requires->yui_module('moodle-quizaccess_offlinemode-navigation', 'M.quizaccess_offlinemode.navigation.init', array($page)); if (!empty($USER->idnumber)) { $user = '******' . $USER->idnumber; } else { $user = '******' . $USER->id; } $emergencysavefilename = clean_filename(format_string($attemptobj->get_quiz_name()) . $user . '-a' . $attemptid . '-d197001010000.attemptdata'); $PAGE->requires->yui_module('moodle-quizaccess_offlinemode-download', 'M.quizaccess_offlinemode.download.init', array($emergencysavefilename, get_config('quizaccess_offlinemode', 'publickey')));
/** * Output a page with an optional message, and JavaScript code to close the * current window and redirect the parent window to a new URL. * @param moodle_url $url the URL to redirect the parent window to. * @param string $message message to display before closing the window. (optional) * @return string HTML to output. */ public function close_attempt_popup($url, $message = '') { $output = ''; $output .= $this->header(); $output .= $this->box_start(); if ($message) { $output .= html_writer::tag('p', $message); $output .= html_writer::tag('p', get_string('windowclosing', 'quiz')); $delay = 5; } else { $output .= html_writer::tag('p', get_string('pleaseclose', 'quiz')); $delay = 0; } $this->page->requires->js_init_call('M.mod_quiz.secure_window.close', array($url, $delay), false, quiz_get_js_module()); $output .= $this->box_end(); $output .= $this->footer(); return $output; }
public function get_contents() { global $PAGE; $PAGE->requires->js_init_call('M.mod_quiz.nav.init', null, false, quiz_get_js_module()); $content = ''; if ($this->attemptobj->get_quiz()->showuserpicture) { $content .= $this->get_user_picture() . "\n"; } $content .= $this->get_before_button_bits(); $content .= $this->get_question_buttons() . "\n"; $content .= '<div class="othernav">' . "\n" . $this->get_end_bits() . "\n</div>\n"; $bc = new block_contents(); $bc->id = 'quiznavigation'; $bc->title = get_string('quiznavigation', 'quiz'); $bc->content = $content; return $bc; }
/** * Do the printheader call, etc. required for a secure page, including the necessary JS. * * @param string $title HTML title tag content, passed to printheader. * @param string $headtags extra stuff to go in the HTML head tag, passed to printheader. * $headtags has been deprectaed since Moodle 2.0 */ public function setup_secure_page($title, $headtags=null) { global $PAGE; $PAGE->set_popup_notification_allowed(false);//prevent message notifications $PAGE->set_title($title); $PAGE->set_cacheable(false); $PAGE->set_pagelayout('popup'); $PAGE->add_body_class('quiz-secure-window'); $PAGE->requires->js_init_call('M.mod_quiz.secure_window.init', null, false, quiz_get_js_module()); }
/** * Outputs the navigation block panel * * @param quiz_nav_panel_base $panel instance of quiz_nav_panel_base */ public function navigation_panel(quiz_nav_panel_base $panel) { $output = ''; $userpicture = $panel->user_picture(); if ($userpicture) { $output .= html_writer::tag('div', $this->render($userpicture), array('id' => 'user-picture', 'class' => 'clearfix')); } $output .= $panel->render_before_button_bits($this); $output .= html_writer::start_tag('div', array('class' => 'qn_buttons')); foreach ($panel->get_question_buttons() as $button) { $output .= $this->render($button); } $output .= html_writer::end_tag('div'); $output .= html_writer::tag('div', $panel->render_end_bits($this), array('class' => 'othernav')); $this->page->requires->js_init_call('M.mod_quiz.nav.init', null, false, quiz_get_js_module()); return $output; }