|
1
|
|
|
<?php |
|
2
|
|
|
// This file is part of Moodle - http://moodle.org/ |
|
3
|
|
|
// |
|
4
|
|
|
// Moodle is free software: you can redistribute it and/or modify |
|
5
|
|
|
// it under the terms of the GNU General Public License as published by |
|
6
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
// (at your option) any later version. |
|
8
|
|
|
// |
|
9
|
|
|
// Moodle is distributed in the hope that it will be useful, |
|
10
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
// GNU General Public License for more details. |
|
13
|
|
|
// |
|
14
|
|
|
// You should have received a copy of the GNU General Public License |
|
15
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Library calls for Moodle and BigBlueButton. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com) |
|
21
|
|
|
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com) |
|
22
|
|
|
* @copyright 2010-2017 Blindside Networks Inc |
|
23
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
defined('MOODLE_INTERNAL') || die; |
|
27
|
|
|
|
|
28
|
|
|
global $CFG; |
|
29
|
|
|
|
|
30
|
|
|
require_once($CFG->dirroot.'/calendar/lib.php'); |
|
31
|
|
|
require_once($CFG->dirroot.'/message/lib.php'); |
|
32
|
|
|
require_once($CFG->dirroot.'/mod/lti/OAuth.php'); |
|
33
|
|
|
require_once($CFG->libdir.'/accesslib.php'); |
|
34
|
|
|
require_once($CFG->libdir.'/completionlib.php'); |
|
35
|
|
|
require_once($CFG->libdir.'/datalib.php'); |
|
36
|
|
|
require_once($CFG->libdir.'/coursecatlib.php'); |
|
37
|
|
|
require_once($CFG->libdir.'/enrollib.php'); |
|
38
|
|
|
require_once($CFG->libdir.'/filelib.php'); |
|
39
|
|
|
require_once($CFG->libdir.'/formslib.php'); |
|
40
|
|
|
|
|
41
|
|
|
if (file_exists(dirname(__FILE__).'/vendor/firebase/php-jwt/src/JWT.php')) { |
|
42
|
|
|
require_once(dirname(__FILE__).'/vendor/firebase/php-jwt/src/JWT.php'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (!isset($CFG->bigbluebuttonbn)) { |
|
46
|
|
|
$CFG->bigbluebuttonbn = array(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (file_exists(dirname(__FILE__).'/config.php')) { |
|
50
|
|
|
require_once(dirname(__FILE__).'/config.php'); |
|
51
|
|
|
// Old BigBlueButtonBN cfg schema. For backward compatibility. |
|
52
|
|
|
global $BIGBLUEBUTTONBN_CFG; |
|
53
|
|
|
|
|
54
|
|
|
if (isset($BIGBLUEBUTTONBN_CFG)) { |
|
55
|
|
|
foreach ((array) $BIGBLUEBUTTONBN_CFG as $key => $value) { |
|
56
|
|
|
$cfgkey = str_replace("bigbluebuttonbn_", "", $key); |
|
57
|
|
|
$CFG->bigbluebuttonbn[$cfgkey] = $value; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/* |
|
63
|
|
|
* DURATIONCOMPENSATION: Feature removed by configuration |
|
64
|
|
|
*/ |
|
65
|
|
|
$CFG->bigbluebuttonbn['scheduled_duration_enabled'] = 0; |
|
66
|
|
|
/* |
|
67
|
|
|
* Remove this block when restored |
|
68
|
|
|
*/ |
|
69
|
|
|
|
|
70
|
|
|
const BIGBLUEBUTTONBN_DEFAULT_SERVER_URL = 'http://test-install.blindsidenetworks.com/bigbluebutton/'; |
|
71
|
|
|
const BIGBLUEBUTTONBN_DEFAULT_SHARED_SECRET = '8cd8ef52e8e101574e400365b55e11a6'; |
|
72
|
|
|
|
|
73
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_CREATE = 'Create'; |
|
74
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_JOIN = 'Join'; |
|
75
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_LOGOUT = 'Logout'; |
|
76
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_IMPORT = 'Import'; |
|
77
|
|
|
const BIGBLUEBUTTONBN_LOG_EVENT_DELETE = 'Delete'; |
|
78
|
|
|
|
|
79
|
|
|
function bigbluebuttonbn_supports($feature) { |
|
80
|
|
|
|
|
81
|
|
|
if (!$feature) { |
|
82
|
|
|
return null; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$features = array( |
|
86
|
|
|
(string) FEATURE_IDNUMBER => true, |
|
87
|
|
|
(string) FEATURE_GROUPS => true, |
|
88
|
|
|
(string) FEATURE_GROUPINGS => true, |
|
89
|
|
|
(string) FEATURE_GROUPMEMBERSONLY => true, |
|
90
|
|
|
(string) FEATURE_MOD_INTRO => true, |
|
91
|
|
|
(string) FEATURE_BACKUP_MOODLE2 => true, |
|
92
|
|
|
(string) FEATURE_COMPLETION_TRACKS_VIEWS => true, |
|
93
|
|
|
(string) FEATURE_GRADE_HAS_GRADE => false, |
|
94
|
|
|
(string) FEATURE_GRADE_OUTCOMES => false, |
|
95
|
|
|
(string) FEATURE_SHOW_DESCRIPTION => true, |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
if (isset($features[(string) $feature])) { |
|
99
|
|
|
return $features[$feature]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return null; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Given an object containing all the necessary data, |
|
107
|
|
|
* (defined by the form in mod_form.php) this function |
|
108
|
|
|
* will create a new instance and return the id number |
|
109
|
|
|
* of the new instance. |
|
110
|
|
|
* |
|
111
|
|
|
* @param object $data An object from the form in mod_form.php |
|
112
|
|
|
* @param object $mform An object from the form in mod_form.php |
|
113
|
|
|
* |
|
114
|
|
|
* @return int The id of the newly inserted bigbluebuttonbn record |
|
115
|
|
|
*/ |
|
116
|
|
|
function bigbluebuttonbn_add_instance($data, $mform) { |
|
|
|
|
|
|
117
|
|
|
global $DB; |
|
118
|
|
|
|
|
119
|
|
|
$draftitemid = isset($data->presentation) ? $data->presentation : null; |
|
120
|
|
|
$context = context_module::instance($data->coursemodule); |
|
121
|
|
|
|
|
122
|
|
|
bigbluebuttonbn_process_pre_save($data); |
|
123
|
|
|
|
|
124
|
|
|
unset($data->presentation); |
|
125
|
|
|
$bigbluebuttonbnid = $DB->insert_record('bigbluebuttonbn', $data); |
|
126
|
|
|
$data->id = $bigbluebuttonbnid; |
|
127
|
|
|
|
|
128
|
|
|
bigbluebuttonbn_update_media_file($bigbluebuttonbnid, $context, $draftitemid); |
|
129
|
|
|
|
|
130
|
|
|
bigbluebuttonbn_process_post_save($data); |
|
131
|
|
|
|
|
132
|
|
|
return $bigbluebuttonbnid; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Given an object containing all the necessary data, |
|
137
|
|
|
* (defined by the form in mod_form.php) this function |
|
138
|
|
|
* will update an existing instance with new data. |
|
139
|
|
|
* |
|
140
|
|
|
* @return bool Success/Fail |
|
141
|
|
|
*/ |
|
142
|
|
|
function bigbluebuttonbn_update_instance($data, $mform) { |
|
|
|
|
|
|
143
|
|
|
global $DB; |
|
144
|
|
|
|
|
145
|
|
|
$data->id = $data->instance; |
|
146
|
|
|
$draftitemid = isset($data->presentation) ? $data->presentation : null; |
|
147
|
|
|
$context = context_module::instance($data->coursemodule); |
|
148
|
|
|
|
|
149
|
|
|
bigbluebuttonbn_process_pre_save($data); |
|
150
|
|
|
|
|
151
|
|
|
unset($data->presentation); |
|
152
|
|
|
$DB->update_record('bigbluebuttonbn', $data); |
|
153
|
|
|
|
|
154
|
|
|
bigbluebuttonbn_update_media_file($data->id, $context, $draftitemid); |
|
155
|
|
|
|
|
156
|
|
|
bigbluebuttonbn_process_post_save($data); |
|
157
|
|
|
|
|
158
|
|
|
return true; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* Given an ID of an instance of this module, |
|
163
|
|
|
* this function will permanently delete the instance |
|
164
|
|
|
* and any data that depends on it. |
|
165
|
|
|
* |
|
166
|
|
|
* @param int $id Id of the module instance |
|
167
|
|
|
* |
|
168
|
|
|
* @return bool Success/Failure |
|
169
|
|
|
*/ |
|
170
|
|
|
function bigbluebuttonbn_delete_instance($id) { |
|
171
|
|
|
global $DB; |
|
172
|
|
|
|
|
173
|
|
|
if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $id))) { |
|
174
|
|
|
return false; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
// End the session associated with this instance (if it's running). |
|
178
|
|
|
$meetingid = $bigbluebuttonbn->meetingid.'-'.$bigbluebuttonbn->course.'-'.$bigbluebuttonbn->id; |
|
179
|
|
|
$modpw = $bigbluebuttonbn->moderatorpass; |
|
180
|
|
|
|
|
181
|
|
|
if (bigbluebuttonbn_is_meeting_running($meetingid)) { |
|
182
|
|
|
bigbluebuttonbn_end_meeting($meetingid, $modpw); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
// Perform delete. |
|
186
|
|
|
if (!$DB->delete_records('bigbluebuttonbn', array('id' => $bigbluebuttonbn->id))) { |
|
187
|
|
|
return false; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
if (!$DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id))) { |
|
191
|
|
|
return false; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
// Log action performed. |
|
195
|
|
|
return bigbluebuttonbn_delete_instance_log($bigbluebuttonbn); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
function bigbluebuttonbn_delete_instance_log($bigbluebuttonbn) { |
|
199
|
|
|
global $DB, $USER; |
|
200
|
|
|
|
|
201
|
|
|
$log = new stdClass(); |
|
202
|
|
|
$log->meetingid = $bigbluebuttonbn->meetingid; |
|
203
|
|
|
$log->courseid = $bigbluebuttonbn->course; |
|
204
|
|
|
$log->bigbluebuttonbnid = $bigbluebuttonbn->id; |
|
205
|
|
|
$log->userid = $USER->id; |
|
206
|
|
|
$log->timecreated = time(); |
|
207
|
|
|
$log->log = BIGBLUEBUTTONBN_LOG_EVENT_DELETE; |
|
208
|
|
|
|
|
209
|
|
|
$logs = $DB->get_records('bigbluebuttonbn_logs', |
|
210
|
|
|
array('bigbluebuttonbnid' => $bigbluebuttonbn->id, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_CREATE, 'meta' => "{\"record\":true}") |
|
211
|
|
|
); |
|
212
|
|
|
$log->meta = "{\"has_recordings\":false}"; |
|
213
|
|
|
if (!empty($logs)) { |
|
214
|
|
|
$log->meta = "{\"has_recordings\":true}"; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
if (!$DB->insert_record('bigbluebuttonbn_logs', $log)) { |
|
218
|
|
|
return false; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
return true; |
|
222
|
|
|
} |
|
223
|
|
|
/** |
|
224
|
|
|
* Return a small object with summary information about what a |
|
225
|
|
|
* user has done with a given particular instance of this module |
|
226
|
|
|
* Used for user activity reports. |
|
227
|
|
|
* $return->time = the time they did it |
|
228
|
|
|
* $return->info = a short text description. |
|
229
|
|
|
* |
|
230
|
|
|
* @return bool |
|
231
|
|
|
*/ |
|
232
|
|
|
function bigbluebuttonbn_user_outline($course, $user, $mod, $bigbluebuttonbn) { |
|
|
|
|
|
|
233
|
|
|
global $DB; |
|
234
|
|
|
|
|
235
|
|
|
$completed = $DB->count_records('bigbluebuttonbn_logs', array('courseid' => $course->id, |
|
236
|
|
|
'bigbluebuttonbnid' => $bigbluebuttonbn->id, |
|
237
|
|
|
'userid' => $user->id, |
|
238
|
|
|
'log' => 'Join', ), '*'); |
|
239
|
|
|
|
|
240
|
|
|
if ($completed > 0) { |
|
241
|
|
|
return fullname($user).' '.get_string('view_message_has_joined', 'bigbluebuttonbn').' '. |
|
242
|
|
|
get_string('view_message_session_for', 'bigbluebuttonbn').' '.(string) $completed.' '. |
|
243
|
|
|
get_string('view_message_times', 'bigbluebuttonbn'); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
return ''; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Print a detailed representation of what a user has done with |
|
251
|
|
|
* a given particular instance of this module, for user activity reports. |
|
252
|
|
|
* |
|
253
|
|
|
* @return bool |
|
254
|
|
|
*/ |
|
255
|
|
|
function bigbluebuttonbn_user_complete($course, $user, $mod, $bigbluebuttonbn) { |
|
|
|
|
|
|
256
|
|
|
global $DB; |
|
257
|
|
|
|
|
258
|
|
|
$completed = $DB->count_recorda('bigbluebuttonbn_logs', array('courseid' => $course->id, |
|
259
|
|
|
'bigbluebuttonbnid' => $bigbluebuttonbn->id, |
|
260
|
|
|
'userid' => $user->id, |
|
261
|
|
|
'log' => 'Join', ), '*', IGNORE_MULTIPLE); |
|
262
|
|
|
|
|
263
|
|
|
return $completed > 0; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Returns all other caps used in module. |
|
268
|
|
|
* |
|
269
|
|
|
* @return string[] |
|
270
|
|
|
*/ |
|
271
|
|
|
function bigbluebuttonbn_get_extra_capabilities() { |
|
272
|
|
|
return array('moodle/site:accessallgroups'); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* List of view style log actions. |
|
277
|
|
|
* |
|
278
|
|
|
* @return string[] |
|
279
|
|
|
*/ |
|
280
|
|
|
function bigbluebuttonbn_get_view_actions() { |
|
281
|
|
|
return array('view', 'view all'); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* List of update style log actions. |
|
286
|
|
|
* |
|
287
|
|
|
* @return string[] |
|
288
|
|
|
*/ |
|
289
|
|
|
function bigbluebuttonbn_get_post_actions() { |
|
290
|
|
|
return array('update', 'add', 'create', 'join', 'end', 'left', 'publish', 'unpublish', 'delete'); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @global object |
|
295
|
|
|
* @global object |
|
296
|
|
|
* |
|
297
|
|
|
* @param array $courses |
|
298
|
|
|
* @param array $htmlarray Passed by reference |
|
299
|
|
|
*/ |
|
300
|
|
|
function bigbluebuttonbn_print_overview($courses, &$htmlarray) { |
|
301
|
|
|
|
|
302
|
|
|
if (empty($courses) || !is_array($courses) || count($courses) == 0) { |
|
303
|
|
|
return array(); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
$bns = get_all_instances_in_courses('bigbluebuttonbn', $courses); |
|
307
|
|
|
|
|
308
|
|
|
foreach ($bns as $bn) { |
|
309
|
|
|
$now = time(); |
|
310
|
|
|
if ($bn->openingtime and (!$bn->closingtime or $bn->closingtime > $now)) { |
|
311
|
|
|
// A bigbluebuttonbn is scheduled. |
|
312
|
|
|
if (empty($htmlarray[$bn->course]['bigbluebuttonbn'])) { |
|
313
|
|
|
$htmlarray[$bn->course]['bigbluebuttonbn'] = ''; |
|
314
|
|
|
} |
|
315
|
|
|
$htmlarray[$bn->course]['bigbluebuttonbn'] = bigbluebuttonbn_print_overview_element($bn, $now); |
|
316
|
|
|
} |
|
317
|
|
|
} |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
function bigbluebuttonbn_print_overview_element($bigbluebuttonbn, $now) { |
|
321
|
|
|
global $CFG; |
|
322
|
|
|
|
|
323
|
|
|
$start = 'started_at'; |
|
324
|
|
|
if ($bigbluebuttonbn->openingtime > $now) { |
|
325
|
|
|
$start = 'starts_at'; |
|
326
|
|
|
} |
|
327
|
|
|
$classes = ''; |
|
328
|
|
|
if ($bigbluebuttonbn->visible) { |
|
329
|
|
|
$classes = 'class="dimmed" '; |
|
330
|
|
|
} |
|
331
|
|
|
$str = '<div class="bigbluebuttonbn overview">'."\n"; |
|
332
|
|
|
$str .= ' <div class="name">'.get_string('modulename', 'bigbluebuttonbn').': '."\n"; |
|
333
|
|
|
$str .= ' <a '.$classes.'href="'.$CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bigbluebuttonbn->coursemodule. |
|
334
|
|
|
'">'.$bigbluebuttonbn->name.'</a>'."\n"; |
|
335
|
|
|
$str .= ' </div>'."\n"; |
|
336
|
|
|
$str .= ' <div class="info">'.get_string($start, 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->openingtime). |
|
337
|
|
|
'</div>'."\n"; |
|
338
|
|
|
$str .= ' <div class="info">'.get_string('ends_at', 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->closingtime) |
|
339
|
|
|
.'</div>'."\n"; |
|
340
|
|
|
$str .= '</div>'."\n"; |
|
341
|
|
|
|
|
342
|
|
|
return $str; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* Given a course_module object, this function returns any |
|
347
|
|
|
* "extra" information that may be needed when printing |
|
348
|
|
|
* this activity in a course listing. |
|
349
|
|
|
* See get_array_of_activities() in course/lib.php. |
|
350
|
|
|
* |
|
351
|
|
|
* @global object |
|
352
|
|
|
* |
|
353
|
|
|
* @param object $coursemodule |
|
354
|
|
|
* |
|
355
|
|
|
* @return null|cached_cm_info |
|
356
|
|
|
*/ |
|
357
|
|
|
function bigbluebuttonbn_get_coursemodule_info($coursemodule) { |
|
358
|
|
|
global $DB; |
|
359
|
|
|
|
|
360
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $coursemodule->instance), |
|
361
|
|
|
'id, name, intro, introformat'); |
|
362
|
|
|
if (!$bigbluebuttonbn) { |
|
363
|
|
|
return null; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
$info = new cached_cm_info(); |
|
367
|
|
|
$info->name = $bigbluebuttonbn->name; |
|
368
|
|
|
|
|
369
|
|
|
if ($coursemodule->showdescription) { |
|
370
|
|
|
// Convert intro to html. Do not filter cached version, filters run at display time. |
|
371
|
|
|
$info->content = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $coursemodule->id, false); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
return $info; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Runs any processes that must run before |
|
379
|
|
|
* a bigbluebuttonbn insert/update. |
|
380
|
|
|
* |
|
381
|
|
|
* @global object |
|
382
|
|
|
* |
|
383
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
|
384
|
|
|
**/ |
|
385
|
|
|
function bigbluebuttonbn_process_pre_save(&$bigbluebuttonbn) { |
|
386
|
|
|
$bigbluebuttonbn->timemodified = time(); |
|
387
|
|
|
|
|
388
|
|
|
if (!isset($bigbluebuttonbn->timecreated) || !$bigbluebuttonbn->timecreated) { |
|
389
|
|
|
$bigbluebuttonbn->timecreated = time(); |
|
390
|
|
|
// Assign password only if it is a new activity. |
|
391
|
|
|
$bigbluebuttonbn->moderatorpass = bigbluebuttonbn_random_password(12); |
|
392
|
|
|
$bigbluebuttonbn->viewerpass = bigbluebuttonbn_random_password(12); |
|
393
|
|
|
$bigbluebuttonbn->timemodified = 0; |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
if (!isset($bigbluebuttonbn->wait)) { |
|
397
|
|
|
$bigbluebuttonbn->wait = 0; |
|
398
|
|
|
} |
|
399
|
|
|
if (!isset($bigbluebuttonbn->record)) { |
|
400
|
|
|
$bigbluebuttonbn->record = 0; |
|
401
|
|
|
} |
|
402
|
|
|
if (!isset($bigbluebuttonbn->recordings_deleted_activities)) { |
|
403
|
|
|
$bigbluebuttonbn->recordings_deleted_activities = 0; |
|
404
|
|
|
} |
|
405
|
|
|
if (!isset($bigbluebuttonbn->recordings_html)) { |
|
406
|
|
|
$bigbluebuttonbn->recordings_html = 0; |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
$bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* Runs any processes that must be run |
|
414
|
|
|
* after a bigbluebuttonbn insert/update. |
|
415
|
|
|
* |
|
416
|
|
|
* @global object |
|
417
|
|
|
* |
|
418
|
|
|
* @param object $bigbluebuttonbn BigBlueButtonBN form data |
|
419
|
|
|
**/ |
|
420
|
|
|
function bigbluebuttonbn_process_post_save(&$bigbluebuttonbn) { |
|
421
|
|
|
global $DB, $CFG; |
|
422
|
|
|
|
|
423
|
|
|
$action = get_string('mod_form_field_notification_msg_modified', 'bigbluebuttonbn'); |
|
424
|
|
|
|
|
425
|
|
|
/* Now that an id was assigned, generate and set the meetingid property based on |
|
426
|
|
|
* [Moodle Instance + Activity ID + BBB Secret] (but only for new activities) */ |
|
427
|
|
|
if (isset($bigbluebuttonbn->add) && !empty($bigbluebuttonbn->add)) { |
|
428
|
|
|
$meetingid = sha1($CFG->wwwroot.$bigbluebuttonbn->id.bigbluebuttonbn_get_cfg_shared_secret()); |
|
429
|
|
|
$DB->set_field('bigbluebuttonbn', 'meetingid', $meetingid, array('id' => $bigbluebuttonbn->id)); |
|
430
|
|
|
|
|
431
|
|
|
$action = get_string('mod_form_field_notification_msg_created', 'bigbluebuttonbn'); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
bigbluebuttonbn_process_post_save_event($bigbluebuttonbn); |
|
435
|
|
|
|
|
436
|
|
|
if (isset($bigbluebuttonbn->notification) && $bigbluebuttonbn->notification) { |
|
437
|
|
|
bigbluebuttonbn_notification_process($bigbluebuttonbn, $action); |
|
438
|
|
|
} |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
function bigbluebuttonbn_process_post_save_event($bigbluebuttonbn) { |
|
442
|
|
|
global $DB; |
|
443
|
|
|
|
|
444
|
|
|
// Delete evento to the calendar when/if openingtime is NOT set. |
|
445
|
|
|
if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) { |
|
446
|
|
|
$DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id)); |
|
447
|
|
|
|
|
448
|
|
|
return; |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
// Add evento to the calendar as openingtime is set. |
|
452
|
|
|
$event = new stdClass(); |
|
453
|
|
|
$event->name = $bigbluebuttonbn->name; |
|
454
|
|
|
$event->courseid = $bigbluebuttonbn->course; |
|
455
|
|
|
$event->groupid = 0; |
|
456
|
|
|
$event->userid = 0; |
|
457
|
|
|
$event->modulename = 'bigbluebuttonbn'; |
|
458
|
|
|
$event->instance = $bigbluebuttonbn->id; |
|
459
|
|
|
$event->timestart = $bigbluebuttonbn->openingtime; |
|
460
|
|
|
$event->durationtime = 0; |
|
461
|
|
|
|
|
462
|
|
|
if ($bigbluebuttonbn->closingtime) { |
|
463
|
|
|
$event->durationtime = $bigbluebuttonbn->closingtime - $bigbluebuttonbn->openingtime; |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
$event->id = $DB->get_field('event', 'id', array('modulename' => 'bigbluebuttonbn', |
|
467
|
|
|
'instance' => $bigbluebuttonbn->id)); |
|
468
|
|
|
if ($event->id) { |
|
469
|
|
|
$calendarevent = calendar_event::load($event->id); |
|
470
|
|
|
$calendarevent->update($event); |
|
471
|
|
|
|
|
472
|
|
|
return; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
calendar_event::create($event); |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
/** |
|
479
|
|
|
* Update the bigbluebuttonbn activity to include any file |
|
480
|
|
|
* that was uploaded, or if there is none, set the |
|
481
|
|
|
* presentation field to blank. |
|
482
|
|
|
* |
|
483
|
|
|
* @param int $bigbluebuttonbnid the bigbluebuttonbn id |
|
484
|
|
|
* @param stdClass $context the context |
|
485
|
|
|
* @param int $draftitemid the draft item |
|
486
|
|
|
*/ |
|
487
|
|
|
function bigbluebuttonbn_update_media_file($bigbluebuttonbnid, $context, $draftitemid) { |
|
488
|
|
|
global $DB; |
|
489
|
|
|
|
|
490
|
|
|
// Set the filestorage object. |
|
491
|
|
|
$fs = get_file_storage(); |
|
492
|
|
|
// Save the file if it exists that is currently in the draft area. |
|
493
|
|
|
file_save_draft_area_files($draftitemid, $context->id, 'mod_bigbluebuttonbn', 'presentation', 0); |
|
494
|
|
|
// Get the file if it exists. |
|
495
|
|
|
$files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0, |
|
496
|
|
|
'itemid, filepath, filename', false); |
|
497
|
|
|
// Check that there is a file to process. |
|
498
|
|
|
$filesrc = ''; |
|
499
|
|
|
if (count($files) == 1) { |
|
500
|
|
|
// Get the first (and only) file. |
|
501
|
|
|
$file = reset($files); |
|
502
|
|
|
$filesrc = '/'.$file->get_filename(); |
|
503
|
|
|
} |
|
504
|
|
|
// Set the presentation column in the bigbluebuttonbn table. |
|
505
|
|
|
$DB->set_field('bigbluebuttonbn', 'presentation', $filesrc, array('id' => $bigbluebuttonbnid)); |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
/** |
|
509
|
|
|
* Serves the bigbluebuttonbn attachments. Implements needed access control ;-). |
|
510
|
|
|
* |
|
511
|
|
|
* @category files |
|
512
|
|
|
* |
|
513
|
|
|
* @param stdClass $course course object |
|
514
|
|
|
* @param stdClass $cm course module object |
|
515
|
|
|
* @param stdClass $context context object |
|
516
|
|
|
* @param string $filearea file area |
|
517
|
|
|
* @param array $args extra arguments |
|
518
|
|
|
* @param bool $forcedownload whether or not force download |
|
519
|
|
|
* @param array $options additional options affecting the file serving |
|
520
|
|
|
* |
|
521
|
|
|
* @return false|null false if file not found, does not return if found - justsend the file |
|
522
|
|
|
*/ |
|
523
|
|
|
function bigbluebuttonbn_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) { |
|
524
|
|
|
if ($context->contextlevel != CONTEXT_MODULE) { |
|
525
|
|
|
return false; |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
if ($filearea !== 'presentation') { |
|
529
|
|
|
return false; |
|
530
|
|
|
} |
|
531
|
|
|
|
|
532
|
|
|
if (!array_key_exists($filearea, bigbluebuttonbn_get_file_areas())) { |
|
533
|
|
|
return false; |
|
534
|
|
|
} |
|
535
|
|
|
|
|
536
|
|
|
$filename = bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args); |
|
537
|
|
|
if (!$filename) { |
|
538
|
|
|
return false; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
$fullpath = "/$context->id/mod_bigbluebuttonbn/$filearea/0/".$filename; |
|
542
|
|
|
$fs = get_file_storage(); |
|
543
|
|
|
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { |
|
544
|
|
|
return false; |
|
545
|
|
|
} |
|
546
|
|
|
|
|
547
|
|
|
// Finally send the file. |
|
548
|
|
|
send_stored_file($file, 0, 0, $forcedownload, $options); // download MUST be forced - security! |
|
549
|
|
|
} |
|
550
|
|
|
|
|
551
|
|
|
function bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args) { |
|
552
|
|
|
global $DB; |
|
553
|
|
|
|
|
554
|
|
|
if (count($args) > 1) { |
|
555
|
|
|
if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance))) { |
|
556
|
|
|
return; |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
$cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache'); |
|
560
|
|
|
$noncekey = sha1($bigbluebuttonbn->id); |
|
561
|
|
|
$presentationnonce = $cache->get($noncekey); |
|
562
|
|
|
$noncevalue = $presentationnonce['value']; |
|
563
|
|
|
$noncecounter = $presentationnonce['counter']; |
|
564
|
|
|
|
|
565
|
|
|
if ($args['0'] != $noncevalue) { |
|
566
|
|
|
return; |
|
567
|
|
|
} |
|
568
|
|
|
|
|
569
|
|
|
// The nonce value is actually used twice because BigBlueButton reads the file two times. |
|
570
|
|
|
$noncecounter += 1; |
|
571
|
|
|
$cache->set($noncekey, array('value' => $noncevalue, 'counter' => $noncecounter)); |
|
572
|
|
|
if ($noncecounter == 2) { |
|
573
|
|
|
$cache->delete($noncekey); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
return $args['1']; |
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
require_course_login($course, true, $cm); |
|
580
|
|
|
|
|
581
|
|
|
if (!has_capability('mod/bigbluebuttonbn:join', $context)) { |
|
582
|
|
|
return; |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
return implode('/', $args); |
|
586
|
|
|
} |
|
587
|
|
|
|
|
588
|
|
|
/** |
|
589
|
|
|
* Returns an array of file areas. |
|
590
|
|
|
* |
|
591
|
|
|
* @category files |
|
592
|
|
|
* |
|
593
|
|
|
* @return array a list of available file areas |
|
594
|
|
|
*/ |
|
595
|
|
|
function bigbluebuttonbn_get_file_areas() { |
|
596
|
|
|
$areas = array(); |
|
597
|
|
|
$areas['presentation'] = get_string('mod_form_block_presentation', 'bigbluebuttonbn'); |
|
598
|
|
|
|
|
599
|
|
|
return $areas; |
|
600
|
|
|
} |
|
601
|
|
|
|
|
602
|
|
|
/** |
|
603
|
|
|
* Returns an array with all the roles contained in the database. |
|
604
|
|
|
* |
|
605
|
|
|
* @return array a list of available roles |
|
606
|
|
|
*/ |
|
607
|
|
|
function bigbluebuttonbn_get_db_moodle_roles($rolename = 'all') { |
|
608
|
|
|
global $DB; |
|
609
|
|
|
|
|
610
|
|
|
$roletarget = array(); |
|
611
|
|
|
if ($rolename != 'all') { |
|
612
|
|
|
$roletarget['shortname'] = $rolename; |
|
613
|
|
|
} |
|
614
|
|
|
return $DB->get_records('role', $roletarget); |
|
615
|
|
|
} |
|
616
|
|
|
|
|
617
|
|
|
function bigbluebuttonbn_notification_process($bigbluebuttonbn, $action) { |
|
618
|
|
|
global $USER; |
|
619
|
|
|
|
|
620
|
|
|
// Prepare message. |
|
621
|
|
|
$msg = new stdClass(); |
|
622
|
|
|
|
|
623
|
|
|
// Build the message_body. |
|
624
|
|
|
$msg->action = $action; |
|
625
|
|
|
$msg->activity_type = ''; |
|
626
|
|
|
$msg->activity_title = $bigbluebuttonbn->name; |
|
627
|
|
|
|
|
628
|
|
|
// Add the meeting details to the message_body. |
|
629
|
|
|
$msg->action = ucfirst($action); |
|
630
|
|
|
$msg->activity_description = ''; |
|
631
|
|
|
if (!empty($bigbluebuttonbn->intro)) { |
|
632
|
|
|
$msg->activity_description = trim($bigbluebuttonbn->intro); |
|
633
|
|
|
} |
|
634
|
|
|
$msg->activity_openingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->openingtime); |
|
635
|
|
|
$msg->activity_closingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->closingtime); |
|
636
|
|
|
$msg->activity_owner = fullname($USER); |
|
637
|
|
|
|
|
638
|
|
|
// Send notification to all users enrolled. |
|
639
|
|
|
bigbluebuttonbn_notification_send($USER, $bigbluebuttonbn, bigbluebuttonbn_notification_msg_html($msg)); |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
function bigbluebuttonbn_notification_msg_html($msg) { |
|
643
|
|
|
$messagetext = '<p>'.$msg->activity_type.' "'.$msg->activity_title.'" '. |
|
644
|
|
|
get_string('email_body_notification_meeting_has_been', 'bigbluebuttonbn').' '.$msg->action.'.</p>'."\n"; |
|
645
|
|
|
$messagetext .= '<p><b>'.$msg->activity_title.'</b> '. |
|
646
|
|
|
get_string('email_body_notification_meeting_details', 'bigbluebuttonbn').':'."\n"; |
|
647
|
|
|
$messagetext .= '<table border="0" style="margin: 5px 0 0 20px"><tbody>'."\n"; |
|
648
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
|
649
|
|
|
get_string('email_body_notification_meeting_title', 'bigbluebuttonbn').': </td><td>'."\n"; |
|
650
|
|
|
$messagetext .= $msg->activity_title.'</td></tr>'."\n"; |
|
651
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
|
652
|
|
|
get_string('email_body_notification_meeting_description', 'bigbluebuttonbn').': </td><td>'."\n"; |
|
653
|
|
|
$messagetext .= $msg->activity_description.'</td></tr>'."\n"; |
|
654
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
|
655
|
|
|
get_string('email_body_notification_meeting_start_date', 'bigbluebuttonbn').': </td><td>'."\n"; |
|
656
|
|
|
$messagetext .= $msg->activity_openingtime.'</td></tr>'."\n"; |
|
657
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'. |
|
658
|
|
|
get_string('email_body_notification_meeting_end_date', 'bigbluebuttonbn').': </td><td>'."\n"; |
|
659
|
|
|
$messagetext .= $msg->activity_closingtime.'</td></tr>'."\n"; |
|
660
|
|
|
$messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.$msg->action.' '. |
|
661
|
|
|
get_string('email_body_notification_meeting_by', 'bigbluebuttonbn').': </td><td>'."\n"; |
|
662
|
|
|
$messagetext .= $msg->activity_owner.'</td></tr></tbody></table></p>'."\n"; |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
function bigbluebuttonbn_notification_send($sender, $bigbluebuttonbn, $message = '') { |
|
666
|
|
|
global $DB; |
|
667
|
|
|
|
|
668
|
|
|
$context = context_course::instance($bigbluebuttonbn->course); |
|
669
|
|
|
$course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST); |
|
670
|
|
|
|
|
671
|
|
|
// Complete message. |
|
672
|
|
|
$msg = new stdClass(); |
|
673
|
|
|
$msg->user_name = fullname($sender); |
|
674
|
|
|
$msg->user_email = $sender->email; |
|
675
|
|
|
$msg->course_name = "$course->fullname"; |
|
676
|
|
|
$message .= '<p><hr/><br/>'.get_string('email_footer_sent_by', 'bigbluebuttonbn').' '. |
|
677
|
|
|
$msg->user_name.'('.$msg->user_email.') '; |
|
678
|
|
|
$message .= get_string('email_footer_sent_from', 'bigbluebuttonbn').' '.$msg->course_name.'.</p>'; |
|
679
|
|
|
|
|
680
|
|
|
$users = get_enrolled_users($context); |
|
681
|
|
|
foreach ($users as $user) { |
|
682
|
|
|
if ($user->id != $sender->id) { |
|
683
|
|
|
$messageid = message_post_message($sender, $user, $message, FORMAT_HTML); |
|
684
|
|
|
$msgsend = ' was sent.'; |
|
685
|
|
|
if (empty($messageid)) { |
|
686
|
|
|
$msgsend = ' was NOT sent.'; |
|
687
|
|
|
} |
|
688
|
|
|
debugging('Msg to '.$msg->user_name.$msgsend, DEBUG_DEVELOPER); |
|
689
|
|
|
} |
|
690
|
|
|
} |
|
691
|
|
|
} |
|
692
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.