listing.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * This script initiates a video conference session, calling the BigBlueButton API.
  5. *
  6. * @package chamilo.plugin.bigbluebutton
  7. */
  8. $course_plugin = 'bbb'; //needed in order to load the plugin lang variables
  9. require_once __DIR__.'/config.php';
  10. $plugin = BBBPlugin::create();
  11. $tool_name = $plugin->get_lang('Videoconference');
  12. $htmlHeadXtra[] = api_get_js_simple(api_get_path(WEB_PLUGIN_PATH).'bbb/resources/utils.js');
  13. $isGlobal = isset($_GET['global']) ? true : false;
  14. $isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id'] : false;
  15. $action = isset($_GET['action']) ? $_GET['action'] : '';
  16. $bbb = new bbb('', '', $isGlobal, $isGlobalPerUser);
  17. $conferenceManager = $bbb->isConferenceManager();
  18. if ($bbb->isGlobalConference()) {
  19. api_block_anonymous_users();
  20. } else {
  21. api_protect_course_script(true);
  22. }
  23. $message = '';
  24. if ($conferenceManager) {
  25. switch ($action) {
  26. case 'add_to_calendar':
  27. if ($bbb->isGlobalConference()) {
  28. return false;
  29. }
  30. $courseInfo = api_get_course_info();
  31. $agenda = new Agenda('course');
  32. $id = (int) $_GET['id'];
  33. $title = sprintf($plugin->get_lang('VideoConferenceXCourseX'), $id, $courseInfo['name']);
  34. $content = Display::url($plugin->get_lang('GoToTheVideoConference'), $_GET['url']);
  35. $eventId = $agenda->addEvent(
  36. $_REQUEST['start'],
  37. null,
  38. 'true',
  39. $title,
  40. $content,
  41. ['everyone']
  42. );
  43. if (!empty($eventId)) {
  44. $message = Display::return_message($plugin->get_lang('VideoConferenceAddedToTheCalendar'), 'success');
  45. } else {
  46. $message = Display::return_message(get_lang('Error'), 'error');
  47. }
  48. break;
  49. case 'copy_record_to_link_tool':
  50. $result = $bbb->copyRecordingToLinkTool($_GET['id']);
  51. if ($result) {
  52. $message = Display::return_message($plugin->get_lang('VideoConferenceAddedToTheLinkTool'), 'success');
  53. } else {
  54. $message = Display::return_message(get_lang('Error'), 'error');
  55. }
  56. break;
  57. case 'regenerate_record':
  58. if ($plugin->get('allow_regenerate_recording') !== 'true') {
  59. api_not_allowed();
  60. }
  61. $result = $bbb->regenerateRecording($_GET['id'], $_GET['record_id']);
  62. if ($result) {
  63. $message = Display::return_message(get_lang('Success'), 'success');
  64. } else {
  65. $message = Display::return_message(get_lang('Error'), 'error');
  66. }
  67. Display::addFlash($message);
  68. header('Location: '.$bbb->getListingUrl());
  69. break;
  70. case 'delete_record':
  71. $result = $bbb->deleteRecording($_GET['id']);
  72. if ($result) {
  73. $message = Display::return_message(get_lang('Deleted'), 'success');
  74. } else {
  75. $message = Display::return_message(get_lang('Error'), 'error');
  76. }
  77. Display::addFlash($message);
  78. header('Location: '.$bbb->getListingUrl());
  79. exit;
  80. break;
  81. case 'end':
  82. $bbb->endMeeting($_GET['id']);
  83. $message = Display::return_message(
  84. $plugin->get_lang('MeetingClosed').'<br />'.$plugin->get_lang(
  85. 'MeetingClosedComment'
  86. ),
  87. 'success',
  88. false
  89. );
  90. if (file_exists(__DIR__.'/config.vm.php')) {
  91. require __DIR__.'/../../vendor/autoload.php';
  92. require __DIR__.'/lib/vm/AbstractVM.php';
  93. require __DIR__.'/lib/vm/VMInterface.php';
  94. require __DIR__.'/lib/vm/DigitalOceanVM.php';
  95. require __DIR__.'/lib/VM.php';
  96. $config = require __DIR__.'/config.vm.php';
  97. $vm = new VM($config);
  98. $vm->resizeToMinLimit();
  99. }
  100. Display::addFlash($message);
  101. header('Location: '.$bbb->getListingUrl());
  102. exit;
  103. break;
  104. case 'publish':
  105. $result = $bbb->publishMeeting($_GET['id']);
  106. break;
  107. case 'unpublish':
  108. $result = $bbb->unpublishMeeting($_GET['id']);
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. $meetings = $bbb->getMeetings(
  115. api_get_course_int_id(),
  116. api_get_session_id(),
  117. api_get_group_id()
  118. );
  119. if (!empty($meetings)) {
  120. $meetings = array_reverse($meetings);
  121. }
  122. $usersOnline = $bbb->getUsersOnlineInCurrentRoom();
  123. $maxUsers = $bbb->getMaxUsersLimit();
  124. $status = $bbb->isServerRunning();
  125. $videoConferenceName = $bbb->getCurrentVideoConferenceName();
  126. $meetingExists = $bbb->meetingExists($videoConferenceName);
  127. $showJoinButton = false;
  128. // Only conference manager can see the join button
  129. $userCanSeeJoinButton = $conferenceManager;
  130. if ($bbb->isGlobalConference() && $bbb->isGlobalConferencePerUserEnabled()) {
  131. // Any user can see the "join button" BT#12620
  132. $userCanSeeJoinButton = true;
  133. }
  134. if (($meetingExists || $userCanSeeJoinButton) && ($maxUsers == 0 || $maxUsers > $usersOnline)) {
  135. $showJoinButton = true;
  136. }
  137. $conferenceUrl = $bbb->getConferenceUrl();
  138. $courseInfo = api_get_course_info();
  139. $formToString = '';
  140. if ($bbb->isGlobalConference() === false &&
  141. $conferenceManager &&
  142. !empty($courseInfo) &&
  143. $plugin->get('enable_conference_in_course_groups') === 'true'
  144. ) {
  145. $url = api_get_self().'?'.api_get_cidreq(true, false).'&gidReq=';
  146. $htmlHeadXtra[] = '<script>
  147. $(document).ready(function(){
  148. $("#group_select").on("change", function() {
  149. var groupId = $(this).find("option:selected").val();
  150. var url = "'.$url.'";
  151. window.location.replace(url+groupId);
  152. });
  153. });
  154. </script>';
  155. $form = new FormValidator(api_get_self().'?'.api_get_cidreq());
  156. $groupId = api_get_group_id();
  157. $groups = GroupManager::get_groups();
  158. if ($groups) {
  159. $meetingsInGroup = $bbb->getAllMeetingsInCourse(api_get_course_int_id(), api_get_session_id(), 1);
  160. $meetingsGroup = array_column($meetingsInGroup, 'status', 'group_id');
  161. foreach ($groups as &$groupData) {
  162. $itemGroupId = $groupData['id'];
  163. if (isset($meetingsGroup[$itemGroupId]) && $meetingsGroup[$itemGroupId] == 1) {
  164. $groupData['name'] .= ' ('.get_lang('Active').')';
  165. }
  166. }
  167. $groupList[0] = get_lang('Select');
  168. $groupList = array_merge($groupList, array_column($groups, 'name', 'iid'));
  169. $form->addSelect('group_id', get_lang('Groups'), $groupList, ['id' => 'group_select']);
  170. $form->setDefaults(['group_id' => $groupId]);
  171. $formToString = $form->returnForm();
  172. }
  173. }
  174. $tpl = new Template($tool_name);
  175. $tpl->assign('allow_to_edit', $conferenceManager);
  176. $tpl->assign('meetings', $meetings);
  177. $tpl->assign('conference_url', $conferenceUrl);
  178. $tpl->assign('users_online', $usersOnline);
  179. $tpl->assign('conference_manager', $conferenceManager);
  180. $tpl->assign('max_users_limit', $maxUsers);
  181. $tpl->assign('bbb_status', $status);
  182. $tpl->assign('show_join_button', $showJoinButton);
  183. $tpl->assign('message', $message);
  184. $tpl->assign('form', $formToString);
  185. // Default URL
  186. $urlList[] = Display::url(
  187. $plugin->get_lang('EnterConference'),
  188. $conferenceUrl,
  189. ['target' => '_blank', 'class' => 'btn btn-primary btn-large']
  190. );
  191. $type = $plugin->get('launch_type');
  192. $warningIntefaceMessage = '';
  193. $showClientOptions = false;
  194. switch ($type) {
  195. case BBBPlugin::LAUNCH_TYPE_DEFAULT:
  196. $urlList = [];
  197. $urlList[] = Display::url(
  198. $plugin->get_lang('EnterConference'),
  199. $conferenceUrl.'&interface='.$plugin->get('interface'),
  200. ['target' => '_blank', 'class' => 'btn btn-primary btn-large']
  201. );
  202. break;
  203. case BBBPlugin::LAUNCH_TYPE_SET_BY_TEACHER:
  204. if ($conferenceManager) {
  205. $urlList = $plugin->getUrlInterfaceLinks($conferenceUrl);
  206. $warningIntefaceMessage = Display::return_message($plugin->get_lang('ParticipantsWillUseSameInterface'));
  207. $showClientOptions = true;
  208. } else {
  209. $meetingInfo = $bbb->getMeetingByName($videoConferenceName);
  210. switch ($meetingInfo['interface']) {
  211. case BBBPlugin::INTERFACE_FLASH:
  212. $url = $plugin->getFlashUrl($conferenceUrl);
  213. break;
  214. case BBBPlugin::INTERFACE_HTML5:
  215. $url = $plugin->getHtmlUrl($conferenceUrl);
  216. break;
  217. }
  218. }
  219. break;
  220. case BBBPlugin::LAUNCH_TYPE_SET_BY_STUDENT:
  221. if ($conferenceManager) {
  222. $urlList = $plugin->getUrlInterfaceLinks($conferenceUrl);
  223. $showClientOptions = true;
  224. } else {
  225. if ($meetingExists) {
  226. $meetingInfo = $bbb->getMeetingByName($videoConferenceName);
  227. $meetinUserInfo = $bbb->getMeetingParticipantInfo($meetingInfo['id'], api_get_user_id());
  228. $urlList = $plugin->getUrlInterfaceLinks($conferenceUrl);
  229. $showClientOptions = true;
  230. }
  231. }
  232. break;
  233. }
  234. $tpl->assign('enter_conference_links', $urlList);
  235. $tpl->assign('warning_inteface_msg', $warningIntefaceMessage);
  236. $tpl->assign('show_client_options', $showClientOptions);
  237. $listing_tpl = 'bbb/view/listing.tpl';
  238. $content = $tpl->fetch($listing_tpl);
  239. $actionLinks = '';
  240. if (api_is_platform_admin()) {
  241. $actionLinks .= Display::toolbarButton(
  242. $plugin->get_lang('AdminView'),
  243. api_get_path(WEB_PLUGIN_PATH).'bbb/admin.php',
  244. 'list',
  245. 'primary'
  246. );
  247. $tpl->assign(
  248. 'actions',
  249. Display::toolbarAction('toolbar', [$actionLinks])
  250. );
  251. }
  252. $tpl->assign('content', $content);
  253. $tpl->display_one_col_template();