-
Notifications
You must be signed in to change notification settings - Fork 4
/
sessions.php
291 lines (236 loc) · 10.1 KB
/
sessions.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
<?php
require_once '../../config.php';
require_once 'lib.php';
require_once 'session_form.php';
require_once 'createmeeting.php';
require_once 'updatemeeting.php';
require_once 'sendemailsessionupdated.php';
require_once 'deletemeeting.php';
require_once 'sendemailsessiondeleted.php';
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
$f = optional_param('f', 0, PARAM_INT); // webinar Module ID
$s = optional_param('s', 0, PARAM_INT); // webinar session ID
$c = optional_param('c', 0, PARAM_INT); // copy session
$d = optional_param('d', 0, PARAM_INT); // delete session
$confirm = optional_param('confirm', false, PARAM_BOOL); // delete confirmation
$nbdays = 1; // default number to show
$session = null;
if ($id) {
if (!$cm = $DB->get_record('course_modules', array('id' => $id))) {
error(get_string('error:incorrectcoursemoduleid', 'webinar'));
}
if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
error(get_string('error:coursemisconfigured', 'webinar'));
}
if (!$webinar = $DB->get_record('webinar', array('id' => $cm->instance))) {
error(get_string('error:incorrectcoursemodule', 'webinar'));
}
}
elseif ($s) {
if (!$session = webinar_get_session($s)) {
error(get_string('error:incorrectcoursemodulesession', 'webinar'));
}
if (!$webinar = $DB->get_record('webinar', array('id' => $session->webinar))) {
error(get_string('error:incorrectwebinarid', 'webinar'));
}
if (!$course = $DB->get_record('course', array('id' => $webinar->course))) {
error(get_string('error:coursemisconfigured', 'webinar'));
}
if (!$cm = get_coursemodule_from_instance('webinar', $webinar->id, $course->id)) {
error(get_string('error:incorrectcoursemoduleid', 'webinar'));
}
$nbdays = count($session->sessiondates);
}
else {
if (!$webinar = $DB->get_record('webinar', array('id' => $f))) {
error(get_string('error:incorrectwebinarid', 'webinar'));
}
if (!$course = $DB->get_record('course', array('id' => $webinar->course))) {
error(get_string('error:coursemisconfigured', 'webinar'));
}
if (!$cm = get_coursemodule_from_instance('webinar', $webinar->id, $course->id)) {
error(get_string('error:incorrectcoursemoduleid', 'webinar'));
}
}
require_course_login($course);
$errorstr = '';
$context = context_course::instance($course->id, CONTEXT_COURSE); //get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('mod/webinar:editsessions', $context);
$returnurl = "view.php?f=$webinar->id";
// Handle deletions
if ($d and $confirm) {
if (!confirm_sesskey()) {
print_error('confirmsesskeybad', 'error');
}
/* Delete meeting through Adobe Connect API call */
delete_meeting($webinar, $session);
//Send email to all registered attendees when session is deleted
send_email_sessiondeleted($webinar, $session);
if (webinar_delete_session($session)) {
add_to_log($course->id, 'webinar', 'delete session', 'sessions.php?s='.$session->id, $webinar->id, $cm->id);
}
else {
add_to_log($course->id, 'webinar', 'delete session (FAILED)', 'sessions.php?s='.$session->id, $webinar->id, $cm->id);
print_error('error:couldnotdeletesession', 'webinar', $returnurl);
}
redirect($returnurl);
}
$customfields = webinar_get_session_customfields();
$mform = new mod_webinar_session_form(null, compact('id', 'f', 's', 'c', 'nbdays', 'customfields', 'course'));
//$mform = new mod_webinar_session_form(null, array('webinar'=> $webinar), compact('id', 'f', 's', 'c', 'nbdays', 'customfields', 'course'));
if ($mform->is_cancelled()){
redirect($returnurl);
}
if ($fromform = $mform->get_data()) { // Form submitted
if (empty($fromform->submitbutton)) {
print_error('error:unknownbuttonclicked', 'webinar', $returnurl);
}
$date = new object();
$date->timestart = $fromform->timestart;
$date->timefinish = $fromform->timefinish;
$sessiondates[] = $date;
$todb = new object();
$todb->webinar = $webinar->id;
$todb->capacity = $fromform->capacity;
$todb->presenter = $fromform->presenter;
$presenter_details = array();
$presenters = $DB->get_records_sql("SELECT
u.firstname,
u.lastname,
u.email
FROM
{$CFG->prefix}user u
WHERE
u.id = $todb->presenter LIMIT 1");
if($presenters) {
foreach($presenters as $presenter) {
$presenter_details = $presenter;
}
}
$sessionid = null;
// begin_sql();
$update = false;
if (!$c and $session != null) {
$update = true;
/* Update meeting details through Adobe Connect API call */
update_meeting($webinar, $session, $date, $presenter_details);
//Send email to all registered attendees when session/meeting details are changed
send_email_sessionupdated($webinar, $session, $cm, $date);
$sessionid = $session->id;
$todb->id = $session->id;
if (!webinar_update_session($todb, $sessiondates)) {
rollback_sql();
add_to_log($course->id, 'webinar', 'update session (FAILED)', "sessions.php?s=$session->id", $webinar->id, $cm->id);
print_error('error:couldnotupdatesession', 'webinar', $returnurl);
}
// Remove old site-wide calendar entry
if (!webinar_remove_session_from_site_calendar($session)) {
rollback_sql();
print_error('error:couldnotupdatecalendar', 'webinar', $returnurl);
}
}
else {
//Create meeting through Adobe Connect API call
$webinardetails = create_meeting($webinar, $fromform, $date, $presenter_details);
$todb->scoid = $webinardetails->scoid;
$todb->urlpath = $webinardetails->urlpath;
if (!$sessionid = webinar_add_session($todb, $sessiondates)) {
rollback_sql();
add_to_log($course->id, 'webinar', 'add session (FAILED)', 'sessions.php?f='.$webinar->id, $webinar->id, $cm->id);
print_error('error:couldnotaddsession', 'webinar', $returnurl);
}
}
foreach ($customfields as $field) {
$fieldname = "custom_$field->shortname";
if (!isset($fromform->$fieldname)) {
$fromform->$fieldname = ''; // need to be able to clear fields
}
if (!webinar_save_customfield_value($field->id, $fromform->$fieldname, $sessionid, 'session')) {
rollback_sql();
print_error('error:couldnotsavecustomfield', 'webinar', $returnurl);
}
}
// Retrieve record that was just inserted/updated
if (!$session = webinar_get_session($sessionid)) {
rollback_sql();
print_error('error:couldnotfindsession', 'webinar', $returnurl);
}
// Put the session in the site-wide calendar (needs customfields to be up to date)
if (!webinar_add_session_to_site_calendar($session, $webinar)) {
rollback_sql();
print_error('error:couldnotupdatecalendar', 'webinar', $returnurl);
}
if ($update) {
add_to_log($course->id, 'webinar', 'update session', "sessions.php?s=$session->id", $webinar->id, $cm->id);
}
else {
add_to_log($course->id, 'webinar', 'add session', 'webinar', 'sessions.php?f='.$webinar->id, $webinar->id, $cm->id);
}
//commit_sql();
redirect($returnurl);
}
elseif ($session != null) { // Edit mode
// Set values for the form
$date = new object();
$date->timestart = $session->sessiondates[0]->timestart;
$date->timefinish = $session->sessiondates[0]->timefinish;
$sessiondates[] = $date;
$toform = new object();
$toform->timestart = $date->timestart;
$toform->timefinish = $date->timefinish;
$toform->webinar = $session->id;
$toform->capacity = $session->capacity;
$toform->presenter = $session->presenter;
$toform->scoid = $session->scoid;
$toform->urlpath = $session->urlpath;
foreach ($customfields as $field) {
$fieldname = "custom_$field->shortname";
$toform->$fieldname = webinar_get_customfield_value($field, $session->id, 'session');
}
$mform->set_data($toform);
}
if ($c) {
$heading = get_string('copyingsession', 'webinar', $webinar->name);
}
else if ($d) {
$heading = get_string('deletingsession', 'webinar', $webinar->name);
}
else if ($id or $f) {
$heading = get_string('addingsession', 'webinar', $webinar->name);
}
else {
$heading = get_string('editingsession', 'webinar', $webinar->name);
}
$pagetitle = format_string($webinar->name);
$navlinks[] = array('name' => get_string('modulenameplural', 'webinar'), 'link' => "index.php?id=$course->id", 'type' => 'title');
$navlinks[] = array('name' => $pagetitle, 'link' => "view.php?f=$webinar->id", 'type' => 'activityinstance');
$navlinks[] = array('name' => $heading, 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
/*print_header_simple($pagetitle, '', $navigation, '', '', true,
update_module_button($cm->id, $course->id, get_string('modulename', 'webinar')), navmenu($course, $cm));*/
$PAGE->set_pagetype('webinar');
$PAGE->set_title($webinar->name);
$PAGE->set_heading($webinar->name);
$PAGE->navbar->add($webinar->name);
echo $OUTPUT->header();
//print_box_start();
echo $OUTPUT->box_start();
//print_heading($heading, 'center');
echo $OUTPUT->heading($heading);
if (!empty($errorstr)) {
echo '<div class="notifyproblem" align="center"><span style="font-size: 12px; line-height: 18px;">'.$errorstr.'</span></div>';
}
if ($d) {
$viewattendees = has_capability('mod/webinar:viewattendees', $context);
webinar_print_session($session, $viewattendees);
//JoeB - dev change for Moodle 2.3 - replace reference to deprecated function notice_yesno()
//notice_yesno(get_string('deletesessionconfirm', 'webinar', format_string($webinar->name)),
// "sessions.php?s=$session->id&d=1&confirm=1&sesskey=$USER->sesskey", $returnurl);
echo $OUTPUT->confirm(get_string('deletesessionconfirm', 'webinar', format_string($webinar->name)),
"sessions.php?s=$session->id&d=1&confirm=1&sesskey=$USER->sesskey", $returnurl);
}
else {
$mform->display();
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer($course);