PageRenderTime 41ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/enrol/users_forms.php

https://bitbucket.org/ngmares/moodle
PHP | 134 lines | 76 code | 36 blank | 22 comment | 2 complexity | 06ed23274c76d5f7af0d704dd0e608e6 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.0, 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. * Various enrol UI forms
  18. *
  19. * @package core
  20. * @subpackage enrol
  21. * @copyright 2010 Petr Skoda {@link http://skodak.org}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once("$CFG->libdir/formslib.php");
  26. class enrol_users_assign_form extends moodleform {
  27. function definition() {
  28. global $CFG, $DB;
  29. $mform = $this->_form;
  30. $user = $this->_customdata['user'];
  31. $course = $this->_customdata['course'];
  32. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  33. $assignable = $this->_customdata['assignable'];
  34. $assignable = array_reverse($assignable, true); // students first
  35. $ras = get_user_roles($context, $user->id, true);
  36. foreach ($ras as $ra) {
  37. unset($assignable[$ra->roleid]);
  38. }
  39. $mform->addElement('header','general', fullname($user));
  40. $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
  41. $mform->addElement('hidden', 'id');
  42. $mform->setType('id', PARAM_INT);
  43. $mform->addElement('hidden', 'user');
  44. $mform->setType('user', PARAM_INT);
  45. $mform->addElement('hidden', 'action');
  46. $mform->setType('action', PARAM_ACTION);
  47. $mform->addElement('hidden', 'ifilter');
  48. $mform->setType('ifilter', PARAM_ALPHA);
  49. $mform->addElement('hidden', 'page');
  50. $mform->setType('page', PARAM_INT);
  51. $mform->addElement('hidden', 'perpage');
  52. $mform->setType('perpage', PARAM_INT);
  53. $mform->addElement('hidden', 'sort');
  54. $mform->setType('sort', PARAM_ALPHA);
  55. $mform->addElement('hidden', 'dir');
  56. $mform->setType('dir', PARAM_ALPHA);
  57. $this->add_action_buttons();
  58. $this->set_data(array('action'=>'assign', 'user'=>$user->id));
  59. }
  60. }
  61. class enrol_users_addmember_form extends moodleform {
  62. function definition() {
  63. global $CFG, $DB;
  64. $mform = $this->_form;
  65. $user = $this->_customdata['user'];
  66. $course = $this->_customdata['course'];
  67. $context = get_context_instance(CONTEXT_COURSE, $course->id);
  68. $allgroups = $this->_customdata['allgroups'];
  69. $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
  70. $options = array();
  71. foreach ($allgroups as $group) {
  72. if (isset($usergroups[$group->id])) {
  73. continue;
  74. }
  75. $options[$group->id] = $group->name;
  76. }
  77. $mform->addElement('header','general', fullname($user));
  78. $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
  79. $mform->addElement('hidden', 'id');
  80. $mform->setType('id', PARAM_INT);
  81. $mform->addElement('hidden', 'user');
  82. $mform->setType('user', PARAM_INT);
  83. $mform->addElement('hidden', 'action');
  84. $mform->setType('action', PARAM_ACTION);
  85. $mform->addElement('hidden', 'ifilter');
  86. $mform->setType('ifilter', PARAM_ALPHA);
  87. $mform->addElement('hidden', 'page');
  88. $mform->setType('page', PARAM_INT);
  89. $mform->addElement('hidden', 'perpage');
  90. $mform->setType('perpage', PARAM_INT);
  91. $mform->addElement('hidden', 'sort');
  92. $mform->setType('sort', PARAM_ALPHA);
  93. $mform->addElement('hidden', 'dir');
  94. $mform->setType('dir', PARAM_ALPHA);
  95. $this->add_action_buttons();
  96. $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
  97. }
  98. }