-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditattendees.php
243 lines (207 loc) · 9.49 KB
/
editattendees.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
<?php
require_once '../../config.php';
require_once 'lib.php';
define('MAX_USERS_PER_PAGE', 5000);
$s = required_param('s', PARAM_INT); // facetoface session ID
$add = optional_param('add', 0, PARAM_BOOL);
$remove = optional_param('remove', 0, PARAM_BOOL);
$showall = optional_param('showall', 0, PARAM_BOOL);
$searchtext = optional_param('searchtext', '', PARAM_CLEAN); // search string
$suppressemail = optional_param('suppressemail', false, PARAM_BOOL); // send email notifications
$previoussearch = optional_param('previoussearch', 0, PARAM_BOOL);
$backtoallsessions = optional_param('backtoallsessions', 0, PARAM_INT); // facetoface activity to go back to
if (!$session = facetoface_get_session($s)) {
print_error('error:incorrectcoursemodulesession', 'facetoface');
}
if (!$facetoface = get_record('facetoface', 'id', $session->facetoface)) {
print_error('error:incorrectfacetofaceid', 'facetoface');
}
if (!$course = get_record('course', 'id', $facetoface->course)) {
print_error('error:coursemisconfigured', 'facetoface');
}
if (!$cm = get_coursemodule_from_instance('facetoface', $facetoface->id, $course->id)) {
print_error('error:incorrectcoursemodule', 'facetoface');
}
/// Check essential permissions
require_course_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('mod/facetoface:viewattendees', $context);
/// Get some language strings
$strsearch = get_string('search');
$strshowall = get_string('showall');
$strsearchresults = get_string('searchresults');
$strfacetofaces = get_string('modulenameplural', 'facetoface');
$strfacetoface = get_string('modulename', 'facetoface');
$errors = array();
/// Handle the POST actions sent to the page
if ($frm = data_submitted()) {
// Add button
if ($add and !empty($frm->addselect) and confirm_sesskey()) {
require_capability('mod/facetoface:addattendees', $context);
foreach ($frm->addselect as $adduser) {
if (!$adduser = clean_param($adduser, PARAM_INT)) {
continue; // invalid userid
}
// Make sure that the user is enroled in the course
if (!has_capability('moodle/course:view', $context, $adduser)) {
$user = get_record('user', 'id', $adduser);
if (!enrol_into_course($course, $user, 'manual')) {
$errors[] = get_string('error:enrolmentfailed', 'facetoface', fullname($user));
$errors[] = get_string('error:addattendee', 'facetoface', fullname($user));
continue; // don't sign the user up
}
}
if (facetoface_get_user_submissions($facetoface->id, $adduser)) {
$erruser = get_record('user', 'id', $adduser, '','','','', 'id, firstname, lastname');
$errors[] = get_string('error:addalreadysignedupattendee', 'facetoface', fullname($erruser));
}
else {
if (!facetoface_session_has_capacity($session, $context)) {
$errors[] = get_string('full', 'facetoface');
break; // no point in trying to add other people
}
// Check if we are waitlisting or booking
if ($session->datetimeknown) {
$status = MDL_F2F_STATUS_BOOKED;
} else {
$status = MDL_F2F_STATUS_WAITLISTED;
}
if (!facetoface_user_#($session, $facetoface, $course, '', MDL_F2F_BOTH,
$status, $adduser, !$suppressemail)) {
$erruser = get_record('user', 'id', $adduser, '','','','', 'id, firstname, lastname');
$errors[] = get_string('error:addattendee', 'facetoface', fullname($erruser));
}
}
}
}
// Remove button
else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
require_capability('mod/facetoface:removeattendees', $context);
foreach ($frm->removeselect as $removeuser) {
if (!$removeuser = clean_param($removeuser, PARAM_INT)) {
continue; // invalid userid
}
if (facetoface_user_cancel($session, $removeuser, true, $cancelerr)) {
// Notify the user of the cancellation if the session hasn't started yet
$timenow = time();
if (!$suppressemail and !facetoface_has_session_started($session, $timenow)) {
facetoface_send_cancellation_notice($facetoface, $session, $removeuser);
}
}
else {
$errors[] = $cancelerr;
$erruser = get_record('user', 'id', $removeuser, '','','','', 'id, firstname, lastname');
$errors[] = get_string('error:removeattendee', 'facetoface', fullname($erruser));
}
}
// Update attendees
facetoface_update_attendees($session);
}
// "Show All" button
elseif ($showall) {
$searchtext = '';
$previoussearch = 0;
}
}
/// Main page
$pagetitle = format_string($facetoface->name);
$navlinks[] = array('name' => $strfacetofaces, 'link' => "index.php?id=$course->id", 'type' => 'title');
$navlinks[] = array('name' => $pagetitle, 'link' => "view.php?f=$facetoface->id", 'type' => 'activityinstance');
$navlinks[] = array('name' => get_string('attendees', 'facetoface'), 'link' => "attendees.php?s=$session->id&backtoallsessions=$backtoallsessions", 'type' => 'activityinstance');
$navlinks[] = array('name' => get_string('addremoveattendees', 'facetoface'), 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
print_header_simple($pagetitle, '', $navigation, '', '', true,
update_module_button($cm->id, $course->id, $strfacetoface), navmenu($course, $cm));
print_box_start();
print_heading(get_string('addremoveattendees', 'facetoface'), 'center');
/// Get the list of currently signed-up users
$existingusers = facetoface_get_attendees($session->id);
$existingcount = $existingusers ? count($existingusers) : 0;
$select = "username <> 'guest' AND deleted = 0 AND confirmed = 1";
/// Apply search terms
$searchtext = trim($searchtext);
if ($searchtext !== '') { // Search for a subset of remaining users
$LIKE = sql_ilike();
$FULLNAME = sql_fullname();
$selectsql = " AND ($FULLNAME $LIKE '%$searchtext%' OR
email $LIKE '%$searchtext%' OR
idnumber $LIKE '%$searchtext%' OR
username $LIKE '%$searchtext%') ";
$select .= $selectsql;
}
/// All non-signed up system users
$availableusers = get_recordset_sql('SELECT id, firstname, lastname, email
FROM '.$CFG->prefix.'user
WHERE '.$select.'
AND id NOT IN
(
SELECT u.id
FROM '.$CFG->prefix.'facetoface_#s s
JOIN '.$CFG->prefix.'facetoface_#s_status ss ON s.id = ss.#id
JOIN '.$CFG->prefix.'user u ON u.id=s.userid
WHERE s.sessionid='.$session->id.'
AND ss.statuscode >= '.MDL_F2F_STATUS_BOOKED.'
AND ss.superceded = 0
)
ORDER BY lastname ASC, firstname ASC');
$usercount = count_records_select('user', $select) - $existingcount;
// Get all signed up non-attendees
$nonattendees = 0;
$nonattendees_rs = get_recordset_sql(
"
SELECT
u.id,
u.firstname,
u.lastname,
u.email,
ss.statuscode
FROM
{$CFG->prefix}facetoface_sessions s
JOIN
{$CFG->prefix}facetoface_#s su
ON s.id = su.sessionid
JOIN
{$CFG->prefix}facetoface_#s_status ss
ON su.id = ss.#id
JOIN
{$CFG->prefix}user u
ON u.id = su.userid
WHERE
s.id = {$session->id}
AND ss.superceded != 1
AND ss.statuscode = ".MDL_F2F_STATUS_REQUESTED."
ORDER BY
u.lastname, u.firstname
"
);
$table = new object();
$table->head = array(get_string('name'), get_string('email'), get_string('status'));
$table->align = array('left');
$table->size = array('50%');
$table->width = '70%';
while ($user = rs_fetch_next_record($nonattendees_rs)) {
$data = array();
$data[] = fullname($user);
$data[] = $user->email;
$data[] = get_string('status_'.facetoface_get_status($user->statuscode), 'facetoface');
$table->data[] = $data;
$nonattendees++;
}
/// Prints a form to add/remove users from the session
include('editattendees.html');
if (!empty($errors)) {
$msg = '<p>';
foreach ($errors as $e) {
$msg .= $e.'<br />';
}
$msg .= '</p>';
print_simple_box_start('center');
notify($msg);
print_simple_box_end();
}
// Bottom of the page links
print '<p style="text-align: center">';
$url = $CFG->wwwroot.'/mod/facetoface/attendees.php?s='.$session->id.'&backtoallsessions='.$backtoallsessions;
print '<a href="'.$url.'">'.get_string('goback', 'facetoface').'</a></p>';
print_box_end();
print_footer($course);