Completed
Push — master ( 16d8be...175c16 )
by Jesus
03:09
created

locallib.php ➔ bigbluebuttonbn_getRecordingArrayRow()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 20
rs 9.2
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
    $duration = intval($duration);
76
    if( $duration > 0 )
77
        $params .= '&duration='.$duration;
78
79
    $maxParticipants = intval($maxParticipants);
80
    if( $maxParticipants > 0 )
81
        $params .= '&maxParticipants='.$maxParticipants;
82
83
    if( trim( $welcome ) )
84
        $params .= '&welcome='.urlencode($welcome);
85
86
    foreach ($metadata as $key => $value) {
87
        $params .= '&'.$key.'='.urlencode($value);
88
    }
89
90
    $url = $url_create.$params.'&checksum='.sha1("create".$params.$SALT);
91
    return $url;
92
}
93
94
function bigbluebuttonbn_getIsMeetingRunningURL( $meetingID, $URL, $SALT ) {
95
    $base_url = $URL."api/isMeetingRunning?";
96
    $params = 'meetingID='.urlencode($meetingID);
97
    $url = $base_url.$params.'&checksum='.sha1("isMeetingRunning".$params.$SALT);
98
    return $url;
99
}
100
101 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...
102
    $base_url = $URL."api/getMeetingInfo?";
103
    $params = 'meetingID='.urlencode($meetingID).'&password='.urlencode($modPW);
104
    $url = $base_url.$params.'&checksum='.sha1("getMeetingInfo".$params.$SALT);
105
    return $url;
106
}
107
108
function bigbluebuttonbn_getMeetingsURL( $URL, $SALT ) {
109
    $base_url = $URL."api/getMeetings?";
110
    $url = $base_url.'&checksum='.sha1("getMeetings".$SALT);
111
    return $url;
112
}
113
114 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...
115
    $base_url = $URL."api/end?";
116
    $params = 'meetingID='.urlencode($meetingID).'&password='.urlencode($modPW);
117
    $url = $base_url.$params.'&checksum='.sha1("end".$params.$SALT);
118
    return $url;
119
}
120
121
function bigbluebuttonbn_getRecordingsURL( $URL, $SALT, $meetingID=null ) {
122
    $base_url_record = $URL."api/getRecordings?";
123
    if( $meetingID == null ) {
124
        $params = "";
125
    } else {
126
        $params = "meetingID=".urlencode($meetingID);
127
    }
128
    $url = $base_url_record.$params."&checksum=".sha1("getRecordings".$params.$SALT);
129
    return $url;
130
}
131
132
function bigbluebuttonbn_getDeleteRecordingsURL( $recordID, $URL, $SALT ) {
133
    $url_delete = $URL."api/deleteRecordings?";
134
    $params = 'recordID='.urlencode($recordID);
135
    $url = $url_delete.$params.'&checksum='.sha1("deleteRecordings".$params.$SALT);
136
    return $url;
137
}
138
139
function bigbluebuttonbn_getPublishRecordingsURL( $recordID, $set, $URL, $SALT ) {
140
    $url_publish = $URL."api/publishRecordings?";
141
    $params = 'recordID='.$recordID."&publish=".$set;
142
    $url = $url_publish.$params.'&checksum='.sha1("publishRecordings".$params.$SALT);
143
    return $url;
144
}
145
146
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 ) {
147
    $create_meeting_url = bigbluebuttonbn_getCreateMeetingURL($username, $meetingID, $aPW, $mPW, $welcomeString, $logoutURL, $SALT, $URL, $record, $duration, $voiceBridge, $maxParticipants, $metadata);
148
    if( !is_null($presentation_name) && !is_null($presentation_url) ) {
149
        $xml = bigbluebuttonbn_wrap_xml_load_file( $create_meeting_url,
150
                BIGBLUEBUTTONBN_METHOD_POST,
151
                "<?xml version='1.0' encoding='UTF-8'?><modules><module name='presentation'><document url='".$presentation_url."' /></module></modules>"
152
                );
153
    } else {
154
        $xml = bigbluebuttonbn_wrap_xml_load_file( $create_meeting_url );
155
    }
156
157
    if ( $xml ) {
158
        if ($xml->meetingID)
159
            return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey, 'meetingID' => $xml->meetingID, 'attendeePW' => $xml->attendeePW, 'moderatorPW' => $xml->moderatorPW, 'hasBeenForciblyEnded' => $xml->hasBeenForciblyEnded );
160
        else
161
            return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey );
162
    } else {
163
        return null;
164
    }
165
}
166
167
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...
168
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingsURL($URL, $SALT) );
169
170
    if( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey ) {    //The meetings were returned
171
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
172
173
    } else if($xml && $xml->returncode == 'SUCCESS'){                    //If there were meetings already created
174
        foreach ($xml->meetings->meeting as $meeting) {
175
            $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...
176
        }
177
        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...
178
179 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...
180
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
181
182
    } else { //If the server is unreachable, then prompts the user of the necessary action
183
        return null;
184
    }
185
}
186
187
function bigbluebuttonbn_getMeetingInfo( $meetingID, $modPW, $URL, $SALT ) {
188
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
189
    return $xml;
190
}
191
192
function bigbluebuttonbn_getMeetingInfoArray( $meetingID, $modPW, $URL, $SALT ) {
193
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingInfoURL( $meetingID, $modPW, $URL, $SALT ) );
194
195
    if( $xml && $xml->returncode == 'SUCCESS' && $xml->messageKey == null){//The meeting info was returned
196
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey );
197
198
    } else if($xml && $xml->returncode == 'SUCCESS'){ //If there were meetings already created
199
        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 );
200
201 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...
202
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
203
204
    } else { //If the server is unreachable, then prompts the user of the necessary action
205
        return null;
206
    }
207
}
208
209
function bigbluebuttonbn_getRecordingsArray( $meetingIDs, $URL, $SALT ) {
210
    $recordings = array();
211
212
    if ( is_array($meetingIDs) ) {
213
        // getRecordings is executes using a method POST (supported only on BBB 1.0 and later)
214
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getRecordingsURL( $URL, $SALT ), BIGBLUEBUTTONBN_METHOD_POST, $meetingIDs );
215
    } else {
216
        // getRecordings is executes using a method GET supported by any version of BBB
217
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getRecordingsURL( $URL, $SALT, $meetingIDs ) );
218
    }
219
220 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...
221
        foreach ( $xml->recordings->recording as $recording ) {
222
            $recordings[] = bigbluebuttonbn_getRecordingArrayRow($recording);
223
        }
224
225
        usort($recordings, 'bigbluebuttonbn_recordingBuildSorter');
226
    }
227
228
    return $recordings;
229
}
230
231
function bigbluebuttonbn_index_recordings($recordings, $index_key='recordID') {
232
    $indexed_recordings = array();
233
234
    foreach ($recordings as $recording) {
235
        $indexed_recordings[$recording[$index_key]] = $recording;
236
    }
237
238
    return $indexed_recordings;
239
}
240
241
function bigbluebuttonbn_getRecordingArray( $recordingID, $meetingID, $URL, $SALT ) {
242
    $recordingArray = array();
243
244
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getRecordingsURL( $URL, $SALT, $meetingID ) );
245
246 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...
247
        foreach ($xml->recordings->recording as $recording) {
248
            if( $recording->recordID == $recordingID ) {
249
                $recordingArray = bigbluebuttonbn_getRecordingArrayRow($recording);
250
                break;
251
            }
252
        }
253
    }
254
255
    return $recordingArray;
256
}
257
258
function bigbluebuttonbn_getRecordingArrayRow( $recording ) {
259
    $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...
260
261
    $playbackArray = array();
262
    foreach ( $recording->playback->format as $format ) {
263
        $playbackArray[(string) $format->type] = array( 'type' => (string) $format->type, 'url' => (string) $format->url, 'length' => (string) $format->length );
264
    }
265
266
    //Add the metadata to the recordings array
267
    $metadataArray = array();
268
    $metadata = get_object_vars($recording->metadata);
269
    foreach ( $metadata as $key => $value ) {
270
        if ( is_object($value) ) $value = '';
271
        $metadataArray['meta_'.$key] = $value;
272
    }
273
274
    $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;
275
276
    return $recordingArrayRow;
277
}
278
279
function bigbluebuttonbn_recordingBuildSorter($a, $b){
280
    if( $a['startTime'] < $b['startTime']) return -1;
281
    else if( $a['startTime'] == $b['startTime']) return 0;
282
    else return 1;
283
}
284
285 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...
286
    $ids = 	explode(",", $recordIDs);
