listing.php 11 KB

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