Completed
Pull Request — master (#257)
by
unknown
01:56
created

viewlib.php ➔ bigbluebuttonbn_view_render_room()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 16
nop 3
dl 0
loc 43
rs 8.9208
c 0
b 0
f 0
1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
17
/**
18
 * View a BigBlueButton room.
19
 *
20
 * @package   mod_bigbluebuttonbn
21
 * @copyright 2010 onwards, Blindside Networks Inc
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author    Jesus Federico  (jesus [at] blindsidenetworks [dt] com)
24
 * @author    Fred Dixon  (ffdixon [at] blindsidenetworks [dt] com)
25
 * @author    Darko Miletic  (darko.miletic [at] gmail [dt] com)
26
 */
27
28
defined('MOODLE_INTERNAL') || die();
29
30
/**
31
 * Displays the view for groups.
32
 *
33
 * @param array $bbbsession
34
 * @return void
35
 */
36
function bigbluebuttonbn_view_groups(&$bbbsession) {
37
    global $CFG;
38
    // Find out current group mode.
39
    $groupmode = groups_get_activity_groupmode($bbbsession['cm']);
40
    if ($groupmode == NOGROUPS) {
41
        // No groups mode.
42
        return;
43
    }
44
    // Separate or visible group mode.
45
    $groups = groups_get_activity_allowed_groups($bbbsession['cm']);
46
    if (empty($groups)) {
47
        // No groups in this course.
48
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_nogroups_warning', 'bigbluebuttonbn'), 'info', true);
49
        return;
50
    }
51
    $bbbsession['group'] = groups_get_activity_group($bbbsession['cm'], true);
52
    $groupname = get_string('allparticipants');
53
    if ($bbbsession['group'] != 0) {
54
        $groupname = groups_get_group_name($bbbsession['group']);
55
    }
56
    // Assign group default values.
57
    $bbbsession['meetingid'] .= '['.$bbbsession['group'].']';
58
    $bbbsession['meetingname'] .= ' ('.$groupname.')';
59
    if (count($groups) == 0) {
60
        // Only the All participants group exists.
61
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_notenrolled_warning', 'bigbluebuttonbn'), 'info');
62
        return;
63
    }
64
    $context = context_module::instance($bbbsession['cm']->id);
65
    if (has_capability('moodle/site:accessallgroups', $context)) {
66
        bigbluebuttonbn_view_message_box($bbbsession, get_string('view_groups_selection_warning', 'bigbluebuttonbn'));
67
    }
68
    $urltoroot = $CFG->wwwroot.'/mod/bigbluebuttonbn/view.php?id='.$bbbsession['cm']->id;
69
    groups_print_activity_menu($bbbsession['cm'], $urltoroot);
70
    echo '<br><br>';
71
}
72
73
/**
74
 * Displays the view for messages.
75
 *
76
 * @param array $bbbsession
77
 * @param string $message
78
 * @param string $type
79
 * @param boolean $onlymoderator
80
 * @return void
81
 */
82
function bigbluebuttonbn_view_message_box(&$bbbsession, $message, $type = 'warning', $onlymoderator = false) {
83
    global $OUTPUT;
84
    if ($onlymoderator && !$bbbsession['moderator'] && !$bbbsession['administrator']) {
85
        return;
86
    }
87
    echo $OUTPUT->box_start('generalbox boxaligncenter');
88
    echo '<br><div class="alert alert-' . $type . '">' . $message . '</div>';
89
    echo $OUTPUT->box_end();
90
}
91
92
/**
93
 * Displays the general view.
94
 *
95
 * @param array $bbbsession
96
 * @param string $activity
97
 * @return void
98
 */
99
function bigbluebuttonbn_view_render(&$bbbsession, $activity) {
100
    global $OUTPUT, $PAGE;
101
    $type = null;
102
    if (isset($bbbsession['bigbluebuttonbn']->type)) {
103
        $type = $bbbsession['bigbluebuttonbn']->type;
104
    }
105
    $typeprofiles = bigbluebuttonbn_get_instance_type_profiles();
106
    $enabledfeatures = bigbluebuttonbn_get_enabled_features($typeprofiles, $type);
107
    $pinginterval = (int)\mod_bigbluebuttonbn\locallib\config::get('waitformoderator_ping_interval') * 1000;
108
    // JavaScript for locales.
109
    $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn');
110
    // JavaScript variables.
111
    $jsvars = array('activity' => $activity, 'ping_interval' => $pinginterval,
112
        'locale' => bigbluebuttonbn_get_localcode(), 'profile_features' => $typeprofiles[0]['features']);
113
    $output  = '';
114
    // Renders warning messages when configured.
115
    $output .= bigbluebuttonbn_view_warning_default_server($bbbsession);
116
    $output .= bigbluebuttonbn_view_warning_general($bbbsession);
117
118
    // Renders the rest of the page.
119
    $output .= $OUTPUT->heading($bbbsession['meetingname'], 3);
120
    // Renders the completed description.
121
    $desc = file_rewrite_pluginfile_urls($bbbsession['meetingdescription'], 'pluginfile.php',
122
        $bbbsession['context']->id, 'mod_bigbluebuttonbn', 'intro', null);
123
    $output .= $OUTPUT->heading($desc, 5);
124
125
    if ($enabledfeatures['showroom']) {
126
        $output .= bigbluebuttonbn_view_render_room($bbbsession, $activity, $jsvars);
127
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-rooms',
128
            'M.mod_bigbluebuttonbn.rooms.init', array($jsvars));
129
    }
130
    // Show recordings should only be enabled if recordings are also enabled in session.
131
    if ($enabledfeatures['showrecordings'] && $bbbsession['record']) {
132
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings'));
133
        $output .= bigbluebuttonbn_view_render_recording_section($bbbsession, $type, $enabledfeatures, $jsvars);
134
        $output .= html_writer::end_tag('div');
135
        $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-recordings',
136
            'M.mod_bigbluebuttonbn.recordings.init', array($jsvars));
137
    } else if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY) {
138
        $recordingsdisabled = get_string('view_message_recordings_disabled', 'bigbluebuttonbn');
139
        $output .= bigbluebuttonbn_render_warning($recordingsdisabled, 'danger');
140
    }
