PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/enrol/users_forms.php

http://github.com/moodle/moodle
PHP | 198 lines | 116 code | 46 blank | 36 comment | 3 complexity | 103512ddc5d6013ea606c5a2558f698f 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. * Various enrol UI forms
  18. *
  19. * @package core_enrol
  20. * @copyright 2010 Petr Skoda {@link http://skodak.org}
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die();
  24. require_once("$CFG->libdir/formslib.php");
  25. class enrol_users_assign_form extends moodleform {
  26. function definition() {
  27. global $CFG, $DB;
  28. $mform = $this->_form;
  29. $user = $this->_customdata['user'];
  30. $course = $this->_customdata['course'];
  31. $context = context_course::instance($course->id);
  32. $assignable = $this->_customdata['assignable'];
  33. $assignable = array_reverse($assignable, true); // students first
  34. $ras = get_user_roles($context, $user->id, true);
  35. foreach ($ras as $ra) {
  36. unset($assignable[$ra->roleid]);
  37. }
  38. $mform->addElement('header','general', fullname($user));
  39. $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
  40. $mform->addElement('hidden', 'id');
  41. $mform->setType('id', PARAM_INT);
  42. $mform->addElement('hidden', 'user');
  43. $mform->setType('user', PARAM_INT);
  44. $mform->addElement('hidden', 'action');
  45. $mform->setType('action', PARAM_ALPHANUMEXT);
  46. $mform->addElement('hidden', 'ifilter');
  47. $mform->setType('ifilter', PARAM_ALPHA);
  48. $mform->addElement('hidden', 'page');
  49. $mform->setType('page', PARAM_INT);
  50. $mform->addElement('hidden', 'perpage');
  51. $mform->setType('perpage', PARAM_INT);
  52. $mform->addElement('hidden', 'sort');
  53. $mform->setType('sort', PARAM_ALPHA);
  54. $mform->addElement('hidden', 'dir');
  55. $mform->setType('dir', PARAM_ALPHA);
  56. $this->add_action_buttons();
  57. $this->set_data(array('action'=>'assign', 'user'=>$user->id));
  58. }
  59. }
  60. class enrol_users_addmember_form extends moodleform {
  61. function definition() {
  62. global $CFG, $DB;
  63. $mform = $this->_form;
  64. $user = $this->_customdata['user'];
  65. $course = $this->_customdata['course'];
  66. $context = context_course::instance($course->id, IGNORE_MISSING);
  67. $allgroups = $this->_customdata['allgroups'];
  68. $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
  69. $options = array();
  70. foreach ($allgroups as $group) {
  71. if (isset($usergroups[$group->id])) {
  72. continue;
  73. }
  74. $options[$group->id] = $group->name;
  75. }
  76. $mform->addElement('header','general', fullname($user));
  77. $mform->addElement('select', 'groupids', get_string('addgroup', 'group'), $options, array('multiple' => 'multiple'));
  78. $mform->addRule('groupids', null, 'required');
  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_ALPHANUMEXT);
  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. }
  99. /**
  100. * Form that lets users filter the enrolled user list.
  101. */
  102. class enrol_users_filter_form extends moodleform {
  103. function definition() {
  104. global $CFG, $DB;
  105. $manager = $this->_customdata['manager'];
  106. $mform = $this->_form;
  107. // Text search box.
  108. $mform->addElement('text', 'search', get_string('search'));
  109. $mform->setType('search', PARAM_RAW);
  110. // Filter by enrolment plugin type.
  111. $mform->addElement('select', 'ifilter', get_string('enrolmentinstances', 'enrol'),
  112. array(0 => get_string('all')) + (array)$manager->get_enrolment_instance_names());
  113. // Role select dropdown includes all roles, but using course-specific
  114. // names if applied. The reason for not restricting to roles that can
  115. // be assigned at course level is that upper-level roles display in the
  116. // enrolments table so it makes sense to let users filter by them.
  117. $visibleroles = $manager->get_viewable_roles();
  118. $rolenames = array();
  119. foreach ($visibleroles as $id => $role) {
  120. $rolenames[$id] = $role;
  121. }
  122. $mform->addElement('select', 'role', get_string('role'),
  123. array(0 => get_string('all')) + $rolenames);
  124. // Filter by group.
  125. $allgroups = $manager->get_all_groups();
  126. $groupsmenu[0] = get_string('allparticipants');
  127. $groupsmenu[-1] = get_string('nogroup', 'enrol');
  128. foreach($allgroups as $gid => $unused) {
  129. $groupsmenu[$gid] = $allgroups[$gid]->name;
  130. }
  131. if (count($groupsmenu) > 1) {
  132. $mform->addElement('select', 'filtergroup', get_string('group'), $groupsmenu);
  133. }
  134. // Status active/inactive.
  135. $mform->addElement('select', 'status', get_string('status'),
  136. array(-1 => get_string('all'),
  137. ENROL_USER_ACTIVE => get_string('active'),
  138. ENROL_USER_SUSPENDED => get_string('inactive')));
  139. // Submit button does not use add_action_buttons because that adds
  140. // another fieldset which causes the CSS style to break in an unfixable
  141. // way due to fieldset quirks.
  142. $group = array();
  143. $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
  144. $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
  145. $mform->addGroup($group, 'buttons', '', ' ', false);
  146. // Add hidden fields required by page.
  147. $mform->addElement('hidden', 'id', $this->_customdata['id']);
  148. $mform->setType('id', PARAM_INT);
  149. $mform->addElement('hidden', 'newcourse', $this->_customdata['newcourse']);
  150. $mform->setType('newcourse', PARAM_BOOL);
  151. }
  152. }