Completed
Push — master ( bfa4f1...253dc9 )
by Jesus
02:28
created

locallib.php ➔ bigbluebuttonbn_getRecordingArrayRow()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 6
nop 1
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php
2
/**
3
 * Internal library of functions for module BigBlueButtonBN.
4
 *
5
 * @package   mod
6
 * @subpackage bigbluebuttonbn
7
 * @author    Fred Dixon  (ffdixon [at] blindsidenetworks [dt] com)
8
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
9
 * @copyright 2010-2015 Blindside Networks Inc.
10
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
11
 */
12
13
defined('MOODLE_INTERNAL') || die;
14
15
global $BIGBLUEBUTTONBN_CFG, $CFG;
16
17
require_once(dirname(__FILE__).'/lib.php');
18
19
const BIGBLUEBUTTONBN_FORCED = true;
20
21
const BIGBLUEBUTTONBN_ROLE_VIEWER = 'viewer';
22
const BIGBLUEBUTTONBN_ROLE_MODERATOR = 'moderator';
23
const BIGBLUEBUTTONBN_METHOD_GET = 'GET';
24
const BIGBLUEBUTTONBN_METHOD_POST = 'POST';
25
26
const BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED = 'activity_viewed';
27
const BIGBLUEBUTTON_EVENT_MEETING_CREATED = 'meeting_created';
28
const BIGBLUEBUTTON_EVENT_MEETING_ENDED = 'meeting_ended';
29
const BIGBLUEBUTTON_EVENT_MEETING_JOINED = 'meeting_joined';
30
const BIGBLUEBUTTON_EVENT_MEETING_LEFT = "meeting_left";
31
const BIGBLUEBUTTON_EVENT_RECORDING_DELETED = 'recording_deleted';
32
const BIGBLUEBUTTON_EVENT_RECORDING_IMPORTED = 'recording_imported';
33
const BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED = 'recording_published';
34
const BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED = 'recording_unpublished';
35
36
function bigbluebuttonbn_logs(array $bbbsession, $event, array $overrides = [], $meta = NULL ) {
37
    global $DB;
38
39
    $log = new stdClass();
40
41
    $log->courseid = isset($overrides['courseid'])? $overrides['courseid']: $bbbsession['course']->id;
42
    $log->bigbluebuttonbnid = isset($overrides['bigbluebuttonbnid'])? $overrides['bigbluebuttonbnid']: $bbbsession['bigbluebuttonbn']->id;
43
    $log->userid = isset($overrides['userid'])? $overrides['userid']: $bbbsession['userID'];
44
    $log->meetingid = isset($overrides['meetingid'])? $overrides['meetingid']: $bbbsession['meetingid'];
45
    $log->timecreated = isset($overrides['timecreated'])? $overrides['timecreated']: time();
46
    $log->log = $event;
47
    if ( isset($meta) ) {
48
        $log->meta = $meta;
49
    } else if( $event == BIGBLUEBUTTONBN_LOG_EVENT_CREATE) {
50
        $log->meta = '{"record":'.($bbbsession['record']? 'true': 'false').'}';
51
    }
52
53
    $returnid = $DB->insert_record('bigbluebuttonbn_logs', $log);
0 ignored issues
show
Unused Code introduced by
$returnid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
}
55
56
 ////////////////////////////
57
//  BigBlueButton API Calls  //
58
 ////////////////////////////
59
function bigbluebuttonbn_getJoinURL( $meetingID, $userName, $PW, $SALT, $URL, $logoutURL ) {
60
    $url_join = $URL."api/join?";
61
    $params = 'meetingID='.urlencode($meetingID).'&fullName='.urlencode($userName).'&password='.urlencode($PW).'&logoutURL='.urlencode($logoutURL);
62
    $url = $url_join.$params.'&checksum='.sha1("join".$params.$SALT);
63
    return $url;
64
}
65
66
function bigbluebuttonbn_getCreateMeetingURL($name, $meetingID, $attendeePW, $moderatorPW, $welcome, $logoutURL, $SALT, $URL, $record = 'false', $duration=0, $voiceBridge=0, $maxParticipants=0, $metadata=array() ) {
67
    $url_create = $URL."api/create?";
68
69
    $params = 'name='.urlencode($name).'&meetingID='.urlencode($meetingID).'&attendeePW='.urlencode($attendeePW).'&moderatorPW='.urlencode($moderatorPW).'&logoutURL='.urlencode($logoutURL).'&record='.$record;
70
71
    $voiceBridge = intval($voiceBridge);
72
    if ( $voiceBridge > 0 && $voiceBridge < 79999) {
73
        $params .= '&voiceBridge='.$voiceBridge;
74
    }
75
76
    $duration = intval($duration);
77
    if( $duration > 0 ) {
78
        $params .= '&duration='.$duration;
79
    }
80
81
    $maxParticipants = intval($maxParticipants);
82
    if( $maxParticipants > 0 ) {
83
        $params .= '&maxParticipants='.$maxParticipants;
84
    }
85
86
    if( trim( $welcome ) ) {
87
        $params .= '&welcome='.urlencode($welcome);
88
    }
89
90
    foreach ($metadata as $key => $value) {
91
        $params .= '&'.$key.'='.urlencode($value);
92
    }
93
94
    $url = $url_create.$params.'&checksum='.sha1("create".$params.$SALT);
95
    return $url;
96
}
97
98
function bigbluebuttonbn_getIsMeetingRunningURL( $meetingID, $URL, $SALT ) {
99
    $base_url = $URL."api/isMeetingRunning?";
100
    $params = 'meetingID='.urlencode($meetingID);
101
    $url = $base_url.$params.'&checksum='.sha1("isMeetingRunning".$params.$SALT);
102
    return $url;
103
}
104
105 View Code Duplication
function bigbluebuttonbn_getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
    $base_url = $URL."api/getMeetingInfo?";
107
    $params = 'meetingID='.urlencode($meetingID).'&password='.urlencode($modPW);
108
    $url = $base_url.$params.'&checksum='.sha1("getMeetingInfo".$params.$SALT);
109
    return $url;
110
}
111
112
function bigbluebuttonbn_getMeetingsURL( $URL, $SALT ) {
113
    $base_url = $URL."api/getMeetings?";
114
    $url = $base_url.'&checksum='.sha1("getMeetings".$SALT);
115
    return $url;
116
}
117
118 View Code Duplication
function bigbluebuttonbn_getEndMeetingURL( $meetingID, $modPW, $URL, $SALT ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
    $base_url = $URL."api/end?";
120
    $params = 'meetingID='.urlencode($meetingID).'&password='.urlencode($modPW);
121
    $url = $base_url.$params.'&checksum='.sha1("end".$params.$SALT);
122
    return $url;
123
}
124
125
function bigbluebuttonbn_getRecordingsURL( $URL, $SALT, $meetingID=null ) {
126
    $base_url_record = $URL."api/getRecordings?";
127
    if( $meetingID == null ) {
128
        $params = "";
129
    } else {
130
        $params = "meetingID=".urlencode($meetingID);
131
    }
132
    $url = $base_url_record.$params."&checksum=".sha1("getRecordings".$params.$SALT);
133
    return $url;
134
}
135
136
function bigbluebuttonbn_getDeleteRecordingsURL( $recordID, $URL, $SALT ) {
137
    $url_delete = $URL."api/deleteRecordings?";
138
    $params = 'recordID='.urlencode($recordID);
139
    $url = $url_delete.$params.'&checksum='.sha1("deleteRecordings".$params.$SALT);
140
    return $url;
141
}
142
143
function bigbluebuttonbn_getPublishRecordingsURL( $recordID, $set, $URL, $SALT ) {
144
    $url_publish = $URL."api/publishRecordings?";
145
    $params = 'recordID='.$recordID."&publish=".$set;
146
    $url = $url_publish.$params.'&checksum='.sha1("publishRecordings".$params.$SALT);
147
    return $url;
148
}
149
150
function bigbluebuttonbn_getCreateMeetingArray( $username, $meetingID, $welcomeString, $mPW, $aPW, $SALT, $URL, $logoutURL, $record='false', $duration=0, $voiceBridge=0, $maxParticipants=0, $metadata=array(), $presentation_name=null, $presentation_url=null ) {
151
    $create_meeting_url = bigbluebuttonbn_getCreateMeetingURL($username, $meetingID, $aPW, $mPW, $welcomeString, $logoutURL, $SALT, $URL, $record, $duration, $voiceBridge, $maxParticipants, $metadata);
152
    if( !is_null($presentation_name) && !is_null($presentation_url) ) {
153
        $xml = bigbluebuttonbn_wrap_xml_load_file( $create_meeting_url,
154
                BIGBLUEBUTTONBN_METHOD_POST,
155
                "<?xml version='1.0' encoding='UTF-8'?><modules><module name='presentation'><document url='".$presentation_url."' /></module></modules>"
156
                );
157
    } else {
158
        $xml = bigbluebuttonbn_wrap_xml_load_file( $create_meeting_url );
159
    }
160
161
    if ( $xml ) {
162
        if ($xml->meetingID) {
163
            return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey, 'meetingID' => $xml->meetingID, 'attendeePW' => $xml->attendeePW, 'moderatorPW' => $xml->moderatorPW, 'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded );
164
        } else {
165
            return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey );
166
        }
167
    } else {
168
        return null;
169
    }
