Completed
Push — master ( 63aa89...ef28c1 )
by Jesus
02:13
created

view.php ➔ bigbluebuttonbn_view_after()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
File has mixed line endings; this may cause incorrect results
Loading history...
2
/**
3
 * View a BigBlueButton room
4
 *
5
 * @package   mod_bigbluebuttonbn
6
 * @author    Fred Dixon  (ffdixon [at] blindsidenetworks [dt] com)
7
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
8
 * @copyright 2010-2015 Blindside Networks Inc.
9
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v2 or later
10
 */
11
12
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
13
require_once(dirname(__FILE__).'/locallib.php');
14
15
$id = required_param('id', PARAM_INT);              // Course Module ID, or
16
$b  = optional_param('n', 0, PARAM_INT);            // bigbluebuttonbn instance ID
17
$group  = optional_param('group', 0, PARAM_INT);    // group instance ID
18
19 View Code Duplication
if ($id) {
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...
20
    $cm = get_coursemodule_from_id('bigbluebuttonbn', $id, 0, false, MUST_EXIST);
21
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
22
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $cm->instance), '*', MUST_EXIST);
23
} elseif ($b) {
24
    $bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $b), '*', MUST_EXIST);
25
    $course = $DB->get_record('course', array('id' => $bigbluebuttonbn->course), '*', MUST_EXIST);
26
    $cm = get_coursemodule_from_instance('bigbluebuttonbn', $bigbluebuttonbn->id, $course->id, false, MUST_EXIST);
27
} else {
28
    print_error(get_string('view_error_url_missing_parameters', 'bigbluebuttonbn'));
29
}
30
31
require_login($course, true, $cm);
32
33
$version_major = bigbluebuttonbn_get_moodle_version_major();
34
if ( $version_major < '2013111800' ) {
35
    //This is valid before v2.6
36
    $module = $DB->get_record('modules', array('name' => 'bigbluebuttonbn'));
37
    $module_version = $module->version;
38
} else {
39
    //This is valid after v2.6
40
    $module_version = get_config('mod_bigbluebuttonbn', 'version');
41
}
42
$context = bigbluebuttonbn_get_context_module($cm->id);
43
44
45
bigbluebuttonbn_event_log(BIGBLUEBUTTON_EVENT_ACTIVITY_VIEWED, $bigbluebuttonbn, $context, $cm);
46
47
////////////////////////////////////////////////
48
/////  BigBlueButton Session Setup Starts  /////
49
////////////////////////////////////////////////
50
// BigBluebuttonBN activity data
51
$bbbsession['bigbluebuttonbn'] = $bigbluebuttonbn;
52
53
// User data
54
$bbbsession['username'] = fullname($USER);
55
$bbbsession['userID'] = $USER->id;
56
$bbbsession['roles'] = get_user_roles($context, $USER->id, true);
57
58
// User roles
59
if( $bigbluebuttonbn->participants == null || $bigbluebuttonbn->participants == "" || $bigbluebuttonbn->participants == "[]" ){
60
    //The room that is being used comes from a previous version
61
    $bbbsession['moderator'] = has_capability('mod/bigbluebuttonbn:moderate', $context);
62
} else {
63
    $bbbsession['moderator'] = bigbluebuttonbn_is_moderator($bbbsession['userID'], $bbbsession['roles'], $bigbluebuttonbn->participants);
64
}
65
$bbbsession['administrator'] = has_capability('moodle/category:manage', $context);
66
$bbbsession['managerecordings'] = ($bbbsession['administrator'] || has_capability('mod/bigbluebuttonbn:managerecordings', $context));
67
68
// BigBlueButton server data
69
$bbbsession['endpoint'] = bigbluebuttonbn_get_cfg_server_url();
70
$bbbsession['shared_secret'] = bigbluebuttonbn_get_cfg_shared_secret();
71
72
// Server data
73
$bbbsession['modPW'] = $bigbluebuttonbn->moderatorpass;
74
$bbbsession['viewerPW'] = $bigbluebuttonbn->viewerpass;
75
76
// Database info related to the activity
77
$bbbsession['meetingdescription'] = $bigbluebuttonbn->intro;
78
$bbbsession['welcome'] = $bigbluebuttonbn->welcome;
79
if( !isset($bbbsession['welcome']) || $bbbsession['welcome'] == '') {
80
    $bbbsession['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn');
81
}
82
83
$bbbsession['userlimit'] = bigbluebuttonbn_get_cfg_userlimit_editable()? intval($bigbluebuttonbn->userlimit): intval(bigbluebuttonbn_get_cfg_userlimit_default());
84
$bbbsession['voicebridge'] = ($bigbluebuttonbn->voicebridge > 0)? 70000 + $bigbluebuttonbn->voicebridge: $bigbluebuttonbn->voicebridge;
85
$bbbsession['wait'] = $bigbluebuttonbn->wait;
86
$bbbsession['record'] = $bigbluebuttonbn->record;
87
if( $bigbluebuttonbn->record )
88
    $bbbsession['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn');
