-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheditattendees.php
270 lines (224 loc) · 9.36 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
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
<?php
require_once '../../config.php';
require_once 'lib.php';
require_once 'signupmeeting.php';
require_once 'cancelsignupmeeting.php';
require_once 'sendemailsignup.php';
require_once 'sendemailcancelsignup.php';
define('MAX_USERS_PER_PAGE', 5000);
$s = required_param('s', PARAM_INT); // webinar 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_RAW); // 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); // webinar activity to go back to
if (!$session = webinar_get_session($s)) {
print_error('error:incorrectcoursemodulesession', 'webinar');
}
if (!$webinar = $DB->get_record('webinar', array('id' => $session->webinar))) {
print_error('error:incorrectwebinarid', 'webinar');
}
if (!$course = $DB->get_record('course', array('id' => $webinar->course))) {
print_error('error:coursemisconfigured', 'webinar');
}
if (!$cm = get_coursemodule_from_instance('webinar', $webinar->id, $course->id)) {
print_error('error:incorrectcoursemodule', 'webinar');
}
/// Check essential permissions
require_course_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('mod/webinar:viewattendees', $context);
/// Get some language strings
$strsearch = get_string('search');
$strshowall = get_string('showall');
$strsearchresults = get_string('searchresults');
$strwebinars = get_string('modulenameplural', 'webinar');
$strwebinar = get_string('modulename', 'webinar');
$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/webinar: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 = $DB->get_record('user', array('id' => $adduser));
}
if (!webinar_session_has_capacity($session, $context)) {
$errors[] = get_string('full', 'webinar');
break; // no point in trying to add other people
}
// Check if we are waitlisting or booking
//if ($session->datetimeknown) {
// $status = WEBINAR_STATUS_BOOKED;
//}
//else {
$status = WEBINAR_STATUS_WAITLISTED;
//}
if (!webinar_user_signup($session, $webinar, $course, '', WEBINAR_BOTH,
$status, $adduser, !$suppressemail)) {
$erruser = $DB->get_record('user', array('id' => $adduser), 'id, firstname, lastname');
$errors[] = get_string('error:addattendee', 'webinar', fullname($erruser));
}
else {
//Sign up user to this webinar through Adobe Connect API call
signup_meeting($webinar, $session, $user);
//Send registration email to user
send_email_signup($webinar, $session, $cm, $user);
}
}
}
// Remove button
else if ($remove and !empty($frm->removeselect) and confirm_sesskey()) {
require_capability('mod/webinar:removeattendees', $context);
foreach ($frm->removeselect as $removeuser) {
if (!$removeuser = clean_param($removeuser, PARAM_INT)) {
continue; // invalid userid
}
if (webinar_user_cancel($session, $removeuser, true, $cancelerr)) {
// Notify the user of the cancellation if the session hasn't started yet
$timenow = time();
if (!$suppressemail and !webinar_has_session_started($session, $timenow)) {
webinar_send_cancellation_notice($webinar, $session, $removeuser);
}
}
else {
$errors[] = $cancelerr;
$erruser = $DB->get_record('user', array('id' => $removeuser), 'id, firstname, lastname');
$errors[] = get_string('error:removeattendee', 'webinar', fullname($erruser));
}
}
// Update attendees
webinar_update_attendees($session);
$user = $DB->get_record('user', array('id' => $removeuser));
//Unregister this user from this webinar through Adobe Connect API call
cancelsignup_meeting($webinar, $session, $user);
//Send cancel registration email to user
send_email_cancelsignup($webinar, $session, $cm, $user);
}
// "Show All" button
elseif ($showall) {
$searchtext = '';
$previoussearch = 0;
}
}
/// Main page
$pagetitle = format_string($webinar->name);
$navlinks[] = array('name' => $strwebinars, 'link' => "index.php?id=$course->id", 'type' => 'title');
$navlinks[] = array('name' => $pagetitle, 'link' => "view.php?f=$webinar->id", 'type' => 'activityinstance');
$navlinks[] = array('name' => get_string('attendees', 'webinar'), 'link' => "attendees.php?s=$session->id", 'type' => 'activityinstance');
$navlinks[] = array('name' => get_string('addremoveattendees', 'webinar'), 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
/*print_header_simple($pagetitle, '', $navigation, '', '', true,
update_module_button($cm->id, $course->id, $strwebinar), navmenu($course, $cm));*/
$PAGE->set_pagetype('webinar');
$PAGE->set_title($webinar->name);
$PAGE->set_heading($webinar->name);
$PAGE->set_url('/editattendees.php?s='.$session->id.'&backtoallsessions='.$backtoallsessions);
echo $OUTPUT->header();
echo $OUTPUT->box_start();
echo $OUTPUT->heading(get_string('addremoveattendees', 'webinar'));
/// Get the list of currently signed-up users
$existingusers = webinar_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 = $DB->get_recordset_sql('SELECT u.id, u.firstname, u.lastname, u.email
FROM '.$CFG->prefix.'user u, '.$CFG->prefix.'enrol e, '.$CFG->prefix.'user_enrolments ue
WHERE
e.courseid = '.$course->id.'
AND
ue.enrolid = e.id
AND
u.id = ue.userid
ORDER BY u.lastname ASC, u.firstname ASC');
$availablecount = $DB->get_recordset_sql('SELECT COUNT(u.id) AS avusers
FROM '.$CFG->prefix.'user u, '.$CFG->prefix.'enrol e, '.$CFG->prefix.'user_enrolments ue
WHERE
e.courseid = '.$course->id.'
AND
ue.enrolid = e.id
AND
u.id = ue.userid');
foreach ($availablecount as $ac) {
$potential_users = $ac->avusers;
}
//$usercount = $DB->count_records_select('user', $select) - $existingcount;
$usercount = $potential_users;
// Get all signed up non-attendees
$nonattendees = 0;
$nonattendees_sql = "
SELECT
u.id,
u.firstname,
u.lastname,
u.email,
ss.statuscode
FROM
{$CFG->prefix}webinar_sessions s
JOIN
{$CFG->prefix}webinar_signups su
ON s.id = su.sessionid
JOIN
{$CFG->prefix}webinar_signups_status ss
ON su.id = ss.signupid
JOIN
{$CFG->prefix}user u
ON u.id = su.userid
WHERE
s.id = {$session->id}
AND ss.superceded != 1
AND ss.statuscode = ".WEBINAR_STATUS_REQUESTED."
ORDER BY
u.lastname, u.firstname
";
$nonattendees_rs = $DB->get_recordset_sql($nonattendees_sql);
$table = new html_table();
$table->head = array(get_string('name'), get_string('email'), get_string('status'));
$table->align = array('left');
$table->size = array('50%');
$table->width = '70%';
if ($na_rs = $DB->get_recordset_sql($nonattendees_sql)) {
foreach ($na_rs as $record) {
$data[] = $record->firstname . ' ' . $record->lastname;
$data[] = $record->email;
//$data[] = get_string('status_'.webinar_get_status($user->statuscode), 'webinar');
$table->data[] = $data;
}
$na_rs->close();
}
/// 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/webinar/attendees.php?s='.$session->id.'&backtoallsessions='.$backtoallsessions;
print '<a href="'.$url.'">'.get_string('goback', 'webinar').'</a></p>';
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);