141
    echo $output.html_writer::empty_tag('br').html_writer::empty_tag('br').html_writer::empty_tag('br');
142
    $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-broker', 'M.mod_bigbluebuttonbn.broker.init', array($jsvars));
143
}
144
145
/**
146
 * Renders the view for recordings.
147
 *
148
 * @param array $bbbsession
149
 * @param integer $type
150
 * @param array $enabledfeatures
151
 * @param array $jsvars
152
 * @return string
153
 */
154
function bigbluebuttonbn_view_render_recording_section(&$bbbsession, $type, $enabledfeatures, &$jsvars) {
155
    if ($type == BIGBLUEBUTTONBN_TYPE_ROOM_ONLY) {
156
        return '';
157
    }
158
    $output = '';
159
    if ($type == BIGBLUEBUTTONBN_TYPE_ALL && $bbbsession['record']) {
160
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_header'));
161
        $output .= html_writer::tag('h4', get_string('view_section_title_recordings', 'bigbluebuttonbn'));
162
        $output .= html_writer::end_tag('div');
163
    }
164
    if ($type == BIGBLUEBUTTONBN_TYPE_RECORDING_ONLY || $bbbsession['record']) {
165
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_content'));
166
        $output .= bigbluebuttonbn_view_render_recordings($bbbsession, $enabledfeatures, $jsvars);
167
        $output .= html_writer::end_tag('div');
168
        $output .= html_writer::start_tag('div', array('id' => 'bigbluebuttonbn_view_recordings_footer'));
169
        $output .= bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures);
170
        $output .= html_writer::end_tag('div');
171
    }
172
    return $output;
173
}
174
175
/**
176
 * Evaluates if the warning box should be shown.
177
 *
178
 * @param array $bbbsession
179
 *
180
 * @return boolean
181
 */