287
    foreach( $ids as $id){
288
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getDeleteRecordingsURL($id, $URL, $SALT) );
289
        if( $xml && $xml->returncode != 'SUCCESS' )
290
            return false;
291
    }
292
    return true;
293
}
294
295 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...
296
    $ids = 	explode(",", $recordIDs);
297
    foreach( $ids as $id){
298
        $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getPublishRecordingsURL($id, $set, $URL, $SALT) );
299
        if( $xml && $xml->returncode != 'SUCCESS' )
300
            return false;
301
    }
302
    return true;
303
}
304
305
function bigbluebuttonbn_doEndMeeting( $meetingID, $modPW, $URL, $SALT ) {
306
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getEndMeetingURL( $meetingID, $modPW, $URL, $SALT ) );
307
308
    if( $xml ) { //If the xml packet returned failure it displays the message to the user
309
        return array('returncode' => $xml->returncode, 'message' => $xml->message, 'messageKey' => $xml->messageKey);
310
    }
311
    else { //If the server is unreachable, then prompts the user of the necessary action
312
        return null;
313
    }
314
}
315
316
function bigbluebuttonbn_isMeetingRunning( $meetingID, $URL, $SALT ) {
317
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getIsMeetingRunningURL( $meetingID, $URL, $SALT ) );
318
    if ( $xml && $xml->returncode == 'SUCCESS' ) {
319
        return ( ( $xml->running == 'true' ) ? true : false);
320
    } else {
321
        return ( false );
322
    }
323
}
324
325
326
function bigbluebuttonbn_getServerVersion( $URL ){
327
    $xml = bigbluebuttonbn_wrap_xml_load_file( $URL."api" );
328
    if ( $xml && $xml->returncode == 'SUCCESS' ) {
329
        return $xml->version;
330
    } else {
331
        return NULL;
332
    }
333
}
334
335
function bigbluebuttonbn_getMeetingXML( $meetingID, $URL, $SALT ) {
336
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getIsMeetingRunningURL( $meetingID, $URL, $SALT ) );
337
    if ( $xml && $xml->returncode == 'SUCCESS') {
338
        return ( str_replace('</response>', '', str_replace("<?xml version=\"1.0\"?>\n<response>", '', $xml->asXML())));
339
    } else {
340
        return 'false';
341
    }
342
}
343
344
function bigbluebuttonbn_wrap_xml_load_file($url, $method=BIGBLUEBUTTONBN_METHOD_GET, $data=null) {
345
    if ( bigbluebuttonbn_debugdisplay() ) error_log("Request to: ".$url);
346
347
    if (extension_loaded('curl')) {
348
        $c = new curl();
349
        $c->setopt( Array( "SSL_VERIFYPEER" => true));
350
        if( $method == BIGBLUEBUTTONBN_METHOD_POST ) {
351
            if( !is_null($data) ) {
352
                if( !is_array($data) ) {
353
                    $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...
354
                            'Content-Type: text/xml',
355
                            'Content-Length: '.strlen($data),
356
                            'Content-Language: en-US'
357
                        );
358
                    $response = $c->post($url, $data, $options);
359
360
                } else {
361
                    $response = $c->post($url, $data);
362
                }
363
364
            } else {
365
                $response = $c->post($url);
366
            }
367
368
        } else {
369
            $response = $c->get($url);
370
        }
371
372
        if ($response) {
373
            $previous = libxml_use_internal_errors(true);
374
            try {
375
                $xml = new SimpleXMLElement($response, LIBXML_NOCDATA);
376
                return $xml;
377
            } catch (Exception $e){
378
                libxml_use_internal_errors($previous);
379
                $error = 'Caught exception: '.$e->getMessage();
380
                error_log($error);
381
                return NULL;
382
            }
383
        } else {
384
            error_log("No response on wrap_simplexml_load_file");
385
            return NULL;
386
        }
387
388
    } else {
389
        $previous = libxml_use_internal_errors(true);
390
        try {
391
            $xml = simplexml_load_file($url,'SimpleXMLElement', LIBXML_NOCDATA);
392
            return $xml;
393
        } catch  (Exception $e){
394
            libxml_use_internal_errors($previous);
395
            return NULL;
396
        }
397
    }
398
}
399
400
function bigbluebuttonbn_get_role_name($role_shortname){
401
    $role = bigbluebuttonbn_get_db_moodle_roles($role_shortname);
402
    if( $role != null && $role->name != "") {
403
        $role_name = $role->name;
404
    } else {
405
        switch ($role_shortname) {
406
            case 'manager':         $role_name = get_string('manager', 'role'); break;
407
            case 'coursecreator':   $role_name = get_string('coursecreators'); break;
408
            case 'editingteacher':  $role_name = get_string('defaultcourseteacher'); break;
409
            case 'teacher':         $role_name = get_string('noneditingteacher'); break;
410
            case 'student':         $role_name = get_string('defaultcoursestudent'); break;
411
            case 'guest':           $role_name = get_string('guest'); break;
412
            case 'user':            $role_name = get_string('authenticateduser'); break;
413
            case 'frontpage':       $role_name = get_string('frontpageuser', 'role'); break;
414
            // We should not get here, the role UI should require the name for custom roles!
415
            default:                $role_name = $role_shortname; break;
416
        }
417
    }
418
419
    return $role_name;
420
}
421
422
function bigbluebuttonbn_get_roles($rolename='all', $format='json'){
423
    $roles = bigbluebuttonbn_get_db_moodle_roles($rolename);
424
    $roles_array = array();
425
    foreach($roles as $role){
426
        if( $format=='json' ) {
427
            array_push($roles_array,
428
                    array( "id" => $role->shortname,
429
                        "name" => bigbluebuttonbn_get_role_name($role->shortname)
430
                    )
431
            );
432
        } else {
433
            $roles_array[$role->shortname] = bigbluebuttonbn_get_role_name($role->shortname);
434
        }
435
    }
436
    return $roles_array;
437
}
438
439
function bigbluebuttonbn_get_roles_json($rolename='all'){
440
    return json_encode(bigbluebuttonbn_get_roles($rolename));
441
}
442
443
function bigbluebuttonbn_get_users_json($users, $full=false) {
444
    if( $full ) {
445
        return json_encode($users);
446
    } else {
447
        $users_array = array();
448
        foreach($users as $user){
449
            array_push($users_array,
450
                    array( "id" => $user->id,
451
                            "name" => $user->firstname.' '.$user->lastname
452
                    )
453
            );
454
        }
455
        return json_encode($users_array);
456
    }
457
}
458
459
function bigbluebuttonbn_get_participant_list($bigbluebuttonbn=null, $context=null){
460
    global $CFG, $USER;
461
462
    $participant_list_array = array();
463
464
    if( $bigbluebuttonbn != null ) {
465
        $participant_list = json_decode($bigbluebuttonbn->participants);
466
        if (is_array($participant_list)) {
467
            foreach($participant_list as $participant){
468
                array_push($participant_list_array,
469
                        array(
470
                            "selectiontype" => $participant->selectiontype,
471
                            "selectionid" => $participant->selectionid,
472
                            "role" => $participant->role
473
                        )
474
                );
475
            }
476
        }
477
    } else {
478
        array_push($participant_list_array,
479
                array(
480
                    "selectiontype" => "all",
481
                    "selectionid" => "all",
482
                    "role" => BIGBLUEBUTTONBN_ROLE_VIEWER
483
                )
484
        );
485
486
        $moderator_defaults = bigbluebuttonbn_get_cfg_moderator_default();
487
        if ( !isset($moderator_defaults) ) {
488
            $moderator_defaults = array('owner');
489
        } else {
490
            $moderator_defaults = explode(',', $moderator_defaults);
491
        }
492
        foreach( $moderator_defaults as $moderator_default ) {
493
            if( $moderator_default == 'owner' ) {
494
                $users = bigbluebuttonbn_get_users($context);
495
                foreach( $users as $user ){
496
                    if( $user->id == $USER->id ){
497
                        array_push($participant_list_array,
498
                                array(
499
                                        "selectiontype" => "user",
500
                                        "selectionid" => $USER->id,
501
                                        "role" => BIGBLUEBUTTONBN_ROLE_MODERATOR
502
                                )
503
                        );
504
                        break;
505
                    }
506
                }
507
            } else {
508
                array_push($participant_list_array,
509
                        array(
510
                                "selectiontype" => "role",
511
                                "selectionid" => $moderator_default,
512
                                "role" => BIGBLUEBUTTONBN_ROLE_MODERATOR
513
                        )
514
                );
515
            }
516
        }
517
    }
518
519
    return $participant_list_array;
520
}
521
522
function bigbluebuttonbn_get_participant_list_json($bigbluebuttonbnid=null){
523
    return json_encode(bigbluebuttonbn_get_participant_list($bigbluebuttonbnid));
524
}
525
526
function bigbluebuttonbn_is_moderator($user, $roles, $participants) {
527
    $participant_list = json_decode($participants);
528
529
    if (is_array($participant_list)) {
530
        // Iterate looking for all configuration
531 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...
532
            if( $participant->selectiontype == 'all' ) {
533
                if ( $participant->role == BIGBLUEBUTTONBN_ROLE_MODERATOR )
534
                    return true;
535
            }
536
        }
537
538
        //Iterate looking for roles
539
        $db_moodle_roles = bigbluebuttonbn_get_db_moodle_roles();
540
        foreach($participant_list as $participant){
541
            if( $participant->selectiontype == 'role' ) {
542
                foreach( $roles as $role ) {
543
                    $db_moodle_role = bigbluebuttonbn_moodle_db_role_lookup($db_moodle_roles, $role->roleid);
544
                    if( $participant->selectionid == $db_moodle_role->shortname ) {
545
                        if ( $participant->role == BIGBLUEBUTTONBN_ROLE_MODERATOR )
546
                            return true;
547
                    }
548
                }
549
            }
550
        }
551
552
        //Iterate looking for users
553 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...
554
            if( $participant->selectiontype == 'user' ) {
555
                if( $participant->selectionid == $user ) {
556
                    if ( $participant->role == BIGBLUEBUTTONBN_ROLE_MODERATOR )
557
                        return true;
558
                }
559
            }
560
        }
