MDL-38852 repository_filesystem: missing setType calls
[moodle.git] / enrol / users_forms.php
blob212793587396e53359fb770bd98ef74c3f0fa8c5
1 <?php
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.
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/>.
18 /**
19 * Various enrol UI forms
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
27 defined('MOODLE_INTERNAL') || die();
29 require_once("$CFG->libdir/formslib.php");
31 class enrol_users_assign_form extends moodleform {
32 function definition() {
33 global $CFG, $DB;
35 $mform = $this->_form;
37 $user = $this->_customdata['user'];
38 $course = $this->_customdata['course'];
39 $context = context_course::instance($course->id);
40 $assignable = $this->_customdata['assignable'];
41 $assignable = array_reverse($assignable, true); // students first
43 $ras = get_user_roles($context, $user->id, true);
44 foreach ($ras as $ra) {
45 unset($assignable[$ra->roleid]);
48 $mform->addElement('header','general', fullname($user));
50 $mform->addElement('select', 'roleid', get_string('addrole', 'role'), $assignable);
52 $mform->addElement('hidden', 'id');
53 $mform->setType('id', PARAM_INT);
55 $mform->addElement('hidden', 'user');
56 $mform->setType('user', PARAM_INT);
58 $mform->addElement('hidden', 'action');
59 $mform->setType('action', PARAM_ALPHANUMEXT);
61 $mform->addElement('hidden', 'ifilter');
62 $mform->setType('ifilter', PARAM_ALPHA);
64 $mform->addElement('hidden', 'page');
65 $mform->setType('page', PARAM_INT);
67 $mform->addElement('hidden', 'perpage');
68 $mform->setType('perpage', PARAM_INT);
70 $mform->addElement('hidden', 'sort');
71 $mform->setType('sort', PARAM_ALPHA);
73 $mform->addElement('hidden', 'dir');
74 $mform->setType('dir', PARAM_ALPHA);
76 $this->add_action_buttons();
78 $this->set_data(array('action'=>'assign', 'user'=>$user->id));
82 class enrol_users_addmember_form extends moodleform {
83 function definition() {
84 global $CFG, $DB;
86 $mform = $this->_form;
88 $user = $this->_customdata['user'];
89 $course = $this->_customdata['course'];
90 $context = context_course::instance($course->id, IGNORE_MISSING);
91 $allgroups = $this->_customdata['allgroups'];
92 $usergroups = groups_get_all_groups($course->id, $user->id, 0, 'g.id');
94 $options = array();
95 foreach ($allgroups as $group) {
96 if (isset($usergroups[$group->id])) {
97 continue;
99 $options[$group->id] = $group->name;
102 $mform->addElement('header','general', fullname($user));
104 $mform->addElement('select', 'groupid', get_string('addgroup', 'group'), $options);
106 $mform->addElement('hidden', 'id');
107 $mform->setType('id', PARAM_INT);
109 $mform->addElement('hidden', 'user');
110 $mform->setType('user', PARAM_INT);
112 $mform->addElement('hidden', 'action');
113 $mform->setType('action', PARAM_ALPHANUMEXT);
115 $mform->addElement('hidden', 'ifilter');
116 $mform->setType('ifilter', PARAM_ALPHA);
118 $mform->addElement('hidden', 'page');
119 $mform->setType('page', PARAM_INT);
121 $mform->addElement('hidden', 'perpage');
122 $mform->setType('perpage', PARAM_INT);
124 $mform->addElement('hidden', 'sort');
125 $mform->setType('sort', PARAM_ALPHA);
127 $mform->addElement('hidden', 'dir');
128 $mform->setType('dir', PARAM_ALPHA);
130 $this->add_action_buttons();
132 $this->set_data(array('action'=>'addmember', 'user'=>$user->id));
138 * Form that lets users filter the enrolled user list.
140 class enrol_users_filter_form extends moodleform {
141 function definition() {
142 global $CFG, $DB;
144 $manager = $this->_customdata['manager'];
146 $mform = $this->_form;
148 // Text search box.
149 $mform->addElement('text', 'search', get_string('search'));
150 $mform->setType('search', PARAM_RAW);
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());
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;
165 $mform->addElement('select', 'role', get_string('role'),
166 array(0 => get_string('all')) + $rolenames);
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);
176 // Add hidden fields required by page.
177 $mform->addElement('hidden', 'id', $this->_customdata['id']);
178 $mform->setType('id', PARAM_INT);