182
function bigbluebuttonbn_view_warning_shown($bbbsession) {
183
    if (is_siteadmin($bbbsession['userID'])) {
184
        return true;
185
    }
186
    $generalwarningroles = explode(',', \mod_bigbluebuttonbn\locallib\config::get('general_warning_roles'));
187
    $userroles = bigbluebuttonbn_get_user_roles($bbbsession['context'], $bbbsession['userID']);
188
    foreach ($userroles as $userrole) {
189
        if (in_array($userrole->shortname, $generalwarningroles)) {
190
            return true;
191
        }
192
    }
193
    return false;
194
}
195
196
/**
197
 * Renders the view for room.
198
 *
199
 * @param array $bbbsession
200
 * @param string $activity
201
 * @param array $jsvars
202
 *
203
 * @return string
204
 */
205
function bigbluebuttonbn_view_render_room(&$bbbsession, $activity, &$jsvars) {
206
    global $OUTPUT;
207
    // JavaScript variables for room.
208
    $openingtime = '';
209
    if ($bbbsession['openingtime']) {
210
        $openingtime = get_string('mod_form_field_openingtime', 'bigbluebuttonbn').': '.
211
            userdate($bbbsession['openingtime']);
212
    }
213
    $closingtime = '';
214
    if ($bbbsession['closingtime']) {
215
        $closingtime = get_string('mod_form_field_closingtime', 'bigbluebuttonbn').': '.
216
            userdate($bbbsession['closingtime']);
217
    }
218
    $jsvars += array(
219
        'meetingid' => $bbbsession['meetingid'],
220
        'bigbluebuttonbnid' => $bbbsession['bigbluebuttonbn']->id,
221
        'userlimit' => $bbbsession['userlimit'],
222
        'opening' => $openingtime,
223
        'closing' => $closingtime,
224
    );
225
    // Main box.
226
    $output  = $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_message_box');
227
    $output .= '<br><span id="status_bar"></span>';
228
    $output .= '<br><span id="control_panel"></span>';
229
    $output .= $OUTPUT->box_end();
230
    // Guest name input box.
231
    if(isguestuser($USER)){
0 ignored issues
show
Bug introduced by
The variable $USER 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...
232
        $output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_guestnameinput_box');
233
        $output .= '<br><span>Name eingeben:</span>';
234
        //added script
235
        $output .= '<script>function setUsernameCustom(){document.getElementById(\'join_button_input\').setAttribute(\'onClick\', document.getElementById(\'join_button_input\').getAttribute(\'onClick\').replace(/action=join&(usernamecustom=[^&]*&)?/,\'action=join&usernamecustom=\'+document.getElementById(\'nameinputfield\').value+\'&\'))}</script>';
236
        $output .= '<br><span><input type="text" oninput="javascript:setUsernameCustom()" name="nameinputfield" id="nameinputfield" value="Gast"></span>';
237
        $output .= $OUTPUT->box_end();
238
    }
239
    // Action button box.
240
    $output .= $OUTPUT->box_start('generalbox boxaligncenter', 'bigbluebuttonbn_view_action_button_box');
241
    $output .= '<br><br><span id="join_button"></span>&nbsp;<span id="end_button"></span>'."\n";
242
    $output .= $OUTPUT->box_end();
243
    if ($activity == 'ended') {
244
        $output .= bigbluebuttonbn_view_ended($bbbsession);
245
    }
246
    return $output;
247
}
248
249
/**
250
 * Renders the view for recordings.
251
 *
252
 * @param array $bbbsession
253
 * @param array $enabledfeatures
254
 * @param array $jsvars
255
 *
256
 * @return string
257
 */
