Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 402] [Versions 311 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Implementaton of the quizaccess_securewindow plugin.
  19   *
  20   * @package    quizaccess
  21   * @subpackage securewindow
  22   * @copyright  2011 The Open University
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->dirroot . '/mod/quiz/accessrule/accessrulebase.php');
  30  
  31  
  32  /**
  33   * A rule for ensuring that the quiz is opened in a popup, with some JavaScript
  34   * to prevent copying and pasting, etc.
  35   *
  36   * @copyright  2009 Tim Hunt
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class quizaccess_securewindow extends quiz_access_rule_base {
  40      /** @var array options that should be used for opening the secure popup. */
  41      protected static $popupoptions = array(
  42          'left' => 0,
  43          'top' => 0,
  44          'fullscreen' => true,
  45          'scrollbars' => true,
  46          'resizeable' => false,
  47          'directories' => false,
  48          'toolbar' => false,
  49          'titlebar' => false,
  50          'location' => false,
  51          'status' => false,
  52          'menubar' => false,
  53      );
  54  
  55      public static function make(quiz $quizobj, $timenow, $canignoretimelimits) {
  56  
  57          if ($quizobj->get_quiz()->browsersecurity !== 'securewindow') {
  58              return null;
  59          }
  60  
  61          return new self($quizobj, $timenow);
  62      }
  63  
  64      public function attempt_must_be_in_popup() {
  65          return !$this->quizobj->is_preview_user();
  66      }
  67  
  68      public function get_popup_options() {
  69          return self::$popupoptions;
  70      }
  71  
  72      public function setup_attempt_page($page) {
  73          $page->set_popup_notification_allowed(false); // Prevent message notifications.
  74          $page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title);
  75          $page->set_pagelayout('secure');
  76  
  77          if ($this->quizobj->is_preview_user()) {
  78              return;
  79          }
  80  
  81          $page->add_body_class('quiz-secure-window');
  82          $page->requires->js_init_call('M.mod_quiz.secure_window.init',
  83                  null, false, quiz_get_js_module());
  84      }
  85  
  86      /**
  87       * @return array key => lang string any choices to add to the quiz Browser
  88       *      security settings menu.
  89       */
  90      public static function get_browser_security_choices() {
  91          return array('securewindow' =>
  92                  get_string('popupwithjavascriptsupport', 'quizaccess_securewindow'));
  93      }
  94  }