3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * This script serves draft files of current user
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
{
34 function definition() {
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
{
72 function definition() {
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'));