Merge branch 'MDL-31829_22' of git://github.com/timhunt/moodle into MOODLE_22_STABLE
[moodle.git] / admin / roles / permissions_forms.php
blob32b646ef66a05f6fb85470c8bf8e79766e3b774b
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This script serves draft files of current user
21 * @package core
22 * @subpackage role
23 * @copyright 2009 Petr Skoda (skodak) info@skodak.org
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once("$CFG->libdir/formslib.php");
31 class role_allow_form extends moodleform {
33 // Define the form
34 function definition() {
35 global $CFG;
37 $mform = $this->_form;
38 list($context, $capability, $overridableroles) = $this->_customdata;
40 list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
41 foreach($needed as $id=>$unused) {
42 unset($overridableroles[$id]);
44 foreach($forbidden as $id=>$unused) {
45 unset($overridableroles[$id]);
48 $mform->addElement('header', 'allowheader', get_string('roleallowheader', 'role'));
50 $mform->addElement('select', 'roleid', get_string('roleselect', 'role'), $overridableroles);
52 $mform->addElement('hidden','capability');
53 $mform->setType('capability', PARAM_CAPABILITY);
54 $mform->setDefault('capability', $capability->name);
56 $mform->addElement('hidden','contextid');
57 $mform->setType('contextid', PARAM_INT);
58 $mform->setDefault('contextid', $context->id);
60 $mform->addElement('hidden','allow');
61 $mform->setType('allow', PARAM_INT);
62 $mform->setDefault('allow', 1);
64 $this->add_action_buttons(true, get_string('allow', 'role'));
69 class role_prohibit_form extends moodleform {
71 // Define the form
72 function definition() {
73 global $CFG;
75 $mform = $this->_form;
76 list($context, $capability, $overridableroles) = $this->_customdata;
78 list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
79 foreach($forbidden as $id=>$unused) {
80 unset($overridableroles[$id]);
83 $mform->addElement('header', 'ptohibitheader', get_string('roleprohibitheader', 'role'));
85 $mform->addElement('select', 'roleid', get_string('roleselect', 'role'), $overridableroles);
87 $mform->addElement('hidden','capability');
88 $mform->setType('capability', PARAM_CAPABILITY);
89 $mform->setDefault('capability', $capability->name);
91 $mform->addElement('hidden','contextid');
92 $mform->setType('contextid', PARAM_INT);
93 $mform->setDefault('contextid', $context->id);
95 $mform->addElement('hidden','prohibit');
96 $mform->setType('prohibit', PARAM_INT);
97 $mform->setDefault('prohibit', 1);
99 $this->add_action_buttons(true, get_string('prohibit', 'role'));