MDL-26956 enrol form: add missing setType calls.
[moodle.git] / enrol / users_forms.php
CommitLineData
df997f84
PS
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
19 * Various enrol UI forms
20 *
21 * @package core
22 * @subpackage enrol
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
97795859 27defined('MOODLE_INTERNAL') || die();
df997f84
PS
28
29require_once("$CFG->libdir/formslib.php");
30
31class enrol_users_assign_form extends moodleform {
32 function definition() {
a70eb30f 33 global $CFG, $DB;
df997f84
PS
34
35 $mform = $this->_form;
36
37 $user = $this->_customdata['user'];
38 $course = $this->_customdata['course'];
55bcef29 39 $context = context_course::instance($course->id);
df997f84
PS
40 $assignable = $this->_customdata['assignable'];
41 $assignable = array_reverse($assignable, true); // students first
42
43 $ras = get_user_roles($context, $user->id, true);
44 foreach ($ras as $ra) {
45 unset($assignable[$ra->roleid]);
46 }
47
48 $mform->addElement('header','general', fullname($user));
49
50 $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
51
52 $mform->addElement('hidden', 'id');
53 $mform->setType('id', PARAM_INT);
54
55 $mform->addElement('hidden', 'user');
56 $mform->setType('user', PARAM_INT);
57
58 $mform->addElement('hidden', 'action');
405aca35 59 $mform->setType('action', PARAM_ALPHANUMEXT);
df997f84
PS
60
61 $mform->addElement('hidden', 'ifilter');
62 $mform->setType('ifilter', PARAM_ALPHA);
63
64 $mform->addElement('hidden', 'page');
65 $mform->setType('page', PARAM_INT);
66
67 $mform->addElement('hidden', 'perpage');
68 $mform->setType('perpage', PARAM_INT);
69
70 $mform->addElement('hidden', 'sort');
71 $mform->setType('sort', PARAM_ALPHA);
72
73 $mform->addElement('hidden', 'dir');
74 $mform->setType('dir', PARAM_ALPHA);
75
76 $this->add_action_buttons();
77
df997f84
PS
78 $this->set_data(array('action'=>'assign', 'user'=>$user->id));
79 }
80}
81
82class enrol_users_addmember_form extends moodleform {
83 function definition() {
a70eb30f 84 global $CFG, $DB;
df997f84
PS
85
86 $mform = $this->_form;
87
88 $user = $this->_customdata['user'];
89 $course = $this->_customdata['course'];
55bcef29 90 $context = context_course::instance($course->id, IGNORE_MISSING);
df997f84
PS
91 $allgroups = $this->_customdata['allgroups'];
92 $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
93
94 $options = array();
95 foreach ($allgroups as $group) {
96 if (isset($usergroups[$group->id])) {
97 continue;
98 }
99 $options[$group->id] = $group->name;
100 }
101
102 $mform->addElement('header','general', fullname($user));
103
104 $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
105
106 $mform->addElement('hidden', 'id');
107 $mform->setType('id', PARAM_INT);
108
109 $mform->addElement('hidden', 'user');
110 $mform->setType('user', PARAM_INT);
111
112 $mform->addElement('hidden', 'action');
405aca35 113 $mform->setType('action', PARAM_ALPHANUMEXT);
df997f84
PS
114
115 $mform->addElement('hidden', 'ifilter');
116 $mform->setType('ifilter', PARAM_ALPHA);
117
118 $mform->addElement('hidden', 'page');
119 $mform->setType('page', PARAM_INT);
120
121 $mform->addElement('hidden', 'perpage');
122 $mform->setType('perpage', PARAM_INT);
123
124 $mform->addElement('hidden', 'sort');
125 $mform->setType('sort', PARAM_ALPHA);
126
127 $mform->addElement('hidden', 'dir');
128 $mform->setType('dir', PARAM_ALPHA);
129
130 $this->add_action_buttons();
131
df997f84
PS
132 $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
133 }
71638033 134}
135
136
137/**
138 * Form that lets users filter the enrolled user list.
139 */
140class enrol_users_filter_form extends moodleform {
141 function definition() {
142 global $CFG, $DB;
143
144 $manager = $this->_customdata['manager'];
145
146 $mform = $this->_form;
147
148 // Text search box.
149 $mform->addElement('text', 'search', get_string('search'));
0e0a9806 150 $mform->setType('search', PARAM_RAW);
71638033 151
152 // Filter by enrolment plugin type.
153 $mform->addElement('select', 'ifilter', get_string('enrolmentinstances', 'enrol'),
154 array(0 => get_string('all')) + (array)$manager->get_enrolment_instance_names());
155
156 // Role select dropdown includes all roles, but using course-specific
157 // names if applied. The reason for not restricting to roles that can
158 // be assigned at course level is that upper-level roles display in the
159 // enrolments table so it makes sense to let users filter by them.
160 $allroles = get_all_roles($manager->get_context());
161 $rolenames = array();
162 foreach ($allroles as $id => $role) {
163 $rolenames[$id] = $role->name;
164 }
165 $mform->addElement('select', 'role', get_string('role'),
166 array(0 => get_string('all')) + $rolenames);
167
168 // Submit button does not use add_action_buttons because that adds
169 // another fieldset which causes the CSS style to break in an unfixable
170 // way due to fieldset quirks.
171 $group = array();
172 $group[] = $mform->createElement('submit', 'submitbutton', get_string('filter'));
173 $group[] = $mform->createElement('submit', 'resetbutton', get_string('reset'));
174 $mform->addGroup($group, 'buttons', '', ' ', false);
175
176 // Add hidden fields required by page.
177 $mform->addElement('hidden', 'id', $this->_customdata['id']);
0e0a9806 178 $mform->setType('id', PARAM_INT);
71638033 179 }
180}