예제 #1
0
            $attempturl = "attempt.php?id={$cm->id}";
            // Prepare options depending on whether the quiz should be a popup.
            if ($quiz->popup == 1) {
                $window = 'quizpopup';
                $windowoptions = "left=0, top=0, height='+window.screen.height+', " . "width='+window.screen.width+', channelmode=yes, fullscreen=yes, " . "scrollbars=yes, resizeable=no, directories=no, toolbar=no, " . "titlebar=no, location=no, status=no, menubar=no";
                if (!empty($CFG->usesid) && !isset($_COOKIE[session_name()])) {
                    $attempturl = sid_process_url($attempturl);
                }
                echo '<input type="button" value="' . $buttontext . '" onclick="javascript:';
                if ($strconfirmstartattempt) {
                    $strconfirmstartattempt = addslashes($strconfirmstartattempt);
                    echo "if (confirm('" . addslashes_js($strconfirmstartattempt) . "')) ";
                }
                echo "window.open('{$attempturl}','{$window}','{$windowoptions}');", '" />';
            } else {
                if ($quiz->popup == 2 && !quiz_check_safe_browser()) {
                    notify(get_string('safebrowsererror', 'quiz'));
                } else {
                    print_single_button("attempt.php", array('id' => $cm->id), $buttontext, 'get', '', false, '', false, $strconfirmstartattempt);
                }
            }
            ?>
<noscript>
<div>
    <?php 
            print_heading(get_string('noscript', 'quiz'));
            ?>
</div>
</noscript>
<?php 
        }
예제 #2
0
if (!($attemptnumber = (int) get_field_sql('SELECT MAX(attempt)+1 FROM ' . "{$CFG->prefix}quiz_attempts WHERE quiz = '{$quiz->id}' AND " . "userid = '{$USER->id}' AND timefinish > 0 AND preview != 1"))) {
    $attemptnumber = 1;
}
$strattemptnum = get_string('attempt', 'quiz', $attemptnumber);
$strquizzes = get_string("modulenameplural", "quiz");
$popup = $quiz->popup && !$ispreviewing;
// Controls whether this is shown in a javascript-protected window or with a safe browser.
/// We intentionally do not check open and close times here. Instead we do it lower down.
/// This is to deal with what happens when someone submits close to the exact moment when the quiz closes.
/// Check number of attempts
$numberofpreviousattempts = count_records_select('quiz_attempts', "quiz = '{$quiz->id}' AND " . "userid = '{$USER->id}' AND timefinish > 0 AND preview != 1");
if (!empty($quiz->attempts) and $numberofpreviousattempts >= $quiz->attempts) {
    print_error('nomoreattempts', 'quiz', "view.php?id={$cm->id}");
}
/// Check safe browser
if (!$ispreviewing && $quiz->popup == 2 && !quiz_check_safe_browser()) {
    print_error('safebrowsererror', 'quiz', "view.php?id={$cm->id}");
}
/// Check subnet access
if (!$ispreviewing && !empty($quiz->subnet) && !address_in_subnet(getremoteaddr(), $quiz->subnet)) {
    print_error("subneterror", "quiz", "view.php?id={$cm->id}");
}
/// Check password access
if ($ispreviewing && $forcenew) {
    unset($SESSION->passwordcheckedquizzes[$quiz->id]);
}
if (!empty($quiz->password) and empty($SESSION->passwordcheckedquizzes[$quiz->id])) {
    $enteredpassword = optional_param('quizpassword', '', PARAM_RAW);
    if (optional_param('cancelpassword', false)) {
        // User clicked cancel in the password form.
        redirect($CFG->wwwroot . '/mod/quiz/view.php?q=' . $quiz->id);
예제 #3
0
 public function prevent_access() {
     if (!$this->_quizobj->is_preview_user() && !quiz_check_safe_browser()) {
         return get_string('safebrowsererror', 'quiz');
     } else {
         return false;
     }
 }