170
}
171
172
function bigbluebuttonbn_getMeetingsArray($meetingID, $URL, $SALT ) {
0 ignored issues
show
Unused Code introduced by
The parameter $meetingID 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...
173
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingsURL($URL, $SALT) );
174
175
    if ( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey ) {    //The meetings were returned
176
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
177
178
    } else if($xml && $xml->returncode == 'SUCCESS') {                    //If there were meetings already created
179
        foreach ($xml->meetings->meeting as $meeting) {
180
            $meetings[] = array( 'meetingID' => $meeting->meetingID, 'moderatorPW' => $meeting->moderatorPW, 'attendeePW' => $meeting->attendeePW, 'hasBeenForciblyEnded' => $meeting->hasBeenForciblyEnded, 'running' => $meeting->running );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$meetings was never initialized. Although not strictly required by PHP, it is generally a good practice to add $meetings = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
181
        }
182
        return $meetings;
0 ignored issues
show
Bug introduced by
The variable $meetings does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
183
184 View Code Duplication
    } else if( $xml ) { //If the xml packet returned failure it displays the message to the user
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
185
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
186
187
    } else { //If the server is unreachable, then prompts the user of the necessary action
188
        return null;
189
    }
190
}
191
192
function bigbluebuttonbn_getMeetingInfo( $meetingID, $modPW, $URL, $SALT ) {
193
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
194
    return $xml;
195
}
196
197
function bigbluebuttonbn_getMeetingInfoArray( $meetingID, $modPW, $URL, $SALT ) {
198
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
199
200
    if( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey == null){//The meeting info was returned
201
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey );
202
203
    } else if($xml && $xml->returncode == 'SUCCESS'){ //If there were meetings already created
204
        return array('returncode' => $xml->returncode, 'meetingID' => $xml->meetingID, 'moderatorPW' => $xml->moderatorPW, 'attendeePW' => $xml->attendeePW, 'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded, 'running' => $xml->running, 'recording' => $xml->recording, 'startTime' => $xml->startTime, 'endTime' => $xml->endTime, 'participantCount' => $xml->participantCount, 'moderatorCount' => $xml->moderatorCount, 'attendees' => $xml->attendees, 'metadata' => $xml->metadata );
205
206 View Code Duplication
    } else if( ($xml && $xml->returncode == 'FAILED') || $xml) { //If the xml packet returned failure it displays the message to the user
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
207
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
208
209
    } else { //If the server is unreachable, then prompts the user of the necessary action
210
        return null;
211
    }
212
}
213
214
function bigbluebuttonbn_getRecordingsArray( $meetingIDs, $URL, $SALT ) {
215
    $recordings = array();
216
217
    if ( is_array($meetingIDs) ) {
218
        // getRecordings is executes using a method POST (supported only on BBB 1.0 and later)
219
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getRecordingsURL( $URL, $SALT ), BIGBLUEBUTTONBN_METHOD_POST, $meetingIDs );
220
    } else {
221
        // getRecordings is executes using a method GET supported by any version of BBB
222
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getRecordingsURL( $URL, $SALT, $meetingIDs ) );
223
    }
224
225 View Code Duplication
    if ( $xml && $xml->returncode == 'SUCCESS' && isset($xml->recordings) ) { //If there were meetings already created
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
226
        foreach ( $xml->recordings->recording as $recording ) {
227
            $recordings[] = bigbluebuttonbn_getRecordingArrayRow($recording);
228
        }
229
230
        usort($recordings, 'bigbluebuttonbn_recordingBuildSorter');
231
    }
232
233
    return $recordings;
234
}
235
236
function bigbluebuttonbn_index_recordings($recordings, $index_key='recordID') {
237
    $indexed_recordings = array();
238
239
    foreach ($recordings as $recording) {
240
        $indexed_recordings[$recording[$index_key]] = $recording;
241
    }
242
243
    return $indexed_recordings;
244
}
245
246
function bigbluebuttonbn_getRecordingArray( $recordingID, $meetingID, $URL, $SALT ) {
247
    $recordingArray = array();
248
249
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getRecordingsURL( $URL, $SALT, $meetingID ) );
250
251 View Code Duplication
    if ( $xml && $xml->returncode == 'SUCCESS' && isset($xml->recordings) ) { //If there were meetings already created
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
252
        foreach ($xml->recordings->recording as $recording) {
253
            if( $recording->recordID == $recordingID ) {
254
                $recordingArray = bigbluebuttonbn_getRecordingArrayRow($recording);
255
                break;
256
            }
257
        }
258
    }
259
260
    return $recordingArray;
261
}
262
263
function bigbluebuttonbn_getRecordingArrayRow( $recording ) {
264
    $recordingArrayRow = array();
0 ignored issues
show
Unused Code introduced by
$recordingArrayRow is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
265
266
    $playbackArray = array();
267
    foreach ( $recording->playback->format as $format ) {
268
        $playbackArray[(string) $format->type] = array( 'type' => (string) $format->type, 'url' => (string) $format->url, 'length' => (string) $format->length );
269
    }
270
271
    //Add the metadata to the recordings array
272
    $metadataArray = array();
273
    $metadata = get_object_vars($recording->metadata);
274
    foreach ( $metadata as $key => $value ) {
275
        if ( is_object($value) ) {
276
            $value = '';
277
        }
278
        $metadataArray['meta_'.$key] = $value;
279
    }
280
281
    $recordingArrayRow = array( 'recordID' => (string) $recording->recordID, 'meetingID' => (string) $recording->meetingID, 'meetingName' => (string) $recording->name, 'published' => (string) $recording->published, 'startTime' => (string) $recording->startTime, 'endTime' => (string) $recording->endTime, 'playbacks' => $playbackArray ) + $metadataArray;
282
283
    return $recordingArrayRow;
284
}
285
286
function bigbluebuttonbn_recordingBuildSorter($a, $b){
287
    if ( $a['startTime'] < $b['startTime'] ) {
288
        return -1;
289
    } else if ( $a['startTime'] == $b['startTime']) {
290
        return 0;
291
    } else {
292
        return 1;
293
    }
294
}
295
296 View Code Duplication
function bigbluebuttonbn_doDeleteRecordings( $recordIDs, $URL, $SALT ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
297
    $ids = 	explode(",", $recordIDs);
298
    foreach( $ids as $id){
299
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getDeleteRecordingsURL($id, $URL, $SALT) );
300
        if( $xml && $xml->returncode != 'SUCCESS' ) {
301
            return false;
302
        }
303
    }
304
    return true;
305
}
306
307 View Code Duplication
function bigbluebuttonbn_doPublishRecordings( $recordIDs, $set, $URL, $SALT ) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
308
    $ids = 	explode(",", $recordIDs);
309
    foreach( $ids as $id){
310
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getPublishRecordingsURL($id, $set, $URL, $SALT) );
311
        if( $xml && $xml->returncode != 'SUCCESS' ) {
312
            return false;
313
        }
314
    }
315
    return true;
316
}
317
318
function bigbluebuttonbn_doEndMeeting( $meetingID, $modPW, $URL, $SALT ) {
319
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getEndMeetingURL( $meetingID, $modPW, $URL, $SALT ) );
320
321
    if( $xml ) { //If the xml packet returned failure it displays the message to the user
322
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
323
    }
324
    else { //If the server is unreachable, then prompts the user of the necessary action
325
        return null;
326
    }
327
}
328
329
function bigbluebuttonbn_isMeetingRunning( $meetingID, $URL, $SALT ) {
330
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getIsMeetingRunningURL( $meetingID, $URL, $SALT ) );
331
    if ( $xml && $xml->returncode == 'SUCCESS' ) {
332
        return ( ( $xml->running == 'true' ) ? true : false);
333
    } else {
334
        return ( false );
335
    }
336
}
337
338
339
function bigbluebuttonbn_getServerVersion( $URL ){
340
    $xml = bigbluebuttonbn_wrap_xml_load_file( $URL."api" );
341
    if ( $xml && $xml->returncode == 'SUCCESS' ) {
342
        return $xml->version;
343
    } else {
344
        return NULL;
345
    }
346
}
347
348
function bigbluebuttonbn_getMeetingXML( $meetingID, $URL, $SALT ) {
349
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getIsMeetingRunningURL( $meetingID, $URL, $SALT ) );
350
    if ( $xml && $xml->returncode == 'SUCCESS') {
351
        return ( str_replace('</response>', '', str_replace("<?xml version=\"1.0\"?>\n<response>", '', $xml->asXML())));
352
    } else {
353
        return 'false';
354
    }
