listing.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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_simple(
  11. api_get_path(WEB_PLUGIN_PATH).'bbb/resources/utils.js'
  12. );
  13. $htmlHeadXtra[] = "<script>var _p = {web_plugin: '".api_get_path(WEB_PLUGIN_PATH)."'}</script>";
  14. $tpl = new Template($tool_name);
  15. $isGlobal = isset($_GET['global']) ? true : false;
  16. $isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id'] : false;
  17. $bbb = new bbb('', '', $isGlobal, $isGlobalPerUser);
  18. $action = isset($_GET['action']) ? $_GET['action'] : null;
  19. $conferenceManager = $bbb->isConferenceManager();
  20. if ($bbb->isGlobalConference()) {
  21. api_block_anonymous_users();
  22. } else {
  23. api_protect_course_script(true);
  24. }
  25. $message = null;
  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 = intval($_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. array('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 'delete_record':
  60. $result = $bbb->deleteRecording($_GET['id']);
  61. if ($result) {
  62. $message = Display::return_message(get_lang('Deleted'), 'success');
  63. } else {
  64. $message = Display::return_message(get_lang('Error'), 'error');
  65. }
  66. Display::addFlash($message);
  67. header('Location: '.$bbb->getListingUrl());
  68. break;
  69. case 'end':
  70. $bbb->endMeeting($_GET['id']);
  71. $message = Display::return_message(
  72. $plugin->get_lang('MeetingClosed').'<br />'.$plugin->get_lang(
  73. 'MeetingClosedComment'
  74. ),
  75. 'success',
  76. false
  77. );
  78. if (file_exists(__DIR__.'/config.vm.php')) {
  79. require __DIR__.'/../../vendor/autoload.php';
  80. require __DIR__.'/lib/vm/AbstractVM.php';
  81. require __DIR__.'/lib/vm/VMInterface.php';
  82. require __DIR__.'/lib/vm/DigitalOceanVM.php';
  83. require __DIR__.'/lib/VM.php';
  84. $config = require __DIR__.'/config.vm.php';
  85. $vm = new VM($config);
  86. $vm->resizeToMinLimit();
  87. }
  88. Display::addFlash($message);
  89. header('Location: '.$bbb->getListingUrl());
  90. exit;
  91. break;
  92. case 'publish':
  93. $result = $bbb->publishMeeting($_GET['id']);
  94. break;
  95. case 'unpublish':
  96. $result = $bbb->unpublishMeeting($_GET['id']);
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. $meetings = $bbb->getMeetings(
  103. api_get_course_int_id(),
  104. api_get_session_id(),
  105. api_get_group_id()
  106. );
  107. if (!empty($meetings)) {
  108. $meetings = array_reverse($meetings);
  109. }
  110. $usersOnline = $bbb->getUsersOnlineInCurrentRoom();
  111. $maxUsers = $bbb->getMaxUsersLimit();
  112. $status = $bbb->isServerRunning();
  113. $meetingExists = $bbb->meetingExists($bbb->getCurrentVideoConferenceName());
  114. $showJoinButton = false;
  115. if (($meetingExists || $conferenceManager) && ($maxUsers == 0 || $maxUsers > $usersOnline)) {
  116. $showJoinButton = true;
  117. }
  118. $conferenceUrl = $bbb->getConferenceUrl();
  119. $courseInfo = api_get_course_info();
  120. $formToString = '';
  121. if ($bbb->isGlobalConference() === false &&
  122. $conferenceManager &&
  123. !empty($courseInfo) &&
  124. $plugin->get('enable_conference_in_course_groups') === 'true'
  125. ) {
  126. $url = api_get_self().'?'.api_get_cidreq(true, false).'&gidReq=';
  127. $htmlHeadXtra[] = '<script>
  128. $(document).ready(function(){
  129. $("#group_select").on("change", function() {
  130. var groupId = $(this).find("option:selected").val();
  131. var url = "'.$url.'";
  132. window.location.replace(url+groupId);
  133. });
  134. });
  135. </script>';
  136. $form = new FormValidator(api_get_self().'?'.api_get_cidreq());
  137. $groupId = api_get_group_id();
  138. $groups = GroupManager::get_groups();
  139. if ($groups) {
  140. $meetingsInGroup = $bbb->getAllMeetingsInCourse(api_get_course_int_id(), api_get_session_id(), 1);
  141. $meetingsGroup = array_column($meetingsInGroup, 'status', 'group_id');
  142. foreach ($groups as &$groupData) {
  143. $itemGroupId = $groupData['id'];
  144. if (isset($meetingsGroup[$itemGroupId]) && $meetingsGroup[$itemGroupId] == 1) {
  145. $groupData['name'] .= ' ('.get_lang('Active').')';
  146. }
  147. }
  148. $groupList[0] = get_lang('Select');
  149. $groupList = array_merge($groupList, array_column($groups, 'name', 'iid'));
  150. $form->addSelect('group_id', get_lang('Groups'), $groupList, ['id' => 'group_select']);
  151. $form->setDefaults(['group_id' => $groupId]);
  152. $formToString = $form->returnForm();
  153. }
  154. }
  155. $tpl = new Template($tool_name);
  156. $tpl->assign('allow_to_edit', $conferenceManager);
  157. $tpl->assign('meetings', $meetings);
  158. $tpl->assign('conference_url', $conferenceUrl);
  159. $tpl->assign('users_online', $usersOnline);
  160. $tpl->assign('conference_manager', $conferenceManager);
  161. $tpl->assign('max_users_limit', $maxUsers);
  162. $tpl->assign('bbb_status', $status);
  163. $tpl->assign('show_join_button', $showJoinButton);
  164. $tpl->assign('message', $message);
  165. $tpl->assign('form', $formToString);
  166. $listing_tpl = 'bbb/listing.tpl';
  167. $content = $tpl->fetch($listing_tpl);
  168. if (api_is_platform_admin()) {
  169. $actionLinks = Display::toolbarButton(
  170. $plugin->get_lang('AdminView'),
  171. api_get_path(WEB_PLUGIN_PATH).'bbb/admin.php',
  172. 'list',
  173. 'primary'
  174. );
  175. $tpl->assign(
  176. 'actions',
  177. Display::toolbarAction('toolbar', [$actionLinks])
  178. );
  179. }
  180. $tpl->assign('content', $content);
  181. $tpl->display_one_col_template();