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