-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathswitch.php
71 lines (57 loc) · 2.18 KB
/
switch.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
<?php
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
/**
* The purpose of this file is to allow the user to turn off and on the editor
* and js in the user's profile
*
* @package local
* @subpackage profileswitches
* @copyright 2012 Itamar Tzadok
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../config.php');
$id = required_param('id', PARAM_INT); // User id
$returnurl = required_param('returnurl', PARAM_URL);
$editor = optional_param('editor',-1, PARAM_INT);
$ajax = optional_param('ajax',-1, PARAM_INT);
$PAGE->set_url('/local/profileswitches/switch.php', array('id'=>$id));
if ($USER->id != $id) {
print_error('invaliduserid');
}
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
}
require_login();
$user = $USER;
$syscontext = get_system_context();
if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
if (is_siteadmin($user) || has_capability('moodle/user:editownprofile', $syscontext)) {
// Switch editor
if ($editor != -1) {
$DB->set_field('user', 'htmleditor', $editor, array('id' => $id));
$user->htmleditor = $editor;
}
// Switch ajax in the era of profile ajax setting
if (isset($user->ajax) and $ajax != -1) {
$DB->set_field('user', 'ajax', $ajax, array('id' => $id));
$user->ajax = $ajax;
// Switch ajax in the new era via theme
} else if ($ajax != -1) {
set_user_preference('courseajax', $ajax);
}
}
}
redirect($returnurl);