-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt_to_disguise.php
109 lines (93 loc) · 3.73 KB
/
prompt_to_disguise.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
* Display a prompt to whether switch to disguise or not.
*
* @package auth_disguise
* @copyright 2023 Catalyst IT {@link https://catalyst-au.net}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirroot . '/auth/disguise/lib.php');
use auth_disguise\manager\disguise;
redirect_if_major_upgrade_required();
$returnurl = optional_param('returnurl', "", PARAM_LOCALURL);
$nexturl = optional_param('nexturl', "", PARAM_LOCALURL);
$contextid = optional_param('contextid', 0, PARAM_INT);
$switchidentity = optional_param('switchidentity', 0, PARAM_INT);
$optional = optional_param('optional', 0, PARAM_BOOL);
// Set page url/
$PAGE->set_url('/auth/disguise/prompt_to_disguise.php');
// Context/
$context = context::instance_by_id($contextid);
$PAGE->set_context($context);
// Check if $USER is logged in.
isloggedin() || redirect($CFG->wwwroot . '/login/index.php');
// Not switching identity, so just continue.
if ($switchidentity == AUTH_DISGUISE_CONTINUE_WITH_CURRENT_ID) {
disguise::ignore_disguise_for_context($contextid);
redirect($returnurl);
}
// Switch ID.
if ($switchidentity == AUTH_DISGUISE_SWITCH_TO_DISGUISE_ID) {
disguise::disguise_user($contextid, $USER->id);
redirect($nexturl);
}
// Set up PAGE.
$context = context::instance_by_id($contextid);
$PAGE->set_context($context);
$PAGE->set_url('/auth/disguise/prompt_to_disguise.php');
$PAGE->set_pagelayout('admin');
// Check if it is course context.
if ($context->contextlevel == CONTEXT_COURSE) {
$course = $DB->get_record('course', ['id' => $context->instanceid], '*', MUST_EXIST);
$PAGE->set_course($course);
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
} else if ($context->contextlevel == CONTEXT_MODULE) {
$cm = $DB->get_record('course_modules', ['id' => $context->instanceid], '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
$PAGE->set_cm($cm, $course);
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('title', 'auth_disguise'));
// Alert Box.
if ($optional) {
echo $OUTPUT->notification(get_string('switch_to_optional_disguise_id_warning', 'auth_disguise'), 'warning');
} else {
echo $OUTPUT->notification(get_string('switch_to_forced_disguise_id_warning', 'auth_disguise'), 'warning');
}
// Continue button.
echo $OUTPUT->single_button(
new moodle_url('/auth/disguise/prompt_to_disguise.php', [
'contextid' => $contextid,
'switchidentity' => AUTH_DISGUISE_CONTINUE_WITH_CURRENT_ID,
'returnurl' => $returnurl,
]),
get_string('continue_with_current_id', 'auth_disguise'),
'get'
);
// Switch identity button.
echo $OUTPUT->single_button(
new moodle_url('/auth/disguise/prompt_to_disguise.php', [
'contextid' => $contextid,
'switchidentity' => AUTH_DISGUISE_SWITCH_TO_DISGUISE_ID,
'nexturl' => $nexturl,
]),
get_string('switch_to_disguise_id', 'auth_disguise'),
'get'
);
echo $OUTPUT->footer();