355
}
356
357
function bigbluebuttonbn_wrap_xml_load_file($url, $method=BIGBLUEBUTTONBN_METHOD_GET, $data=null) {
358
    if ( bigbluebuttonbn_debugdisplay() ) error_log("Request to: ".$url);
359
360
    if (extension_loaded('curl')) {
361
        $c = new curl();
362
        $c->setopt( Array( "SSL_VERIFYPEER" => true));
363
        if( $method == BIGBLUEBUTTONBN_METHOD_POST ) {
364
            if( !is_null($data) ) {
365
                if( !is_array($data) ) {
366
                    $options['CURLOPT_HTTPHEADER'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
367
                            'Content-Type: text/xml',
368
                            'Content-Length: '.strlen($data),
369
                            'Content-Language: en-US'
370
                        );
371
                    $response = $c->post($url, $data, $options);
372
373
                } else {
374
                    $response = $c->post($url, $data);
375
                }
376
377
            } else {
378
                $response = $c->post($url);
379
            }
380
381
        } else {
382
            $response = $c->get($url);
383
        }
384
385
        if ($response) {
386
            $previous = libxml_use_internal_errors(true);
387
            try {
388
                $xml = new SimpleXMLElement($response, LIBXML_NOCDATA);
389
                return $xml;
390
            } catch (Exception $e){
391
                libxml_use_internal_errors($previous);
392
                $error = 'Caught exception: '.$e->getMessage();
393
                error_log($error);
394
                return NULL;
395
            }
396
        } else {
397
            error_log("No response on wrap_simplexml_load_file");
398
            return NULL;
399
        }
400
401
    } else {
402
        $previous = libxml_use_internal_errors(true);
403
        try {
404
            $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
405
            return $xml;
406
        } catch  (Exception $e){
407
            libxml_use_internal_errors($previous);
408
            return NULL;
409
        }
410
    }
411
}
412
413
function bigbluebuttonbn_get_role_name($role_shortname){
414
    $role = bigbluebuttonbn_get_db_moodle_roles($role_shortname);
415
    if( $role != null && $role->name != "") {
416
        $role_name = $role->name;
417
    } else {
418
        switch ($role_shortname) {
419
            case 'manager':         $role_name = get_string('manager', 'role'); break;
420
            case 'coursecreator':   $role_name = get_string('coursecreators'); break;
421
            case 'editingteacher':  $role_name = get_string('defaultcourseteacher'); break;
422
            case 'teacher':         $role_name = get_string('noneditingteacher'); break;
423
            case 'student':         $role_name = get_string('defaultcoursestudent'); break;
424
            case 'guest':           $role_name = get_string('guest'); break;
425
            case 'user':            $role_name = get_string('authenticateduser'); break;
426
            case 'frontpage':       $role_name = get_string('frontpageuser', 'role'); break;
427
            // We should not get here, the role UI should require the name for custom roles!
428
            default:                $role_name = $role_shortname; break;
429
        }
430
    }
431
432
    return $role_name;
433
}
434
435
function bigbluebuttonbn_get_roles($rolename='all', $format='json'){
436
    $roles = bigbluebuttonbn_get_db_moodle_roles($rolename);
437
    $roles_array = array();
438
    foreach($roles as $role){
439
        if( $format=='json' ) {
440
            array_push($roles_array,
441
                    array( "id" => $role->shortname,
442
                        "name" => bigbluebuttonbn_get_role_name($role->shortname)
443
                    )
444
            );
445
        } else {
446
            $roles_array[$role->shortname] = bigbluebuttonbn_get_role_name($role->shortname);
447
        }
448
    }
449
    return $roles_array;
450
}
451
452
function bigbluebuttonbn_get_roles_json($rolename='all'){
453
    return json_encode(bigbluebuttonbn_get_roles($rolename));
454
}
455
456
function bigbluebuttonbn_get_users_json($users, $full=false) {
457
    if( $full ) {
458
        return json_encode($users);
459
    } else {
460
        $users_array = array();
461
        foreach($users as $user){
462
            array_push($users_array,
463
                    array( "id" => $user->id,
464
                            "name" => $user->firstname.' '.$user->lastname
465
                    )
466
            );
467
        }
468
        return json_encode($users_array);
469
    }
470
}
471
472
function bigbluebuttonbn_get_participant_list($bigbluebuttonbn=null, $context=null){
473
    global $CFG, $USER;
474
475
    $participant_list_array = array();
476
477
    if( $bigbluebuttonbn != null ) {
478
        $participant_list = json_decode($bigbluebuttonbn->participants);
479
        if (is_array($participant_list)) {
480
            foreach($participant_list as $participant){
481
                array_push($participant_list_array,
482
                        array(
483
                            "selectiontype" => $participant->selectiontype,
484
                            "selectionid" => $participant->selectionid,
485
                            "role" => $participant->role
486
                        )
487
                );
488
            }
489
        }
490
    } else {
491
        array_push($participant_list_array,
492
                array(
493
                    "selectiontype" => "all",
494
                    "selectionid" => "all",
495
                    "role" => BIGBLUEBUTTONBN_ROLE_VIEWER
496
                )
497
        );
498
499
        $moderator_defaults = bigbluebuttonbn_get_cfg_moderator_default();
500
        if ( !isset($moderator_defaults) ) {
501
            $moderator_defaults = array('owner');
502
        } else {
503
            $moderator_defaults = explode(',', $moderator_defaults);
504
        }
505
        foreach( $moderator_defaults as $moderator_default ) {
506
            if( $moderator_default == 'owner' ) {
507
                $users = bigbluebuttonbn_get_users($context);
508
                foreach( $users as $user ){
509
                    if( $user->id == $USER->id ){
510
                        array_push($participant_list_array,
511
                                array(
512
                                        "selectiontype" => "user",
513
                                        "selectionid" => $USER->id,
514
                                        "role" => BIGBLUEBUTTONBN_ROLE_MODERATOR
515
                                )
516
                        );
517
                        break;
518
                    }
519
                }
520
            } else {
521
                array_push($participant_list_array,
522
                        array(
523
                                "selectiontype" => "role",
524
                                "selectionid" => $moderator_default,
525
                                "role" => BIGBLUEBUTTONBN_ROLE_MODERATOR
526
                        )
527
                );
528
            }
529
        }
530
    }
531
532
    return $participant_list_array;
533
}
534
535
function bigbluebuttonbn_get_participant_list_json($bigbluebuttonbnid=null){
536
    return json_encode(bigbluebuttonbn_get_participant_list($bigbluebuttonbnid));
537
}
538
539
function bigbluebuttonbn_is_moderator($user, $roles, $participants) {
540
    $participant_list = json_decode($participants);
541
542
    if (is_array($participant_list)) {
543
        // Iterate looking for all configuration
544 View Code Duplication
        foreach($participant_list as $participant){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
545
            if( $participant->selectiontype == 'all' ) {
546
                if ( $participant->role == BIGBLUEBUTTONBN_ROLE_MODERATOR ) {
547
                    return true;
548
                }
549
            }
550
        }
551
552
        //Iterate looking for roles
553
        $db_moodle_roles = bigbluebuttonbn_get_db_moodle_roles();
554
        foreach($participant_list as $participant){
555
            if( $participant->selectiontype == 'role' ) {
556
                foreach( $roles as $role ) {
557
                    $db_moodle_role = bigbluebuttonbn_moodle_db_role_lookup($db_moodle_roles, $role->roleid);
558
                    if( $participant->selectionid == $db_moodle_role->shortname ) {
559
                        if ( $participant->role == BIGBLUEBUTTONBN_ROLE_MODERATOR ) {
560
                            return true;
561
                        }
562
                    }
563
                }
564
            }
565
        }
566
567
        //Iterate looking for users
568 View Code Duplication
        foreach($participant_list as $participant){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
569
            if( $participant->selectiontype == 'user' ) {
570
                if( $participant->selectionid == $user ) {
571
                    if ( $participant->role == BIGBLUEBUTTONBN_ROLE_MODERATOR ) {
572
                        return true;
573
                    }
574
                }
575
            }
576
        }
577
    }
578
579
    return false;
580
}
581
582
function bigbluebuttonbn_moodle_db_role_lookup($db_moodle_roles, $role_id) {
583
    foreach( $db_moodle_roles as $db_moodle_role ){
584
        if( $role_id ==  $db_moodle_role->id ) {
585
            return $db_moodle_role;
586
        }
587
    }
588
}
589
590
function bigbluebuttonbn_get_error_key($messageKey, $defaultKey = null) {
591
    $key = $defaultKey;
592
    if ( $messageKey == "checksumError" ) {
593
        $key = 'index_error_checksum';
594
    } else if ( $messageKey == 'maxConcurrent' ) {
595
        $key = 'view_error_max_concurrent';
596
    }
597
    return $key;
598
}
599
600
function bigbluebuttonbn_voicebridge_unique($voicebridge, $id=null) {
601
    global $DB;
602
603
    $is_unique = true;
604
    if ( $voicebridge != 0 ) {
605
        $table = "bigbluebuttonbn";
606
        $select = "voicebridge = ".$voicebridge;
607
        if ( $id ) {
608
            $select .= " AND id <> ".$id;
609
        }
610
        if ( $rooms = $DB->get_records_select($table, $select)  ) {
0 ignored issues
show
Unused Code introduced by
$rooms is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
611
            $is_unique = false;
612
        }
613
    }
614
615
    return $is_unique;
616
}
617
618
function bigbluebuttonbn_get_duration($openingtime, $closingtime) {
0 ignored issues
show
Unused Code introduced by
The parameter $openingtime 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...
619
    global $CFG;
620
621
    $duration = 0;
622
    $now = time();
623
    if ( $closingtime > 0 && $now < $closingtime ) {
624
        $duration = ceil(($closingtime - $now)/60);
625
        $compensation_time = intval(bigbluebuttonbn_get_cfg_scheduled_duration_compensation());
626
        $duration = intval($duration) + $compensation_time;
627
    }
628
629
    return $duration;
630
}
631
632
function bigbluebuttonbn_get_presentation_array($context, $presentation, $id=null) {
633
    $presentation_name = null;
634
    $presentation_url = null;
635
    $presentation_icon = null;
636
    $presentation_mimetype_description = null;
637
638
    if ( !empty($presentation) ) {
639
        $fs = get_file_storage();
640
        $files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0, 'itemid, filepath, filename', false);
641
        if (count($files) < 1) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
642
            //resource_print_filenotfound($resource, $cm, $course);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
643
            //die;
644
            //exit;
645
        } else {
646
            $file = reset($files);
647
            unset($files);
648
            $presentation_name = $file->get_filename();
649
            $presentation_icon = file_file_icon($file, 24);
650
            $presentation_mimetype_description = get_mimetype_description($file);
651
652
            if( !is_null($id) ) {
653
                //Create the nonce component for granting a temporary public access
654
                $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache');
655
                $presentation_nonce_key = sha1($id);
656
                $presentation_nonce_value = bigbluebuttonbn_generate_nonce();
657
                $cache->set($presentation_nonce_key, array( "value" => $presentation_nonce_value, "counter" => 0 ));
658
659
                //The item id was adapted for granting public access to the presentation once in order to allow BigBlueButton to gather the file
660
                $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $presentation_nonce_value, $file->get_filepath(), $file->get_filename());
661
            } else {
662
                $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename());
663
            }
664
            $presentation_url = $url->out(false);
665
        }
666
    }
667
668
    $presentation_array = array( "url" => $presentation_url, "name" => $presentation_name, "icon" => $presentation_icon, "mimetype_description" => $presentation_mimetype_description);
669
670
    return $presentation_array;