561
    }
562
563
    return false;
564
}
565
566
function bigbluebuttonbn_moodle_db_role_lookup($db_moodle_roles, $role_id) {
567
    foreach( $db_moodle_roles as $db_moodle_role ){
568
        if( $role_id ==  $db_moodle_role->id ) {
569
            return $db_moodle_role;
570
        }
571
    }
572
}
573
574
function bigbluebuttonbn_get_error_key($messageKey, $defaultKey = null) {
575
    $key = $defaultKey;
576
    if ( $messageKey == "checksumError" ){
577
        $key = 'index_error_checksum';
578
    } else if ( $messageKey == 'maxConcurrent' ) {
579
        $key = 'view_error_max_concurrent';
580
    }
581
    return $key;
582
}
583
584
function bigbluebuttonbn_voicebridge_unique($voicebridge, $id=null) {
585
    global $DB;
586
587
    $is_unique = true;
588
    if( $voicebridge != 0 ) {
589
        $table = "bigbluebuttonbn";
590
        $select = "voicebridge = ".$voicebridge;
591
        if( $id ) $select .= " AND id <> ".$id;
592
        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...
593
            $is_unique = false;
594
        }
595
    }
596
597
    return $is_unique;
598
}
599
600
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...
601
    global $CFG;
602
603
    $duration = 0;
604
    $now = time();
605
    if( $closingtime > 0 && $now < $closingtime ) {
606
        $duration = ceil(($closingtime - $now)/60);
607
        $compensation_time = intval(bigbluebuttonbn_get_cfg_scheduled_duration_compensation());
608
        $duration = intval($duration) + $compensation_time;
609
    }
610
611
    return $duration;
612
}
613
614
function bigbluebuttonbn_get_presentation_array($context, $presentation, $id=null) {
615
    $presentation_name = null;
616
    $presentation_url = null;
617
    $presentation_icon = null;
618
    $presentation_mimetype_description = null;
619
620
    if( !empty($presentation) ) {
621
        $fs = get_file_storage();
622
        $files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0, 'itemid, filepath, filename', false);
623
        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...
624
            //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...
625
            //die;
626
            //exit;
627
        } else {
628
            $file = reset($files);
629
            unset($files);
630
            $presentation_name = $file->get_filename();
631
            $presentation_icon = file_file_icon($file, 24);
632
            $presentation_mimetype_description = get_mimetype_description($file);
633
634
            if( !is_null($id) ) {
635
                //Create the nonce component for granting a temporary public access
636
                $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache');
637
                $presentation_nonce_key = sha1($id);
638
                $presentation_nonce_value = bigbluebuttonbn_generate_nonce();
639
                $cache->set($presentation_nonce_key, array( "value" => $presentation_nonce_value, "counter" => 0 ));
640
641
                //The item id was adapted for granting public access to the presentation once in order to allow BigBlueButton to gather the file
642
                $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $presentation_nonce_value, $file->get_filepath(), $file->get_filename());
643
            } else {
644
                $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename());
645
            }
646
            $presentation_url = $url->out(false);
647
        }
648
    }
649
650
    $presentation_array = array( "url" => $presentation_url, "name" => $presentation_name, "icon" => $presentation_icon, "mimetype_description" => $presentation_mimetype_description);
651
652
    return $presentation_array;
653
}
654
655
function bigbluebuttonbn_generate_nonce() {
656
657
    $mt = microtime();
658
    $rand = mt_rand();
659
660
    return md5($mt.$rand);
661
}
662
663
function bigbluebuttonbn_random_password( $length = 8 ) {
664
665
    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
666
    $password = substr( str_shuffle( $chars ), 0, $length );
667
668
    return $password;
669
}
670
671
function bigbluebuttonbn_get_moodle_version_major() {
672
    global $CFG;
673
674
    $version_array = explode('.', $CFG->version);
675
    return $version_array[0];
676
}
677
678
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...
679
    $context = context_module::instance($cm->id);
680
    $event_properties = array('context' => $context, 'objectid' => $bigbluebuttonbn->id);
681
682
    switch ($event_type) {
683
        case BIGBLUEBUTTON_EVENT_MEETING_JOINED:
684
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_joined::create($event_properties);
685
            break;
686
        case BIGBLUEBUTTON_EVENT_MEETING_CREATED:
687
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_created::create($event_properties);
688
            break;
689
        case BIGBLUEBUTTON_EVENT_MEETING_ENDED:
690
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_ended::create($event_properties);
691
            break;
692
        case BIGBLUEBUTTON_EVENT_MEETING_LEFT:
693
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_meeting_left::create($event_properties);
694
            break;
695
        case BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED:
696
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_recording_published::create($event_properties);
697
            break;
698
        case BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED:
699
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_recording_unpublished::create($event_properties);
700
            break;
701
        case BIGBLUEBUTTON_EVENT_RECORDING_DELETED:
702
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_recording_deleted::create($event_properties);
703
            break;
704
        case BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED:
705
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_activity_viewed::create($event_properties);
706
            break;
707
        case BIGBLUEBUTTON_EVENT_ACTIVITY_MANAGEMENT_VIEWED:
708
            $event = \mod_bigbluebuttonbn\event\bigbluebuttonbn_activity_management_viewed::create($event_properties);
709
            break;
710
    }
711
712
    $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...
713
}
714
715
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...
716
    global $DB;
717
718
    switch ($event_type) {
719
        case BIGBLUEBUTTON_EVENT_MEETING_JOINED:
720
            $event = 'join';
721
            break;
722
        case BIGBLUEBUTTON_EVENT_MEETING_CREATED:
723
            $event = 'create';
724
            break;
725
        case BIGBLUEBUTTON_EVENT_MEETING_ENDED:
726
            $event = 'end';
727
            break;
728
        case BIGBLUEBUTTON_EVENT_MEETING_LEFT:
729
            $event = 'left';
730
            break;
731
        case BIGBLUEBUTTON_EVENT_RECORDING_PUBLISHED:
732
            $event = 'publish';
733
            break;
734
        case BIGBLUEBUTTON_EVENT_RECORDING_UNPUBLISHED:
735
            $event = 'unpublish';
736
            break;
737
        case BIGBLUEBUTTON_EVENT_RECORDING_DELETED:
738
            $event = 'delete';
739
            break;
740
        case BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED:
741
            $event = 'view';
742
            break;
743
        case BIGBLUEBUTTON_EVENT_ACTIVITY_MANAGEMENT_VIEWED:
744
            $event = 'view all';
745
            break;
746
        default:
747
            return;
748
    }
