listing.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * This script initiates a video conference session, calling the BigBlueButton API
  4. * @package chamilo.plugin.bigbluebutton
  5. */
  6. $course_plugin = 'bbb'; //needed in order to load the plugin lang variables
  7. require_once __DIR__.'/config.php';
  8. $plugin = BBBPlugin::create();
  9. $tool_name = $plugin->get_lang('Videoconference');
  10. $htmlHeadXtra[] = api_get_js('plugins/bbb/utils.js');
  11. $htmlHeadXtra[] = "<script>var _p = {web_plugin: '" . api_get_path(WEB_PLUGIN_PATH). "'}</script>";
  12. $tpl = new Template($tool_name);
  13. $isGlobal = isset($_GET['global']) ? true : false;
  14. $isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id']: false;
  15. $bbb = new bbb('', '', $isGlobal, $isGlobalPerUser);
  16. $action = isset($_GET['action']) ? $_GET['action'] : null;
  17. $conferenceManager = $bbb->isConferenceManager();
  18. if ($bbb->isGlobalConference()) {
  19. api_block_anonymous_users();
  20. } else {
  21. api_protect_course_script(true);
  22. }
  23. if ($conferenceManager) {
  24. switch ($action) {
  25. case 'add_to_calendar':
  26. if ($bbb->isGlobalConference()) {
  27. return false;
  28. }
  29. $courseInfo = api_get_course_info();
  30. $agenda = new Agenda('course');
  31. $id = intval($_GET['id']);
  32. $title = sprintf($plugin->get_lang('VideoConferenceXCourseX'), $id, $courseInfo['name']);
  33. $content = Display::url($plugin->get_lang('GoToTheVideoConference'), $_GET['url']);
  34. $eventId = $agenda->addEvent(
  35. $_REQUEST['start'],
  36. null,
  37. 'true',
  38. $title,
  39. $content,
  40. array('everyone')
  41. );
  42. if (!empty($eventId)) {
  43. Display::addFlash(
  44. Display::return_message($plugin->get_lang('VideoConferenceAddedToTheCalendar'), 'success')
  45. );
  46. } else {
  47. Display::addFlash(
  48. Display::return_message(get_lang('Error'), 'error')
  49. );
  50. }
  51. break;
  52. case 'copy_record_to_link_tool':
  53. $result = $bbb->copyRecordingToLinkTool($_GET['id']);
  54. if ($result) {
  55. Display::addFlash(
  56. Display::return_message($plugin->get_lang('VideoConferenceAddedToTheLinkTool'), 'success')
  57. );
  58. } else {
  59. Display::addFlash(
  60. Display::return_message(get_lang('Error'), 'error')
  61. );
  62. }
  63. break;
  64. case 'delete_record':
  65. $result = $bbb->deleteRecording($_GET['id']);
  66. if ($result) {
  67. $message = Display::return_message(get_lang('Deleted'), 'success');
  68. } else {
  69. $message = Display::return_message(get_lang('Error'), 'error');
  70. }
  71. Display::addFlash($message);
  72. header('Location: '.$bbb->getListingUrl());
  73. break;
  74. case 'end':
  75. $bbb->endMeeting($_GET['id']);
  76. Display::addFlash(
  77. Display::return_message(
  78. $plugin->get_lang('MeetingClosed') . '<br />' .
  79. $plugin->get_lang('MeetingClosedComment'),
  80. 'success',
  81. false
  82. )
  83. );
  84. if (file_exists(__DIR__ . '/config.vm.php')) {
  85. require __DIR__ . '/../../vendor/autoload.php';
  86. require __DIR__ . '/lib/vm/AbstractVM.php';
  87. require __DIR__ . '/lib/vm/VMInterface.php';
  88. require __DIR__ . '/lib/vm/DigitalOceanVM.php';
  89. require __DIR__ . '/lib/VM.php';
  90. $config = require __DIR__ . '/config.vm.php';
  91. $vm = new VM($config);
  92. $vm->resizeToMinLimit();
  93. }
  94. header('Location: '.$bbb->getListingUrl());
  95. exit;
  96. break;
  97. case 'publish':
  98. $result = $bbb->publishMeeting($_GET['id']);
  99. break;
  100. case 'unpublish':
  101. $result = $bbb->unpublishMeeting($_GET['id']);
  102. break;
  103. default:
  104. break;
  105. }
  106. }
  107. $meetings = $bbb->getMeetings(
  108. api_get_course_int_id(),
  109. api_get_session_id(),
  110. api_get_group_id()
  111. );
  112. if (!empty($meetings)) {
  113. $meetings = array_reverse($meetings);
  114. }
  115. $usersOnline = $bbb->getUsersOnlineInCurrentRoom();
  116. $maxUsers = $bbb->getMaxUsersLimit();
  117. $status = $bbb->isServerRunning();
  118. $meetingExists = $bbb->meetingExists($bbb->getCurrentVideoConferenceName());
  119. $showJoinButton = false;
  120. // Only conference manager can see the join button
  121. $userCanSeeJoinButton = $conferenceManager;
  122. if ($bbb->isGlobalConference() && $bbb->isGlobalConferencePerUserEnabled()) {
  123. // Any user can see the "join button" BT#12620
  124. $userCanSeeJoinButton = true;
  125. }
  126. if (($meetingExists || $userCanSeeJoinButton) && ($maxUsers == 0 || $maxUsers > $usersOnline)) {
  127. $showJoinButton = true;
  128. }
  129. $conferenceUrl = $bbb->getConferenceUrl();
  130. $courseInfo = api_get_course_info();
  131. $formToString = '';
  132. if ($bbb->isGlobalConference() === false &&
  133. $conferenceManager &&
  134. !empty($courseInfo) &&
  135. $plugin->get('enable_conference_in_course_groups') === 'true'
  136. ) {
  137. $url = api_get_self().'?'.api_get_cidreq(true, false).'&gidReq=';
  138. $htmlHeadXtra[] = '<script>
  139. $(document).ready(function(){
  140. $("#group_select").on("change", function() {
  141. var groupId = $(this).find("option:selected").val();
  142. var url = "'.$url.'";
  143. window.location.replace(url+groupId);
  144. });
  145. });
  146. </script>';
  147. $form = new FormValidator(api_get_self().'?'.api_get_cidreq());
  148. $groupId = api_get_group_id();
  149. $groups = GroupManager::get_groups();
  150. if ($groups) {
  151. $meetingsInGroup = $bbb->getAllMeetingsInCourse(api_get_course_int_id(), api_get_session_id(), 1);
  152. $meetingsGroup = array_column($meetingsInGroup, 'status', 'group_id');
  153. foreach ($groups as &$groupData) {
  154. $itemGroupId = $groupData['id'];
  155. if (isset($meetingsGroup[$itemGroupId]) && $meetingsGroup[$itemGroupId] == 1) {
  156. $groupData['name'] .= ' ('.get_lang('Active').')';
  157. }
  158. }
  159. $groupList[0] = get_lang('Select');
  160. $groupList = array_merge($groupList, array_column($groups, 'name', 'iid'));
  161. $form->addSelect('group_id', get_lang('Groups'), $groupList, ['id' => 'group_select']);
  162. $form->setDefaults(['group_id' => $groupId]);
  163. $formToString = $form->returnForm();
  164. }
  165. }
  166. $tpl = new Template($tool_name);
  167. $tpl->assign('allow_to_edit', $conferenceManager);
  168. $tpl->assign('meetings', $meetings);
  169. $tpl->assign('conference_url', $conferenceUrl);
  170. $tpl->assign('users_online', $usersOnline);
  171. $tpl->assign('conference_manager', $conferenceManager);
  172. $tpl->assign('max_users_limit', $maxUsers);
  173. $tpl->assign('bbb_status', $status);
  174. $tpl->assign('show_join_button', $showJoinButton);
  175. $tpl->assign('form', $formToString);
  176. if ($status == false) {
  177. Display::addFlash(
  178. Display::return_message(get_lang('ServerIsNotRunning'))
  179. );
  180. }
  181. $listing_tpl = '@plugin/bbb/listing.tpl';
  182. $content = $tpl->fetch($listing_tpl);
  183. if (api_is_platform_admin()) {
  184. $actionLinks = [
  185. Display::toolbarButton(
  186. $plugin->get_lang('AdminView'),
  187. api_get_path(WEB_PLUGIN_PATH) . 'bbb/admin.php?'.api_get_cidreq(),
  188. 'list',
  189. 'primary'
  190. )
  191. ];
  192. $tpl->assign('actions', implode(PHP_EOL, $actionLinks));
  193. }
  194. $tpl->assign('content', $content);
  195. $tpl->display_one_col_template();