PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/roles/permissions_forms.php

http://github.com/moodle/moodle
PHP | 101 lines | 51 code | 26 blank | 24 comment | 0 complexity | 0ac6d1ba9460e91d5a4a6cce9b1ae238 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. * This script serves draft files of current user
  18. *
  19. * @package core
  20. * @subpackage role
  21. * @copyright 2009 Petr Skoda (skodak) info@skodak.org
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. require_once("$CFG->libdir/formslib.php");
  25. class role_allow_form extends moodleform {
  26. // Define the form
  27. function definition() {
  28. global $CFG;
  29. $mform = $this->_form;
  30. list($context, $capability, $overridableroles) = $this->_customdata;
  31. list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
  32. foreach($needed as $id=>$unused) {
  33. unset($overridableroles[$id]);
  34. }
  35. foreach($forbidden as $id=>$unused) {
  36. unset($overridableroles[$id]);
  37. }
  38. $mform->addElement('header', 'allowheader', get_string('roleallowheader', 'role'));
  39. $mform->addElement('select', 'roleid', get_string('roleselect', 'role'), $overridableroles);
  40. $mform->addElement('hidden','capability');
  41. $mform->setType('capability', PARAM_CAPABILITY);
  42. $mform->setDefault('capability', $capability->name);
  43. $mform->addElement('hidden','contextid');
  44. $mform->setType('contextid', PARAM_INT);
  45. $mform->setDefault('contextid', $context->id);
  46. $mform->addElement('hidden','allow');
  47. $mform->setType('allow', PARAM_INT);
  48. $mform->setDefault('allow', 1);
  49. $this->add_action_buttons(true, get_string('allow', 'role'));
  50. }
  51. }
  52. class role_prohibit_form extends moodleform {
  53. // Define the form
  54. function definition() {
  55. global $CFG;
  56. $mform = $this->_form;
  57. list($context, $capability, $overridableroles) = $this->_customdata;
  58. list($needed, $forbidden) = get_roles_with_cap_in_context($context, $capability->name);
  59. foreach($forbidden as $id=>$unused) {
  60. unset($overridableroles[$id]);
  61. }
  62. $mform->addElement('header', 'ptohibitheader', get_string('roleprohibitheader', 'role'));
  63. $mform->addElement('select', 'roleid', get_string('roleselect', 'role'), $overridableroles);
  64. $mform->addElement('hidden','capability');
  65. $mform->setType('capability', PARAM_CAPABILITY);
  66. $mform->setDefault('capability', $capability->name);
  67. $mform->addElement('hidden','contextid');
  68. $mform->setType('contextid', PARAM_INT);
  69. $mform->setDefault('contextid', $context->id);
  70. $mform->addElement('hidden','prohibit');
  71. $mform->setType('prohibit', PARAM_INT);
  72. $mform->setDefault('prohibit', 1);
  73. $this->add_action_buttons(true, get_string('prohibit', 'role'));
  74. }
  75. }