Completed
Pull Request — master (#33)
by Jesus
02:27
created

lib.php ➔ bigbluebuttonbn_print_overview()   B

Complexity

Conditions 9
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 10
nc 5
nop 2
dl 0
loc 19
rs 7.756
c 0
b 0
f 0
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
    if (!$feature) {
81
        return null;
82
    }
83
84
    $features = array(
85
        (string) FEATURE_IDNUMBER => true,
86
        (string) FEATURE_GROUPS => true,
87
        (string) FEATURE_GROUPINGS => true,
88
        (string) FEATURE_GROUPMEMBERSONLY => true,
89
        (string) FEATURE_MOD_INTRO => true,
90
        (string) FEATURE_BACKUP_MOODLE2 => true,
91
        (string) FEATURE_COMPLETION_TRACKS_VIEWS => true,
92
        (string) FEATURE_GRADE_HAS_GRADE => false,
93
        (string) FEATURE_GRADE_OUTCOMES => false,
94
        (string) FEATURE_SHOW_DESCRIPTION => true,
95
    );
96
97
    if (isset($features[(string) $feature])) {
98
        return $features[$feature];
99
    }
100
101
    return null;
102
}
103
104
/**
105
 * Given an object containing all the necessary data,
106
 * (defined by the form in mod_form.php) this function
107
 * will create a new instance and return the id number
108
 * of the new instance.
109
 *
110
 * @param object $data  An object from the form in mod_form.php
111
 * @param object $mform An object from the form in mod_form.php
112
 *
113
 * @return int The id of the newly inserted bigbluebuttonbn record
114
 */
115
function bigbluebuttonbn_add_instance($data, $mform) {
0 ignored issues
show
Unused Code introduced by
The parameter $mform is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
    global $DB;
117
118
    $draftitemid = isset($data->presentation) ? $data->presentation : null;
119
    $context = context_module::instance($data->coursemodule);
120
121
    bigbluebuttonbn_process_pre_save($data);
122
123
    unset($data->presentation);
124
    $bigbluebuttonbnid = $DB->insert_record('bigbluebuttonbn', $data);
125
    $data->id = $bigbluebuttonbnid;
126
127
    bigbluebuttonbn_update_media_file($bigbluebuttonbnid, $context, $draftitemid);
128
129
    bigbluebuttonbn_process_post_save($data);
130
131
    return $bigbluebuttonbnid;
132
}
133
134
/**
135
 * Given an object containing all the necessary data,
136
 * (defined by the form in mod_form.php) this function
137
 * will update an existing instance with new data.
138
 *
139
 * @return bool Success/Fail
140
 */
141
function bigbluebuttonbn_update_instance($data, $mform) {
0 ignored issues
show
Unused Code introduced by
The parameter $mform is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
142
    global $DB;
143
144
    $data->id = $data->instance;
145
    $draftitemid = isset($data->presentation) ? $data->presentation : null;
146
    $context = context_module::instance($data->coursemodule);
147
148
    bigbluebuttonbn_process_pre_save($data);
149
150
    unset($data->presentation);
151
    $DB->update_record('bigbluebuttonbn', $data);
152
153
    bigbluebuttonbn_update_media_file($data->id, $context, $draftitemid);
154
155
    bigbluebuttonbn_process_post_save($data);
156
157
    return true;
158
}
159
160
/**
161
 * Given an ID of an instance of this module,
162
 * this function will permanently delete the instance
163
 * and any data that depends on it.
164
 *
165
 * @param int $id Id of the module instance
166
 *
167
 * @return bool Success/Failure
168
 */
169
function bigbluebuttonbn_delete_instance($id) {
170
    global $DB, $USER;
171
172
    if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $id))) {
173
        return false;
174
    }
175
176
    // End the session associated with this instance (if it's running).
177
    $meetingid = $bigbluebuttonbn->meetingid.'-'.$bigbluebuttonbn->course.'-'.$bigbluebuttonbn->id;
178
    $modpw = $bigbluebuttonbn->moderatorpass;
179
180
    if (bigbluebuttonbn_is_meeting_running($meetingid)) {
181
        bigbluebuttonbn_end_meeting($meetingid, $modpw);
182
    }
