Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

   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 for BigBlueButton interaction.
  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   */
  25  
  26  use core\notification;
  27  use mod_bigbluebuttonbn\instance;
  28  use mod_bigbluebuttonbn\local\exceptions\server_not_available_exception;
  29  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  30  use mod_bigbluebuttonbn\logger;
  31  use mod_bigbluebuttonbn\meeting;
  32  use mod_bigbluebuttonbn\plugin;
  33  use mod_bigbluebuttonbn\recording;
  34  
  35  require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
  36  
  37  global $SESSION, $PAGE, $CFG, $DB, $USER, $OUTPUT;
  38  
  39  $action = required_param('action', PARAM_TEXT);
  40  $id = optional_param('id', 0, PARAM_INT);
  41  $bn = optional_param('bn', 0, PARAM_INT);
  42  $rid = optional_param('rid', '', PARAM_TEXT);
  43  $rtype = optional_param('rtype', 'presentation', PARAM_TEXT);
  44  $errors = optional_param('errors', '', PARAM_TEXT);
  45  $timeline = optional_param('timeline', 0, PARAM_INT);
  46  $index = optional_param('index', 0, PARAM_INT);
  47  $group = optional_param('group', -1, PARAM_INT);
  48  
  49  // Get the bbb instance from either the cmid (id), or the instanceid (bn).
  50  if ($id) {
  51      $instance = instance::get_from_cmid($id);
  52  } else {
  53      if ($bn) {
  54          $instance = instance::get_from_instanceid($bn);
  55      }
  56  }
  57  
  58  if (!$instance) {
  59      throw new moodle_exception('view_error_url_missing_parameters', plugin::COMPONENT);
  60  }
  61  
  62  $cm = $instance->get_cm();
  63  $course = $instance->get_course();
  64  $bigbluebuttonbn = $instance->get_instance_data();
  65  $context = $instance->get_context();
  66  
  67  require_login($course, true, $cm);
  68  
  69  // Note : this uses the group optional_param as a value to decide which groupid.
  70  $groupid = groups_get_activity_group($cm, true) ?: null;
  71  if ($groupid) {
  72      $instance->set_group_id($groupid);
  73  }
  74  
  75  // Print the page header.
  76  $PAGE->set_context($context);
  77  $PAGE->set_url('/mod/bigbluebuttonbn/bbb_view.php', ['id' => $cm->id, 'bigbluebuttonbn' => $bigbluebuttonbn->id]);
  78  $PAGE->set_title(format_string($bigbluebuttonbn->name));
  79  $PAGE->set_cacheable(false);
  80  $PAGE->set_heading($course->fullname);
  81  $PAGE->blocks->show_only_fake_blocks();
  82  
  83  switch (strtolower($action)) {
  84      case 'logout':
  85          if (isset($errors) && $errors != '') {
  86              $errors = (array) json_decode(urldecode($errors));
  87              $msgerrors = '';
  88              foreach ($errors as $error) {
  89                  $msgerrors .= html_writer::tag('p', $error->{'message'}, ['class' => 'alert alert-danger']) . "\n";
  90              }
  91              throw new moodle_exception('view_error_bigbluebutton', 'bigbluebuttonbn',
  92                  $CFG->wwwroot . '/mod/bigbluebuttonbn/view.php?id=' . $id, $msgerrors, $errors);
  93          }
  94  
  95          if (empty($bigbluebuttonbn)) {
  96              echo get_string('view_message_tab_close', 'bigbluebuttonbn');
  97              die();
  98          }
  99          // Moodle event logger: Create an event for meeting left.
 100          logger::log_meeting_left_event($instance);
 101  
 102          // Update the cache.
 103          $meeting = new meeting($instance);
 104          $meeting->update_cache();
 105  
 106          // Check the origin page.
 107          $select = "userid = ? AND log = ?";
 108          $params = [
 109              'userid' => $USER->id,
 110              'log' => logger::EVENT_JOIN,
 111          ];
 112          $accesses = $DB->get_records_select('bigbluebuttonbn_logs', $select, $params, 'id ASC', 'id, meta', 1);
 113          $lastaccess = end($accesses);
 114          if (!empty($lastaccess->meta)) {
 115              $lastaccess = json_decode($lastaccess->meta);
 116              // If the user acceded from Timeline it should be redirected to the Dashboard.
 117              if (isset($lastaccess->origin) && $lastaccess->origin == logger::ORIGIN_TIMELINE) {
 118                  redirect($CFG->wwwroot . '/my/');
 119              }
 120          }
 121          break;
 122      case 'join':
 123          if (empty($bigbluebuttonbn)) {
 124              throw new moodle_exception('view_error_unable_join', 'bigbluebuttonbn');
 125              break;
 126          }
 127          // Check the origin page.
 128          $origin = logger::ORIGIN_BASE;
 129          if ($timeline) {
 130              $origin = logger::ORIGIN_TIMELINE;
 131          } else if ($index) {
 132              $origin = logger::ORIGIN_INDEX;
 133          }
 134  
 135          try {
 136              $url = meeting::join_meeting($instance, $origin);
 137              redirect($url);
 138          } catch (server_not_available_exception $e) {
 139              bigbluebutton_proxy::handle_server_not_available($instance);
 140          }
 141          // We should never reach this point.
 142          break;
 143  
 144      case 'play':
 145          $recording = recording::get_record(['id' => $rid]);
 146          if ($href = $recording->get_remote_playback_url($rtype)) {
 147              logger::log_recording_played_event($instance, $rid);
 148              redirect(urldecode($href));
 149          } else {
 150              notification::add(get_string('recordingurlnotfound', 'mod_bigbluebuttonbn'), notification::ERROR);
 151              redirect($instance->get_view_url());
 152          }
 153          // We should never reach this point.
 154          break;
 155  }
 156  // When we reach this point, we can close the tab or window where BBB was opened.
 157  echo $OUTPUT->header();
 158  // Behat does not like when we close the Windows as it is expecting to locate
 159  // on click part of the pages (bug with selenium raising an exception). So this is a workaround.
 160  if (!defined('BEHAT_SITE_RUNNING')) {
 161      $PAGE->requires->js_call_amd('mod_bigbluebuttonbn/rooms', 'setupWindowAutoClose');
 162  }
 163  echo $OUTPUT->footer();