source: moodle/trunk/fuentes/admin/roles/ajax.php @ 1331

Last change on this file since 1331 was 1331, checked in by jrpelegrina, 3 years ago

Updated to moodle 3.0.3

File size: 2.6 KB
Line 
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 * This file processes AJAX requests and returns JSON
19 *
20 * This is a server part of yui permissions manager module
21 *
22 * @package core_role
23 * @copyright 2015 Martin Mastny
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26define('AJAX_SCRIPT', true);
27
28require(__DIR__ . '/../../config.php');
29
30$contextid = required_param('contextid', PARAM_INT);
31$getroles = optional_param('getroles', 0, PARAM_BOOL);
32
33list($context, $course, $cm) = get_context_info_array($contextid);
34
35require_login($course, false, $cm);
36require_capability('moodle/role:review', $context);
37require_sesskey();
38
39list($overridableroles, $overridecounts, $nameswithcounts) = get_overridable_roles($context,
40        ROLENAME_BOTH, true);
41
42if ($getroles) {
43    echo json_encode($overridableroles);
44    die();
45}
46
47$capability = required_param('capability', PARAM_CAPABILITY);
48$roleid = required_param('roleid', PARAM_INT);
49$action = required_param('action', PARAM_ALPHA);
50
51$capability = $DB->get_record('capabilities', array('name' => $capability), '*', MUST_EXIST);
52
53if (!isset($overridableroles[$roleid])) {
54    throw new moodle_exception('invalidarguments');
55}
56
57if (!has_capability('moodle/role:override', $context)) {
58    if (!has_capability('moodle/role:safeoverride', $context) || !is_safe_capability($capability)) {
59        require_capability('moodle/role:override', $context);
60    }
61}
62
63switch ($action) {
64    case 'allow':
65        role_change_permission($roleid, $context, $capability->name, CAP_ALLOW);
66        break;
67    case 'prevent':
68        role_change_permission($roleid, $context, $capability->name, CAP_PREVENT);
69        break;
70    case 'prohibit':
71        role_change_permission($roleid, $context, $capability->name, CAP_PROHIBIT);
72        break;
73    case 'unprohibit':
74        role_change_permission($roleid, $context, $capability->name, CAP_INHERIT);
75        break;
76    default:
77        throw new moodle_exception('invalidarguments');
78}
79
80echo json_encode($action);
81die();
Note: See TracBrowser for help on using the repository browser.