123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?php
- /* For license terms, see /license.txt */
- /**
- * This script initiates a video conference session, calling the BigBlueButton API.
- *
- * @package chamilo.plugin.bigbluebutton
- */
- $course_plugin = 'bbb'; //needed in order to load the plugin lang variables
- require_once __DIR__.'/config.php';
- $plugin = BBBPlugin::create();
- $tool_name = $plugin->get_lang('Videoconference');
- $htmlHeadXtra[] = api_get_js_simple(api_get_path(WEB_PLUGIN_PATH).'bbb/resources/utils.js');
- $isGlobal = isset($_GET['global']) ? true : false;
- $isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id'] : false;
- $action = isset($_GET['action']) ? $_GET['action'] : '';
- $bbb = new bbb('', '', $isGlobal, $isGlobalPerUser);
- $conferenceManager = $bbb->isConferenceManager();
- if ($bbb->isGlobalConference()) {
- api_block_anonymous_users();
- } else {
- api_protect_course_script(true);
- }
- $courseInfo = api_get_course_info();
- $courseCode = isset($courseInfo['code']) ? $courseInfo['code'] : '';
- $message = '';
- if ($conferenceManager) {
- switch ($action) {
- case 'add_to_calendar':
- if ($bbb->isGlobalConference()) {
- return false;
- }
- $courseInfo = api_get_course_info();
- $agenda = new Agenda('course');
- $id = (int) $_GET['id'];
- $title = sprintf($plugin->get_lang('VideoConferenceXCourseX'), $id, $courseInfo['name']);
- $content = Display::url($plugin->get_lang('GoToTheVideoConference'), $_GET['url']);
- $eventId = $agenda->addEvent(
- $_REQUEST['start'],
- null,
- 'true',
- $title,
- $content,
- ['everyone']
- );
- if (!empty($eventId)) {
- $message = Display::return_message($plugin->get_lang('VideoConferenceAddedToTheCalendar'), 'success');
- } else {
- $message = Display::return_message(get_lang('Error'), 'error');
- }
- break;
- case 'copy_record_to_link_tool':
- $result = $bbb->copyRecordingToLinkTool($_GET['id']);
- if ($result) {
- $message = Display::return_message($plugin->get_lang('VideoConferenceAddedToTheLinkTool'), 'success');
- } else {
- $message = Display::return_message(get_lang('Error'), 'error');
- }
- break;
- case 'regenerate_record':
- if ($plugin->get('allow_regenerate_recording') !== 'true') {
- api_not_allowed(true);
- }
- $recordId = isset($_GET['record_id']) ? $_GET['record_id'] : '';
- $result = $bbb->regenerateRecording($_GET['id'], $recordId);
- if ($result) {
- $message = Display::return_message(get_lang('Success'), 'success');
- } else {
- $message = Display::return_message(get_lang('Error'), 'error');
- }
- Display::addFlash($message);
- header('Location: '.$bbb->getListingUrl());
- exit;
- break;
- case 'delete_record':
- $result = $bbb->deleteRecording($_GET['id']);
- if ($result) {
- $message = Display::return_message(get_lang('Deleted'), 'success');
- } else {
- $message = Display::return_message(get_lang('Error'), 'error');
- }
- Display::addFlash($message);
- header('Location: '.$bbb->getListingUrl());
- exit;
- break;
- case 'end':
- $bbb->endMeeting($_GET['id']);
- $message = Display::return_message(
- $plugin->get_lang('MeetingClosed').'<br />'.$plugin->get_lang('MeetingClosedComment'),
- 'success',
- false
- );
- if (file_exists(__DIR__.'/config.vm.php')) {
- require __DIR__.'/../../vendor/autoload.php';
- require __DIR__.'/lib/vm/AbstractVM.php';
- require __DIR__.'/lib/vm/VMInterface.php';
- require __DIR__.'/lib/vm/DigitalOceanVM.php';
- require __DIR__.'/lib/VM.php';
- $config = require __DIR__.'/config.vm.php';
- $vm = new VM($config);
- $vm->resizeToMinLimit();
- }
- Display::addFlash($message);
- header('Location: '.$bbb->getListingUrl());
- exit;
- break;
- case 'publish':
- $bbb->publishMeeting($_GET['id']);
- Display::addFlash(Display::return_message(get_lang('Updated')));
- header('Location: '.$bbb->getListingUrl());
- exit;
- break;
- case 'unpublish':
- $bbb->unpublishMeeting($_GET['id']);
- Display::addFlash(Display::return_message(get_lang('Updated')));
- header('Location: '.$bbb->getListingUrl());
- exit;
- break;
- case 'logout':
- if ($plugin->get('allow_regenerate_recording') !== 'true') {
- api_not_allowed(true);
- }
- $allow = api_get_course_setting('bbb_force_record_generation', $courseInfo) == 1 ? true : false;
- if ($allow) {
- $result = $bbb->getMeetingByRemoteId($_GET['remote_id']);
- if (!empty($result)) {
- $result = $bbb->regenerateRecording($result['id']);
- if ($result) {
- Display::addFlash(Display::return_message(get_lang('Success')));
- } else {
- Display::addFlash(Display::return_message(get_lang('Error'), 'error'));
- }
- }
- }
- header('Location: '.$bbb->getListingUrl());
- exit;
- break;
- default:
- break;
- }
- }
- $meetings = $bbb->getMeetings(
- api_get_course_int_id(),
- api_get_session_id(),
- api_get_group_id()
- );
- if (!empty($meetings)) {
- $meetings = array_reverse($meetings);
- }
- $usersOnline = $bbb->getUsersOnlineInCurrentRoom();
- $maxUsers = $bbb->getMaxUsersLimit();
- $status = $bbb->isServerRunning();
- $videoConferenceName = $bbb->getCurrentVideoConferenceName();
- $meetingExists = $bbb->meetingExists($videoConferenceName);
- $showJoinButton = false;
- // Only conference manager can see the join button
- $userCanSeeJoinButton = $conferenceManager;
- if ($bbb->isGlobalConference() && $bbb->isGlobalConferencePerUserEnabled()) {
- // Any user can see the "join button" BT#12620
- $userCanSeeJoinButton = true;
- }
- if (($meetingExists || $userCanSeeJoinButton) && ($maxUsers == 0 || $maxUsers > $usersOnline)) {
- $showJoinButton = true;
- }
- $conferenceUrl = $bbb->getConferenceUrl();
- $courseInfo = api_get_course_info();
- $formToString = '';
- if ($bbb->isGlobalConference() === false &&
- $conferenceManager &&
- !empty($courseInfo) &&
- $plugin->get('enable_conference_in_course_groups') === 'true'
- ) {
- $url = api_get_self().'?'.api_get_cidreq(true, false).'&gidReq=';
- $htmlHeadXtra[] = '<script>
- $(document).ready(function() {
- $("#group_select").on("change", function() {
- var groupId = $(this).find("option:selected").val();
- var url = "'.$url.'";
- window.location.replace(url+groupId);
- });
- });
- </script>';
- $form = new FormValidator(api_get_self().'?'.api_get_cidreq());
- $groupId = api_get_group_id();
- $groups = GroupManager::get_groups();
- if ($groups) {
- $meetingsInGroup = $bbb->getAllMeetingsInCourse(api_get_course_int_id(), api_get_session_id(), 1);
- $meetingsGroup = array_column($meetingsInGroup, 'status', 'group_id');
- foreach ($groups as &$groupData) {
- $itemGroupId = $groupData['id'];
- if (isset($meetingsGroup[$itemGroupId]) && $meetingsGroup[$itemGroupId] == 1) {
- $groupData['name'] .= ' ('.get_lang('Active').')';
- }
- }
- $groupList[0] = get_lang('Select');
- $groupList = array_merge($groupList, array_column($groups, 'name', 'iid'));
- $form->addSelect('group_id', get_lang('Groups'), $groupList, ['id' => 'group_select']);
- $form->setDefaults(['group_id' => $groupId]);
- $formToString = $form->returnForm();
- }
- }
- // Default URL
- $urlList[] = Display::url(
- $plugin->get_lang('EnterConference'),
- $conferenceUrl,
- ['target' => '_blank', 'class' => 'btn btn-primary btn-large']
- );
- $type = $plugin->get('launch_type');
- $warningInterfaceMessage = '';
- $showClientOptions = false;
- switch ($type) {
- case BBBPlugin::LAUNCH_TYPE_DEFAULT:
- $urlList = [];
- $urlList[] = Display::url(
- $plugin->get_lang('EnterConference'),
- $conferenceUrl.'&interface='.$plugin->get('interface'),
- ['target' => '_blank', 'class' => 'btn btn-primary btn-large']
- );
- break;
- case BBBPlugin::LAUNCH_TYPE_SET_BY_TEACHER:
- if ($conferenceManager) {
- $urlList = $plugin->getUrlInterfaceLinks($conferenceUrl);
- $warningInterfaceMessage = Display::return_message($plugin->get_lang('ParticipantsWillUseSameInterface'));
- $showClientOptions = true;
- } else {
- $meetingInfo = $bbb->getMeetingByName($videoConferenceName);
- switch ($meetingInfo['interface']) {
- case BBBPlugin::INTERFACE_FLASH:
- $url = $plugin->getFlashUrl($conferenceUrl);
- break;
- case BBBPlugin::INTERFACE_HTML5:
- $url = $plugin->getHtmlUrl($conferenceUrl);
- break;
- }
- }
- break;
- case BBBPlugin::LAUNCH_TYPE_SET_BY_STUDENT:
- if ($conferenceManager) {
- $urlList = $plugin->getUrlInterfaceLinks($conferenceUrl);
- $showClientOptions = true;
- } else {
- if ($meetingExists) {
- $urlList = $plugin->getUrlInterfaceLinks($conferenceUrl);
- $showClientOptions = true;
- }
- }
- break;
- }
- $tpl = new Template($tool_name);
- $tpl->assign('allow_to_edit', $conferenceManager);
- $tpl->assign('meetings', $meetings);
- $tpl->assign('conference_url', $conferenceUrl);
- $tpl->assign('users_online', $usersOnline);
- $tpl->assign('conference_manager', $conferenceManager);
- $tpl->assign('max_users_limit', $maxUsers);
- $tpl->assign('bbb_status', $status);
- $tpl->assign('show_join_button', $showJoinButton);
- $tpl->assign('message', $message);
- $tpl->assign('form', $formToString);
- $tpl->assign('enter_conference_links', $urlList);
- $tpl->assign('warning_inteface_msg', $warningInterfaceMessage);
- $tpl->assign('show_client_options', $showClientOptions);
- $listing_tpl = 'bbb/view/listing.tpl';
- $content = $tpl->fetch($listing_tpl);
- $actionLinks = '';
- if (api_is_platform_admin()) {
- $actionLinks .= Display::toolbarButton(
- $plugin->get_lang('AdminView'),
- api_get_path(WEB_PLUGIN_PATH).'bbb/admin.php',
- 'list',
- 'primary'
- );
- $tpl->assign(
- 'actions',
- Display::toolbarAction('toolbar', [$actionLinks])
- );
- }
- $tpl->assign('content', $content);
- $tpl->display_one_col_template();
|