671
}
672
673
function bigbluebuttonbn_generate_nonce() {
674
675
    $mt = microtime();
676
    $rand = mt_rand();
677
678
    return md5($mt.$rand);
679
}
680
681
function bigbluebuttonbn_random_password( $length = 8 ) {
682
683
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
684
    $password = substr( str_shuffle( $chars ), 0, $length );
685
686
    return $password;
687
}
688
689
function bigbluebuttonbn_get_moodle_version_major() {
690
    global $CFG;
691
692
    $version_array = explode('.', $CFG->version);
693
    return $version_array[0];
694
}
695
696
function bigbluebuttonbn_event_log_standard($event_type, $bigbluebuttonbn, $context, $cm) {
0 ignored issues
show
Unused Code introduced by
The parameter $context 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...
697
    $context = context_module::instance($cm->id);
698
    $event_properties = array('context' => $context, 'objectid' => $bigbluebuttonbn->id);
699
700
    switch ($event_type) {
701
        case BIGBLUEBUTTON_EVENT_MEETING_JOINED:
702
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_joined::create($event_properties);
703
            break;
704
        case BIGBLUEBUTTON_EVENT_MEETING_CREATED:
705
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_created::create($event_properties);
706
            break;
707
        case BIGBLUEBUTTON_EVENT_MEETING_ENDED:
708
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_ended::create($event_properties);
709
            break;
710
        case BIGBLUEBUTTON_EVENT_MEETING_LEFT:
711
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_left::create($event_properties);
712
            break;
713
        case BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED:
714
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_recording_published::create($event_properties);
715
            break;
716
        case BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED:
717
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_recording_unpublished::create($event_properties);
718
            break;
719
        case BIGBLUEBUTTON_EVENT_RECORDING_DELETED:
720
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_recording_deleted::create($event_properties);
721
            break;
722
        case BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED:
723
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_activity_viewed::create($event_properties);
724
            break;
725
        case BIGBLUEBUTTON_EVENT_ACTIVITY_MANAGEMENT_VIEWED:
726
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_activity_management_viewed::create($event_properties);
727
            break;
728
    }
729
730
    $event->trigger();
0 ignored issues
show
Bug introduced by
The variable $event does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
731
}
732
733
function bigbluebuttonbn_event_log_legacy($event_type, $bigbluebuttonbn, $context, $cm) {
0 ignored issues
show
Unused Code introduced by
The parameter $context 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...
734
    global $DB;
735
736
    switch ($event_type) {
737
        case BIGBLUEBUTTON_EVENT_MEETING_JOINED:
738
            $event = 'join';
739
            break;
740
        case BIGBLUEBUTTON_EVENT_MEETING_CREATED:
741
            $event = 'create';
742
            break;
743
        case BIGBLUEBUTTON_EVENT_MEETING_ENDED:
744
            $event = 'end';
745
            break;
746
        case BIGBLUEBUTTON_EVENT_MEETING_LEFT:
747
            $event = 'left';
748
            break;
749
        case BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED:
750
            $event = 'publish';
751
            break;
752
        case BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED:
753
            $event = 'unpublish';
754
            break;
755
        case BIGBLUEBUTTON_EVENT_RECORDING_DELETED:
756
            $event = 'delete';
757
            break;
758
        case BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED:
759
            $event = 'view';
760
            break;
761
        case BIGBLUEBUTTON_EVENT_ACTIVITY_MANAGEMENT_VIEWED:
762
            $event = 'view all';
763
            break;
764
        default:
765
            return;
766
    }
767
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
768
769
    add_to_log($course->id, 'bigbluebuttonbn', $event, '', $bigbluebuttonbn->name, $cm->id);
770
}
771
772
function bigbluebuttonbn_event_log($event_type, $bigbluebuttonbn, $context, $cm) {
773
    global $CFG;
774
775
    $version_major = bigbluebuttonbn_get_moodle_version_major();
776
    if ( $version_major < '2014051200' ) {
777
        //This is valid before v2.7
778
        bigbluebuttonbn_event_log_legacy($event_type, $bigbluebuttonbn, $context, $cm);
779
780
    } else {
781
        //This is valid after v2.7
782
        bigbluebuttonbn_event_log_standard($event_type, $bigbluebuttonbn, $context, $cm);
783
    }
784
}
785
786
function bigbluebuttonbn_bbb_broker_get_recordings($meetingid, $password, $forced=false) {
0 ignored issues
show
Unused Code introduced by
The parameter $meetingid 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...
Unused Code introduced by
The parameter $password 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...
Unused Code introduced by
The parameter $forced 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...
787
    global $CFG;
788
789
    $recordings = array();
0 ignored issues
show
Unused Code introduced by
$recordings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
790
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
0 ignored issues
show
Unused Code introduced by
$endpoint is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
791
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
0 ignored issues
show
Unused Code introduced by
$shared_secret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
792
    $cache_ttl = bigbluebuttonbn_get_cfg_waitformoderator_cache_ttl();
0 ignored issues
show
Unused Code introduced by
$cache_ttl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
793
794
    $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache');
0 ignored issues
show
Unused Code introduced by
$cache is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
795
}
796
797
function bigbluebuttonbn_bbb_broker_participant_joined($meetingid, $is_moderator) {
798
    $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache');
799
    $result = $cache->get($meetingid);
800
    $meeting_info = json_decode($result['meeting_info']);
801
    $meeting_info->participantCount += 1;
802
    if( $is_moderator ) {
803
        $meeting_info->moderatorCount += 1;
804
    }
805
    $cache->set($meetingid, array('creation_time' => $result['creation_time'], 'meeting_info' => json_encode($meeting_info) ));
806
}
807
808
function bigbluebuttonbn_bbb_broker_is_meeting_running($meeting_info) {
809
    $meeting_running = ( isset($meeting_info) && isset($meeting_info->returncode) && $meeting_info->returncode == 'SUCCESS' );
810
811
    return $meeting_running;
812
}
813
814
function bigbluebuttonbn_bbb_broker_get_meeting_info($meetingid, $password, $forced=false) {
815
    global $CFG;
816
817
    $meeting_info = array();
0 ignored issues
show
Unused Code introduced by
$meeting_info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
818
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
819
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
820
    $cache_ttl = bigbluebuttonbn_get_cfg_waitformoderator_cache_ttl();
821
822
    $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache');
823
    $result = $cache->get($meetingid);
824
    $now = time();
825
    if( isset($result) && $now < ($result['creation_time'] + $cache_ttl) && !$forced ) {
826
        //Use the value in the cache
827
        $meeting_info = json_decode($result['meeting_info']);
828
    } else {
829
        //Ping again and refresh the cache
830
        $meeting_info = (array) bigbluebuttonbn_getMeetingInfo( $meetingid, $password, $endpoint, $shared_secret );
831
        $cache->set($meetingid, array('creation_time' => time(), 'meeting_info' => json_encode($meeting_info) ));
832
    }
833
834
    return $meeting_info;
835
}
836
837
function bigbluebuttonbn_bbb_broker_do_end_meeting($meetingid, $password){
838
    global $CFG;
839
840
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
841
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
842
843
    bigbluebuttonbn_doEndMeeting($meetingid, $password, $endpoint, $shared_secret);
844
}
845
846
function bigbluebuttonbn_bbb_broker_do_publish_recording($recordingid, $publish=true){
847
    global $CFG;
848
849
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
850
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
851
852
    bigbluebuttonbn_doPublishRecordings($recordingid, ($publish)? 'true': 'false', $endpoint, $shared_secret);
853
}
854
855
function bigbluebuttonbn_bbb_broker_do_publish_recording_imported($recordingid, $courseID, $bigbluebuttonbnID, $publish=true){
0 ignored issues
show
Unused Code introduced by
The parameter $courseID 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...
856
    global $DB;
857
858
    //Locate the record to be updated
859
    $records = $DB->get_records('bigbluebuttonbn_logs', array('bigbluebuttonbnid' => $bigbluebuttonbnID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
860
861
    $recordings_imported = array();
0 ignored issues
show
Unused Code introduced by
$recordings_imported is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
862
    foreach ($records as $key => $record) {
863
        $meta = json_decode($record->meta, true);
864
        if( $recordingid == $meta['recording']['recordID'] ) {
865
            // Found, prepare data for the update
866
            $meta['recording']['published'] = ($publish)? 'true': 'false';
867
            $records[$key]->meta = json_encode($meta);
868
869
            // Proceed with the update
870
            $DB->update_record("bigbluebuttonbn_logs", $records[$key]);
871
        }
872
    }
873
}
874
875
function bigbluebuttonbn_bbb_broker_do_delete_recording($recordingid){
876
    global $CFG;
877
878
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
879
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
880
881
    bigbluebuttonbn_doDeleteRecordings($recordingid, $endpoint, $shared_secret);
882
}
883
884
function bigbluebuttonbn_bbb_broker_do_delete_recording_imported($recordingid, $courseID, $bigbluebuttonbnID){
0 ignored issues
show
Unused Code introduced by
The parameter $courseID 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...
885
    global $DB;
886
887
    //Locate the record to be updated
888
    $records = $DB->get_records('bigbluebuttonbn_logs', array('bigbluebuttonbnid' => $bigbluebuttonbnID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
889
890
    $recordings_imported = array();
0 ignored issues
show
Unused Code introduced by
$recordings_imported is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
891
    foreach ($records as $key => $record) {
892
        $meta = json_decode($record->meta, true);
893
        if( $recordingid == $meta['recording']['recordID'] ) {
894
            // Execute delete
895
            $DB->delete_records("bigbluebuttonbn_logs", array('id' => $key));
896
        }
897
    }
898
}
899
900
function bigbluebuttonbn_bbb_broker_validate_parameters($params) {
901
    $error = '';
902
903
    if ( !isset($params['callback']) ) {
904
        $error = bigbluebuttonbn_bbb_broker_add_error($error, 'This call must include a javascript callback.');
905
    }
906
907
    if ( !isset($params['action']) ) {
908
        $error = bigbluebuttonbn_bbb_broker_add_error($error, 'Action parameter must be included.');
909
    } else {
910
        switch ( strtolower($params['action']) ){
911
            case 'server_ping':
912
            case 'meeting_info':
913
            case 'meeting_end':
914
                if ( !isset($params['id']) ) {
915
                    $error = bigbluebuttonbn_bbb_broker_add_error($error, 'The meetingID must be specified.');
916
                }
917
                break;
918
            case 'recording_list':
919
            case 'recording_info':
920
            case 'recording_publish':
921
            case 'recording_unpublish':
922
            case 'recording_delete':
923
            case 'recording_import':
924
                if ( !isset($params['id']) ) {
925
                    $error = bigbluebuttonbn_bbb_broker_add_error($error, 'The recordingID must be specified.');
926
                }
927
                break;
928
            case 'recording_ready':
929
                if( empty($params['signed_parameters']) ) {
930
                    $error = bigbluebuttonbn_bbb_broker_add_error($error, 'A JWT encoded string must be included as [signed_parameters].');
931
                }
932
                break;
933
            default:
934
                $error = bigbluebuttonbn_bbb_broker_add_error($error, 'Action '.$params['action'].' can not be performed.');
935
        }
936
    }
937
938
    return $error;
939
}
940
941
function bigbluebuttonbn_bbb_broker_add_error($org_msg, $new_msg='') {
942
    $error = $org_msg;
943
944
    if( !empty($new_msg) ) {
945
        if( !empty($error) ) $error .= ' ';
946
        $error .= $new_msg;
947
    }
948
949
    return $error;
950
}
951
952
function bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools=["publishing", "deleting"]) {
953
    global $OUTPUT, $CFG, $USER;
954
955
    $row = null;
956
957
    if ( $bbbsession['managerecordings'] || $recording['published'] == 'true' ) {
958
        $startTime = isset($recording['startTime'])? floatval($recording['startTime']):0;
959
        $startTime = $startTime - ($startTime % 1000);
960
        $duration = intval(array_values($recording['playbacks'])[0]['length']);
961
962
        //For backward compatibility
963
        if( isset($recording['meta_contextactivity']) ) {
964
            $meta_activity = str_replace('"', '\"', $recording['meta_contextactivity']);
0 ignored issues
show
Unused Code introduced by
$meta_activity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
965
        } if( isset($recording['meta_bbb-recording-name']) ) {
966
            $meta_activity = str_replace('"', '\"', $recording['meta_bbb-recording-name']);
967
        } else {
968
            $meta_activity = str_replace('"', '\"', $recording['meetingName']);
969
        }
970
971
        if( isset($recording['meta_contextactivitydescription']) ) {
972
            $meta_description = str_replace('"', '\"', $recording['meta_contextactivitydescription']);
973
        } else if( isset($recording['meta_bbb-recording-description']) ) {
974
            $meta_description = str_replace('"', '\"', $recording['meta_bbb-recording-description']);
975
        } else {
976
            $meta_description = '';
977
        }
978
979
        //Set recording_types
980
        if ( isset($recording['imported']) ) {
981
            $attributes = 'data-imported="true" title='.get_string('view_recording_link_warning', 'bigbluebuttonbn');
982
        } else {
983
            $attributes = 'data-imported="false"';
984
        }
985
986
        $recording_types = '';
987
        if ($recording['published'] == 'true') {
988
            $recording_types .= '<div id="playbacks-'.$recording['recordID'].'" '.$attributes.'>';
989
        } else {
990
            $recording_types .= '<div id="playbacks-'.$recording['recordID'].'" '.$attributes.'" hidden>';
991
        }
992
        foreach ( $recording['playbacks'] as $playback ) {
993
            $recording_types .= $OUTPUT->action_link($playback['url'], get_string('view_recording_format_'.$playback['type'], 'bigbluebuttonbn'), null, array('title' => get_string('view_recording_format_'.$playback['type'], 'bigbluebuttonbn'), 'target' => '_new') ).'&#32;';
994
        }
995
        $recording_types .= '</div>';
996
997
        //Initialize variables for styling text
998
        $head = $tail = '';
999
1000
        //Set actionbar, if user is allowed to manage recordings
1001
        $actionbar = '';
1002
        if ( $bbbsession['managerecordings'] ) {
1003
            // Set style for imported links
1004
            if( isset($recording['imported']) ) {
1005
                $recordings_imported_count = 0;
1006
                $tag_tail = ' '.get_string('view_recording_link', 'bigbluebuttonbn');
1007
                $head = '<i>';
1008
                $tail = '</i>';
1009
            } else {
1010
                $recordings_imported_array = bigbluebuttonbn_getRecordingsImportedAllInstancesArray($recording['recordID']);
1011
                $recordings_imported_count = count($recordings_imported_array);
1012
                $tag_tail = '';
1013
            }
1014
1015
            $url = '#';
1016
            $action = null;
1017
1018
            if (in_array("publishing", $tools)) {
1019
                ///Set action [show|hide]
1020
                if ( $recording['published'] == 'true' ){
1021
                    $manage_tag = 'hide';
1022
                    $manage_action = 'unpublish';
1023
                } else {
1024
                    $manage_tag = 'show';
1025
                    $manage_action = 'publish';
1026
                }
1027
                $onclick = 'M.mod_bigbluebuttonbn.broker_manageRecording("'.$manage_action.'", "'.$recording['recordID'].'", "'.$recording['meetingID'].'");';
1028
1029
                if ( bigbluebuttonbn_get_cfg_recording_icons_enabled() ) {
1030
                    //With icon for publish/unpublish
1031
                    $icon_attributes = array('id' => 'recording-btn-'.$manage_action.'-'.$recording['recordID']);
1032
                    $icon = new pix_icon('t/'.$manage_tag, get_string($manage_tag).$tag_tail, 'moodle', $icon_attributes);
1033
                    $link_attributes = array('id' => 'recording-link-'.$manage_action.'-'.$recording['recordID'], 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1034
                    $actionbar .= $OUTPUT->action_icon($url, $icon, $action, $link_attributes, false);
1035
                } else {
1036
                    //With text for publish/unpublish
1037
                    $link_attributes = array('title' => get_string($manage_tag).$tag_tail, 'class' => 'btn btn-xs', 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1038
                    $actionbar .= $OUTPUT->action_link($url, get_string($manage_tag).$tag_tail, $action, $link_attributes);
1039
                    $actionbar .= "&nbsp;";
1040
                }
1041
            }
1042
1043
            if (in_array("deleting", $tools)) {
1044
                $onclick = 'M.mod_bigbluebuttonbn.broker_manageRecording("delete", "'.$recording['recordID'].'", "'.$recording['meetingID'].'");';
1045
1046
                if ( bigbluebuttonbn_get_cfg_recording_icons_enabled() ) {
1047
                    //With icon for delete
1048
                    $icon_attributes = array('id' => 'recording-btn-delete-'.$recording['recordID']);
1049
                    $icon = new pix_icon('t/delete', get_string('delete').$tag_tail, 'moodle', $icon_attributes);
1050
                    $link_attributes = array('id' => 'recording-link-delete-'.$recording['recordID'], 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1051
                    $actionbar .= $OUTPUT->action_icon($url, $icon, $action, $link_attributes, false);
1052
                } else {
1053
                    //With text for delete
1054
                    $link_attributes = array('title' => get_string('delete').$tag_tail, 'class' => 'btn btn-xs btn-danger', 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1055
                    $actionbar .= $OUTPUT->action_link($url, get_string('delete').$tag_tail, $action, $link_attributes);
1056
                }
1057
            }
1058
1059
            if (in_array("importing", $tools)) {
1060
                $onclick = 'M.mod_bigbluebuttonbn.broker_manageRecording("import", "'.$recording['recordID'].'", "'.$recording['meetingID'].'");';
1061
1062
                if ( bigbluebuttonbn_get_cfg_recording_icons_enabled() ) {
1063
                    //With icon for import
1064
                    $icon_attributes = array('id' => 'recording-btn-import-'.$recording['recordID']);
1065
                    $icon = new pix_icon('i/import', get_string('import'), 'moodle', $icon_attributes);
1066
                    $link_attributes = array('id' => 'recording-link-import-'.$recording['recordID'], 'onclick' => $onclick);
1067
                    $actionbar .= $OUTPUT->action_icon($url, $icon, $action, $link_attributes, false);
1068
                } else {
1069
                    //With text for import
1070
                    $link_attributes = array('title' => get_string('import'), 'class' => 'btn btn-xs btn-danger', 'onclick' => $onclick);
1071
                    $actionbar .= $OUTPUT->action_link($url, get_string('import'), $action, $link_attributes);
1072
                }
1073
            }
1074
        }
1075
1076
        //Set corresponding format
1077
        $dateformat = get_string('strftimerecentfull', 'langconfig').' %Z';
1078
        $formattedStartDate = userdate($startTime / 1000, $dateformat, usertimezone($USER->timezone));
1079
1080
        $row = new stdClass();
1081
        $row->recording = "{$head}{$recording_types}{$tail}";
1082
        $row->activity = "{$head}{$meta_activity}{$tail}";
1083
        $row->description = "{$head}{$meta_description}{$tail}";
1084
        $row->date = floatval($recording['startTime']);
1085
        $row->date_formatted = "{$head}{$formattedStartDate}{$tail}";
1086
        $row->duration = "{$duration}";
1087
        $row->duration_formatted = "{$head}{$duration}{$tail}";
1088
        if ( $bbbsession['managerecordings'] ) {
1089
            $row->actionbar = $actionbar;
1090
        }
1091
    }
1092
1093
    return $row;
1094
}
1095
1096
function bigbluebuttonbn_get_recording_columns($bbbsession, $recordings) {
0 ignored issues
show
Unused Code introduced by
The parameter $recordings 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...
1097
    ///Set strings to show
1098
    $view_recording_recording = get_string('view_recording_recording', 'bigbluebuttonbn');
1099
    $view_recording_activity = get_string('view_recording_activity', 'bigbluebuttonbn');
1100
    $view_recording_description = get_string('view_recording_description', 'bigbluebuttonbn');
1101
    $view_recording_date = get_string('view_recording_date', 'bigbluebuttonbn');
1102
    $view_recording_duration = get_string('view_recording_duration', 'bigbluebuttonbn');
1103
    $view_recording_actionbar = get_string('view_recording_actionbar', 'bigbluebuttonbn');
1104
1105
    ///Initialize table headers
1106
    $recordingsbn_columns = array(
1107
        array("key" =>"recording", "label" => $view_recording_recording, "width" => "125px", "allowHTML" => true),
1108
        array("key" =>"activity", "label" => $view_recording_activity, "sortable" => true, "width" => "175px", "allowHTML" => true),
1109
        array("key" =>"description", "label" => $view_recording_description, "sortable" => true, "width" => "250px", "allowHTML" => true),
1110
        array("key" =>"date", "label" => $view_recording_date, "sortable" => true, "width" => "220px", "allowHTML" => true),
1111
        array("key" =>"duration", "label" => $view_recording_duration, "width" => "50px")
1112
        );
1113
1114
    if ( $bbbsession['managerecordings'] ) {
1115
        array_push($recordingsbn_columns, array("key" =>"actionbar", "label" => $view_recording_actionbar, "width" => "75px", "allowHTML" => true));
1116
    }
1117
1118
    return $recordingsbn_columns;
1119
}
1120
1121
function bigbluebuttonbn_get_recording_data($bbbsession, $recordings, $tools=["publishing", "deleting"]) {
1122
    $table_data = array();
1123
1124
    ///Build table content
1125
    if ( isset($recordings) && !array_key_exists('messageKey', $recordings)) {  // There are recordings for this meeting
1126
        foreach ( $recordings as $recording ) {
1127
            $row = bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools);
1128
            if( $row != null ) {
1129
                array_push($table_data, $row);
1130
            }
1131
        }
1132
    }
1133
1134
    return $table_data;
1135
}
1136
1137
function bigbluebuttonbn_get_recording_table($bbbsession, $recordings, $tools=['publishing','deleting']) {
1138
    global $OUTPUT, $CFG;
1139
1140
    ///Set strings to show
1141
    $view_recording_recording = get_string('view_recording_recording', 'bigbluebuttonbn');
1142
    $view_recording_course = get_string('view_recording_course', 'bigbluebuttonbn');
0 ignored issues
show
Unused Code introduced by
$view_recording_course is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1143
    $view_recording_activity = get_string('view_recording_activity', 'bigbluebuttonbn');
1144
    $view_recording_description = get_string('view_recording_description', 'bigbluebuttonbn');
1145
    $view_recording_date = get_string('view_recording_date', 'bigbluebuttonbn');
1146
    $view_recording_length = get_string('view_recording_length', 'bigbluebuttonbn');
0 ignored issues
show
Unused Code introduced by
$view_recording_length is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1147
    $view_recording_duration = get_string('view_recording_duration', 'bigbluebuttonbn');
1148
    $view_recording_actionbar = get_string('view_recording_actionbar', 'bigbluebuttonbn');
1149
    $view_duration_min = get_string('view_recording_duration_min', 'bigbluebuttonbn');
0 ignored issues
show
Unused Code introduced by
$view_duration_min is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1150
1151
    ///Declare the table
1152
    $table = new html_table();
1153
    $table->data = array();
1154
1155
    ///Initialize table headers
1156
    if ( $bbbsession['managerecordings'] ) {
1157
        $table->head  = array ($view_recording_recording, $view_recording_activity, $view_recording_description, $view_recording_date, $view_recording_duration, $view_recording_actionbar);
1158
        $table->align = array ('left', 'left', 'left', 'left', 'center', 'left');
1159
    } else {
1160
        $table->head  = array ($view_recording_recording, $view_recording_activity, $view_recording_description, $view_recording_date, $view_recording_duration);
1161
        $table->align = array ('left', 'left', 'left', 'left', 'center');
1162
    }
1163
1164
    ///Build table content
1165
    if ( isset($recordings) && !array_key_exists('messageKey', $recordings)) {  // There are recordings for this meeting
1166
        foreach ( $recordings as $recording ){
1167
            $row = new html_table_row();
1168
            $row->id = 'recording-td-'.$recording['recordID'];
1169
            if ( isset($recording['imported']) ) {
1170
                $row->attributes['data-imported'] = 'true';
1171
                $row->attributes['title'] = get_string('view_recording_link_warning', 'bigbluebuttonbn');
1172
            } else {
1173
                $row->attributes['data-imported'] = 'false';
1174
            }
1175
1176
            $row_data = bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools);
1177
            if( $row_data != null ) {
1178
                $row_data->date_formatted = str_replace(" ", "&nbsp;", $row_data->date_formatted);
1179
                if ( $bbbsession['managerecordings'] ) {
1180
                    $row->cells = array ($row_data->recording, $row_data->activity, $row_data->description, $row_data->date_formatted, $row_data->duration_formatted, $row_data->actionbar );
1181
                } else {
1182
                    $row->cells = array ($row_data->recording, $row_data->activity, $row_data->description, $row_data->date_formatted, $row_data->duration_formatted );
1183
                }
1184
1185
                array_push($table->data, $row);
1186
            }
1187
        }
1188
    }
1189
1190
    return $table;
1191
}
1192
1193
function bigbluebuttonbn_send_notification_recording_ready($bigbluebuttonbn) {
1194
    $sender = get_admin();
1195
1196
    // Prepare message
1197
    $msg = new stdClass();
1198
1199
    /// Build the message_body
1200
    $msg->activity_type = "";
1201
    $msg->activity_title = $bigbluebuttonbn->name;
1202
    $message_text = '<p>'.get_string('email_body_recording_ready_for', 'bigbluebuttonbn').' '.$msg->activity_type.' &quot;'.$msg->activity_title.'&quot; '.get_string('email_body_recording_ready_is_ready', 'bigbluebuttonbn').'.</p>';
1203
1204
    bigbluebuttonbn_send_notification($sender, $bigbluebuttonbn, $message_text);
1205
}
1206
1207
function bigbluebuttonbn_server_offers($capability_name){
1208
    global $CFG;
1209
1210
    $capability_offered = null;
1211
1212
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
1213
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
1214
1215
    //Validates if the server may have extended capabilities
1216
    $parse = parse_url($endpoint);
1217
    $host = $parse['host'];
1218
    $host_ends = explode(".", $host);
1219
    $host_ends_length = count($host_ends);
1220
1221
    if( $host_ends_length > 0 && $host_ends[$host_ends_length -1] == 'com' &&  $host_ends[$host_ends_length -2] == 'blindsidenetworks' ) {
1222
        //Validate the capabilities offered
1223
        $capabilities = bigbluebuttonbn_getCapabilitiesArray( $endpoint, $shared_secret );
1224
        if( $capabilities ) {
1225
            foreach ($capabilities as $capability) {
1226
                if ( $capability["name"] == $capability_name) {
1227
                    $capability_offered = $capability;
1228
                }
1229
            }
1230
        }
1231
    }
1232
1233
    return $capability_offered;
1234
}
1235
1236
function bigbluebuttonbn_server_offers_bn_capabilities(){
1237
    //Validates if the server may have extended capabilities
1238
    $parsed_url = parse_url(bigbluebuttonbn_get_cfg_server_url());
1239
    $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
1240
    $host_ends = explode(".", $host);
1241
    $host_ends_length = count($host_ends);
1242
1243
    return ( $host_ends_length > 0 && $host_ends[$host_ends_length -1] == 'com' && $host_ends[$host_ends_length -2] == 'blindsidenetworks' );
1244
}
1245
1246
function bigbluebuttonbn_get_locales_for_ui() {
1247
    $locales = array(
1248
            'not_started' => get_string('view_message_conference_not_started', 'bigbluebuttonbn'),
1249
            'wait_for_moderator' => get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn'),
1250
            'in_progress' => get_string('view_message_conference_in_progress', 'bigbluebuttonbn'),
1251
            'started_at' => get_string('view_message_session_started_at', 'bigbluebuttonbn'),
1252
            'session_no_users' => get_string('view_message_session_no_users', 'bigbluebuttonbn'),
1253
            'session_has_user' => get_string('view_message_session_has_user', 'bigbluebuttonbn'),
1254
            'session_has_users' => get_string('view_message_session_has_users', 'bigbluebuttonbn'),
1255
            'has_joined' => get_string('view_message_has_joined', 'bigbluebuttonbn'),
1256
            'have_joined' => get_string('view_message_have_joined', 'bigbluebuttonbn'),
1257
            'user' => get_string('view_message_user', 'bigbluebuttonbn'),
1258
            'users' => get_string('view_message_users', 'bigbluebuttonbn'),
1259
            'viewer' => get_string('view_message_viewer', 'bigbluebuttonbn'),
1260
            'viewers' => get_string('view_message_viewers', 'bigbluebuttonbn'),
1261
            'moderator' => get_string('view_message_moderator', 'bigbluebuttonbn'),
1262
            'moderators' => get_string('view_message_moderators', 'bigbluebuttonbn'),
1263
            'publish' => get_string('view_recording_list_actionbar_publish', 'bigbluebuttonbn'),
1264
            'publishing' => get_string('view_recording_list_actionbar_publishing', 'bigbluebuttonbn'),
1265
            'unpublish' => get_string('view_recording_list_actionbar_unpublish', 'bigbluebuttonbn'),
1266
            'unpublishing' => get_string('view_recording_list_actionbar_unpublishing', 'bigbluebuttonbn'),
1267
            'modal_title' => get_string('view_recording_modal_title', 'bigbluebuttonbn'),
1268
            'modal_button' => get_string('view_recording_modal_button', 'bigbluebuttonbn'),
1269
            'userlimit_reached' => get_string('view_error_userlimit_reached', 'bigbluebuttonbn'),
1270
            'recording' => get_string('view_recording', 'bigbluebuttonbn'),
1271
            'recording_link' => get_string('view_recording_link', 'bigbluebuttonbn'),
1272
            'recording_link_warning' => get_string('view_recording_link_warning', 'bigbluebuttonbn'),
1273
            'unpublish_confirmation' => get_string('view_recording_unpublish_confirmation', 'bigbluebuttonbn'),
1274
            'unpublish_confirmation_warning_s' => get_string('view_recording_unpublish_confirmation_warning_s', 'bigbluebuttonbn'),
1275
            'unpublish_confirmation_warning_p' => get_string('view_recording_unpublish_confirmation_warning_p', 'bigbluebuttonbn'),
1276
            'delete_confirmation' => get_string('view_recording_delete_confirmation', 'bigbluebuttonbn'),
1277
            'delete_confirmation_warning_s' => get_string('view_recording_delete_confirmation_warning_s', 'bigbluebuttonbn'),
1278
            'delete_confirmation_warning_p' => get_string('view_recording_delete_confirmation_warning_p', 'bigbluebuttonbn'),
1279
            'import_confirmation' => get_string('view_recording_import_confirmation', 'bigbluebuttonbn'),
1280
            'conference_ended' => get_string('view_message_conference_has_ended', 'bigbluebuttonbn'),
1281
            'conference_not_started' => get_string('view_message_conference_not_started', 'bigbluebuttonbn'),
1282
    );
1283
    return $locales;
1284
}
1285
1286
function bigbluebuttonbn_get_cfg_server_url_default() {
1287
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1288
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_server_url)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_server_url: (isset($CFG->bigbluebuttonbn_server_url)? $CFG->bigbluebuttonbn_server_url: (isset($CFG->BigBlueButtonBNServerURL)? $CFG->BigBlueButtonBNServerURL: 'http://test-install.blindsidenetworks.com/bigbluebutton/')));
1289
}
1290
1291
function bigbluebuttonbn_get_cfg_shared_secret_default() {
1292
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1293
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_shared_secret)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_shared_secret: (isset($CFG->bigbluebuttonbn_shared_secret)? $CFG->bigbluebuttonbn_shared_secret: (isset($CFG->BigBlueButtonBNSecuritySalt)? $CFG->BigBlueButtonBNSecuritySalt: '8cd8ef52e8e101574e400365b55e11a6')));
1294
}
1295
1296
function bigbluebuttonbn_get_cfg_voicebridge_editable() {
1297
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1298
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_voicebridge_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_voicebridge_editable: (isset($CFG->bigbluebuttonbn_voicebridge_editable)? $CFG->bigbluebuttonbn_voicebridge_editable: false));
1299
}
1300
1301
function bigbluebuttonbn_get_cfg_recording_default() {
1302
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1303
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_default: (isset($CFG->bigbluebuttonbn_recording_default)? $CFG->bigbluebuttonbn_recording_default: true));
1304
}
1305
1306
function bigbluebuttonbn_get_cfg_recording_editable() {
1307
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1308
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_editable: (isset($CFG->bigbluebuttonbn_recording_editable)? $CFG->bigbluebuttonbn_recording_editable: true));
1309
}
1310
1311
function bigbluebuttonbn_get_cfg_recording_tagging_default() {
1312
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1313
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_default: (isset($CFG->bigbluebuttonbn_recordingtagging_default)? $CFG->bigbluebuttonbn_recordingtagging_default: false));
1314
}
1315
1316
function bigbluebuttonbn_get_cfg_recording_tagging_editable() {
1317
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1318
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_editable: (isset($CFG->bigbluebuttonbn_recordingtagging_editable)? $CFG->bigbluebuttonbn_recordingtagging_editable: false));
1319
}
1320
1321
function bigbluebuttonbn_get_cfg_recording_icons_enabled() {
1322
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1323
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_icons_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_icons_enabled: (isset($CFG->bigbluebuttonbn_recording_icons_enabled)? $CFG->bigbluebuttonbn_recording_icons_enabled: true));
1324
}
1325
1326
function bigbluebuttonbn_get_cfg_importrecordings_enabled() {
1327
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1328
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_importrecordings_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_importrecordings_enabled: (isset($CFG->bigbluebuttonbn_importrecordings_enabled)? $CFG->bigbluebuttonbn_importrecordings_enabled: false));
1329
}
1330
1331
function bigbluebuttonbn_get_cfg_importrecordings_from_deleted_activities_enabled() {
1332
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1333
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_importrecordings_from_deleted_activities_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_importrecordings_from_deleted_activities_enabled: (isset($CFG->bigbluebuttonbn_importrecordings_from_deleted_activities_enabled)? $CFG->bigbluebuttonbn_importrecordings_from_deleted_activities_enabled: false));
1334
}
1335
1336
function bigbluebuttonbn_get_cfg_waitformoderator_default() {
1337
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1338
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_default: (isset($CFG->bigbluebuttonbn_waitformoderator_default)? $CFG->bigbluebuttonbn_waitformoderator_default: false));
1339
}
1340
1341
function bigbluebuttonbn_get_cfg_waitformoderator_editable() {
1342
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1343
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_editable: (isset($CFG->bigbluebuttonbn_waitformoderator_editable)? $CFG->bigbluebuttonbn_waitformoderator_editable: true));
1344
}
1345
1346
function bigbluebuttonbn_get_cfg_waitformoderator_ping_interval() {
1347
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1348
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_ping_interval)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_ping_interval: (isset($CFG->bigbluebuttonbn_waitformoderator_ping_interval)? $CFG->bigbluebuttonbn_waitformoderator_ping_interval: 15));
1349
}
1350
1351
function bigbluebuttonbn_get_cfg_waitformoderator_cache_ttl() {
1352
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1353
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_cache_ttl)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_cache_ttl: (isset($CFG->bigbluebuttonbn_waitformoderator_cache_ttl)? $CFG->bigbluebuttonbn_waitformoderator_cache_ttl: 60));
1354
}
1355
1356
function bigbluebuttonbn_get_cfg_userlimit_default() {
1357
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1358
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_default: (isset($CFG->bigbluebuttonbn_userlimit_default)? $CFG->bigbluebuttonbn_userlimit_default: 0));
1359
}
1360
1361
function bigbluebuttonbn_get_cfg_userlimit_editable() {
1362
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1363
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_editable: (isset($CFG->bigbluebuttonbn_userlimit_editable)? $CFG->bigbluebuttonbn_userlimit_editable: false));
1364
}
1365
1366
function bigbluebuttonbn_get_cfg_preuploadpresentation_enabled() {
1367
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1368
    if (extension_loaded('curl')) {
1369
        // This feature only works if curl is installed
1370
        return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_preuploadpresentation_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_preuploadpresentation_enabled: (isset($CFG->bigbluebuttonbn_preuploadpresentation_enabled)? $CFG->bigbluebuttonbn_preuploadpresentation_enabled: false));
1371
    } else {
1372
        return false;
1373
    }