749
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
750
751
    add_to_log($course->id, 'bigbluebuttonbn', $event, '', $bigbluebuttonbn->name, $cm->id);
752
}
753
754
function bigbluebuttonbn_event_log($event_type, $bigbluebuttonbn, $context, $cm) {
755
    global $CFG;
756
757
    $version_major = bigbluebuttonbn_get_moodle_version_major();
758
    if ( $version_major < '2014051200' ) {
759
        //This is valid before v2.7
760
        bigbluebuttonbn_event_log_legacy($event_type, $bigbluebuttonbn, $context, $cm);
761
762
    } else {
763
        //This is valid after v2.7
764
        bigbluebuttonbn_event_log_standard($event_type, $bigbluebuttonbn, $context, $cm);
765
    }
766
}
767
768
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...
769
    global $CFG;
770
771
    $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...
772
    $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...
773
    $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...
774
    $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...
775
776
    $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...
777
}
778
779
function bigbluebuttonbn_bbb_broker_participant_joined($meetingid, $is_moderator) {
780
    $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache');
781
    $result = $cache->get($meetingid);
782
    $meeting_info = json_decode($result['meeting_info']);
783
    $meeting_info->participantCount += 1;
784
    if( $is_moderator ) {
785
        $meeting_info->moderatorCount += 1;
786
    }
787
    $cache->set($meetingid, array('creation_time' => $result['creation_time'], 'meeting_info' => json_encode($meeting_info) ));
788
}
789
790
function bigbluebuttonbn_bbb_broker_is_meeting_running($meeting_info) {
791
    $meeting_running = ( isset($meeting_info) && isset($meeting_info->returncode) && $meeting_info->returncode == 'SUCCESS' );
792
793
    return $meeting_running;
794
}
795
796
function bigbluebuttonbn_bbb_broker_get_meeting_info($meetingid, $password, $forced=false) {
797
    global $CFG;
798
799
    $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...
800
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
801
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
802
    $cache_ttl = bigbluebuttonbn_get_cfg_waitformoderator_cache_ttl();
803
804
    $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'meetings_cache');
805
    $result = $cache->get($meetingid);
806
    $now = time();
807
    if( isset($result) && $now < ($result['creation_time'] + $cache_ttl) && !$forced ) {
808
        //Use the value in the cache
809
        $meeting_info = json_decode($result['meeting_info']);
810
    } else {
811
        //Ping again and refresh the cache
812
        $meeting_info = (array) bigbluebuttonbn_getMeetingInfo( $meetingid, $password, $endpoint, $shared_secret );
813
        $cache->set($meetingid, array('creation_time' => time(), 'meeting_info' => json_encode($meeting_info) ));
814
    }
815
816
    return $meeting_info;
817
}
818
819
function bigbluebuttonbn_bbb_broker_do_end_meeting($meetingid, $password){
820
    global $CFG;
821
822
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
823
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
824
825
    bigbluebuttonbn_doEndMeeting($meetingid, $password, $endpoint, $shared_secret);
826
}
827
828
function bigbluebuttonbn_bbb_broker_do_publish_recording($recordingid, $publish=true){
829
    global $CFG;
830
831
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
832
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
833
834
    bigbluebuttonbn_doPublishRecordings($recordingid, ($publish)? 'true': 'false', $endpoint, $shared_secret);
835
}
836
837
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...
838
    global $DB;
839
840
    //Locate the record to be updated
