forked from mynameisdongyoung/Face-to-Face2.0
/
attendees.php
361 lines (314 loc) · 13.7 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
<?php
require_once '../../config.php';
require_once 'lib.php';
global $DB;
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$f = optional_param('f', 0, PARAM_INT); // facetoface activity ID
$s = optional_param('s', 0, PARAM_INT); // facetoface session ID
$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); // facetoface activity to go back to
if ($id) {
if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
print_error('error:incorrectcoursemoduleid', 'facetoface');
}
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('error:coursemisconfigured', 'facetoface');
}
if (!$facetoface = $DB->get_record('facetoface', array('id'=>$cm->instance))) {
print_error('error:incorrectcoursemodule', 'facetoface');
}
}
elseif ($s) {
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');
}
}
else {
if (!$facetoface = $DB->get_record('facetoface', array('id'=>$f))) {
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');
}
}
require_course_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('mod/facetoface:viewattendees', $context);
// Handle submitted data
if ($form = data_submitted()) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
}
require_capability('mod/facetoface:takeattendance', $context);
if ($cancelform) {
redirect("attendees.php?s=$s&backtoallsessions=$backtoallsessions");
}
elseif (!empty($form->requests)) {
// Approve requests
if (facetoface_approve_requests($form)) {
add_to_log($course->id, 'facetoface', 'approve requests', "view.php?id=$cm->id", $facetoface->id, $cm->id);
}
}
elseif (facetoface_take_attendance($form)) {
add_to_log($course->id, 'facetoface', 'take attendance', "view.php?id=$cm->id", $facetoface->id, $cm->id);
}
else {
add_to_log($course->id, 'facetoface', 'take attendance (FAILED)', "view.php?id=$cm->id", $facetoface->id, $cm->id);
}
}
$pagetitle = format_string($facetoface->name);
$PAGE->set_cm($cm);
$PAGE->set_url('/mod/facetoface/view.php', array('id' => $cm->id));
$PAGE->set_title($pagetitle);
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
if ($takeattendance && !has_capability('mod/facetoface:takeattendance', $context)) {
$takeattendance = 0;
}
// Check the session has already started
if ($takeattendance && $session->datetimeknown && !facetoface_has_session_started($session, time())) {
error('Can not take attendance for a session that has not yet started', 'attendees.php?s='.$session->id);
exit();
}
$heading = '';
if ($takeattendance) {
$heading = get_string('takeattendance', 'facetoface');
}
else {
add_to_log($course->id, 'facetoface', 'view attendees', "view.php?id=$cm->id", $facetoface->id, $cm->id);
$heading = get_string('attendees', 'facetoface');
}
$heading .= ' - ' . format_string($facetoface->name);
echo $OUTPUT->box_start();
echo $OUTPUT->heading($heading);
if ($takeattendance) {
echo '<form action="attendees.php?s='.$s.'" method="post">';
echo '<p>'. get_string('attendanceinstructions', 'facetoface');
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
echo '<input type="hidden" name="s" value="'.$s.'" />';
echo '<input type="hidden" name="backtoallsessions" value="'.$backtoallsessions.'" /></p>';
}
else {
facetoface_print_session($session, true);
}
$table = new html_table();
$table->head = array(get_string('name'));
$table->summary = get_string('attendeestablesummary', 'facetoface');
$table->align = array('left');
$table->size = array('100%');
$table->width = '50%';
if ($takeattendance) {
$table->head[] = get_string('currentstatus', 'facetoface');
$table->align[] = array('center');
$table->head[] = get_string('attendedsession', 'facetoface');
$table->align[] = array('center');
}
else {
if (!get_config(NULL, 'facetoface_hidecost')) {
$table->head[] = get_string('cost', 'facetoface');
$table->align[] = array('center');
if (!get_config(NULL, 'facetoface_hidediscount')) {
$table->head[] = get_string('discountcode', 'facetoface');
$table->align[] = array('center');
}
}
$table->head[] = get_string('attendance', 'facetoface');
$table->align[] = array('center');
}
$status_options = array();
foreach ($MDL_F2F_STATUS as $key => $value) {
if ($key <= MDL_F2F_STATUS_BOOKED) {
continue;
}
$status_options[$key] = get_string('status_'.$value, 'facetoface');
}
if ($attendees = facetoface_get_attendees($session->id)) {
foreach($attendees as $attendee) {
$data = array();
$data[] = "<a href=\"$CFG->wwwroot/user/view.php?id={$attendee->id}&course={$course->id}\">". format_string(fullname($attendee)).'</a>';
if ($takeattendance) {
// Show current status
$data[] = get_string('status_'.facetoface_get_status($attendee->statuscode), 'facetoface');
$optionid = 'submissionid_'.$attendee->submissionid;
$status = $attendee->statuscode;
//$select = choose_from_menu($status_options, $optionid, $status, 'choose', '', '0', true);
$select = html_writer::select($status_options, $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);
}
else {
echo $OUTPUT->heading(get_string('nosignedupusers', 'facetoface'));
}
if ($takeattendance) {
echo '<p>';
echo '<input type="submit" value="'.get_string('saveattendance', 'facetoface').'" />';
echo ' <input type="submit" name="cancelform" value="'.get_string('cancel').'" />';
echo '</p></form>';
}
else {
// Actions
print '<p>';
if (has_capability('mod/facetoface:takeattendance', $context)) {
if (!$takeattendance && !empty($attendees) && $session->datetimeknown && facetoface_has_session_started($session, time())) {
// Take attendance
echo '<a href="attendees.php?s='.$session->id.'&takeattendance=1&backtoallsessions='.$backtoallsessions.'">'.get_string('takeattendance', 'facetoface').'</a> - ';
}
}
if (has_capability('mod/facetoface:addattendees', $context) ||
has_capability('mod/facetoface:removeattendees', $context)) {
// Add/remove attendees
echo '<a href="editattendees.php?s='.$session->id.'&backtoallsessions='.$backtoallsessions.'">'.get_string('addremoveattendees', 'facetoface').'</a> - ';
}
// Go back
$url = "$CFG->wwwroot/course/view.php?id=$course->id";
if ($backtoallsessions) {
$url = "view.php?f={$facetoface->id}&backtoallsessions=$backtoallsessions";
}
print '<a href="'.$url.'">'.get_string('goback', 'facetoface').'</a></p>';
}
// View unapproved requests
if (!$takeattendance && ($attendees = facetoface_get_requests($session->id))) {
echo '<br id="unapproved" />';
echo $OUTPUT->heading(get_string('unapprovedrequests', 'facetoface'));
echo '<form action="attendees.php?s='.$s.'" method="post">';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
echo '<input type="hidden" name="s" value="'.$s.'" />';
echo '<input type="hidden" name="backtoallsessions" value="'.$backtoallsessions.'" /></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');
$cantakeattendance = has_capability('mod/facetoface:takeattendance', $context);
foreach($attendees as $attendee) {
// Check the logged in user has permissions to see the user
if (!$cantakeattendance) {
if (facetoface_get_manageremail($attendee->id) !== $USER->email) {
continue;
}
}
$data = array();
$data[] = "<a href=\"{$CFG->wwwroot}/user/view.php?id={$attendee->id}&course={$course->id}\">". format_string(fullname($attendee)).'</a>';
$data[] = userdate($attendee->timerequested, get_string('strftimedatetime'));
$data[] = '<input type="radio" name="requests['.$attendee->id.']" value="0" checked="checked" />';
$data[] = '<input type="radio" name="requests['.$attendee->id.']" value="1" />';
$data[] = '<input type="radio" name="requests['.$attendee->id.']" value="2" />';
$table->data[] = $data;
}
if (empty($table->data)) {
$table->data[] = array(get_string('noactionableunapprovedrequests', 'facetoface'), '', '');
}
echo html_writer::table($table);
echo '<p><input type="submit" value="Update requests" /></p>';
echo '</form>';
}
// View cancellations
if (!$takeattendance and has_capability('mod/facetoface:viewcancellations', $context) and
($attendees = facetoface_get_cancellations($session->id))) {
echo '<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($attendees as $attendee) {
$data = array();
$data[] = "<a href=\"$CFG->wwwroot/user/view.php?id={$attendee->id}&course={$course->id}\">". format_string(fullname($attendee)).'</a>';
$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);
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);
function facetoface_get_cancellations($sessionid)
{
global $CFG,$DB;
$fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
// Nasty SQL follows:
// Load currently cancelled users,
// include most recent booked/waitlisted time also
$sql = "
SELECT
su.id AS signupid,
u.id,
u.firstname,
u.lastname,
MAX(ss.timecreated) AS timesignedup,
c.timecreated AS timecancelled,
c.note AS cancelreason
FROM
{facetoface_signups} su
JOIN
{user} u
ON u.id = su.userid
JOIN
{facetoface_signups_status} c
ON su.id = c.signupid
AND c.statuscode = ".MDL_F2F_STATUS_USER_CANCELLED."
AND c.superceded = 0
LEFT JOIN
{facetoface_signups_status} ss
ON su.id = ss.signupid
AND ss.statuscode IN (
".MDL_F2F_STATUS_BOOKED.",
".MDL_F2F_STATUS_WAITLISTED.",
".MDL_F2F_STATUS_REQUESTED."
)
AND ss.superceded = 1
WHERE
su.sessionid = {$sessionid}
GROUP BY
su.id,
u.id,
u.firstname,
u.lastname,
c.timecreated,
c.note
ORDER BY
{$fullname},
c.timecreated
";
return $DB->get_records_sql($sql);
}
function facetoface_get_requests($sessionid)
{
global $CFG,$DB;
$fullname = $DB->sql_fullname('u.firstname', 'u.lastname');
$sql = "SELECT su.id AS signupid, u.id, u.firstname, u.lastname,
ss.timecreated AS timerequested
FROM {facetoface_signups} su
JOIN {facetoface_signups_status} ss ON su.id=ss.signupid
JOIN {user} u ON u.id = su.userid
WHERE su.sessionid = $sessionid AND ss.superceded != 1 AND ss.statuscode = ".MDL_F2F_STATUS_REQUESTED."
ORDER BY $fullname, ss.timecreated";
return $DB->get_records_sql($sql);
}