258
function bigbluebuttonbn_view_render_recordings(&$bbbsession, $enabledfeatures, &$jsvars) {
259
    $recordings = bigbluebutton_get_recordings_for_table_view($bbbsession, $enabledfeatures);
260
261
    if (empty($recordings) || array_key_exists('messageKey', $recordings)) {
262
        // There are no recordings to be shown.
263
        return html_writer::div(get_string('view_message_norecordings', 'bigbluebuttonbn'), '',
264
            array('id' => 'bigbluebuttonbn_recordings_table'));
265
    }
266
    // There are recordings for this meeting.
267
    // JavaScript variables for recordings.
268
    $jsvars += array(
269
        'recordings_html' => $bbbsession['bigbluebuttonbn']->recordings_html == '1',
270
    );
271
    // If there are meetings with recordings load the data to the table.
272
    if ($bbbsession['bigbluebuttonbn']->recordings_html) {
273
        // Render a plain html table.
274
        return bigbluebuttonbn_output_recording_table($bbbsession, $recordings)."\n";
275
    }
276
    // JavaScript variables for recordings with YUI.
277
    $jsvars += array(
278
        'bbbid' => $bbbsession['bigbluebuttonbn']->id,
279
    );
280
    // Render a YUI table.
281
    $reset = get_string('reset');
282
    $search = get_string('search');
283
    $output = "<form id='bigbluebuttonbn_recordings_searchform'>
284
                 <input id='searchtext' type='text'>
285
                 <input id='searchsubmit' type='submit' value='{$search}'>
286
                 <input id='searchreset' type='submit' value='{$reset}'>
287
               </form>";
288
    $output .= html_writer::div('', '', array('id' => 'bigbluebuttonbn_recordings_table'));
289
290
    return $output;
291
}
292
293
/**
294
 * Renders the view for importing recordings.
295
 *
296
 * @param array $bbbsession
297
 * @param array $enabledfeatures
298
 *
299
 * @return string
300
 */
301
function bigbluebuttonbn_view_render_imported($bbbsession, $enabledfeatures) {
302
    global $CFG;
303
    if (!$enabledfeatures['importrecordings'] || !$bbbsession['importrecordings']) {
304
        return '';
305
    }
306
    $button = html_writer::tag('input', '',
307
        array('type' => 'button',
308
            'value' => get_string('view_recording_button_import', 'bigbluebuttonbn'),
309
            'class' => 'btn btn-secondary',
310
            'onclick' => 'window.location=\''.$CFG->wwwroot.'/mod/bigbluebuttonbn/import_view.php?bn='.
311
                $bbbsession['bigbluebuttonbn']->id.'\''));
312
    $output  = html_writer::empty_tag('br');
313
    $output .= html_writer::tag('span', $button, array('id' => 'import_recording_links_button'));
314
    $output .= html_writer::tag('span', '', array('id' => 'import_recording_links_table'));
315
    return $output;
316
}
317
318
/**
319
 * Renders the content for ended meeting.
320
 *
321
 * @param array $bbbsession
322
 *
323
 * @return string
324
 */
325
function bigbluebuttonbn_view_ended(&$bbbsession) {
326
    global $OUTPUT;
327
    if (!is_null($bbbsession['presentation']['url'])) {
328
        $attributes = array('title' => $bbbsession['presentation']['name']);
329
        $icon = new pix_icon($bbbsession['presentation']['icon'], $bbbsession['presentation']['mimetype_description']);
330
        return '<h4>'.get_string('view_section_title_presentation', 'bigbluebuttonbn').'</h4>'.
331
            $OUTPUT->action_icon($bbbsession['presentation']['url'], $icon, null, array(), false).
332
            $OUTPUT->action_link($bbbsession['presentation']['url'],
333
                $bbbsession['presentation']['name'], null, $attributes).'<br><br>';
334
    }
335
    return '';
336
}
337
338
/**
339
 * Renders a default server warning message when using test-install.
340
 *
341
 * @param array $bbbsession
342
 *
343
 * @return string
344
 */
345
function bigbluebuttonbn_view_warning_default_server(&$bbbsession) {
346
    if (!is_siteadmin($bbbsession['userID'])) {
347
        return '';
348
    }
349
    if (BIGBLUEBUTTONBN_DEFAULT_SERVER_URL != \mod_bigbluebuttonbn\locallib\config::get('server_url')) {
350
        return '';
351
    }
352
    return bigbluebuttonbn_render_warning(get_string('view_warning_default_server', 'bigbluebuttonbn'), 'warning');
353
}
354
355
/**
356
 * Renders a general warning message when it is configured.
357
 *
358
 * @param array $bbbsession
359
 *
360
 * @return string
361
 */
362
function bigbluebuttonbn_view_warning_general(&$bbbsession) {
363
    if (!bigbluebuttonbn_view_warning_shown($bbbsession)) {
364
        return '';
365
    }
366
    return bigbluebuttonbn_render_warning(
367
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_message'),
368
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_box_type'),
369
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_href'),
370
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_text'),
371
        (string)\mod_bigbluebuttonbn\locallib\config::get('general_warning_button_class')
372
    );
373
}
374