841
    $records = $DB->get_records('bigbluebuttonbn_logs', array('bigbluebuttonbnid' => $bigbluebuttonbnID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
842
843
    $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...
844
    foreach ($records as $key => $record) {
845
        $meta = json_decode($record->meta, true);
846
        if( $recordingid == $meta['recording']['recordID'] ) {
847
            // Found, prepare data for the update
848
            $meta['recording']['published'] = ($publish)? 'true': 'false';
849
            $records[$key]->meta = json_encode($meta);
850
851
            // Proceed with the update
852
            $DB->update_record("bigbluebuttonbn_logs", $records[$key]);
853
        }
854
    }
855
}
856
857
function bigbluebuttonbn_bbb_broker_do_delete_recording($recordingid){
858
    global $CFG;
859
860
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
861
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
862
863
    bigbluebuttonbn_doDeleteRecordings($recordingid, $endpoint, $shared_secret);
864
}
865
866
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...
867
    global $DB;
868
869
    //Locate the record to be updated
870
    $records = $DB->get_records('bigbluebuttonbn_logs', array('bigbluebuttonbnid' => $bigbluebuttonbnID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
871
872
    $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...
873
    foreach ($records as $key => $record) {
874
        $meta = json_decode($record->meta, true);
875
        if( $recordingid == $meta['recording']['recordID'] ) {
876
            // Execute delete
877
            $DB->delete_records("bigbluebuttonbn_logs", array('id' => $key));
878
        }
879
    }
880
}
881
882
function bigbluebuttonbn_bbb_broker_validate_parameters($params) {
883
    $error = '';
884
885
    if ( !isset($params['callback']) ) {
886
        $error = $bigbluebuttonbn_bbb_broker_add_error($error, 'This call must include a javascript callback.');
0 ignored issues
show
Bug introduced by
The variable $bigbluebuttonbn_bbb_broker_add_error does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
887
    }
888
889
    if ( !isset($params['action']) ) {
890
        $error = $bigbluebuttonbn_bbb_broker_add_error($error, 'Action parameter must be included.');
891
    } else {
892
        switch ( strtolower($params['action']) ){
893
            case 'server_ping':
894
            case 'meeting_info':
895
            case 'meeting_end':
896
                if ( !isset($params['id']) ) {
897
                    $error = $bigbluebuttonbn_bbb_broker_add_error($error, 'The meetingID must be specified.');
898
                }
899
                break;
900
            case 'recording_list':
901
            case 'recording_info':
902
            case 'recording_publish':
903
            case 'recording_unpublish':
904
            case 'recording_delete':
905
            case 'recording_import':
906
                if ( !isset($params['id']) ) {
907
                    $error = bigbluebuttonbn_bbb_broker_add_error($error, 'The recordingID must be specified.');
908
                }
909
                break;
910
            case 'recording_ready':
911
                if( empty($params['signed_parameters']) ) {
912
                    $error = bigbluebuttonbn_bbb_broker_add_error($error, 'A JWT encoded string must be included as [signed_parameters].');
913
                }
914
                break;
915
            default:
916
                $error = bigbluebuttonbn_bbb_broker_add_error($error, 'Action '.$params['action'].' can not be performed.');
917
        }
918
    }
919
920
    return $error;
921
}
922
923
function bigbluebuttonbn_bbb_broker_add_error($org_msg, $new_msg='') {
924
    $error = $org_msg;
925
926
    if( !empty($new_msg) ) {
927
        if( !empty($error) ) $error .= ' ';
928
        $error .= $new_msg;
929
    }
930
931
    return $error;
932
}
933
934
function bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools=["publishing", "deleting"]) {
935
    global $OUTPUT, $CFG, $USER;
936
937
    $row = null;
938
939
    if ( $bbbsession['managerecordings'] || $recording['published'] == 'true' ) {
940
        $length = 0;
0 ignored issues
show
Unused Code introduced by
$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...
941
        $startTime = isset($recording['startTime'])? floatval($recording['startTime']):0;
942
        $startTime = $startTime - ($startTime % 1000);
943
        $endTime = isset($recording['endTime'])? floatval($recording['endTime']):0;
944
        $endTime = $endTime - ($endTime % 1000);
0 ignored issues
show
Unused Code introduced by
$endTime 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...
945
        $duration = intval(array_values($recording['playbacks'])[0]['length']);
946
947
        //For backward compatibility
948
        if( isset($recording['meta_contextactivity']) ) {
949
            $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...
950
        } if( isset($recording['meta_bbb-recording-name']) ) {
951
            $meta_activity = str_replace('"', '\"', $recording['meta_bbb-recording-name']);
952
        } else {
953
            $meta_activity = str_replace('"', '\"', $recording['meetingName']);
954
        }
955
956
        if( isset($recording['meta_contextactivitydescription']) ) {
957
            $meta_description = str_replace('"', '\"', $recording['meta_contextactivitydescription']);
958
        } else if( isset($recording['meta_bbb-recording-description']) ) {
959
            $meta_description = str_replace('"', '\"', $recording['meta_bbb-recording-description']);
960
        } else {
961
            $meta_description = '';
962
        }
963
964
        //Set recording_types
965
        if ( isset($recording['imported']) ) {
966
            $attributes = 'data-imported="true" title='.get_string('view_recording_link_warning', 'bigbluebuttonbn');
967
        } else {
968
            $attributes = 'data-imported="false"';
969
        }
970
971
        $recording_types = '';
972
        if ($recording['published'] == 'true') {
973
            $recording_types .= '<div id="playbacks-'.$recording['recordID'].'" '.$attributes.'>';
974
        } else {
975
            $recording_types .= '<div id="playbacks-'.$recording['recordID'].'" '.$attributes.'" hidden>';
976
        }
977
        foreach ( $recording['playbacks'] as $playback ) {
978
            $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;';
979
        }
980
        $recording_types .= '</div>';
981
982
        //Initialize variables for styling text
983
        $head = $tail = '';
984
985
        //Set actionbar, if user is allowed to manage recordings
986
        $actionbar = '';
987
        if ( $bbbsession['managerecordings'] ) {
988
            // Set style for imported links
989
            if( isset($recording['imported']) ) {
990
                $recordings_imported_count = 0;
991
                $tag_tail = ' '.get_string('view_recording_link', 'bigbluebuttonbn');
992
                $head = '<i>';
993
                $tail = '</i>';
994
            } else {
995
                $recordings_imported_array = bigbluebuttonbn_getRecordingsImportedAllInstancesArray($recording['recordID']);
996
                $recordings_imported_count = count($recordings_imported_array);
997
                $tag_tail = '';
998
            }
999
1000
            $url = '#';
1001
            $action = null;
1002
1003
            if (in_array("publishing", $tools)) {
1004
                ///Set action [show|hide]
1005
                if ( $recording['published'] == 'true' ){
1006
                    $manage_tag = 'hide';
1007
                    $manage_action = 'unpublish';
1008
                } else {
1009
                    $manage_tag = 'show';
1010
                    $manage_action = 'publish';
1011
                }
1012
                $onclick = 'M.mod_bigbluebuttonbn.broker_manageRecording("'.$manage_action.'", "'.$recording['recordID'].'", "'.$recording['meetingID'].'");';
1013
1014
                if ( bigbluebuttonbn_get_cfg_recording_icons_enabled() ) {
1015
                    //With icon for publish/unpublish
1016
                    $icon_attributes = array('id' => 'recording-btn-'.$manage_action.'-'.$recording['recordID']);
1017
                    $icon = new pix_icon('t/'.$manage_tag, get_string($manage_tag).$tag_tail, 'moodle', $icon_attributes);
1018
                    $link_attributes = array('id' => 'recording-link-'.$manage_action.'-'.$recording['recordID'], 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1019
                    $actionbar .= $OUTPUT->action_icon($url, $icon, $action, $link_attributes, false);
1020
                } else {
1021
                    //With text for publish/unpublish
1022
                    $link_attributes = array('title' => get_string($manage_tag).$tag_tail, 'class' => 'btn btn-xs', 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1023
                    $actionbar .= $OUTPUT->action_link($url, get_string($manage_tag).$tag_tail, $action, $link_attributes);
1024
                    $actionbar .= "&nbsp;";
1025
                }
1026
            }
1027
1028
            if (in_array("deleting", $tools)) {
1029
                $onclick = 'M.mod_bigbluebuttonbn.broker_manageRecording("delete", "'.$recording['recordID'].'", "'.$recording['meetingID'].'");';
1030
1031
                if ( bigbluebuttonbn_get_cfg_recording_icons_enabled() ) {
1032
                    //With icon for delete
1033
                    $icon_attributes = array('id' => 'recording-btn-delete-'.$recording['recordID']);
1034
                    $icon = new pix_icon('t/delete', get_string('delete').$tag_tail, 'moodle', $icon_attributes);
1035
                    $link_attributes = array('id' => 'recording-link-delete-'.$recording['recordID'], 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1036
                    $actionbar .= $OUTPUT->action_icon($url, $icon, $action, $link_attributes, false);
1037
                } else {
1038
                    //With text for delete
1039
                    $link_attributes = array('title' => get_string('delete').$tag_tail, 'class' => 'btn btn-xs btn-danger', 'onclick' => $onclick, 'data-links' => $recordings_imported_count);
1040
                    $actionbar .= $OUTPUT->action_link($url, get_string('delete').$tag_tail, $action, $link_attributes);
1041
                }
1042
            }
1043
1044
            if (in_array("importing", $tools)) {
1045
                $onclick = 'M.mod_bigbluebuttonbn.broker_manageRecording("import", "'.$recording['recordID'].'", "'.$recording['meetingID'].'");';
1046
1047
                if ( bigbluebuttonbn_get_cfg_recording_icons_enabled() ) {
1048
                    //With icon for import
1049
                    $icon_attributes = array('id' => 'recording-btn-import-'.$recording['recordID']);
1050
                    $icon = new pix_icon('i/import', get_string('import'), 'moodle', $icon_attributes);
1051
                    $link_attributes = array('id' => 'recording-link-import-'.$recording['recordID'], 'onclick' => $onclick);
1052
                    $actionbar .= $OUTPUT->action_icon($url, $icon, $action, $link_attributes, false);
1053
                } else {
1054
                    //With text for import
1055
                    $link_attributes = array('title' => get_string('import'), 'class' => 'btn btn-xs btn-danger', 'onclick' => $onclick);
1056
                    $actionbar .= $OUTPUT->action_link($url, get_string('import'), $action, $link_attributes);
1057
                }
1058
            }
1059
        }
1060
1061
        //Set corresponding format
1062
        $format = '%a %h %d, %Y %H:%M:%S %Z';
1063
        $formattedStartDate = userdate($startTime / 1000, $format, usertimezone($USER->timezone));
1064
1065
        $row = new stdClass();
1066
        $row->recording = "{$head}{$recording_types}{$tail}";
1067
        $row->activity = "{$head}{$meta_activity}{$tail}";
1068
        $row->description = "{$head}{$meta_description}{$tail}";
1069
        $row->date = floatval($recording['startTime']);
1070
        $row->date_formatted = "{$head}{$formattedStartDate}{$tail}";
1071
        $row->duration = "{$duration}";
1072
        $row->duration_formatted = "{$head}{$duration}{$tail}";
1073
        if ( $bbbsession['managerecordings'] ) {
1074
            $row->actionbar = $actionbar;
1075
        }
1076
    }
1077
1078
    return $row;
1079
}
1080
1081
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...
1082
    ///Set strings to show
1083
    $view_recording_recording = get_string('view_recording_recording', 'bigbluebuttonbn');
1084
    $view_recording_activity = get_string('view_recording_activity', 'bigbluebuttonbn');
1085
    $view_recording_description = get_string('view_recording_description', 'bigbluebuttonbn');
1086
    $view_recording_date = get_string('view_recording_date', 'bigbluebuttonbn');
1087
    $view_recording_duration = get_string('view_recording_duration', 'bigbluebuttonbn');
1088
    $view_recording_actionbar = get_string('view_recording_actionbar', 'bigbluebuttonbn');
1089
1090
    ///Initialize table headers
1091
    $recordingsbn_columns = array(
1092
        array("key" =>"recording", "label" => $view_recording_recording, "width" => "125px", "allowHTML" => true),
1093
        array("key" =>"activity", "label" => $view_recording_activity, "sortable" => true, "width" => "175px", "allowHTML" => true),
1094
        array("key" =>"description", "label" => $view_recording_description, "sortable" => true, "width" => "250px", "allowHTML" => true),
1095
        array("key" =>"date", "label" => $view_recording_date, "sortable" => true, "width" => "220px", "allowHTML" => true),
1096
        array("key" =>"duration", "label" => $view_recording_duration, "width" => "50px")
1097
        );
1098
1099
    if ( $bbbsession['managerecordings'] ) {
1100
        array_push($recordingsbn_columns, array("key" =>"actionbar", "label" => $view_recording_actionbar, "width" => "75px", "allowHTML" => true));
1101
    }
1102
1103
    return $recordingsbn_columns;
1104
}
1105
1106
function bigbluebuttonbn_get_recording_data($bbbsession, $recordings, $tools=["publishing", "deleting"]) {
1107
    $table_data = array();
1108
1109
    ///Build table content
1110
    if ( isset($recordings) && !array_key_exists('messageKey', $recordings)) {  // There are recordings for this meeting
1111
        foreach ( $recordings as $recording ) {
1112
            $row = bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools);
1113
            if( $row != null ) {
1114
                array_push($table_data, $row);
1115
            }
1116
        }
1117
    }
1118
1119
    return $table_data;
1120
}
1121
1122
function bigbluebuttonbn_get_recording_table($bbbsession, $recordings, $tools=['publishing','deleting']) {
1123
    global $OUTPUT, $CFG;
1124
1125
    ///Set strings to show
1126
    $view_recording_recording = get_string('view_recording_recording', 'bigbluebuttonbn');
1127
    $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...
1128
    $view_recording_activity = get_string('view_recording_activity', 'bigbluebuttonbn');
1129
    $view_recording_description = get_string('view_recording_description', 'bigbluebuttonbn');
1130
    $view_recording_date = get_string('view_recording_date', 'bigbluebuttonbn');
1131
    $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...
1132
    $view_recording_duration = get_string('view_recording_duration', 'bigbluebuttonbn');
1133
    $view_recording_actionbar = get_string('view_recording_actionbar', 'bigbluebuttonbn');
1134
    $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...
1135
1136
    ///Declare the table
1137
    $table = new html_table();
1138
    $table->data = array();
1139
1140
    ///Initialize table headers
1141
    if ( $bbbsession['managerecordings'] ) {
1142
        $table->head  = array ($view_recording_recording, $view_recording_activity, $view_recording_description, $view_recording_date, $view_recording_duration, $view_recording_actionbar);
1143
        $table->align = array ('left', 'left', 'left', 'left', 'center', 'left');
1144
    } else {
1145
        $table->head  = array ($view_recording_recording, $view_recording_activity, $view_recording_description, $view_recording_date, $view_recording_duration);
1146
        $table->align = array ('left', 'left', 'left', 'left', 'center');
1147
    }
1148
1149
    ///Build table content
1150
    if ( isset($recordings) && !array_key_exists('messageKey', $recordings)) {  // There are recordings for this meeting
1151
        foreach ( $recordings as $recording ){
1152
            $row = new html_table_row();
1153
            $row->id = 'recording-td-'.$recording['recordID'];
1154
            if ( isset($recording['imported']) ) {
1155
                $row->attributes['data-imported'] = 'true';
1156
                $row->attributes['title'] = get_string('view_recording_link_warning', 'bigbluebuttonbn');
1157
            } else {
1158
                $row->attributes['data-imported'] = 'false';
1159
            }
1160
1161
            $row_data = bigbluebuttonbn_get_recording_data_row($bbbsession, $recording, $tools);
1162
            if( $row_data != null ) {
1163
                $row_data->date_formatted = str_replace(" ", "&nbsp;", $row_data->date_formatted);
1164
                if ( $bbbsession['managerecordings'] ) {
1165
                    $row->cells = array ($row_data->recording, $row_data->activity, $row_data->description, $row_data->date_formatted, $row_data->duration_formatted, $row_data->actionbar );
1166
                } else {
1167
                    $row->cells = array ($row_data->recording, $row_data->activity, $row_data->description, $row_data->date_formatted, $row_data->duration_formatted );
1168
                }
1169
1170
                array_push($table->data, $row);
1171
            }
1172
        }
1173
    }
1174
1175
    return $table;
1176
}
1177
1178
function bigbluebuttonbn_send_notification_recording_ready($bigbluebuttonbn) {
1179
    $sender = get_admin();
1180
1181
    // Prepare message
1182
    $msg = new stdClass();
1183
1184
    /// Build the message_body
1185
    $msg->activity_type = "";
1186
    $msg->activity_title = $bigbluebuttonbn->name;
1187
    $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>';
1188
1189
    bigbluebuttonbn_send_notification($sender, $bigbluebuttonbn, $message_text);
1190
}
1191
1192
function bigbluebuttonbn_server_offers($capability_name){
1193
    global $CFG;
1194
1195
    $capability_offered = null;
1196
1197
    $endpoint = bigbluebuttonbn_get_cfg_server_url();
1198
    $shared_secret = bigbluebuttonbn_get_cfg_shared_secret();
1199
1200
    //Validates if the server may have extended capabilities
1201
    $parse = parse_url($endpoint);
1202
    $host = $parse['host'];
1203
    $host_ends = explode(".", $host);
1204
    $host_ends_length = count($host_ends);
1205
1206
    if( $host_ends_length > 0 && $host_ends[$host_ends_length -1] == 'com' &&  $host_ends[$host_ends_length -2] == 'blindsidenetworks' ) {
1207
        //Validate the capabilities offered
1208
        $capabilities = bigbluebuttonbn_getCapabilitiesArray( $endpoint, $shared_secret );
1209
        if( $capabilities ) {
1210
            foreach ($capabilities as $capability) {
1211
                if( $capability["name"] == $capability_name)
1212
                    $capability_offered = $capability;
1213
            }
1214
        }
1215
    }
1216
1217
    return $capability_offered;
1218
}
1219
1220
function bigbluebuttonbn_server_offers_bn_capabilities(){
1221
    //Validates if the server may have extended capabilities
1222
    $parsed_url = parse_url(bigbluebuttonbn_get_cfg_server_url());
1223
    $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
1224
    $host_ends = explode(".", $host);
1225
    $host_ends_length = count($host_ends);
1226
1227
    return ( $host_ends_length > 0 && $host_ends[$host_ends_length -1] == 'com' && $host_ends[$host_ends_length -2] == 'blindsidenetworks' );
1228
}
1229
1230
function bigbluebuttonbn_get_locales_for_ui() {
1231
    $locales = array(
1232
            'not_started' => get_string('view_message_conference_not_started', 'bigbluebuttonbn'),
1233
            'wait_for_moderator' => get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn'),
1234
            'in_progress' => get_string('view_message_conference_in_progress', 'bigbluebuttonbn'),
1235
            'started_at' => get_string('view_message_session_started_at', 'bigbluebuttonbn'),
1236
            'session_no_users' => get_string('view_message_session_no_users', 'bigbluebuttonbn'),
1237
            'session_has_user' => get_string('view_message_session_has_user', 'bigbluebuttonbn'),
1238
            'session_has_users' => get_string('view_message_session_has_users', 'bigbluebuttonbn'),
1239
            'has_joined' => get_string('view_message_has_joined', 'bigbluebuttonbn'),
1240
            'have_joined' => get_string('view_message_have_joined', 'bigbluebuttonbn'),
1241
            'user' => get_string('view_message_user', 'bigbluebuttonbn'),
1242
            'users' => get_string('view_message_users', 'bigbluebuttonbn'),
1243
            'viewer' => get_string('view_message_viewer', 'bigbluebuttonbn'),
1244
            'viewers' => get_string('view_message_viewers', 'bigbluebuttonbn'),
1245
            'moderator' => get_string('view_message_moderator', 'bigbluebuttonbn'),
1246
            'moderators' => get_string('view_message_moderators', 'bigbluebuttonbn'),
1247
            'publish' => get_string('view_recording_list_actionbar_publish', 'bigbluebuttonbn'),
1248
            'publishing' => get_string('view_recording_list_actionbar_publishing', 'bigbluebuttonbn'),
1249
            'unpublish' => get_string('view_recording_list_actionbar_unpublish', 'bigbluebuttonbn'),
1250
            'unpublishing' => get_string('view_recording_list_actionbar_unpublishing', 'bigbluebuttonbn'),
1251
            'modal_title' => get_string('view_recording_modal_title', 'bigbluebuttonbn'),
1252
            'modal_button' => get_string('view_recording_modal_button', 'bigbluebuttonbn'),
1253
            'userlimit_reached' => get_string('view_error_userlimit_reached', 'bigbluebuttonbn'),
1254
            'recording' => get_string('view_recording', 'bigbluebuttonbn'),
1255
            'recording_link' => get_string('view_recording_link', 'bigbluebuttonbn'),
1256
            'recording_link_warning' => get_string('view_recording_link_warning', 'bigbluebuttonbn'),
1257
            'unpublish_confirmation' => get_string('view_recording_unpublish_confirmation', 'bigbluebuttonbn'),
1258
            'unpublish_confirmation_warning_s' => get_string('view_recording_unpublish_confirmation_warning_s', 'bigbluebuttonbn'),
1259
            'unpublish_confirmation_warning_p' => get_string('view_recording_unpublish_confirmation_warning_p', 'bigbluebuttonbn'),
1260
            'delete_confirmation' => get_string('view_recording_delete_confirmation', 'bigbluebuttonbn'),
1261
            'delete_confirmation_warning_s' => get_string('view_recording_delete_confirmation_warning_s', 'bigbluebuttonbn'),
1262
            'delete_confirmation_warning_p' => get_string('view_recording_delete_confirmation_warning_p', 'bigbluebuttonbn'),
1263
            'import_confirmation' => get_string('view_recording_import_confirmation', 'bigbluebuttonbn'),
1264
    );
1265
    return $locales;
1266
}
1267
1268
function bigbluebuttonbn_get_cfg_server_url_default() {
1269
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1270
    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/')));
1271
}
1272
1273
function bigbluebuttonbn_get_cfg_shared_secret_default() {
1274
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1275
    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')));
1276
}
1277
1278
function bigbluebuttonbn_get_cfg_voicebridge_editable() {
1279
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1280
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_voicebridge_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_voicebridge_editable: (isset($CFG->bigbluebuttonbn_voicebridge_editable)? $CFG->bigbluebuttonbn_voicebridge_editable: false));
1281
}
1282
1283
function bigbluebuttonbn_get_cfg_recording_default() {
1284
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1285
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_default: (isset($CFG->bigbluebuttonbn_recording_default)? $CFG->bigbluebuttonbn_recording_default: true));
1286
}
1287
1288
function bigbluebuttonbn_get_cfg_recording_editable() {
1289
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1290
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recording_editable: (isset($CFG->bigbluebuttonbn_recording_editable)? $CFG->bigbluebuttonbn_recording_editable: true));
1291
}
1292
1293
function bigbluebuttonbn_get_cfg_recording_tagging_default() {
1294
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1295
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_default: (isset($CFG->bigbluebuttonbn_recordingtagging_default)? $CFG->bigbluebuttonbn_recordingtagging_default: false));
1296
}
1297
1298
function bigbluebuttonbn_get_cfg_recording_tagging_editable() {
1299
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1300
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingtagging_editable: (isset($CFG->bigbluebuttonbn_recordingtagging_editable)? $CFG->bigbluebuttonbn_recordingtagging_editable: false));
1301
}
1302
1303
function bigbluebuttonbn_get_cfg_recording_icons_enabled() {
1304
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1305
    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));
