Commit | Line | Data |
---|---|---|
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_safebrowser plugin. | |
19 | * | |
20 | * @package quizaccess | |
21 | * @subpackage safebrowser | |
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 | /** | |
0eafc988 TH |
33 | * A rule representing the safe browser check. |
34 | * | |
35 | * @copyright 2009 Oliver Rahs | |
36 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
37 | */ | |
ea38245c | 38 | class quizaccess_safebrowser extends quiz_access_rule_base { |
1d9e1a3c TH |
39 | |
40 | public static function make(quiz $quizobj, $timenow, $canignoretimelimits) { | |
41 | ||
4344c5d5 | 42 | if ($quizobj->get_quiz()->browsersecurity !== 'safebrowser') { |
1d9e1a3c TH |
43 | return null; |
44 | } | |
45 | ||
46 | return new self($quizobj, $timenow); | |
47 | } | |
48 | ||
a28a5d74 | 49 | public function prevent_access() { |
ea38245c | 50 | if (!$this->check_safe_browser()) { |
ffe162d4 | 51 | return get_string('safebrowsererror', 'quizaccess_safebrowser'); |
a28a5d74 TH |
52 | } else { |
53 | return false; | |
54 | } | |
55 | } | |
56 | ||
57 | public function description() { | |
ffe162d4 | 58 | return get_string('safebrowsernotice', 'quizaccess_safebrowser'); |
a28a5d74 | 59 | } |
ea38245c | 60 | |
d755b0f5 TH |
61 | public function setup_attempt_page($page) { |
62 | $page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title); | |
63 | $page->set_cacheable(false); | |
2d0e682d MV |
64 | $page->set_popup_notification_allowed(false); // Prevent message notifications. |
65 | $page->set_heading($page->title); | |
66 | $page->set_pagelayout('secure'); | |
d755b0f5 TH |
67 | } |
68 | ||
ea38245c TH |
69 | /** |
70 | * Checks if browser is safe browser | |
71 | * | |
72 | * @return true, if browser is safe browser else false | |
73 | */ | |
0eafc988 | 74 | public function check_safe_browser() { |
1d9e1a3c TH |
75 | return strpos($_SERVER['HTTP_USER_AGENT'], 'SEB') !== false; |
76 | } | |
77 | ||
78 | /** | |
79 | * @return array key => lang string any choices to add to the quiz Browser | |
80 | * security settings menu. | |
81 | */ | |
82 | public static function get_browser_security_choices() { | |
83 | global $CFG; | |
84 | ||
85 | if (empty($CFG->enablesafebrowserintegration)) { | |
86 | return array(); | |
87 | } | |
88 | ||
ffe162d4 TH |
89 | return array('safebrowser' => |
90 | get_string('requiresafeexambrowser', 'quizaccess_safebrowser')); | |
ea38245c | 91 | } |
a28a5d74 | 92 | } |