1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Main course enrolment management UI.
|
|
|
19 |
*
|
|
|
20 |
* @package core_enrol
|
|
|
21 |
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require('../config.php');
|
|
|
26 |
|
|
|
27 |
$id = required_param('id', PARAM_INT); // course id
|
|
|
28 |
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
|
|
|
29 |
$instanceid = optional_param('instance', 0, PARAM_INT);
|
|
|
30 |
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
|
|
31 |
$confirm2 = optional_param('confirm2', 0, PARAM_BOOL);
|
|
|
32 |
|
|
|
33 |
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
|
|
34 |
$context = context_course::instance($course->id, MUST_EXIST);
|
|
|
35 |
|
|
|
36 |
if ($course->id == SITEID) {
|
|
|
37 |
redirect("$CFG->wwwroot/");
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
require_login($course);
|
|
|
41 |
require_capability('moodle/course:enrolreview', $context);
|
|
|
42 |
|
|
|
43 |
$canconfig = has_capability('moodle/course:enrolconfig', $context);
|
|
|
44 |
|
|
|
45 |
$PAGE->set_url('/enrol/instances.php', array('id'=>$course->id));
|
|
|
46 |
$PAGE->set_pagelayout('admin');
|
|
|
47 |
$PAGE->set_title(get_string('enrolmentinstances', 'enrol'));
|
|
|
48 |
$PAGE->set_heading($course->fullname);
|
|
|
49 |
|
|
|
50 |
$instances = enrol_get_instances($course->id, false);
|
|
|
51 |
$plugins = enrol_get_plugins(false);
|
|
|
52 |
|
|
|
53 |
if ($canconfig and $action and confirm_sesskey()) {
|
|
|
54 |
if (isset($instances[$instanceid]) and isset($plugins[$instances[$instanceid]->enrol])) {
|
|
|
55 |
if ($action === 'up') {
|
|
|
56 |
$order = array_keys($instances);
|
|
|
57 |
$order = array_flip($order);
|
|
|
58 |
$pos = $order[$instanceid];
|
|
|
59 |
if ($pos > 0) {
|
|
|
60 |
$switch = $pos - 1;
|
|
|
61 |
$resorted = array_values($instances);
|
|
|
62 |
$temp = $resorted[$pos];
|
|
|
63 |
$resorted[$pos] = $resorted[$switch];
|
|
|
64 |
$resorted[$switch] = $temp;
|
|
|
65 |
// now update db sortorder
|
|
|
66 |
foreach ($resorted as $sortorder=>$instance) {
|
|
|
67 |
if ($instance->sortorder != $sortorder) {
|
|
|
68 |
$instance->sortorder = $sortorder;
|
|
|
69 |
$DB->update_record('enrol', $instance);
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
redirect($PAGE->url);
|
|
|
74 |
|
|
|
75 |
} else if ($action === 'down') {
|
|
|
76 |
$order = array_keys($instances);
|
|
|
77 |
$order = array_flip($order);
|
|
|
78 |
$pos = $order[$instanceid];
|
|
|
79 |
if ($pos < count($instances) - 1) {
|
|
|
80 |
$switch = $pos + 1;
|
|
|
81 |
$resorted = array_values($instances);
|
|
|
82 |
$temp = $resorted[$pos];
|
|
|
83 |
$resorted[$pos] = $resorted[$switch];
|
|
|
84 |
$resorted[$switch] = $temp;
|
|
|
85 |
// now update db sortorder
|
|
|
86 |
foreach ($resorted as $sortorder=>$instance) {
|
|
|
87 |
if ($instance->sortorder != $sortorder) {
|
|
|
88 |
$instance->sortorder = $sortorder;
|
|
|
89 |
$DB->update_record('enrol', $instance);
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
redirect($PAGE->url);
|
|
|
94 |
|
|
|
95 |
} else if ($action === 'delete') {
|
|
|
96 |
|
|
|
97 |
$instance = $instances[$instanceid];
|
|
|
98 |
$plugin = $plugins[$instance->enrol];
|
|
|
99 |
|
|
|
100 |
if ($plugin->can_delete_instance($instance)) {
|
|
|
101 |
if ($confirm) {
|
|
|
102 |
if (enrol_accessing_via_instance($instance)) {
|
|
|
103 |
if (!$confirm2) {
|
|
|
104 |
$yesurl = new moodle_url('/enrol/instances.php',
|
|
|
105 |
array('id' => $course->id,
|
|
|
106 |
'action' => 'delete',
|
|
|
107 |
'instance' => $instance->id,
|
|
|
108 |
'confirm' => 1,
|
|
|
109 |
'confirm2' => 1,
|
|
|
110 |
'sesskey' => sesskey()));
|
|
|
111 |
$displayname = $plugin->get_instance_name($instance);
|
|
|
112 |
$message = markdown_to_html(get_string('deleteinstanceconfirmself',
|
|
|
113 |
'enrol',
|
|
|
114 |
array('name' => $displayname)));
|
|
|
115 |
echo $OUTPUT->header();
|
|
|
116 |
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
|
|
|
117 |
echo $OUTPUT->footer();
|
|
|
118 |
die();
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
$plugin->delete_instance($instance);
|
|
|
122 |
redirect($PAGE->url);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
echo $OUTPUT->header();
|
|
|
126 |
$yesurl = new moodle_url('/enrol/instances.php',
|
|
|
127 |
array('id' => $course->id,
|
|
|
128 |
'action' => 'delete',
|
|
|
129 |
'instance' => $instance->id,
|
|
|
130 |
'confirm' => 1,
|
|
|
131 |
'sesskey' => sesskey()));
|
|
|
132 |
$displayname = $plugin->get_instance_name($instance);
|
|
|
133 |
$users = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
|
|
|
134 |
if ($users) {
|
|
|
135 |
$message = markdown_to_html(get_string('deleteinstanceconfirm', 'enrol',
|
|
|
136 |
array('name' => $displayname,
|
|
|
137 |
'users' => $users)));
|
|
|
138 |
} else {
|
|
|
139 |
$message = markdown_to_html(get_string('deleteinstancenousersconfirm', 'enrol',
|
|
|
140 |
array('name' => $displayname)));
|
|
|
141 |
}
|
|
|
142 |
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
|
|
|
143 |
echo $OUTPUT->footer();
|
|
|
144 |
die();
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
} else if ($action === 'disable') {
|
|
|
148 |
|
|
|
149 |
$instance = $instances[$instanceid];
|
|
|
150 |
$plugin = $plugins[$instance->enrol];
|
|
|
151 |
if ($plugin->can_hide_show_instance($instance)) {
|
|
|
152 |
if ($instance->status != ENROL_INSTANCE_DISABLED) {
|
|
|
153 |
if (enrol_accessing_via_instance($instance)) {
|
|
|
154 |
if (!$confirm2) {
|
|
|
155 |
$yesurl = new moodle_url('/enrol/instances.php',
|
|
|
156 |
array('id' => $course->id,
|
|
|
157 |
'action' => 'disable',
|
|
|
158 |
'instance' => $instance->id,
|
|
|
159 |
'confirm2' => 1,
|
|
|
160 |
'sesskey' => sesskey()));
|
|
|
161 |
$displayname = $plugin->get_instance_name($instance);
|
|
|
162 |
$message = markdown_to_html(get_string('disableinstanceconfirmself',
|
|
|
163 |
'enrol',
|
|
|
164 |
array('name' => $displayname)));
|
|
|
165 |
echo $OUTPUT->header();
|
|
|
166 |
echo $OUTPUT->confirm($message, $yesurl, $PAGE->url);
|
|
|
167 |
echo $OUTPUT->footer();
|
|
|
168 |
die();
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
$plugin->update_status($instance, ENROL_INSTANCE_DISABLED);
|
|
|
172 |
redirect($PAGE->url);
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
} else if ($action === 'enable') {
|
|
|
177 |
|
|
|
178 |
$instance = $instances[$instanceid];
|
|
|
179 |
$plugin = $plugins[$instance->enrol];
|
|
|
180 |
if ($plugin->can_hide_show_instance($instance)) {
|
|
|
181 |
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
|
|
182 |
$plugin->update_status($instance, ENROL_INSTANCE_ENABLED);
|
|
|
183 |
redirect($PAGE->url);
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
echo $OUTPUT->header();
|
|
|
192 |
echo $OUTPUT->render_participants_tertiary_nav($course);
|
|
|
193 |
|
|
|
194 |
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
|
|
|
195 |
|
|
|
196 |
// display strings
|
|
|
197 |
$strup = get_string('up');
|
|
|
198 |
$strdown = get_string('down');
|
|
|
199 |
$strdelete = get_string('delete');
|
|
|
200 |
$strenable = get_string('enable');
|
|
|
201 |
$strdisable = get_string('disable');
|
|
|
202 |
$strmanage = get_string('manageinstance', 'enrol');
|
|
|
203 |
|
|
|
204 |
$table = new html_table();
|
|
|
205 |
$table->head = array(get_string('name'), get_string('users'), $strup.'/'.$strdown, get_string('edit'));
|
|
|
206 |
$table->align = array('left', 'center', 'center', 'center');
|
|
|
207 |
$table->width = '100%';
|
|
|
208 |
$table->data = array();
|
|
|
209 |
|
|
|
210 |
// iterate through enrol plugins and add to the display table
|
|
|
211 |
$updowncount = 1;
|
|
|
212 |
$icount = count($instances);
|
|
|
213 |
$url = new moodle_url('/enrol/instances.php', array('sesskey'=>sesskey(), 'id'=>$course->id));
|
|
|
214 |
foreach ($instances as $instance) {
|
|
|
215 |
if (!isset($plugins[$instance->enrol])) {
|
|
|
216 |
continue;
|
|
|
217 |
}
|
|
|
218 |
$plugin = $plugins[$instance->enrol];
|
|
|
219 |
|
|
|
220 |
$displayname = $plugin->get_instance_name($instance);
|
|
|
221 |
if (!enrol_is_enabled($instance->enrol) or $instance->status != ENROL_INSTANCE_ENABLED) {
|
|
|
222 |
$displayname = html_writer::tag('span', $displayname, array('class'=>'dimmed_text'));
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
$users = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id));
|
|
|
226 |
|
|
|
227 |
$updown = array();
|
|
|
228 |
$edit = array();
|
|
|
229 |
|
|
|
230 |
if ($canconfig) {
|
|
|
231 |
if ($updowncount > 1) {
|
|
|
232 |
$aurl = new moodle_url($url, array('action'=>'up', 'instance'=>$instance->id));
|
|
|
233 |
$updown[] = $OUTPUT->action_icon($aurl, new pix_icon('t/up', $strup, 'core', array('class' => 'iconsmall')));
|
|
|
234 |
} else {
|
|
|
235 |
$updown[] = $OUTPUT->spacer();
|
|
|
236 |
}
|
|
|
237 |
if ($updowncount < $icount) {
|
|
|
238 |
$aurl = new moodle_url($url, array('action'=>'down', 'instance'=>$instance->id));
|
|
|
239 |
$updown[] = $OUTPUT->action_icon($aurl, new pix_icon('t/down', $strdown, 'core', array('class' => 'iconsmall')));
|
|
|
240 |
} else {
|
|
|
241 |
$updown[] = $OUTPUT->spacer();
|
|
|
242 |
}
|
|
|
243 |
++$updowncount;
|
|
|
244 |
|
|
|
245 |
if ($plugin->can_delete_instance($instance)) {
|
|
|
246 |
$aurl = new moodle_url($url, array('action'=>'delete', 'instance'=>$instance->id));
|
|
|
247 |
$edit[] = $OUTPUT->action_icon($aurl, new pix_icon('t/delete', $strdelete, 'core', array('class' => 'iconsmall')));
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
if (enrol_is_enabled($instance->enrol) && $plugin->can_hide_show_instance($instance)) {
|
|
|
251 |
if ($instance->status == ENROL_INSTANCE_ENABLED) {
|
|
|
252 |
$aurl = new moodle_url($url, array('action'=>'disable', 'instance'=>$instance->id));
|
|
|
253 |
$edit[] = $OUTPUT->action_icon($aurl, new pix_icon('t/hide', $strdisable, 'core', array('class' => 'iconsmall')));
|
|
|
254 |
} else if ($instance->status == ENROL_INSTANCE_DISABLED) {
|
|
|
255 |
$aurl = new moodle_url($url, array('action'=>'enable', 'instance'=>$instance->id));
|
|
|
256 |
$edit[] = $OUTPUT->action_icon($aurl, new pix_icon('t/show', $strenable, 'core', array('class' => 'iconsmall')));
|
|
|
257 |
} else {
|
|
|
258 |
// plugin specific state - do not mess with it!
|
|
|
259 |
$edit[] = $OUTPUT->pix_icon('t/show', get_string('show'));
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
}
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
// link to instance management
|
|
|
266 |
if (enrol_is_enabled($instance->enrol) && $canconfig) {
|
|
|
267 |
if ($icons = $plugin->get_action_icons($instance)) {
|
|
|
268 |
$edit = array_merge($edit, $icons);
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
// Add a row to the table.
|
|
|
273 |
$table->data[] = array($displayname, $users, implode('', $updown), implode('', $edit));
|
|
|
274 |
|
|
|
275 |
}
|
|
|
276 |
echo html_writer::table($table);
|
|
|
277 |
|
|
|
278 |
// access security is in each plugin
|
|
|
279 |
$candidates = array();
|
|
|
280 |
foreach (enrol_get_plugins(true) as $name=>$plugin) {
|
|
|
281 |
if ($plugin->use_standard_editing_ui()) {
|
|
|
282 |
if ($plugin->can_add_instance($course->id)) {
|
|
|
283 |
// Standard add/edit UI.
|
|
|
284 |
$params = array('type' => $name, 'courseid' => $course->id);
|
|
|
285 |
$url = new moodle_url('/enrol/editinstance.php', $params);
|
|
|
286 |
$link = $url->out(false);
|
|
|
287 |
$candidates[$link] = get_string('pluginname', 'enrol_'.$name);
|
|
|
288 |
}
|
|
|
289 |
} else if ($url = $plugin->get_newinstance_link($course->id)) {
|
|
|
290 |
// Old custom UI.
|
|
|
291 |
$link = $url->out(false);
|
|
|
292 |
$candidates[$link] = get_string('pluginname', 'enrol_'.$name);
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
if ($candidates) {
|
|
|
297 |
$select = new url_select($candidates);
|
|
|
298 |
$select->set_label(get_string('addinstance', 'enrol'));
|
|
|
299 |
echo $OUTPUT->render($select);
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
echo $OUTPUT->box_end();
|
|
|
303 |
|
|
|
304 |
echo $OUTPUT->footer();
|