1306
}
1307
1308
function bigbluebuttonbn_get_cfg_importrecordings_enabled() {
1309
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1310
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_importrecordings_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_importrecordings_enabled: (isset($CFG->bigbluebuttonbn_importrecordings_enabled)? $CFG->bigbluebuttonbn_importrecordings_enabled: false));
1311
}
1312
1313
function bigbluebuttonbn_get_cfg_importrecordings_from_deleted_activities_enabled() {
1314
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1315
    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));
1316
}
1317
1318
function bigbluebuttonbn_get_cfg_waitformoderator_default() {
1319
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1320
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_default: (isset($CFG->bigbluebuttonbn_waitformoderator_default)? $CFG->bigbluebuttonbn_waitformoderator_default: false));
1321
}
1322
1323
function bigbluebuttonbn_get_cfg_waitformoderator_editable() {
1324
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1325
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_waitformoderator_editable: (isset($CFG->bigbluebuttonbn_waitformoderator_editable)? $CFG->bigbluebuttonbn_waitformoderator_editable: true));
1326
}
1327
1328
function bigbluebuttonbn_get_cfg_waitformoderator_ping_interval() {
1329
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1330
    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));
1331
}
1332
1333
function bigbluebuttonbn_get_cfg_waitformoderator_cache_ttl() {
1334
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1335
    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));