183
184
    // Perform delete.
185
    if (!$DB->delete_records('bigbluebuttonbn', array('id' => $bigbluebuttonbn->id))) {
186
        return false;
187
    }
188
189
    if (!$DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id))) {
190
        return false;
191
    }
192
193
    $log = new stdClass();
194
195
    $log->meetingid = $bigbluebuttonbn->meetingid;
196
    $log->courseid = $bigbluebuttonbn->course;
197
    $log->bigbluebuttonbnid = $bigbluebuttonbn->id;
198
    $log->userid = $USER->id;
199
    $log->timecreated = time();
200
    $log->log = BIGBLUEBUTTONBN_LOG_EVENT_DELETE;
201
202
    $logs = $DB->get_records('bigbluebuttonbn_logs',
203
        array('bigbluebuttonbnid' => $bigbluebuttonbn->id, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_CREATE));
204
    $hasrecordings = 'false';
205
    if (!empty($logs)) {
206
        foreach ($logs as $l) {
207
            $meta = json_decode($l->meta);
208
            if ($meta->record) {
209
                $hasrecordings = 'true';
210
            }
211
        }
212
    }
213
    $log->meta = "{\"has_recordings\":{$hasrecordings}}";
214
215
    if (!$DB->insert_record('bigbluebuttonbn_logs', $log)) {
216
        return false;
217
    }
218
219
    return true;
220
}
221
222
/**
223
 * Return a small object with summary information about what a
224
 * user has done with a given particular instance of this module
225
 * Used for user activity reports.
226
 * $return->time = the time they did it
227
 * $return->info = a short text description.
228
 *
229
 * @return bool
230
 */
231
function bigbluebuttonbn_user_outline($course, $user, $mod, $bigbluebuttonbn) {
0 ignored issues
show
Unused Code introduced by
The parameter $mod is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
232
    global $DB;
233
234
    $completed = $DB->count_records('bigbluebuttonbn_logs', array('courseid' => $course->id,
235
                                                              'bigbluebuttonbnid' => $bigbluebuttonbn->id,
236
                                                              'userid' => $user->id,
237
                                                              'log' => 'Join', ), '*');
238
239
    if ($completed > 0) {
240
        return fullname($user).' '.get_string('view_message_has_joined', 'bigbluebuttonbn').' '.
241
            get_string('view_message_session_for', 'bigbluebuttonbn').' '.(string) $completed.' '.
242
            get_string('view_message_times', 'bigbluebuttonbn');
243
    }
244
245
    return '';
246
}
247
248
/**
249
 * Print a detailed representation of what a user has done with
250
 * a given particular instance of this module, for user activity reports.
251
 *
252
 * @return bool
253
 */
254
function bigbluebuttonbn_user_complete($course, $user, $mod, $bigbluebuttonbn) {
0 ignored issues
show
Unused Code introduced by
The parameter $mod is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
255
    global $DB;
256
    $completed = $DB->count_recorda('bigbluebuttonbn_logs', array('courseid' => $course->id,
257
                                                              'bigbluebuttonbnid' => $bigbluebuttonbn->id,
258
                                                              'userid' => $user->id,
259
                                                              'log' => 'Join', ), '*', IGNORE_MULTIPLE);
260
261
    return $completed > 0;
262
}
263
264
/**
265
 * Returns all other caps used in module.
266
 *
267
 * @return string[]
268
 */
269
function bigbluebuttonbn_get_extra_capabilities() {
270
    return array('moodle/site:accessallgroups');
271
}
272
273
/**
274
 * List of view style log actions.
275
 *
276
 * @return string[]
277
 */
278
function bigbluebuttonbn_get_view_actions() {
279
    return array('view', 'view all');
280
}
281
282
/**
283
 * List of update style log actions.
284
 *
285
 * @return string[]
286
 */
287
function bigbluebuttonbn_get_post_actions() {
288
    return array('update', 'add', 'create', 'join', 'end', 'left', 'publish', 'unpublish', 'delete');
289
}
290
291
/**
292
 * @global object
293
 * @global object
294
 *
295
 * @param array $courses
296
 * @param array $htmlarray Passed by reference
297
 */
