2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Various enrol UI forms
21 * @copyright 2010 Petr Skoda {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once("$CFG->libdir/formslib.php");
29 class enrol_users_assign_form
extends moodleform
{
30 function definition() {
33 $mform = $this->_form
;
35 $user = $this->_customdata
['user'];
36 $course = $this->_customdata
['course'];
37 $context = context_course
::instance($course->id
);
38 $assignable = $this->_customdata
['assignable'];
39 $assignable = array_reverse($assignable, true); // students first
41 $ras = get_user_roles($context, $user->id
, true);
42 foreach ($ras as $ra) {
43 unset($assignable[$ra->roleid
]);
46 $mform->addElement('header','general', fullname($user));
48 $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
50 $mform->addElement('hidden', 'id');
51 $mform->setType('id', PARAM_INT
);
53 $mform->addElement('hidden', 'user');
54 $mform->setType('user', PARAM_INT
);
56 $mform->addElement('hidden', 'action');
57 $mform->setType('action', PARAM_ALPHANUMEXT
);
59 $mform->addElement('hidden', 'ifilter');
60 $mform->setType('ifilter', PARAM_ALPHA
);
62 $mform->addElement('hidden', 'page');
63 $mform->setType('page', PARAM_INT
);
65 $mform->addElement('hidden', 'perpage');
66 $mform->setType('perpage', PARAM_INT
);
68 $mform->addElement('hidden', 'sort');
69 $mform->setType('sort', PARAM_ALPHA
);
71 $mform->addElement('hidden', 'dir');
72 $mform->setType('dir', PARAM_ALPHA
);
74 $this->add_action_buttons();
76 $this->set_data(array('action'=>'assign', 'user'=>$user->id
));
80 class enrol_users_addmember_form
extends moodleform
{
81 function definition() {
84 $mform = $this->_form
;
86 $user = $this->_customdata
['user'];
87 $course = $this->_customdata
['course'];
88 $context = context_course
::instance($course->id
, IGNORE_MISSING
);
89 $allgroups = $this->_customdata
['allgroups'];
90 $usergroups = groups_get_all_groups($course->id
, $user->id
, 0, 'g.id');
93 foreach ($allgroups as $group) {
94 if (isset($usergroups[$group->id
])) {
97 $options[$group->id
] = $group->name
;
100 $mform->addElement('header','general', fullname($user));
102 $mform->addElement('select', 'groupids', get_string('addgroup', 'group'), $options, array('multiple' => 'multiple'));
103 $mform->addRule('groupids', null, 'required');
105 $mform->addElement('hidden', 'id');
106 $mform->setType('id', PARAM_INT
);
108 $mform->addElement('hidden', 'user');
109 $mform->setType('user', PARAM_INT
);
111 $mform->addElement('hidden', 'action');
112 $mform->setType('action', PARAM_ALPHANUMEXT
);
114 $mform->addElement('hidden', 'ifilter');
115 $mform->setType('ifilter', PARAM_ALPHA
);
117 $mform->addElement('hidden', 'page');
118 $mform->setType('page', PARAM_INT
);
120 $mform->addElement('hidden', 'perpage');
121 $mform->setType('perpage', PARAM_INT
);
123 $mform->addElement('hidden', 'sort');
124 $mform->setType('sort', PARAM_ALPHA
);
126 $mform->addElement('hidden', 'dir');
127 $mform->setType('dir', PARAM_ALPHA
);
129 $this->add_action_buttons();
131 $this->set_data(array('action'=>'addmember', 'user'=>$user->id
));
137 * Form that lets users filter the enrolled user list.
139 class enrol_users_filter_form
extends moodleform
{
140 function definition() {
143 $manager = $this->_customdata
['manager'];
145 $mform = $this->_form
;
148 $mform->addElement('text', 'search', get_string('search'));
149 $mform->setType('search', PARAM_RAW
);
151 // Filter by enrolment plugin type.
152 $mform->addElement('select', 'ifilter', get_string('enrolmentinstances', 'enrol'),
153 array(0 => get_string('all')) +
(array)$manager->get_enrolment_instance_names());
155 // Role select dropdown includes all roles, but using course-specific
156 // names if applied. The reason for not restricting to roles that can
157 // be assigned at course level is that upper-level roles display in the
158 // enrolments table so it makes sense to let users filter by them.
159 $allroles = $manager->get_all_roles();
160 $rolenames = array();
161 foreach ($allroles as $id => $role) {
162 $rolenames[$id] = $role->localname
;
164 $mform->addElement('select', 'role', get_string('role'),
165 array(0 => get_string('all')) +
$rolenames);
168 $allgroups = $manager->get_all_groups();
169 $groupsmenu[0] = get_string('allparticipants');
170 $groupsmenu[-1] = get_string('nogroup', 'enrol');
171 foreach($allgroups as $gid => $unused) {
172 $groupsmenu[$gid] = $allgroups[$gid]->name
;
174 if (count($groupsmenu) > 1) {
175 $mform->addElement('select', 'filtergroup', get_string('group'), $groupsmenu);
178 // Status active/inactive.
179 $mform->addElement('select', 'status', get_string('status'),
180 array(-1 => get_string('all'),
181 ENROL_USER_ACTIVE
=> get_string('active'),
182 ENROL_USER_SUSPENDED
=> get_string('inactive')));
184 // Submit button does not use add_action_buttons because that adds
185 // another fieldset which causes the CSS style to break in an unfixable
186 // way due to fieldset quirks.
188 $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
189 $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
190 $mform->addGroup($group, 'buttons', '', ' ', false);
192 // Add hidden fields required by page.
193 $mform->addElement('hidden', 'id', $this->_customdata
['id']);
194 $mform->setType('id', PARAM_INT
);
195 $mform->addElement('hidden', 'newcourse', $this->_customdata
['newcourse']);
196 $mform->setType('newcourse', PARAM_BOOL
);