1336
}
1337
1338
function bigbluebuttonbn_get_cfg_userlimit_default() {
1339
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1340
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_default: (isset($CFG->bigbluebuttonbn_userlimit_default)? $CFG->bigbluebuttonbn_userlimit_default: 0));
1341
}
1342
1343
function bigbluebuttonbn_get_cfg_userlimit_editable() {
1344
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1345
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_editable)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_userlimit_editable: (isset($CFG->bigbluebuttonbn_userlimit_editable)? $CFG->bigbluebuttonbn_userlimit_editable: false));
1346
}
1347
1348
function bigbluebuttonbn_get_cfg_preuploadpresentation_enabled() {
1349
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1350
    if (extension_loaded('curl')) {
1351
        // This feature only works if curl is installed
1352
        return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_preuploadpresentation_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_preuploadpresentation_enabled: (isset($CFG->bigbluebuttonbn_preuploadpresentation_enabled)? $CFG->bigbluebuttonbn_preuploadpresentation_enabled: false));
1353
    } else {
1354
        return false;
1355
    }
1356
}
1357
1358
function bigbluebuttonbn_get_cfg_sendnotifications_enabled() {
1359
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1360
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_sendnotifications_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_sendnotifications_enabled: (isset($CFG->bigbluebuttonbn_sendnotifications_enabled)? $CFG->bigbluebuttonbn_sendnotifications_enabled: false));
1361
}
1362
1363
function bigbluebuttonbn_get_cfg_recordingready_enabled() {
1364
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1365
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingready_enabled)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_recordingready_enabled: (isset($CFG->bigbluebuttonbn_recordingready_enabled)? $CFG->bigbluebuttonbn_recordingready_enabled: false));
1366
}
1367
1368
function bigbluebuttonbn_get_cfg_moderator_default() {
1369
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1370
    return (isset($BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_moderator_default)? $BIGBLUEBUTTONBN_CFG->bigbluebuttonbn_moderator_default: (isset($CFG->bigbluebuttonbn_moderator_default)? $CFG->bigbluebuttonbn_moderator_default: 'owner'));
1371
}
1372
1373
function bigbluebuttonbn_get_cfg_scheduled_duration_enabled() {
1374
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1375
    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));
1376
}
1377
1378
function bigbluebuttonbn_get_cfg_scheduled_duration_compensation() {
1379
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1380
    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));
1381
}
1382
1383
function bigbluebuttonbn_get_cfg_scheduled_pre_opening() {
1384
    global $BIGBLUEBUTTONBN_CFG, $CFG;
1385
    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));