298
function bigbluebuttonbn_print_overview($courses, &$htmlarray) {
299
300
    if (empty($courses) || !is_array($courses) || count($courses) == 0) {
301
        return array();
302
    }
303
304
    $bns = get_all_instances_in_courses('bigbluebuttonbn', $courses);
305
306
    foreach ($bns as $bn) {
307
        $now = time();
308
        if ($bn->openingtime and (!$bn->closingtime or $bn->closingtime > $now)) {
309
            // A bigbluebuttonbn is scheduled.
310
            if (empty($htmlarray[$bn->course]['bigbluebuttonbn'])) {
311
                $htmlarray[$bn->course]['bigbluebuttonbn'] = '';
312
            }
313
            $htmlarray[$bn->course]['bigbluebuttonbn'] = bigbluebuttonbn_print_overview_element($bn, $now);
314
        }
315
    }
316
}
317
318
function bigbluebuttonbn_print_overview_element($bigbluebuttonbn, $now) {
319
    global $CFG;
320
321
    $start = 'started_at';
322
    if ($bigbluebuttonbn->openingtime > $now) {
323
        $start = 'starts_at';
324
    }
325
    $classes = '';
326
    if ($bigbluebuttonbn->visible) {
327
        $classes = 'class="dimmed" ';
328
    }
329
    $str = '<div class="bigbluebuttonbn overview">'."\n";
330
    $str .= '  <div class="name">'.get_string('modulename', 'bigbluebuttonbn').':&nbsp;'."\n";
331
    $str .= '    <a '.$classes.'href="'.$CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bigbluebuttonbn->coursemodule.
332
      '">'.$bigbluebuttonbn->name.'</a>'."\n";
333
    $str .= '  </div>'."\n";
334
    $str .= '  <div class="info">'.get_string($start, 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->openingtime).
335
        '</div>'."\n";
336
    $str .= '  <div class="info">'.get_string('ends_at', 'bigbluebuttonbn').': '.userdate($bigbluebuttonbn->closingtime)
337
      .'</div>'."\n";
338
    $str .= '</div>'."\n";
339
340
    return $str;
341
}
342
343
/**
344
 * Given a course_module object, this function returns any
345
 * "extra" information that may be needed when printing
346
 * this activity in a course listing.
347
 * See get_array_of_activities() in course/lib.php.
348
 *
349
 * @global object
350
 *
351
 * @param object $coursemodule
352
 *
353
 * @return null|cached_cm_info
354
 */
355
function bigbluebuttonbn_get_coursemodule_info($coursemodule) {
356
    global $DB;
357
358
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $coursemodule->instance),
359
        'id, name, intro, introformat');
360
    if (!$bigbluebuttonbn) {
361
        return null;
362
    }
363
364
    $info = new cached_cm_info();
365
    $info->name = $bigbluebuttonbn->name;
366
367
    if ($coursemodule->showdescription) {
368
        // Convert intro to html. Do not filter cached version, filters run at display time.
369
        $info->content = format_module_intro('bigbluebuttonbn', $bigbluebuttonbn, $coursemodule->id, false);
370
    }
371
372
    return $info;
373
}
374
375
/**
376
 * Runs any processes that must run before
377
 * a bigbluebuttonbn insert/update.
378
 *
379
 * @global object
380
 *
381
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
382
 **/
383
function bigbluebuttonbn_process_pre_save(&$bigbluebuttonbn) {
384
    $bigbluebuttonbn->timemodified = time();
385
386
    if (!isset($bigbluebuttonbn->timecreated) || !$bigbluebuttonbn->timecreated) {
387
        $bigbluebuttonbn->timecreated = time();
388
        // Assign password only if it is a new activity.
389
        $bigbluebuttonbn->moderatorpass = bigbluebuttonbn_random_password(12);
390
        $bigbluebuttonbn->viewerpass = bigbluebuttonbn_random_password(12);
391
        $bigbluebuttonbn->timemodified = null;
392
    }
393
394
    if (!isset($bigbluebuttonbn->wait)) {
395
        $bigbluebuttonbn->wait = 0;
396
    }
397
    if (!isset($bigbluebuttonbn->record)) {
398
        $bigbluebuttonbn->record = 0;
399
    }
400
    if (!isset($bigbluebuttonbn->tagging)) {
401
        $bigbluebuttonbn->tagging = 0;
402
    }
403
    if (!isset($bigbluebuttonbn->recordings_deleted_activities)) {
404
        $bigbluebuttonbn->recordings_deleted_activities = 0;
405
    }
406
    if (!isset($bigbluebuttonbn->recordings_html)) {
407
        $bigbluebuttonbn->recordings_html = 0;
408
    }
409
410
    $bigbluebuttonbn->participants = htmlspecialchars_decode($bigbluebuttonbn->participants);
411
}
412
413
/**
414
 * Runs any processes that must be run
415
 * after a bigbluebuttonbn insert/update.
416
 *
417
 * @global object
418
 *
419
 * @param object $bigbluebuttonbn BigBlueButtonBN form data
420
 **/