89
$bbbsession['tagging'] = $bigbluebuttonbn->tagging;
90
91
$bbbsession['openingtime'] = $bigbluebuttonbn->openingtime;
92
$bbbsession['closingtime'] = $bigbluebuttonbn->closingtime;
93
94
// Additional info related to the course
95
$bbbsession['course'] = $course;
96
$bbbsession['coursename'] = $course->fullname;
97
$bbbsession['cm'] = $cm;
98
$bbbsession['context'] = $context;
99
100
// Metadata (origin)
101
$bbbsession['origin'] = "Moodle";
102
$bbbsession['originVersion'] = $CFG->release;
103
$parsedUrl = parse_url($CFG->wwwroot);
104
$bbbsession['originServerName'] = $parsedUrl['host'];
105
$bbbsession['originServerUrl'] = $CFG->wwwroot;
106
$bbbsession['originServerCommonName'] = '';
107
$bbbsession['originTag'] = 'moodle-mod_bigbluebuttonbn ('.$module_version.')';
108
////////////////////////////////////////////////
109
/////   BigBlueButton Session Setup Ends   /////
110
////////////////////////////////////////////////
111
112
// Validates if the BigBlueButton server is running
113
$serverVersion = bigbluebuttonbn_getServerVersion($bbbsession['endpoint']);
114
if ( !isset($serverVersion) ) { //Server is not working
115 View Code Duplication
    if ( $bbbsession['administrator'] )
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...
116
        print_error( 'view_error_unable_join', 'bigbluebuttonbn', $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn' );
117
    else if ( $bbbsession['moderator'] )
118
        print_error( 'view_error_unable_join_teacher', 'bigbluebuttonbn', $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course );
119
    else
120
        print_error( 'view_error_unable_join_student', 'bigbluebuttonbn', $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course );
121
} else {
122
    $xml = bigbluebuttonbn_wrap_xml_load_file( bigbluebuttonbn_getMeetingsURL( $bbbsession['endpoint'], $bbbsession['shared_secret'] ) );
123
    if ( !isset($xml) || !isset($xml->returncode) || $xml->returncode == 'FAILED' ){ // The shared secret is wrong
124 View Code Duplication
        if ( $bbbsession['administrator'] )
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...
125
            print_error( 'view_error_unable_join', 'bigbluebuttonbn', $CFG->wwwroot.'/admin/settings.php?section=modsettingbigbluebuttonbn' );
126
        else if ( $bbbsession['moderator'] )
127
            print_error( 'view_error_unable_join_teacher', 'bigbluebuttonbn', $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course );
128
        else
129
            print_error( 'view_error_unable_join_student', 'bigbluebuttonbn', $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course );
130
    }
131
}
132
133
// Mark viewed by user (if required)
134
$completion = new completion_info($course);
135
$completion->set_module_viewed($cm);
136
137
// Print the page header
138
$PAGE->set_context($context);
139
$PAGE->set_url($CFG->wwwroot.'/mod/bigbluebuttonbn/view.php', array('id' => $cm->id));
140
$PAGE->set_title(format_string($bigbluebuttonbn->name));
141
$PAGE->set_cacheable(false);
142
$PAGE->set_heading($course->fullname);
143
144
if( $bigbluebuttonbn->newwindow == 1 ) {
145
    $PAGE->blocks->show_only_fake_blocks();
146
147
} else {
148
    $PAGE->set_pagelayout('incourse');
149
}
150
151
// Validate if the user is in a role allowed to join
152
if ( !has_capability('moodle/category:manage', $context) && !has_capability('mod/bigbluebuttonbn:join', $context) ) {
153
    echo $OUTPUT->header();
154
    if (isguestuser()) {
155
        echo $OUTPUT->confirm('<p>'.get_string('view_noguests', 'bigbluebuttonbn').'</p>'.get_string('liketologin'),
156
            get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
157
    } else {
158
        echo $OUTPUT->confirm('<p>'.get_string('view_nojoin', 'bigbluebuttonbn').'</p>'.get_string('liketologin'),
159
            get_login_url(), $CFG->wwwroot.'/course/view.php?id='.$course->id);
160
    }
161
162
    echo $OUTPUT->footer();
163
    exit;
164
}
165
166
// Operation URLs
167
$bbbsession['courseURL'] = $CFG->wwwroot.'/course/view.php?id='.$bigbluebuttonbn->course;
168
$bbbsession['logoutURL'] = $CFG->wwwroot.'/mod/bigbluebuttonbn/bbb_view.php?action=logout&id='.$id.'&bn='.$bbbsession['bigbluebuttonbn']->id;
169
$bbbsession['recordingReadyURL'] = $CFG->wwwroot.'/mod/bigbluebuttonbn/bbb_broker.php?action=recording_ready';
170
$bbbsession['joinURL'] = $CFG->wwwroot.'/mod/bigbluebuttonbn/bbb_view.php?action=join&id='.$id.'&bigbluebuttonbn='.$bbbsession['bigbluebuttonbn']->id;
171
172
// Output starts here
173
echo $OUTPUT->header();
174
175
/// find out current groups mode
176
$groupmode = groups_get_activity_groupmode($bbbsession['cm']);
177
if ($groupmode == NOGROUPS ) {  //No groups mode
178
    $bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid.'-'.$bbbsession['course']->id.'-'.$bbbsession['bigbluebuttonbn']->id;
179
    $bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name;
180
181
} else {                                        // Separate or visible groups mode
182
    echo $OUTPUT->box_start('generalbox boxaligncenter');
183
    echo '<br><div class="alert alert-warning">'.get_string('view_groups_selection_warning', 'bigbluebuttonbn').'</div>';
184
    echo $OUTPUT->box_end();
185
186
    $bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
187
    if ($groupmode == SEPARATEGROUPS ) {
188
        groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id, false, true);
189
        if( $bbbsession['group'] == 0 ) {
190
            if ( $bbbsession['administrator'] ) {
191
                $my_groups = groups_get_all_groups($bbbsession['course']->id);
192
            } else {
193
                $my_groups = groups_get_activity_allowed_groups($bbbsession['cm']);
194
            }
195
            $current_group = current($my_groups);
196
            $bbbsession['group'] = $current_group->id;
197
        }
198
199
    } else {
200
        groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id);
201
    }
202
203
    $bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid.'-'.$bbbsession['course']->id.'-'.$bbbsession['bigbluebuttonbn']->id.'['.$bbbsession['group'].']';
204
    if( $bbbsession['group'] > 0 )
205
        $group_name = groups_get_group_name($bbbsession['group']);
206
    else
207
        $group_name = get_string('allparticipants');
208
    $bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name.' ('.$group_name.')';
209
}
210
// Metadata (context)
211
$bbbsession['contextActivityName'] = $bbbsession['meetingname'];
212
$bbbsession['contextActivityDescription'] = bigbluebuttonbn_html2text($bbbsession['meetingdescription'], 64);
213
$bbbsession['contextActivityTags'] = "";
214
215
$bigbluebuttonbn_activity = 'open';
216
$now = time();
217
if (!empty($bigbluebuttonbn->openingtime) && $now < $bigbluebuttonbn->openingtime ) {
218
    //ACTIVITY HAS NOT BEEN OPENED
219
    $bigbluebuttonbn_activity = 'not_started';
220
221
} else if (!empty($bigbluebuttonbn->closingtime) && $now > $bigbluebuttonbn->closingtime) {
222
    //ACTIVITY HAS BEEN CLOSED
223
    $bigbluebuttonbn_activity = 'ended';
224
    $bbbsession['presentation'] = bigbluebuttonbn_get_presentation_array($context, $bigbluebuttonbn->presentation);
225
226
} else {
227
    //ACTIVITY OPEN
228
    $bbbsession['presentation'] = bigbluebuttonbn_get_presentation_array($bbbsession['context'], $bigbluebuttonbn->presentation, $bigbluebuttonbn->id);
229
}
230
231
// Initialize session variable used across views
232
$SESSION->bigbluebuttonbn_bbbsession = $bbbsession;
233
bigbluebuttonbn_view($bbbsession, $bigbluebuttonbn_activity);
234
235
//JavaScript variables
236
$waitformoderator_ping_interval = bigbluebuttonbn_get_cfg_waitformoderator_ping_interval();
237
$jsVars = array(
238
    'activity' => $bigbluebuttonbn_activity,
239
    'meetingid' => $bbbsession['meetingid'],
240
    'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
241
    'ping_interval' => ($waitformoderator_ping_interval > 0? $waitformoderator_ping_interval * 1000: 15000),
242
    'userlimit' => $bbbsession['userlimit'],
243
    'locales' => bigbluebuttonbn_get_locales_for_ui(),
244
    'opening' => ($bbbsession['openingtime'])? get_string('mod_form_field_openingtime','bigbluebuttonbn').': '.userdate($bbbsession['openingtime']) : '',
245
    'closing' => ($bbbsession['closingtime'])? get_string('mod_form_field_closingtime','bigbluebuttonbn').': '.userdate($bbbsession['closingtime']) : ''
246
);
247
248
$PAGE->requires->data_for_js('bigbluebuttonbn', $jsVars);
249
250
$jsmodule = array(
251
    'name'     => 'mod_bigbluebuttonbn',
252
    'fullpath' => '/mod/bigbluebuttonbn/module.js',
253
    'requires' => array('datasource-get', 'datasource-jsonschema', 'datasource-polling'),
254
);
255
$PAGE->requires->js_init_call('M.mod_bigbluebuttonbn.view_init', array(), false, $jsmodule);
256
257
258
// Finish the page
259
echo $OUTPUT->footer();
260
261
function bigbluebuttonbn_view($bbbsession, $activity) {
262
    global $CFG, $DB, $OUTPUT;
263
264
    echo $OUTPUT->heading($bbbsession['meetingname'], 3);
265
    echo $OUTPUT->heading($bbbsession['meetingdescription'], 5);
266
    echo $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
267
    echo '<br><span id="status_bar"></span><br>';
268
    echo '<span id="control_panel"></span>';
269
    echo $OUTPUT->box_end();
270
271
    echo $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
272
    echo '<br><br><span id="join_button"></span>&nbsp;<span id="end_button"></span>'."\n";
273
    echo $OUTPUT->box_end();
274
275
    if ( $activity == 'not_started' ) {
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...
276
        // Do nothing
277
    } else {
278
        if ( $activity == 'ended' ) {
279
            bigbluebuttonbn_view_ended($bbbsession);
280
        } else {
281
            bigbluebuttonbn_view_joining($bbbsession);
282
        }
283
284
        bigbluebuttonbn_view_recordings($bbbsession);
285
    }
286
}
287
288
function bigbluebuttonbn_view_joining($bbbsession) {
289
290
    if( $bbbsession['tagging'] && ($bbbsession['administrator'] || $bbbsession['moderator']) ){
291
        echo ''.
292
          '<div id="panelContent" class="hidden">'."\n".
293
          '  <div class="yui3-widget-bd">'."\n".
294
          '    <form>'."\n".
295
          '      <fieldset>'."\n".
296
          '        <input type="hidden" name="join" id="meeting_join_url" value="">'."\n".
297
          '        <input type="hidden" name="message" id="meeting_message" value="">'."\n".
298
          '        <div>'."\n".
299
          '          <label for="name">'.get_string('view_recording_name', 'bigbluebuttonbn').'</label><br/>'."\n".
300
          '          <input type="text" name="name" id="recording_name" placeholder="">'."\n".
301
          '        </div><br>'."\n".
302
          '        <div>'."\n".
303
          '          <label for="description">'.get_string('view_recording_description', 'bigbluebuttonbn').'</label><br/>'."\n".
304
          '          <input type="text" name="description" id="recording_description" value="" placeholder="">'."\n".
305
          '        </div><br>'."\n".
306
          '        <div>'."\n".
307
          '          <label for="tags">'.get_string('view_recording_tags', 'bigbluebuttonbn').'</label><br/>'."\n".
308
          '          <input type="text" name="tags" id="recording_tags" value="" placeholder="">'."\n".
309
          '        </div>'."\n".
310
          '      </fieldset>'."\n".
311
          '    </form>'."\n".
312
          '  </div>'."\n".
313
          '</div>';
314
    }
315
}
316
317
function bigbluebuttonbn_view_ended($bbbsession) {
318
    global $OUTPUT;
319
320
    if( !is_null($bbbsession['presentation']['url']) ) {
321
        $attributes = array('title' => $bbbsession['presentation']['name']);
322
        $icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
323
324
        echo '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
325
             ''.$OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).''.
326
             ''.$OUTPUT->action_link($bbbsession['presentation']['url'], $bbbsession['presentation']['name'], null, $attributes).'<br><br>';
327
    }
