forked from catalyst/moodle-mod_facetoface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attendees.php
412 lines (344 loc) · 16.6 KB
/
attendees.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Copyright (C) 2007-2011 Catalyst IT (http://www.catalyst.net.nz)
* Copyright (C) 2011-2013 Totara LMS (http://www.totaralms.com)
* Copyright (C) 2014 onwards Catalyst IT (http://www.catalyst-eu.net)
*
* @package mod
* @subpackage facetoface
* @copyright 2014 onwards Catalyst IT <http://www.catalyst-eu.net>
* @author Stacey Walker <[email protected]>
* @author Alastair Munro <[email protected]>
* @author Aaron Barnes <[email protected]>
* @author Francois Marier <[email protected]>
*/
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once($CFG->dirroot . '/mod/facetoface/lib.php');
// Face-to-face session ID.
$s = required_param('s', PARAM_INT);
$takeattendance = optional_param('takeattendance', false, PARAM_BOOL); // Take attendance.
$cancelform = optional_param('cancelform', false, PARAM_BOOL); // Cancel request.
$backtoallsessions = optional_param('backtoallsessions', 0, PARAM_INT); // Face-to-face activity to return to.
// Load data.
if (!$session = facetoface_get_session($s)) {
print_error('error:incorrectcoursemodulesession', 'facetoface');
}
if (!$facetoface = $DB->get_record('facetoface', array('id' => $session->facetoface))) {
print_error('error:incorrectfacetofaceid', 'facetoface');
}
if (!$course = $DB->get_record('course', array('id' => $facetoface->course))) {
print_error('error:coursemisconfigured', 'facetoface');
}
if (!$cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id)) {
print_error('error:incorrectcoursemodule', 'facetoface');
}
// Load attendees.
$attendees = facetoface_get_attendees($session->id);
// Load cancellations.
$cancellations = facetoface_get_cancellations($session->id);
/*
* Capability checks to see if the current user can view this page
*
* This page is a bit of a special case in this respect as there are four uses for this page.
*
* 1) Viewing attendee list
* - Requires mod/facetoface:viewattendees capability in the course
*
* 2) Viewing cancellation list
* - Requires mod/facetoface:viewcancellations capability in the course
*
* 3) Taking attendance
* - Requires mod/facetoface:takeattendance capabilities in the course
*/
$context = context_course::instance($course->id);
$contextmodule = context_module::instance($cm->id);
require_course_login($course);
// Actions the user can perform.
$canviewattendees = has_capability('mod/facetoface:viewattendees', $context);
$cantakeattendance = has_capability('mod/facetoface:takeattendance', $context);
$canviewcancellations = has_capability('mod/facetoface:viewcancellations', $context);
$canviewsession = $canviewattendees || $cantakeattendance || $canviewcancellations;
$canapproverequests = false;
$requests = array();
$declines = array();
// If a user can take attendance, they can approve staff's booking requests.
if ($cantakeattendance) {
$requests = facetoface_get_requests($session->id);
}
// If requests found (but not in the middle of taking attendance), show requests table.
if ($requests && !$takeattendance) {
$canapproverequests = true;
}
// Check the user is allowed to view this page.
if (!$canviewattendees && !$cantakeattendance && !$canapproverequests && !$canviewcancellations) {
print_error('nopermissions', '', "{$CFG->wwwroot}/mod/facetoface/view.php?id={$cm->id}", get_string('view'));
}
// Check user has permissions to take attendance.
if ($takeattendance && !$cantakeattendance) {
print_error('nopermissions', '', '', get_capability_string('mod/facetoface:takeattendance'));
}
/*
* Handle submitted data
*/
if ($form = data_submitted()) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
}
$return = "{$CFG->wwwroot}/mod/facetoface/attendees.php?s={$s}&backtoallsessions={$backtoallsessions}";
if ($cancelform) {
redirect($return);
} else if (!empty($form->requests)) {
// Approve requests.
if ($canapproverequests && facetoface_approve_requests($form)) {
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\approve_requests::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
}
redirect($return);
} else if ($takeattendance) {
if (facetoface_take_attendance($form)) {
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\take_attendance::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
} else {
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\take_attendance_failed::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
}
redirect($return.'&takeattendance=1');
}
}
/*
* Print page header
*/
// Logging and events trigger.
$params = array(
'context' => $contextmodule,
'objectid' => $session->id
);
$event = \mod_facetoface\event\attendees_viewed::create($params);
$event->add_record_snapshot('facetoface_sessions', $session);
$event->add_record_snapshot('facetoface', $facetoface);
$event->trigger();
$pagetitle = format_string($facetoface->name);
$PAGE->set_url('/mod/facetoface/attendees.php', array('s' => $s));
$PAGE->set_context($context);
$PAGE->set_cm($cm);
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
/*
* Print page content
*/
// If taking attendance, make sure the session has already started.
if ($takeattendance && $session->datetimeknown && !facetoface_has_session_started($session, time())) {
$link = "{$CFG->wwwroot}/mod/facetoface/attendees.php?s={$session->id}";
print_error('error:canttakeattendanceforunstartedsession', 'facetoface', $link);
}
echo $OUTPUT->box_start();
echo $OUTPUT->heading(format_string($facetoface->name));
if ($canviewsession) {
echo facetoface_print_session($session, true);
}
/*
* Print attendees (if user able to view)
*/
if ($canviewattendees || $cantakeattendance) {
if ($takeattendance) {
$heading = get_string('takeattendance', 'facetoface');
} else {
$heading = get_string('attendees', 'facetoface');
}
echo $OUTPUT->heading($heading);
if (empty($attendees)) {
echo $OUTPUT->notification(get_string('nosignedupusers', 'facetoface'));
} else {
if ($takeattendance) {
$attendeesurl = new moodle_url('attendees.php', array('s' => $s, 'takeattendance' => '1'));
echo html_writer::start_tag('form', array('action' => $attendeesurl, 'method' => 'post'));
echo html_writer::tag('p', get_string('attendanceinstructions', 'facetoface'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 's', 'value' => $s));
echo html_writer::empty_tag('input', array('type' => 'hidden', ' name' => 'backtoallsessions', 'value' => $backtoallsessions)) . '</p>';
// Prepare status options array.
$statusoptions = array();
foreach ($MDL_F2F_STATUS as $key => $value) {
if ($key <= MDL_F2F_STATUS_BOOKED) {
continue;
}
$statusoptions[$key] = get_string('status_'.$value, 'facetoface');
}
}
$table = new html_table();
$table->head = array(get_string('name'));
$table->summary = get_string('attendeestablesummary', 'facetoface');
$table->align = array('left');
$table->size = array('100%');
if ($takeattendance) {
$table->head[] = get_string('currentstatus', 'facetoface');
$table->align[] = 'center';
$table->head[] = get_string('attendedsession', 'facetoface');
$table->align[] = 'center';
} else {
if (!get_config(null, 'facetoface_hidecost')) {
$table->head[] = get_string('cost', 'facetoface');
$table->align[] = 'center';
if (!get_config(null, 'facetoface_hidediscount')) {
$table->head[] = get_string('discountcode', 'facetoface');
$table->align[] = 'center';
}
}
$table->head[] = get_string('attendance', 'facetoface');
$table->align[] = 'center';
}
foreach ($attendees as $attendee) {
$data = array();
$attendeeurl = new moodle_url('/user/view.php', array('id' => $attendee->id, 'course' => $course->id));
$data[] = html_writer::link($attendeeurl, format_string(fullname($attendee)));
if ($takeattendance) {
// Show current status.
$data[] = get_string('status_'.facetoface_get_status($attendee->statuscode), 'facetoface');
$optionid = 'submissionid_'.$attendee->submissionid;
$status = $attendee->statuscode;
$select = html_writer::select($statusoptions, $optionid, $status);
$data[] = $select;
} else {
if (!get_config(null, 'facetoface_hidecost')) {
$data[] = facetoface_cost($attendee->id, $session->id, $session);
if (!get_config(null, 'facetoface_hidediscount')) {
$data[] = $attendee->discountcode;
}
}
$data[] = str_replace(' ', ' ', get_string('status_'.facetoface_get_status($attendee->statuscode), 'facetoface'));
}
$table->data[] = $data;
}
echo html_writer::table($table);
if ($takeattendance) {
echo html_writer::start_tag('p');
echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('saveattendance', 'facetoface')));
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'cancelform', 'value' => get_string('cancel')));
echo html_writer::end_tag('p') . html_writer::end_tag('form');
} else {
// Actions.
print html_writer::start_tag('p');
if ($cantakeattendance && $session->datetimeknown && facetoface_has_session_started($session, time())) {
// Take attendance.
$attendanceurl = new moodle_url('attendees.php', array('s' => $session->id, 'takeattendance' => '1', 'backtoallsessions' => $backtoallsessions));
echo html_writer::link($attendanceurl, get_string('takeattendance', 'facetoface')) . ' - ';
}
}
}
if (!$takeattendance) {
if (has_capability('mod/facetoface:addattendees', $context) ||
has_capability('mod/facetoface:removeattendees', $context)) {
// Add/remove attendees.
$editattendeeslink = new moodle_url('editattendees.php', array('s' => $session->id, 'backtoallsessions' => $backtoallsessions));
echo html_writer::link($editattendeeslink, get_string('addremoveattendees', 'facetoface')) . ' - ';
}
}
}
// Go back.
$url = new moodle_url('/course/view.php', array('id' => $course->id));
if ($backtoallsessions) {
$url = new moodle_url('/mod/facetoface/view.php', array('f' => $facetoface->id, 'backtoallsessions' => $backtoallsessions));
}
echo html_writer::link($url, get_string('goback', 'facetoface')) . html_writer::end_tag('p');
/*
* Print unapproved requests (if user able to view)
*/
if ($canapproverequests) {
echo html_writer::empty_tag('br', array('id' => 'unapproved'));
if (!$requests) {
echo $OUTPUT->notification(get_string('noactionableunapprovedrequests', 'facetoface'));
} else {
$canbookuser = (facetoface_session_has_capacity($session, $contextmodule) || $session->allowoverbook);
$OUTPUT->heading(get_string('unapprovedrequests', 'facetoface'));
if (!$canbookuser) {
echo html_writer::tag('p', get_string('cannotapproveatcapacity', 'facetoface'));
}
$action = new moodle_url('attendees.php', array('s' => $s));
echo html_writer::start_tag('form', array('action' => $action->out(), 'method' => 'post'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => $USER->sesskey));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 's', 'value' => $s));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'backtoallsessions', 'value' => $backtoallsessions)) . html_writer::end_tag('p');
$table = new html_table();
$table->summary = get_string('requeststablesummary', 'facetoface');
$table->head = array(get_string('name'), get_string('timerequested', 'facetoface'),
get_string('decidelater', 'facetoface'), get_string('decline', 'facetoface'), get_string('approve', 'facetoface'));
$table->align = array('left', 'center', 'center', 'center', 'center');
foreach ($requests as $attendee) {
$data = array();
$attendeelink = new moodle_url('/user/view.php', array('id' => $attendee->id, 'course' => $course->id));
$data[] = html_writer::link($attendeelink, format_string(fullname($attendee)));
$data[] = userdate($attendee->timerequested, get_string('strftimedatetime'));
$data[] = html_writer::empty_tag('input', array('type' => 'radio', 'name' => 'requests['.$attendee->id.']', 'value' => '0', 'checked' => 'checked'));
$data[] = html_writer::empty_tag('input', array('type' => 'radio', 'name' => 'requests['.$attendee->id.']', 'value' => '1'));
$disabled = ($canbookuser) ? array() : array('disabled' => 'disabled');
$data[] = html_writer::empty_tag('input', array_merge(array('type' => 'radio', 'name' => 'requests['.$attendee->id.']', 'value' => '2'), $disabled));
$table->data[] = $data;
}
echo html_writer::table($table);
echo html_writer::tag('p', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updaterequests', 'facetoface'))));
echo html_writer::end_tag('form');
}
}
/*
* Print cancellations (if user able to view)
*/
if (!$takeattendance && $canviewcancellations && $cancellations) {
echo html_writer::empty_tag('br');
echo $OUTPUT->heading(get_string('cancellations', 'facetoface'));
$table = new html_table();
$table->summary = get_string('cancellationstablesummary', 'facetoface');
$table->head = array(get_string('name'), get_string('timesignedup', 'facetoface'),
get_string('timecancelled', 'facetoface'), get_string('cancelreason', 'facetoface'));
$table->align = array('left', 'center', 'center');
foreach ($cancellations as $attendee) {
$data = array();
$attendeelink = new moodle_url('/user/view.php', array('id' => $attendee->id, 'course' => $course->id));
$data[] = html_writer::link($attendeelink, format_string(fullname($attendee)));
$data[] = userdate($attendee->timesignedup, get_string('strftimedatetime'));
$data[] = userdate($attendee->timecancelled, get_string('strftimedatetime'));
$data[] = format_string($attendee->cancelreason);
$table->data[] = $data;
}
echo html_writer::table($table);
}
/*
* Print page footer
*/
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);