421
function bigbluebuttonbn_process_post_save(&$bigbluebuttonbn) {
422
    global $DB, $CFG;
423
424
    $action = get_string('mod_form_field_notification_msg_modified', 'bigbluebuttonbn');
425
426
    /* Now that an id was assigned, generate and set the meetingid property based on
427
     * [Moodle Instance + Activity ID + BBB Secret] (but only for new activities) */
428
    if (isset($bigbluebuttonbn->add) && !empty($bigbluebuttonbn->add)) {
429
        $meetingid = sha1($CFG->wwwroot.$bigbluebuttonbn->id.bigbluebuttonbn_get_cfg_shared_secret());
430
        $DB->set_field('bigbluebuttonbn', 'meetingid', $meetingid, array('id' => $bigbluebuttonbn->id));
431
432
        $action = get_string('mod_form_field_notification_msg_created', 'bigbluebuttonbn');
433
    }
434
435
    bigbluebuttonbn_process_post_save_event($bigbluebuttonbn);
436
437
    if (isset($bigbluebuttonbn->notification) && $bigbluebuttonbn->notification) {
438
        bigbluebuttonbn_notification_process($bigbluebuttonbn, $action);
439
    }
440
}
441
442
function bigbluebuttonbn_process_post_save_event($bigbluebuttonbn) {
443
    global $DB;
444
445
    // Delete evento to the calendar when/if openingtime is NOT set.
446
    if (!isset($bigbluebuttonbn->openingtime) || !$bigbluebuttonbn->openingtime) {
447
        $DB->delete_records('event', array('modulename' => 'bigbluebuttonbn', 'instance' => $bigbluebuttonbn->id));
448
449
        return;
450
    }
451
452
    // Add evento to the calendar as openingtime is set.
453
    $event = new stdClass();
454
    $event->name = $bigbluebuttonbn->name;
455
    $event->courseid = $bigbluebuttonbn->course;
456
    $event->groupid = 0;
457
    $event->userid = 0;
458
    $event->modulename = 'bigbluebuttonbn';
459
    $event->instance = $bigbluebuttonbn->id;
460
    $event->timestart = $bigbluebuttonbn->openingtime;
461
    $event->durationtime = 0;
462
463
    if ($bigbluebuttonbn->closingtime) {
464
        $event->durationtime = $bigbluebuttonbn->closingtime - $bigbluebuttonbn->openingtime;
465
    }
466
467
    $event->id = $DB->get_field('event', 'id', array('modulename' => 'bigbluebuttonbn',
468
        'instance' => $bigbluebuttonbn->id));
469
    if ($event->id) {
470
        $calendarevent = calendar_event::load($event->id);
471
        $calendarevent->update($event);
472
473
        return;
474
    }
475
476
    calendar_event::create($event);
477
}
478
479
/**
480
 * Update the bigbluebuttonbn activity to include any file
481
 * that was uploaded, or if there is none, set the
482
 * presentation field to blank.
483
 *
484
 * @param int      $bigbluebuttonbnid the bigbluebuttonbn id
485
 * @param stdClass $context            the context
486
 * @param int      $draftitemid        the draft item
487
 */
488
function bigbluebuttonbn_update_media_file($bigbluebuttonbnid, $context, $draftitemid) {
489
    global $DB;
490
491
    // Set the filestorage object.
492
    $fs = get_file_storage();
493
    // Save the file if it exists that is currently in the draft area.
494
    file_save_draft_area_files($draftitemid, $context->id, 'mod_bigbluebuttonbn', 'presentation', 0);
495
    // Get the file if it exists.
496
    $files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0,
497
        'itemid, filepath, filename', false);