1374
}
1375
1376
function bigbluebuttonbn_get_cfg_sendnotifications_enabled() {
1377
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1378
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_sendnotifications_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_sendnotifications_enabled: (isset($CFG->bigbluebuttonbn_sendnotifications_enabled)? $CFG->bigbluebuttonbn_sendnotifications_enabled: false));
1379
}
1380
1381
function bigbluebuttonbn_get_cfg_recordingready_enabled() {
1382
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1383
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingready_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingready_enabled: (isset($CFG->bigbluebuttonbn_recordingready_enabled)? $CFG->bigbluebuttonbn_recordingready_enabled: false));
1384
}
1385
1386
function bigbluebuttonbn_get_cfg_moderator_default() {
1387
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1388
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_moderator_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_moderator_default: (isset($CFG->bigbluebuttonbn_moderator_default)? $CFG->bigbluebuttonbn_moderator_default: 'owner'));
1389
}
1390
1391
function bigbluebuttonbn_get_cfg_scheduled_duration_enabled() {
1392
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1393
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_scheduled_duration_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_scheduled_duration_enabled: (isset($CFG->bigbluebuttonbn_scheduled_duration_enabled)? $CFG->bigbluebuttonbn_scheduled_duration_enabled: false));
1394
}
1395
1396
function bigbluebuttonbn_get_cfg_scheduled_duration_compensation() {
1397
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1398
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_scheduled_duration_compensation)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_scheduled_duration_compensation: (isset($CFG->bigbluebuttonbn_scheduled_duration_compensation)? $CFG->bigbluebuttonbn_scheduled_duration_compensation: 10));
1399
}
1400
1401
function bigbluebuttonbn_get_cfg_scheduled_pre_opening() {
1402
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1403
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_scheduled_pre_opening)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_scheduled_pre_opening: (isset($CFG->bigbluebuttonbn_scheduled_pre_opening)? $CFG->bigbluebuttonbn_scheduled_pre_opening: 10));
1404
}
1405
1406
function bigbluebuttonbn_import_get_courses_for_select(array $bbbsession) {
1407
1408
    if( $bbbsession['administrator'] ) {
1409
        $courses = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.fullname');
1410
        //It includes the name of the site as a course (category 0), so remove the first one
1411
        unset($courses["1"]);
1412
    } else {
1413
        $courses = enrol_get_users_courses($bbbsession['userID'], false, 'id,shortname,fullname');
1414
    }
1415
1416
    $courses_for_select = [];
1417
    foreach($courses as $course) {
1418
        if( $course->id != $bbbsession['course']->id ) {
1419
            $courses_for_select[$course->id] = $course->fullname;
1420
        }
1421
    }
1422
    return $courses_for_select;
1423
}
1424
1425
function bigbluebuttonbn_getRecordedMeetingsDeleted($courseID, $bigbluebuttonbnID=NULL) {
1426
    global $DB;
1427
1428
    $records_deleted = array();
1429
1430
    $filter = array('courseid' => $courseID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_DELETE );
1431
    if ( $bigbluebuttonbnID != NULL ) {
1432
        $filter['id'] = $bigbluebuttonbnID;
1433
    }
1434
1435
    $bigbluebuttonbns_deleted = $DB->get_records('bigbluebuttonbn_logs', $filter);
1436
1437
    foreach ($bigbluebuttonbns_deleted as $key => $bigbluebuttonbn_deleted) {
1438
        $records = $DB->get_records('bigbluebuttonbn_logs', array('courseid' => $courseID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_CREATE));
1439
1440
        if( !empty($records) ) {
1441
            //Remove duplicates
1442
            $unique_records = array();
1443
            foreach ($records as $key => $record) {
1444
                if (array_key_exists($record->meetingid, $unique_records) ) {
1445
                    unset($records[$key]);
1446
                } else {
1447
                    $meta = json_decode($record->meta);
1448
                    if ( !$meta->record ) {
1449
                        unset($records[$key]);
1450
                    } else if ( $bigbluebuttonbn_deleted->meetingid != substr($record->meetingid, 0, strlen($bigbluebuttonbn_deleted->meetingid))) {
1451
                        unset($records[$key]);
1452
                    } else {
1453
                        array_push($unique_records, $record->meetingid);
1454
                    }
1455
                }
1456
            }
1457
1458
            $records_deleted = array_merge($records_deleted, $records);
1459
        }
1460
    }
1461
1462
    return $records_deleted;
1463
}
1464
1465
function bigbluebuttonbn_getRecordedMeetings($courseID, $bigbluebuttonbnID=NULL) {
1466
    global $DB;
1467
1468
    $records = Array();
1469
1470
    $filter = array('course' => $courseID);
1471
    if ( $bigbluebuttonbnID != NULL ) {
1472
        $filter['id'] = $bigbluebuttonbnID;
1473
    }
1474
    $bigbluebuttonbns = $DB->get_records('bigbluebuttonbn', $filter);
1475
1476
    if ( !empty($bigbluebuttonbns) ) {
1477
        $table = 'bigbluebuttonbn_logs';
1478
1479
        //Prepare select for loading records based on existent bigbluebuttonbns
1480
        $select = "";
1481
        foreach ($bigbluebuttonbns as $key => $bigbluebuttonbn) {
1482
            $select .= strlen($select) == 0? "(": " OR ";
1483
            $select .= "bigbluebuttonbnid=".$bigbluebuttonbn->id;
1484
        }
1485
        $select .= ") AND log='".BIGBLUEBUTTONBN_LOG_EVENT_CREATE."'";
1486
1487
        //Execute select for loading records based on existent bigbluebuttonbns
1488
        $records = $DB->get_records_select($table, $select);
1489
1490
        //Remove duplicates
1491
        $unique_records = array();
1492
        foreach ($records as $key => $record) {
1493
            $record_key = $record->meetingid.','.$record->bigbluebuttonbnid.','.$record->meta;
1494
            if( array_search($record_key, $unique_records) === false ) {
1495
                array_push($unique_records, $record_key);
1496
            } else {
1497
                unset($records[$key]);
1498
            }
1499
        }
1500
1501
        //Remove the ones with record=false
1502
        foreach ($records as $key => $record) {
1503
            $meta = json_decode($record->meta);
1504
            if ( !$meta || !$meta->record ) {
1505
                unset($records[$key]);
1506
            }
1507
        }
1508
    }
1509
1510
    return $records;
1511
}
1512
1513
function bigbluebuttonbn_getRecordingsArrayByCourse($courseID, $URL, $SALT) {
1514
    $recordings = array();
1515
1516
    // Load the meetingIDs to be used in the getRecordings request
1517
    $meetingID = '';
1518
    if ( is_numeric($courseID) ) {
1519
        $results = bigbluebuttonbn_getRecordedMeetings($courseID);
1520
1521
        if( bigbluebuttonbn_get_cfg_importrecordings_from_deleted_activities_enabled() ) {
1522
            $results_deleted = bigbluebuttonbn_getRecordedMeetingsDeleted($courseID);
1523
            $results = array_merge($results, $results_deleted);
1524
        }
1525
1526 View Code Duplication
        if( $results ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1527
            //Eliminates duplicates
1528
            $mIDs = array();
1529
            foreach ($results as $result) {
1530
                $mIDs[$result->meetingid] = $result->meetingid;
1531
            }
1532
            //Generates the meetingID string
1533
            foreach ($mIDs as $mID) {
1534
                if (strlen($meetingID) > 0) {
1535
                    $meetingID .= ',';
1536
                }
1537
                $meetingID .= $mID;
1538
            }
1539
        }
1540
    }
1541
1542
    // If there were meetingIDs excecute the getRecordings request
1543
    if ( $meetingID != '' ) {
1544
        $recordings = bigbluebuttonbn_getRecordingsArray($meetingID, $URL, $SALT);
1545
    }
1546
1547
    return $recordings;
1548
}
1549
1550
function bigbluebuttonbn_import_get_recordings_imported($records) {
1551
    $recordings_imported = array();
1552
1553
    foreach ($records as $key => $record) {
1554
        $meta = json_decode($record->meta, true);
1555
        $recordings_imported[] = $meta['recording'];
1556
    }
1557
1558
    return $recordings_imported;
1559
}
1560
1561
function bigbluebuttonbn_import_exlcude_recordings_already_imported($courseID, $bigbluebuttonbnID, $recordings) {
1562
    $recordings_already_imported = bigbluebuttonbn_getRecordingsImportedArray($courseID, $bigbluebuttonbnID);
1563
    $recordings_already_imported_indexed = bigbluebuttonbn_index_recordings($recordings_already_imported);
1564
1565
    foreach ($recordings as $key => $recording) {
1566
        if( isset($recordings_already_imported_indexed[$recording['recordID']]) ) {
1567
            unset($recordings[$key]);
1568
        }
1569
    }
1570
    return $recordings;
1571
}
1572
1573
function bigbluebutton_output_recording_table($bbbsession, $recordings, $tools=['publishing','deleting']) {
1574
1575
    if ( isset($recordings) && !empty($recordings) ) {  // There are recordings for this meeting
1576
        $table = bigbluebuttonbn_get_recording_table($bbbsession, $recordings, $tools);
1577
    }
1578
1579
    $output = '';
1580
    if( isset($table->data) ) {
1581
        //Print the table
1582
        $output .= '<div id="bigbluebuttonbn_html_table">'."\n";
1583
        $output .= html_writer::table($table)."\n";
0 ignored issues
show
Bug introduced by
The variable $table does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1584
        $output .= '</div>'."\n";
1585
1586
    } else {
1587
        $output .= get_string('view_message_norecordings', 'bigbluebuttonbn').'<br>'."\n";
1588
    }
1589
1590
    return $output;
1591
}
1592
1593
function bigbluebuttonbn_getRecordingsImported($courseID, $bigbluebuttonbnID=NULL) {
1594
    global $DB;
1595
1596
    if ( $bigbluebuttonbnID != NULL ) {
1597
        // Fetch only those related to the $courseID and $bigbluebuttonbnID requested
1598
        $recordings_imported = $DB->get_records('bigbluebuttonbn_logs', array('courseid' => $courseID, 'bigbluebuttonbnid' => $bigbluebuttonbnID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
1599
    } else {
1600
        // Fetch all the ones corresponding to the $courseID requested
1601
        $recordings_imported = $DB->get_records('bigbluebuttonbn_logs', array('courseid' => $courseID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
1602
    }
1603
    return $recordings_imported;
1604
}
1605
1606
function bigbluebuttonbn_getRecordingsImportedArray($courseID, $bigbluebuttonbnID=NULL) {
1607
    $recordings_imported = bigbluebuttonbn_getRecordingsImported($courseID, $bigbluebuttonbnID);
1608
    $recordings_imported_array = bigbluebuttonbn_import_get_recordings_imported($recordings_imported);
1609
    return $recordings_imported_array;
1610
}
1611
1612
function bigbluebuttonbn_getRecordingsImportedAllInstances($recordID) {
1613
    global $DB, $CFG;
1614
1615
    $recordings_imported = $DB->get_records_sql('SELECT * FROM '.$CFG->prefix.'bigbluebuttonbn_logs WHERE log=? AND '.$DB->sql_like('meta', '?'), array( BIGBLUEBUTTONBN_LOG_EVENT_IMPORT, '%'.$recordID.'%' ));
1616
    return $recordings_imported;
1617
}
1618
1619
function bigbluebuttonbn_getRecordingsImportedAllInstancesArray($recordID) {
1620
    $recordings_imported = bigbluebuttonbn_getRecordingsImportedAllInstances($recordID);
1621
    $recordings_imported_array = bigbluebuttonbn_import_get_recordings_imported($recordings_imported);
1622
    return $recordings_imported_array;
1623
}
1624
1625
function bigbluebuttonbn_debugdisplay() {
1626
    global $CFG;
1627
1628
    return (bool)$CFG->debugdisplay;
1629
}
1630
1631
function bigbluebuttonbn_html2text($html, $len) {
1632
    $text = strip_tags($html);
1633
    $text = str_replace("&nbsp;", ' ', $text);
1634
    if( strlen($text) > $len ) {
1635
        $text = substr($text, 0, $len)."...";
1636
    } else {
1637
        $text = substr($text, 0, $len);
1638
    }
1639
    return $text;
1640
}
1641