MDL-21437 data - checkbox and multimenu fields search working + require all too
[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'];
39 $context = get_context_instance(CONTEXT_COURSE, $course->id);
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');
59 $mform->setType('action', PARAM_ACTION);
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'];
90 $context = get_context_instance(CONTEXT_COURSE, $course->id);
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');
113 $mform->setType('action', PARAM_ACTION);
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 }
134}
135
136class enrol_users_edit_form extends moodleform {
137 function definition() {
a70eb30f 138 global $CFG, $DB;
df997f84
PS
139
140 $mform = $this->_form;
141
142 $user = $this->_customdata['user'];
143 $course = $this->_customdata['course'];
144 $ue = $this->_customdata['ue'];
145
146
147 $mform->addElement('header','general', '');
148
149 $options = array(ENROL_USER_ACTIVE => get_string('participationactive', 'enrol'),
150 ENROL_USER_SUSPENDED => get_string('participationsuspended', 'enrol'));
151 if (isset($options[$ue->status])) {
152 $mform->addElement('select', 'status', get_string('participationstatus', 'enrol'), $options);
153 }
154
155 $mform->addElement('date_selector', 'timestart', get_string('enroltimestart', 'enrol'), array('optional' => true));
156
157 $mform->addElement('date_selector', 'timeend', get_string('enroltimeend', 'enrol'), array('optional' => true));
158
159 $mform->addElement('hidden', 'id');
160 $mform->setType('id', PARAM_INT);
161
162 $mform->addElement('hidden', 'ue');
163 $mform->setType('ue', PARAM_INT);
164
165 $mform->addElement('hidden', 'action');
166 $mform->setType('action', PARAM_ACTION);
167
168 $mform->addElement('hidden', 'ifilter');
169 $mform->setType('ifilter', PARAM_ALPHA);
170
171 $mform->addElement('hidden', 'page');
172 $mform->setType('page', PARAM_INT);
173
174 $mform->addElement('hidden', 'perpage');
175 $mform->setType('perpage', PARAM_INT);
176
177 $mform->addElement('hidden', 'sort');
178 $mform->setType('sort', PARAM_ALPHA);
179
180 $mform->addElement('hidden', 'dir');
181 $mform->setType('dir', PARAM_ALPHA);
182
183 $this->add_action_buttons();
184
df997f84
PS
185 $this->set_data(array('action'=>'edit', 'ue'=>$ue->id, 'status'=>$ue->status, 'timestart'=>$ue->timestart, 'timeend'=>$ue->timeend));
186 }
187
188 function validation($data, $files) {
189 $errors = parent::validation($data, $files);
190
191 if (!empty($data['timestart']) and !empty($data['timeend'])) {
192 if ($data['timestart'] >= $data['timeend']) {
193 $errors['timestart'] = get_string('error');
194 $errors['timeend'] = get_string('error');
195 }
196 }
197
198 return $errors;
199 }
200}