498
    // Check that there is a file to process.
499
    if (count($files) == 1) {
500
        // Get the first (and only) file.
501
        $file = reset($files);
502
        // Set the presentation column in the bigbluebuttonbn table.
503
        $DB->set_field('bigbluebuttonbn', 'presentation', '/'.$file->get_filename(), array('id' => $bigbluebuttonbnid));
504
    } else {
505
        // Set the presentation column in the bigbluebuttonbn table.
506
        $DB->set_field('bigbluebuttonbn', 'presentation', '', array('id' => $bigbluebuttonbnid));
507
    }
508
}
509
510
/**
511
 * Serves the bigbluebuttonbn attachments. Implements needed access control ;-).
512
 *
513
 * @category files
514
 *
515
 * @param stdClass $course        course object
516
 * @param stdClass $cm            course module object
517
 * @param stdClass $context       context object
518
 * @param string   $filearea      file area
519
 * @param array    $args          extra arguments
520
 * @param bool     $forcedownload whether or not force download
521
 * @param array    $options       additional options affecting the file serving
522
 *
523
 * @return false|null false if file not found, does not return if found - justsend the file
524
 */
525
function bigbluebuttonbn_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
526
    if ($context->contextlevel != CONTEXT_MODULE) {
527
        return false;
528
    }
529
530
    if ($filearea !== 'presentation') {
531
        return false;
532
    }
533
534
    if (!array_key_exists($filearea, bigbluebuttonbn_get_file_areas())) {
535
        return false;
536
    }
537
538
    $filename = bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args);
539
    if (!$filename) {
540
        return false;
541
    }
542
543
    $fullpath = "/$context->id/mod_bigbluebuttonbn/$filearea/0/".$filename;
544
    $fs = get_file_storage();
545
    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
546
        return false;
547
    }
548
549
    // Finally send the file.
550
    send_stored_file($file, 0, 0, $forcedownload, $options); // download MUST be forced - security!
551
}
552
553
function bigbluebuttonbn_pluginfile_filename($course, $cm, $context, $args) {
554
    global $DB;
555
556
    if (count($args) > 1) {
557
        if (!$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance))) {
558
            return;
559
        }
560
561
        $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache');
562
        $noncekey = sha1($bigbluebuttonbn->id);
563
        $presentationnonce = $cache->get($noncekey);
564
        $noncevalue = $presentationnonce['value'];
565
        $noncecounter = $presentationnonce['counter'];
566
567
        if ($args['0'] != $noncevalue) {
568
            return;
569
        }
570
571
        // The nonce value is actually used twice because BigBlueButton reads the file two times.
572
        $noncecounter += 1;
573
        if ($noncecounter < 2) {
574
            $cache->set($noncekey, array('value' => $noncevalue, 'counter' => $noncecounter));
575
        } else {
576
            $cache->delete($noncekey);
577
        }
578
579
        return $args['1'];
580
    }
581
582
    require_course_login($course, true, $cm);
583
584
    if (!has_capability('mod/bigbluebuttonbn:join', $context)) {
585
        return;
586
    }
587
588
    return implode('/', $args);
589
}
590
591
/**
592
 * Returns an array of file areas.
593
 *
594
 * @category files
595
 *
596
 * @return array a list of available file areas
597
 */
598
function bigbluebuttonbn_get_file_areas() {
599
    $areas = array();
600
    $areas['presentation'] = get_string('mod_form_block_presentation', 'bigbluebuttonbn');
601
602
    return $areas;
603
}
604
605
/**
606
 * Returns an array with all the roles contained in the database.
607
 *
608
 * @return array a list of available roles
609
 */