328
}
329
330
function bigbluebuttonbn_view_recordings($bbbsession) {
331
    global $CFG;
332
333
    if( isset($bbbsession['record']) && $bbbsession['record'] ) {
334
        $output = html_writer::tag('h4', get_string('view_section_title_recordings', 'bigbluebuttonbn') );
335
336
        $meetingID='';
337
        $results = bigbluebuttonbn_getRecordedMeetings($bbbsession['course']->id, $bbbsession['bigbluebuttonbn']->id);
338
339 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...
340
            //Eliminates duplicates
341
            $mIDs = array();
342
            foreach ($results as $result) {
343
                $mIDs[$result->meetingid] = $result->meetingid;
344
            }
345
            //Generates the meetingID string
346
            foreach ($mIDs as $mID) {
347
                if (strlen($meetingID) > 0) $meetingID .= ',';
348
                $meetingID .= $mID;
349
            }
350
        }
351
352
        // Get actual recordings
353
        if ( $meetingID != '' ) {
354
            $recordings = bigbluebuttonbn_getRecordingsArray($meetingID, $bbbsession['endpoint'], $bbbsession['shared_secret']);
355
        } else {
356
            $recordings = Array();
357
        }
358
        // Get recording links
359
        $recordings_imported = bigbluebuttonbn_getRecordingsImportedArray($bbbsession['course']->id, $bbbsession['bigbluebuttonbn']->id);
360
        // Merge the recordings
361
        $recordings = array_merge( $recordings, $recordings_imported );
362
        // Render the table
363
        $output .= bigbluebutton_output_recording_table($bbbsession, $recordings)."\n";
364
365
        if ( $bbbsession['managerecordings'] && bigbluebuttonbn_get_cfg_importrecordings_enabled() ) {
366
            $button_import_recordings = html_writer::tag( 'input', '', array('type' => 'button', 'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'), 'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.$bbbsession['bigbluebuttonbn']->id.'\'') );
367
            $output .= html_writer::start_tag('br');
368
            $output .= html_writer::tag('span', $button_import_recordings, ['id'=>"import_recording_links_button"]);
369
            $output .= html_writer::tag('span', '', ['id'=>"import_recording_links_table"]);
370
        }
371
372
        echo $output;
373
    }
374
}
375