MDL-29627 refactor quiz access rules into separate subplugins.
[moodle.git] / mod / quiz / accessrule / securewindow / rule.php
CommitLineData
a28a5d74
TH
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
27defined('MOODLE_INTERNAL') || die();
28
29require_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*/
39class quizaccess_securewindow extends quiz_access_rule_base {
40 /** @var array options that should be used for opening the secure popup. */
41 public 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 /**
56 * Make a link to the review page for an attempt.
57 *
58 * @param string $linktext the desired link text.
59 * @param int $attemptid the attempt id.
60 * @return string HTML for the link.
61 */
62 public function make_review_link($linktext, $attemptid) {
63 global $OUTPUT;
64 $url = $this->_quizobj->review_url($attemptid);
65 $button = new single_button($url, $linktext);
66 $button->add_action(new popup_action('click', $url, 'quizpopup', self::$popupoptions));
67 return $OUTPUT->render($button);
68 }
69
70 /**
71 * Do the printheader call, etc. required for a secure page, including the necessary JS.
72 *
73 * @param string $title HTML title tag content, passed to printheader.
74 * @param string $headtags extra stuff to go in the HTML head tag, passed to printheader.
75 * $headtags has been deprectaed since Moodle 2.0
76 */
77 public function setup_secure_page($title, $headtags=null) {
78 global $PAGE;
79 $PAGE->set_popup_notification_allowed(false);//prevent message notifications
80 $PAGE->set_title($title);
81 $PAGE->set_cacheable(false);
82 $PAGE->set_pagelayout('popup');
83 $PAGE->add_body_class('quiz-secure-window');
84 $PAGE->requires->js_init_call('M.mod_quiz.secure_window.init',
85 null, false, quiz_get_js_module());
86 }
87}