610
function bigbluebuttonbn_get_db_moodle_roles($rolename = 'all') {
611
    global $DB;
612
613
    if ($rolename != 'all') {
614
        $roles = $DB->get_record('role', array('shortname' => $rolename));
615
    } else {
616
        $roles = $DB->get_records('role', array());
617
    }
618
619
    return $roles;
620
}
621
622
function bigbluebuttonbn_notification_process($bigbluebuttonbn, $action) {
623
    global $USER;
624
625
    // Prepare message.
626
    $msg = new stdClass();
627
628
    // Build the message_body.
629
    $msg->action = $action;
630
    $msg->activity_type = '';
631
    $msg->activity_title = $bigbluebuttonbn->name;
632
633
    // Add the meeting details to the message_body.
634
    $msg->action = ucfirst($action);
635
    $msg->activity_description = '';
636
    if (!empty($bigbluebuttonbn->intro)) {
637
        $msg->activity_description = trim($bigbluebuttonbn->intro);
638
    }
639
    $msg->activity_openingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->openingtime);
640
    $msg->activity_closingtime = bigbluebuttonbn_format_activity_time($bigbluebuttonbn->closingtime);
641
    $msg->activity_owner = fullname($USER);
642
643
    // Send notification to all users enrolled.
644
    bigbluebuttonbn_notification_send($USER, $bigbluebuttonbn, bigbluebuttonbn_notification_msg_html($msg));
645
}
646
647
function bigbluebuttonbn_notification_msg_html($msg) {
648
    $messagetext = '<p>'.$msg->activity_type.' &quot;'.$msg->activity_title.'&quot; '.
649
        get_string('email_body_notification_meeting_has_been', 'bigbluebuttonbn').' '.$msg->action.'.</p>'."\n";
650
    $messagetext .= '<p><b>'.$msg->activity_title.'</b> '.
651
        get_string('email_body_notification_meeting_details', 'bigbluebuttonbn').':'."\n";
652
    $messagetext .= '<table border="0" style="margin: 5px 0 0 20px"><tbody>'."\n";
653
    $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
654
        get_string('email_body_notification_meeting_title', 'bigbluebuttonbn').': </td><td>'."\n";
655
    $messagetext .= $msg->activity_title.'</td></tr>'."\n";
656
    $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
657
        get_string('email_body_notification_meeting_description', 'bigbluebuttonbn').': </td><td>'."\n";
658
    $messagetext .= $msg->activity_description.'</td></tr>'."\n";
659
    $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
660
        get_string('email_body_notification_meeting_start_date', 'bigbluebuttonbn').': </td><td>'."\n";
661
    $messagetext .= $msg->activity_openingtime.'</td></tr>'."\n";
662
    $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.
663
        get_string('email_body_notification_meeting_end_date', 'bigbluebuttonbn').': </td><td>'."\n";
664
    $messagetext .= $msg->activity_closingtime.'</td></tr>'."\n";
665
    $messagetext .= '<tr><td style="font-weight:bold;color:#555;">'.$msg->action.' '.
666
        get_string('email_body_notification_meeting_by', 'bigbluebuttonbn').': </td><td>'."\n";
667
    $messagetext .= $msg->activity_owner.'</td></tr></tbody></table></p>'."\n";
668
}
669
670
function bigbluebuttonbn_notification_send($sender, $bigbluebuttonbn, $message = '') {
671
    global $DB;
672
673
    $context = context_course::instance($bigbluebuttonbn->course);
674
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
675
676
    // Complete message.
677
    $msg = new stdClass();
678
    $msg->user_name = fullname($sender);
679
    $msg->user_email = $sender->email;
680
    $msg->course_name = "$course->fullname";
681
    $message .= '<p><hr/><br/>'.get_string('email_footer_sent_by', 'bigbluebuttonbn').' '.
682
        $msg->user_name.'('.$msg->user_email.') ';
683
    $message .= get_string('email_footer_sent_from', 'bigbluebuttonbn').' '.$msg->course_name.'.</p>';
684
685
    $users = get_enrolled_users($context);
686
    foreach ($users as $user) {
687
        if ($user->id != $sender->id) {
688
            $messageid = message_post_message($sender, $user, $message, FORMAT_HTML);
689
            if (!empty($messageid)) {
690
                debugging('Msg to '.$msg->user_name.' was sent.', DEBUG_DEVELOPER);
691
            } else {
692
                debugging('Msg to '.$msg->user_name.' was NOT sent.', DEBUG_DEVELOPER);
693
            }
694
        }
695
    }
696
}
697