1386
}
1387
1388
function bigbluebuttonbn_import_get_courses_for_select(array $bbbsession) {
1389
1390
    if( $bbbsession['administrator'] ) {
1391
        $courses = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.fullname');
1392
        //It includes the name of the site as a course (category 0), so remove the first one
1393
        unset($courses["1"]);
1394
    } else {
1395
        $courses = enrol_get_users_courses($bbbsession['userID'], false, 'id,shortname,fullname');
1396
    }
1397
1398
    $courses_for_select = [];
1399
    foreach($courses as $course) {
1400
        if( $course->id != $bbbsession['course']->id ) {
1401
            $courses_for_select[$course->id] = $course->fullname;
1402
        }
1403
    }
1404
    return $courses_for_select;
1405
}
1406
1407
function bigbluebuttonbn_getRecordedMeetingsDeleted($courseID, $bigbluebuttonbnID=NULL) {
1408
    global $DB;
1409
1410
    $records_deleted = array();
1411
1412
    $filter = array('courseid' => $courseID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_DELETE );
1413
    if ( $bigbluebuttonbnID != NULL ) {
1414
        $filter['id'] = $bigbluebuttonbnID;
1415
    }
1416
1417
    $bigbluebuttonbns_deleted = $DB->get_records('bigbluebuttonbn_logs', $filter);
1418
1419
    foreach ($bigbluebuttonbns_deleted as $key => $bigbluebuttonbn_deleted) {
1420
        $records = $DB->get_records('bigbluebuttonbn_logs', array('courseid' => $courseID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_CREATE));
1421
1422
        if( !empty($records) ) {
1423
            //Remove duplicates
1424
            $unique_records = array();
1425
            foreach ($records as $key => $record) {
1426
                if (array_key_exists($record->meetingid, $unique_records) ) {
1427
                    unset($records[$key]);
1428
                } else {
1429
                    $meta = json_decode($record->meta);
1430
                    if ( !$meta->record ) {
1431
                        unset($records[$key]);
1432
                    } else if ( $bigbluebuttonbn_deleted->meetingid != substr($record->meetingid, 0, strlen($bigbluebuttonbn_deleted->meetingid))) {
1433
                        unset($records[$key]);
1434
                    } else {
1435
                        array_push($unique_records, $record->meetingid);
1436
                    }
1437
                }
1438
            }
1439
1440
            $records_deleted = array_merge($records_deleted, $records);
1441
        }
1442
    }
1443
1444
    return $records_deleted;
1445
}
1446
1447
function bigbluebuttonbn_getRecordedMeetings($courseID, $bigbluebuttonbnID=NULL) {
1448
    global $DB;
1449
1450
    $records = Array();
1451
1452
    $filter = array('course' => $courseID);
1453
    if ( $bigbluebuttonbnID != NULL ) {
1454
        $filter['id'] = $bigbluebuttonbnID;
1455
    }
1456
    $bigbluebuttonbns = $DB->get_records('bigbluebuttonbn', $filter);
1457
1458
    if ( !empty($bigbluebuttonbns) ) {
1459
        $table = 'bigbluebuttonbn_logs';
1460
1461
        //Prepare select for loading records based on existent bigbluebuttonbns
1462
        $select = "";
1463
        foreach ($bigbluebuttonbns as $key => $bigbluebuttonbn) {
1464
            $select .= strlen($select) == 0? "(": " OR ";
1465
            $select .= "bigbluebuttonbnid=".$bigbluebuttonbn->id;
1466
        }
1467
        $select .= ") AND log='".BIGBLUEBUTTONBN_LOG_EVENT_CREATE."'";
1468
1469
        //Execute select for loading records based on existent bigbluebuttonbns
1470
        $records = $DB->get_records_select($table, $select);
1471
1472
        //Remove duplicates
1473
        $unique_records = array();
1474
        foreach ($records as $key => $record) {
1475
            $record_key = $record->meetingid.','.$record->bigbluebuttonbnid.','.$record->meta;
1476
            if( array_search($record_key, $unique_records) === false ) {
1477
                array_push($unique_records, $record_key);
1478
            } else {
1479
                unset($records[$key]);
1480
            }
1481
        }
1482
1483
        //Remove the ones with record=false
1484
        foreach ($records as $key => $record) {
1485
            $meta = json_decode($record->meta);
1486
            if ( !$meta || !$meta->record ) {
1487
                unset($records[$key]);
1488
            }
1489
        }
1490
    }
1491
1492
    return $records;
1493
}
1494
1495
function bigbluebuttonbn_getRecordingsArrayByCourse($courseID, $URL, $SALT) {
1496
    $recordings = array();
1497
1498
    // Load the meetingIDs to be used in the getRecordings request
1499
    $meetingID = '';
1500
    if ( is_numeric($courseID) ) {
1501
        $results = bigbluebuttonbn_getRecordedMeetings($courseID);
1502
1503
        if( bigbluebuttonbn_get_cfg_importrecordings_from_deleted_activities_enabled() ) {
1504
            $results_deleted = bigbluebuttonbn_getRecordedMeetingsDeleted($courseID);
1505
            $results = array_merge($results, $results_deleted);
1506
        }
1507
1508 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...
1509
            //Eliminates duplicates
1510
            $mIDs = array();
1511
            foreach ($results as $result) {
1512
                $mIDs[$result->meetingid] = $result->meetingid;
1513
            }
1514
            //Generates the meetingID string
1515
            foreach ($mIDs as $mID) {
1516
                if (strlen($meetingID) > 0) $meetingID .= ',';
1517
                $meetingID .= $mID;
1518
            }
1519
        }
1520
    }
1521
1522
    // If there were meetingIDs excecute the getRecordings request
1523
    if ( $meetingID != '' ) {
1524
        $recordings = bigbluebuttonbn_getRecordingsArray($meetingID, $URL, $SALT);
1525
    }
1526
1527
    return $recordings;
1528
}
1529
1530
function bigbluebuttonbn_import_get_recordings_imported($records) {
1531
    $recordings_imported = array();
1532
1533
    foreach ($records as $key => $record) {
1534
        $meta = json_decode($record->meta, true);
1535
        $recordings_imported[] = $meta['recording'];
1536
    }
1537
1538
    return $recordings_imported;
1539
}
1540
1541
function bigbluebuttonbn_import_exlcude_recordings_already_imported($courseID, $bigbluebuttonbnID, $recordings) {
1542
    $recordings_already_imported = bigbluebuttonbn_getRecordingsImportedArray($courseID, $bigbluebuttonbnID);
1543
    $recordings_already_imported_indexed = bigbluebuttonbn_index_recordings($recordings_already_imported);
1544
1545
    foreach ($recordings as $key => $recording) {
1546
        if( isset($recordings_already_imported_indexed[$recording['recordID']]) ) {
1547
            unset($recordings[$key]);
1548
        }
1549
    }
1550
    return $recordings;
1551
}
1552
1553
function bigbluebutton_output_recording_table($bbbsession, $recordings, $tools=['publishing','deleting']) {
1554
1555
    if ( isset($recordings) && !empty($recordings) ) {  // There are recordings for this meeting
1556
        $table = bigbluebuttonbn_get_recording_table($bbbsession, $recordings, $tools);
1557
    }
1558
1559
    $output = '';
1560
    if( isset($table->data) ) {
1561
        //Print the table
1562
        $output .= '<div id="bigbluebuttonbn_html_table">'."\n";
1563
        $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...
1564
        $output .= '</div>'."\n";
1565
1566
    } else {
1567
        $output .= get_string('view_message_norecordings', 'bigbluebuttonbn').'<br>'."\n";
1568
    }
1569
1570
    return $output;
1571
}
1572
1573
function bigbluebuttonbn_getRecordingsImported($courseID, $bigbluebuttonbnID=NULL) {
1574
    global $DB;
1575
1576
    if ( $bigbluebuttonbnID != NULL ) {
1577
        // Fetch only those related to the $courseID and $bigbluebuttonbnID requested
1578
        $recordings_imported = $DB->get_records('bigbluebuttonbn_logs', array('courseid' => $courseID, 'bigbluebuttonbnid' => $bigbluebuttonbnID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
1579
    } else {
1580
        // Fetch all the ones corresponding to the $courseID requested
1581
        $recordings_imported = $DB->get_records('bigbluebuttonbn_logs', array('courseid' => $courseID, 'log' => BIGBLUEBUTTONBN_LOG_EVENT_IMPORT));
1582
    }
1583
    return $recordings_imported;
1584
}
1585
1586
function bigbluebuttonbn_getRecordingsImportedArray($courseID, $bigbluebuttonbnID=NULL) {
1587
    $recordings_imported = bigbluebuttonbn_getRecordingsImported($courseID, $bigbluebuttonbnID);
1588
    $recordings_imported_array = bigbluebuttonbn_import_get_recordings_imported($recordings_imported);
1589
    return $recordings_imported_array;
1590
}
1591
1592
function bigbluebuttonbn_getRecordingsImportedAllInstances($recordID) {
1593
    global $DB, $CFG;
1594
1595
    $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.'%' ));
1596
    return $recordings_imported;
1597
}
1598
1599
function bigbluebuttonbn_getRecordingsImportedAllInstancesArray($recordID) {
1600
    $recordings_imported = bigbluebuttonbn_getRecordingsImportedAllInstances($recordID);
1601
    $recordings_imported_array = bigbluebuttonbn_import_get_recordings_imported($recordings_imported);
1602
    return $recordings_imported_array;
1603
}
1604
1605
function bigbluebuttonbn_debugdisplay() {
1606
    global $CFG;
1607
1608
    return (bool)$CFG->debugdisplay;
1609
}
1610
1611
function bigbluebuttonbn_html2text($html, $len) {
1612
    $text = strip_tags($html);
1613
    $text = str_replace("&nbsp;", ' ', $text);
1614
    if( strlen($text) > $len )
1615
        $text = substr($text, 0, $len)."...";
1616
    else
1617
        $text = substr($text, 0, $len);
1618
    return $text;
1619
}