3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Various enrol UI forms
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() {
35 $mform = $this->_form
;
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
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_ACTION
);
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() {
86 $mform = $this->_form
;
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');
95 foreach ($allgroups as $group) {
96 if (isset($usergroups[$group->id
])) {
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_ACTION
);
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
));