bbb.lib.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class bbb
  5. * This script initiates a video conference session, calling the BigBlueButton
  6. * API
  7. * @package chamilo.plugin.bigbluebutton
  8. *
  9. * BigBlueButton-Chamilo connector class
  10. */
  11. //namespace Chamilo\Plugin\BBB;
  12. /**
  13. * Class bbb
  14. * @package Chamilo\Plugin\BBB
  15. */
  16. class bbb
  17. {
  18. public $url;
  19. public $salt;
  20. public $api;
  21. public $userCompleteName = '';
  22. public $protocol = 'http://';
  23. public $debug = false;
  24. public $logoutUrl = '';
  25. public $pluginEnabled = false;
  26. public $enableGlobalConference = false;
  27. public $isGlobalConference = false;
  28. public $groupSupport = false;
  29. /**
  30. * Constructor (generates a connection to the API and the Chamilo settings
  31. * required for the connection to the video conference server)
  32. * @param string $host
  33. * @param string $salt
  34. * @param bool $isGlobalConference
  35. */
  36. public function __construct($host = '', $salt = '', $isGlobalConference = false)
  37. {
  38. // Initialize video server settings from global settings
  39. $plugin = BBBPlugin::create();
  40. $bbbPlugin = $plugin->get('tool_enable');
  41. $bbb_host = !empty($host) ? $host : $plugin->get('host');
  42. $bbb_salt = !empty($salt) ? $salt : $plugin->get('salt');
  43. $this->logoutUrl = $this->getListingUrl();
  44. $this->table = Database::get_main_table('plugin_bbb_meeting');
  45. $this->enableGlobalConference = $plugin->get('enable_global_conference');
  46. $this->isGlobalConference = (bool) $isGlobalConference;
  47. $columns = Database::listTableColumns($this->table);
  48. $this->groupSupport = isset($columns['group_id']) ? true : false;
  49. if ($this->groupSupport) {
  50. // Plugin check
  51. $this->groupSupport = (bool) $plugin->get('enable_conference_in_course_groups');
  52. if ($this->groupSupport) {
  53. // Platform check
  54. $bbbSetting = api_get_setting('bbb_enable_conference_in_course_groups');
  55. $bbbSetting = isset($bbbSetting['bbb']) ? $bbbSetting['bbb'] === 'true' : false;
  56. if ($bbbSetting) {
  57. // Course check
  58. $courseInfo = api_get_course_info();
  59. if ($courseInfo) {
  60. $this->groupSupport = api_get_course_setting('bbb_enable_conference_in_groups') === '1';
  61. }
  62. }
  63. }
  64. }
  65. if ($bbbPlugin == true) {
  66. $userInfo = api_get_user_info();
  67. $this->userCompleteName = $userInfo['complete_name'];
  68. $this->salt = $bbb_salt;
  69. $info = parse_url($bbb_host);
  70. $this->url = $bbb_host.'/bigbluebutton/';
  71. if (isset($info['scheme'])) {
  72. $this->protocol = $info['scheme'].'://';
  73. $this->url = str_replace($this->protocol, '', $this->url);
  74. }
  75. // Setting BBB api
  76. define('CONFIG_SECURITY_SALT', $this->salt);
  77. define('CONFIG_SERVER_BASE_URL', $this->url);
  78. $this->api = new BigBlueButtonBN();
  79. $this->pluginEnabled = true;
  80. }
  81. }
  82. /**
  83. * @return bool
  84. */
  85. public function isGlobalConferenceEnabled()
  86. {
  87. return (bool) $this->enableGlobalConference;
  88. }
  89. /**
  90. * @return bool
  91. */
  92. public function isGlobalConference()
  93. {
  94. if ($this->isGlobalConferenceEnabled() === false) {
  95. return false;
  96. }
  97. return (bool) $this->isGlobalConference;
  98. }
  99. /**
  100. * @return bool
  101. */
  102. public function hasGroupSupport()
  103. {
  104. return $this->groupSupport;
  105. }
  106. /**
  107. * Checks whether a user is teacher in the current course
  108. * @return bool True if the user can be considered a teacher in this course, false otherwise
  109. */
  110. public function isConferenceManager()
  111. {
  112. return api_is_course_admin() || api_is_coach() || api_is_platform_admin();
  113. }
  114. /**
  115. * See this file in you BBB to set up default values
  116. * @param array $params Array of parameters that will be completed if not containing all expected variables
  117. /var/lib/tomcat6/webapps/bigbluebutton/WEB-INF/classes/bigbluebutton.properties
  118. *
  119. More record information:
  120. http://code.google.com/p/bigbluebutton/wiki/RecordPlaybackSpecification
  121. # Default maximum number of users a meeting can have.
  122. # Doesn't get enforced yet but is the default value when the create
  123. # API doesn't pass a value.
  124. defaultMaxUsers=20
  125. # Default duration of the meeting in minutes.
  126. # Current default is 0 (meeting doesn't end).
  127. defaultMeetingDuration=0
  128. # Remove the meeting from memory when the end API is called.
  129. # This allows 3rd-party apps to recycle the meeting right-away
  130. # instead of waiting for the meeting to expire (see below).
  131. removeMeetingWhenEnded=false
  132. # The number of minutes before the system removes the meeting from memory.
  133. defaultMeetingExpireDuration=1
  134. # The number of minutes the system waits when a meeting is created and when
  135. # a user joins. If after this period, a user hasn't joined, the meeting is
  136. # removed from memory.
  137. defaultMeetingCreateJoinDuration=5
  138. *
  139. * @return mixed
  140. */
  141. public function createMeeting($params)
  142. {
  143. $courseCode = api_get_course_id();
  144. $params['c_id'] = api_get_course_int_id();
  145. $params['session_id'] = api_get_session_id();
  146. if ($this->hasGroupSupport()) {
  147. $params['group_id'] = api_get_group_id();
  148. }
  149. $courseCode = is_null($courseCode) ? '' : $courseCode;
  150. $params['attendee_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $courseCode;
  151. $attendeePassword = $params['attendee_pw'];
  152. $params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
  153. $moderatorPassword = $params['moderator_pw'];
  154. $params['record'] = api_get_course_setting('big_blue_button_record_and_store', $courseCode) == 1 ? true : false;
  155. $max = api_get_course_setting('big_blue_button_max_students_allowed', $courseCode);
  156. $max = isset($max) ? $max : -1;
  157. $params['status'] = 1;
  158. // Generate a pseudo-global-unique-id to avoid clash of conferences on
  159. // the same BBB server with several Chamilo portals
  160. $params['remote_id'] = uniqid(true, true);
  161. // Each simultaneous conference room needs to have a different
  162. // voice_bridge composed of a 5 digits number, so generating a random one
  163. $params['voice_bridge'] = rand(10000, 99999);
  164. if ($this->debug) {
  165. error_log("enter create_meeting ".print_r($params, 1));
  166. }
  167. $params['created_at'] = api_get_utc_datetime();
  168. $id = Database::insert($this->table, $params);
  169. if ($id) {
  170. if ($this->debug) {
  171. error_log("create_meeting: $id ");
  172. }
  173. $meetingName = isset($params['meeting_name']) ? $params['meeting_name'] : $this->getCurrentVideoConferenceName();
  174. $welcomeMessage = isset($params['welcome_msg']) ? $params['welcome_msg'] : null;
  175. $record = isset($params['record']) && $params['record'] ? 'true' : 'false';
  176. $duration = isset($params['duration']) ? intval($params['duration']) : 0;
  177. // This setting currently limits the maximum conference duration,
  178. // to avoid lingering sessions on the video-conference server #6261
  179. $duration = 300;
  180. $bbbParams = array(
  181. 'meetingId' => $params['remote_id'], // REQUIRED
  182. 'meetingName' => $meetingName, // REQUIRED
  183. 'attendeePw' => $attendeePassword, // Match this value in getJoinMeetingURL() to join as attendee.
  184. 'moderatorPw' => $moderatorPassword, // Match this value in getJoinMeetingURL() to join as moderator.
  185. 'welcomeMsg' => $welcomeMessage, // ''= use default. Change to customize.
  186. 'dialNumber' => '', // The main number to call into. Optional.
  187. 'voiceBridge' => $params['voice_bridge'], // PIN to join voice. Required.
  188. 'webVoice' => '', // Alphanumeric to join voice. Optional.
  189. 'logoutUrl' => $this->logoutUrl,
  190. 'maxParticipants' => $max, // Optional. -1 = unlimitted. Not supported in BBB. [number]
  191. 'record' => $record, // New. 'true' will tell BBB to record the meeting.
  192. 'duration' => $duration, // Default = 0 which means no set duration in minutes. [number]
  193. //'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
  194. );
  195. if ($this->debug) {
  196. error_log("create_meeting params: ".print_r($bbbParams,1));
  197. }
  198. $status = false;
  199. $meeting = null;
  200. while ($status === false) {
  201. $result = $this->api->createMeetingWithXmlResponseArray(
  202. $bbbParams
  203. );
  204. if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
  205. if ($this->debug) {
  206. error_log(
  207. "create_meeting result: " . print_r($result, 1)
  208. );
  209. }
  210. $meeting = $this->joinMeeting($meetingName, true);
  211. return $meeting;
  212. }
  213. }
  214. return $this->logoutUrl;
  215. }
  216. }
  217. /**
  218. * Tells whether the given meeting exists and is running
  219. * (using course code as name)
  220. * @param string $meetingName Meeting name (usually the course code)
  221. *
  222. * @return bool True if meeting exists, false otherwise
  223. * @assert ('') === false
  224. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  225. */
  226. public function meetingExists($meetingName)
  227. {
  228. if (empty($meetingName)) {
  229. return false;
  230. }
  231. $courseId = api_get_course_int_id();
  232. $sessionId = api_get_session_id();
  233. $conditions = array(
  234. 'where' => array(
  235. 'c_id = ? AND session_id = ? AND meeting_name = ? AND status = 1 ' =>
  236. array($courseId, $sessionId, $meetingName)
  237. )
  238. );
  239. if ($this->hasGroupSupport()) {
  240. $groupId = api_get_group_id();
  241. $conditions = array(
  242. 'where' => array(
  243. 'c_id = ? AND session_id = ? AND meeting_name = ? AND group_id = ? AND status = 1 ' =>
  244. array($courseId, $sessionId, $meetingName, $groupId)
  245. )
  246. );
  247. }
  248. $meetingData = Database::select(
  249. '*',
  250. $this->table,
  251. $conditions,
  252. 'first'
  253. );
  254. if ($this->debug) {
  255. error_log("meeting_exists ".print_r($meetingData, 1));
  256. }
  257. if (empty($meetingData)) {
  258. return false;
  259. } else {
  260. return true;
  261. }
  262. }
  263. /**
  264. * Returns a meeting "join" URL
  265. * @param string The name of the meeting (usually the course code)
  266. * @return mixed The URL to join the meeting, or false on error
  267. * @todo implement moderator pass
  268. * @assert ('') === false
  269. * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
  270. */
  271. public function joinMeeting($meetingName, $loop = false)
  272. {
  273. if (empty($meetingName)) {
  274. return false;
  275. }
  276. $pass = $this->getUserMeetingPassword();
  277. $meetingData = Database::select(
  278. '*',
  279. $this->table,
  280. array('where' => array('meeting_name = ? AND status = 1 ' => $meetingName)),
  281. 'first'
  282. );
  283. if (empty($meetingData) || !is_array($meetingData)) {
  284. if ($this->debug) {
  285. error_log("meeting does not exist: $meetingName");
  286. }
  287. return false;
  288. }
  289. $params = array(
  290. 'meetingId' => $meetingData['remote_id'],
  291. // -- REQUIRED - The unique id for the meeting
  292. 'password' => $this->getModMeetingPassword()
  293. // -- REQUIRED - The moderator password for the meeting
  294. );
  295. $status = false;
  296. $meetingInfoExists = false;
  297. while ($status === false) {
  298. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  299. if ($meetingIsRunningInfo === false) {
  300. //checking with the remote_id didn't work, so just in case and
  301. // to provide backwards support, check with the id
  302. $params = array(
  303. 'meetingId' => $meetingData['id'],
  304. // -- REQUIRED - The unique id for the meeting
  305. 'password' => $this->getModMeetingPassword()
  306. // -- REQUIRED - The moderator password for the meeting
  307. );
  308. $meetingIsRunningInfo = $this->getMeetingInfo($params);
  309. }
  310. if ($this->debug) {
  311. error_log(print_r($meetingIsRunningInfo, 1));
  312. }
  313. if (strval($meetingIsRunningInfo['returncode']) == 'SUCCESS' &&
  314. isset($meetingIsRunningInfo['meetingName']) &&
  315. !empty($meetingIsRunningInfo['meetingName'])
  316. //strval($meetingIsRunningInfo['running']) == 'true'
  317. ) {
  318. $meetingInfoExists = true;
  319. }
  320. if ($this->debug) {
  321. error_log(
  322. "meeting is running: " . intval($meetingInfoExists)
  323. );
  324. }
  325. if ($meetingInfoExists) {
  326. $status = true;
  327. }
  328. if ($loop) {
  329. continue;
  330. } else {
  331. break;
  332. }
  333. }
  334. if ($meetingInfoExists) {
  335. $joinParams = array(
  336. 'meetingId' => $meetingData['remote_id'], // -- REQUIRED - A unique id for the meeting
  337. 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
  338. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  339. //'createTime' => api_get_utc_datetime(), //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  340. 'userID' => api_get_user_id(), //-- OPTIONAL - string
  341. 'webVoiceConf' => '' // -- OPTIONAL - string
  342. );
  343. $url = $this->api->getJoinMeetingURL($joinParams);
  344. $url = $this->protocol.$url;
  345. } else {
  346. $url = $this->logoutUrl;
  347. }
  348. if ($this->debug) {
  349. error_log("return url :" . $url);
  350. }
  351. return $url;
  352. }
  353. /**
  354. * Get information about the given meeting
  355. * @param array ...?
  356. * @return mixed Array of information on success, false on error
  357. * @assert (array()) === false
  358. */
  359. public function getMeetingInfo($params)
  360. {
  361. try {
  362. $result = $this->api->getMeetingInfoWithXmlResponseArray($params);
  363. if ($result == null) {
  364. if ($this->debug) {
  365. error_log("Failed to get any response. Maybe we can't contact the BBB server.");
  366. }
  367. } else {
  368. return $result;
  369. }
  370. } catch (Exception $e) {
  371. if ($this->debug) {
  372. error_log('Caught exception: ', $e->getMessage(), "\n");
  373. }
  374. }
  375. return false;
  376. }
  377. /**
  378. * Gets all the course meetings saved in the plugin_bbb_meeting table
  379. * @return array Array of current open meeting rooms
  380. */
  381. public function getMeetings()
  382. {
  383. $pass = $this->getUserMeetingPassword();
  384. $courseId = api_get_course_int_id();
  385. $sessionId = api_get_session_id();
  386. $conditions = array(
  387. 'where' => array(
  388. 'c_id = ? AND session_id = ? ' => array(
  389. $courseId,
  390. $sessionId,
  391. ),
  392. ),
  393. );
  394. if ($this->hasGroupSupport()) {
  395. $groupId = api_get_group_id();
  396. $conditions = array(
  397. 'where' => array(
  398. 'c_id = ? AND session_id = ? AND group_id = ? ' =>
  399. array($courseId, $sessionId, $groupId)
  400. )
  401. );
  402. }
  403. $meetingList = Database::select(
  404. '*',
  405. $this->table,
  406. $conditions
  407. );
  408. $isGlobal = $this->isGlobalConference();
  409. $newMeetingList = array();
  410. $item = array();
  411. foreach ($meetingList as $meetingDB) {
  412. $meetingBBB = $this->getMeetingInfo(['meetingId' => $meetingDB['remote_id'], 'password' => $pass]);
  413. if ($meetingBBB === false) {
  414. //checking with the remote_id didn't work, so just in case and
  415. // to provide backwards support, check with the id
  416. $params = array(
  417. 'meetingId' => $meetingDB['id'],
  418. // -- REQUIRED - The unique id for the meeting
  419. 'password' => $pass
  420. // -- REQUIRED - The moderator password for the meeting
  421. );
  422. $meetingBBB = $this->getMeetingInfo($params);
  423. }
  424. if ($meetingDB['visibility'] == 0 && $this->isConferenceManager() === false) {
  425. continue;
  426. }
  427. $meetingBBB['end_url'] = $this->endUrl($meetingDB);
  428. if (isset($meetingBBB['returncode']) && (string)$meetingBBB['returncode'] == 'FAILED') {
  429. if ($meetingDB['status'] == 1 && $this->isConferenceManager()) {
  430. $this->endMeeting($meetingDB['id']);
  431. }
  432. } else {
  433. $meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB);
  434. }
  435. $recordArray = array();
  436. $actionLinksArray = array();
  437. if ($meetingDB['record'] == 1) {
  438. // backwards compatibility (when there was no remote ID)
  439. $mId = $meetingDB['remote_id'];
  440. if (empty($mId)) {
  441. $mId = $meetingDB['id'];
  442. }
  443. if (empty($mId)) {
  444. // if the id is still empty (should *never* occur as 'id' is
  445. // the table's primary key), skip this conference
  446. continue;
  447. }
  448. $recordingParams = array(
  449. 'meetingId' => $mId, //-- OPTIONAL - comma separate if multiple ids
  450. );
  451. //To see the recording list in your BBB server do: bbb-record --list
  452. $records = $this->api->getRecordingsWithXmlResponseArray($recordingParams);
  453. if (!empty($records)) {
  454. $count = 1;
  455. if (isset($records['message']) && !empty($records['message'])) {
  456. if ($records['messageKey'] == 'noRecordings') {
  457. $recordArray[] = get_lang('NoRecording');
  458. if ($meetingDB['visibility'] == 0) {
  459. $actionLinksArray[] = Display::url(
  460. Display::return_icon(
  461. 'invisible.png',
  462. get_lang('MakeVisible'),
  463. array(),
  464. ICON_SIZE_MEDIUM
  465. ),
  466. $this->publishUrl($meetingDB)
  467. );
  468. } else {
  469. $actionLinksArray[] = Display::url(
  470. Display::return_icon(
  471. 'visible.png',
  472. get_lang('MakeInvisible'),
  473. array(),
  474. ICON_SIZE_MEDIUM
  475. ),
  476. $this->unPublishUrl($meetingDB)
  477. );
  478. }
  479. }
  480. } else {
  481. foreach ($records as $record) {
  482. //if you get several recordings here and you used a
  483. // previous version of Chamilo, you might want to
  484. // only keep the last result for each chamilo conf
  485. // (see show_links after the end of this loop)
  486. if (is_array($record) && isset($record['recordId'])) {
  487. $url = Display::url(
  488. get_lang('ViewRecord')." [~".$record['playbackFormatLength']."']",
  489. $record['playbackFormatUrl'],
  490. array('target' => '_blank')
  491. );
  492. $actionLinks = '';
  493. if ($this->isConferenceManager()) {
  494. if ($isGlobal === false) {
  495. $actionLinks .= Display::url(
  496. Display::return_icon(
  497. 'link.gif',
  498. get_lang('CopyToLinkTool')
  499. ),
  500. $this->copyToRecordToLinkTool($meetingDB)
  501. );
  502. $actionLinks .= Display::url(
  503. Display::return_icon(
  504. 'agenda.png',
  505. get_lang('AddToCalendar')
  506. ),
  507. $this->addToCalendarUrl($meetingDB, $record)
  508. );
  509. }
  510. $actionLinks .= Display::url(
  511. Display::return_icon(
  512. 'delete.png',
  513. get_lang('Delete')
  514. ),
  515. $this->deleteRecordUrl($meetingDB)
  516. );
  517. if ($meetingDB['visibility'] == 0) {
  518. $actionLinks .= Display::url(
  519. Display::return_icon(
  520. 'invisible.png',
  521. get_lang('MakeVisible'),
  522. array(),
  523. ICON_SIZE_MEDIUM
  524. ),
  525. $this->publishUrl($meetingDB)
  526. );
  527. } else {
  528. $actionLinks .= Display::url(
  529. Display::return_icon(
  530. 'visible.png',
  531. get_lang('MakeInvisible'),
  532. array(),
  533. ICON_SIZE_MEDIUM
  534. ),
  535. $this->unPublishUrl($meetingDB)
  536. );
  537. }
  538. }
  539. $count++;
  540. $recordArray[] = $url;
  541. $actionLinksArray[] = $actionLinks;
  542. } else {
  543. /*if (is_array($record) && isset($record['recordID']) && isset($record['playbacks'])) {
  544. //Fix the bbb timestamp
  545. //$record['startTime'] = substr($record['startTime'], 0, strlen($record['startTime']) -3);
  546. //$record['endTime'] = substr($record['endTime'], 0, strlen($record['endTime']) -3);
  547. //.' - '.api_convert_and_format_date($record['startTime']).' - '.api_convert_and_format_date($record['endTime'])
  548. foreach($record['playbacks'] as $item) {
  549. $url = Display::url(get_lang('ViewRecord'), $item['url'], array('target' => '_blank'));
  550. //$url .= Display::url(get_lang('DeleteRecord'), api_get_self().'?action=delete_record&'.$record['recordID']);
  551. if ($this->isConferenceManager()) {
  552. $url .= Display::url(Display::return_icon('link.gif',get_lang('CopyToLinkTool')), api_get_self().'?action=copy_record_to_link_tool&id='.$meetingDB['id'].'&record_id='.$record['recordID']);
  553. $url .= Display::url(Display::return_icon('agenda.png',get_lang('AddToCalendar')), api_get_self().'?action=add_to_calendar&id='.$meetingDB['id'].'&start='.api_strtotime($meetingDB['created_at']).'&url='.$item['url']);
  554. $url .= Display::url(Display::return_icon('delete.png',get_lang('Delete')), api_get_self().'?action=delete_record&id='.$record['recordID']);
  555. }
  556. //$url .= api_get_self().'?action=publish&id='.$record['recordID'];
  557. $count++;
  558. $recordArray[] = $url;
  559. }
  560. }*/
  561. }
  562. }
  563. }
  564. } else {
  565. $actionLinks = '';
  566. if ($this->isConferenceManager()) {
  567. if ($meetingDB['visibility'] == 0) {
  568. $actionLinks .= Display::url(
  569. Display::return_icon(
  570. 'invisible.png',
  571. get_lang('MakeVisible'),
  572. array(),
  573. ICON_SIZE_MEDIUM
  574. ),
  575. $this->publishUrl($meetingDB)
  576. );
  577. } else {
  578. $actionLinks .= Display::url(
  579. Display::return_icon(
  580. 'visible.png',
  581. get_lang('MakeInvisible'),
  582. array(),
  583. ICON_SIZE_MEDIUM
  584. ),
  585. $this->unPublishUrl($meetingDB)
  586. );
  587. }
  588. }
  589. $actionLinksArray[] = $actionLinks;
  590. $item['action_links'] = implode('<br />', $actionLinksArray);
  591. }
  592. //var_dump($recordArray);
  593. $item['show_links'] = implode('<br />', $recordArray);
  594. $item['action_links'] = implode('<br />', $actionLinksArray);
  595. }
  596. $item['created_at'] = api_convert_and_format_date($meetingDB['created_at']);
  597. //created_at
  598. $meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
  599. $item['publish_url'] = $this->publishUrl($meetingDB);
  600. $item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
  601. if ($meetingDB['status'] == 1) {
  602. $joinParams = array(
  603. 'meetingId' => $meetingDB['remote_id'], //-- REQUIRED - A unique id for the meeting
  604. 'username' => $this->userCompleteName, //-- REQUIRED - The name that will display for the user in the meeting
  605. 'password' => $pass, //-- REQUIRED - The attendee or moderator password, depending on what's passed here
  606. 'createTime' => '', //-- OPTIONAL - string. Leave blank ('') unless you set this correctly.
  607. 'userID' => '', // -- OPTIONAL - string
  608. 'webVoiceConf' => '' // -- OPTIONAL - string
  609. );
  610. $item['go_url'] = $this->protocol.$this->api->getJoinMeetingURL($joinParams);
  611. }
  612. $item = array_merge($item, $meetingDB, $meetingBBB);
  613. $newMeetingList[] = $item;
  614. }
  615. return $newMeetingList;
  616. }
  617. /**
  618. * Function disabled
  619. */
  620. public function publishMeeting($id)
  621. {
  622. //return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
  623. if (empty($id)) {
  624. return false;
  625. }
  626. $id = intval($id);
  627. Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
  628. return true;
  629. }
  630. /**
  631. * Function disabled
  632. */
  633. public function unpublishMeeting($id)
  634. {
  635. //return BigBlueButtonBN::setPublishRecordings($id, 'false', $this->url, $this->salt);
  636. if (empty($id)) {
  637. return false;
  638. }
  639. $id = intval($id);
  640. Database::update($this->table, array('visibility' => 0), array('id = ?' => $id));
  641. return true;
  642. }
  643. /**
  644. * Closes a meeting (usually when the user click on the close button from
  645. * the conferences listing.
  646. * @param string The internal ID of the meeting (id field for this meeting)
  647. * @return void
  648. * @assert (0) === false
  649. */
  650. public function endMeeting($id)
  651. {
  652. if (empty($id)) {
  653. return false;
  654. }
  655. $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
  656. $pass = $this->getUserMeetingPassword();
  657. $endParams = array(
  658. 'meetingId' => $meetingData['remote_id'], // REQUIRED - We have to know which meeting to end.
  659. 'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
  660. );
  661. $this->api->endMeetingWithXmlResponseArray($endParams);
  662. Database::update(
  663. $this->table,
  664. array('status' => 0, 'closed_at' => api_get_utc_datetime()),
  665. array('id = ? ' => $id)
  666. );
  667. }
  668. /**
  669. * Gets the password for a specific meeting for the current user
  670. * @return string A moderator password if user is teacher, or the course code otherwise
  671. */
  672. public function getUserMeetingPassword()
  673. {
  674. if ($this->isConferenceManager()) {
  675. return $this->getModMeetingPassword();
  676. } else {
  677. if ($this->isGlobalConference()) {
  678. return 'url_'.api_get_current_access_url_id();
  679. }
  680. return api_get_course_id();
  681. }
  682. }
  683. /**
  684. * Generated a moderator password for the meeting
  685. * @return string A password for the moderation of the videoconference
  686. */
  687. public function getModMeetingPassword()
  688. {
  689. if ($this->isGlobalConference()) {
  690. return 'url_'.api_get_current_access_url_id().'_mod';
  691. }
  692. return api_get_course_id().'mod';
  693. }
  694. /**
  695. * Get users online in the current course room
  696. * @return int The number of users currently connected to the videoconference
  697. * @assert () > -1
  698. */
  699. public function getUsersOnlineInCurrentRoom()
  700. {
  701. $courseId = api_get_course_int_id();
  702. $sessionId = api_get_session_id();
  703. $conditions = array(
  704. 'where' => array(
  705. 'c_id = ? AND session_id = ? AND status = 1 ' => array(
  706. $courseId,
  707. $sessionId,
  708. ),
  709. ),
  710. );
  711. if ($this->hasGroupSupport()) {
  712. $groupId = api_get_group_id();
  713. $conditions = array(
  714. 'where' => array(
  715. 'c_id = ? AND session_id = ? AND group_id = ? AND status = 1 ' => array(
  716. $courseId,
  717. $sessionId,
  718. $groupId
  719. ),
  720. ),
  721. );
  722. }
  723. $meetingData = Database::select(
  724. '*',
  725. $this->table,
  726. $conditions,
  727. 'first'
  728. );
  729. if (empty($meetingData)) {
  730. return 0;
  731. }
  732. $pass = $this->getModMeetingPassword();
  733. $info = $this->getMeetingInfo(array('meetingId' => $meetingData['remote_id'], 'password' => $pass));
  734. if ($info === false) {
  735. //checking with the remote_id didn't work, so just in case and
  736. // to provide backwards support, check with the id
  737. $params = array(
  738. 'meetingId' => $meetingData['id'],
  739. // -- REQUIRED - The unique id for the meeting
  740. 'password' => $pass
  741. // -- REQUIRED - The moderator password for the meeting
  742. );
  743. $info = $this->getMeetingInfo($params);
  744. }
  745. if (!empty($info) && isset($info['participantCount'])) {
  746. return $info['participantCount'];
  747. }
  748. return 0;
  749. }
  750. /**
  751. * Deletes a previous recording of a meeting
  752. * @param int integral ID of the recording
  753. * @return array ?
  754. * @assert () === false
  755. * @todo Also delete links and agenda items created from this recording
  756. */
  757. public function deleteRecord($id)
  758. {
  759. if (empty($id)) {
  760. return false;
  761. }
  762. $meetingData = Database::select(
  763. '*',
  764. $this->table,
  765. array('where' => array('id = ?' => array($id))),
  766. 'first'
  767. );
  768. $recordingParams = array(
  769. /*
  770. * NOTE: Set the recordId below to a valid id after you have
  771. * created a recorded meeting, and received a real recordID
  772. * back from your BBB server using the
  773. * getRecordingsWithXmlResponseArray method.
  774. */
  775. // REQUIRED - We have to know which recording:
  776. 'recordId' => $meetingData['remote_id'],
  777. );
  778. $result = $this->api->deleteRecordingsWithXmlResponseArray($recordingParams);
  779. if (!empty($result) && isset($result['deleted']) && $result['deleted'] == 'true') {
  780. Database::delete(
  781. $this->table,
  782. array('id = ?' => array($id))
  783. );
  784. }
  785. return $result;
  786. }
  787. /**
  788. * Creates a link in the links tool from the given videoconference recording
  789. * @param int ID of the item in the plugin_bbb_meeting table
  790. * @param string Hash identifying the recording, as provided by the API
  791. * @return mixed ID of the newly created link, or false on error
  792. * @assert (null, null) === false
  793. * @assert (1, null) === false
  794. * @assert (null, 'abcdefabcdefabcdefabcdef') === false
  795. */
  796. public function copyRecordToLinkTool($id)
  797. {
  798. if (empty($id)) {
  799. return false;
  800. }
  801. //$records = BigBlueButtonBN::getRecordingsUrl($id);
  802. $meetingData = Database::select('*', $this->table, array('where' => array('id = ?' => array($id))), 'first');
  803. $records = $this->api->getRecordingsWithXmlResponseArray(array('meetingId' => $meetingData['remote_id']));
  804. if (!empty($records)) {
  805. if (isset($records['message']) && !empty($records['message'])) {
  806. if ($records['messageKey'] == 'noRecordings') {
  807. $recordArray[] = get_lang('NoRecording');
  808. } else {
  809. //$recordArray[] = $records['message'];
  810. }
  811. return false;
  812. } else {
  813. $record = $records[0];
  814. if (is_array($record) && isset($record['recordId'])) {
  815. $url = $record['playbackFormatUrl'];
  816. $link = new Link();
  817. $params['url'] = $url;
  818. $params['title'] = $meetingData['meeting_name'];
  819. $id = $link->save($params);
  820. return $id;
  821. }
  822. }
  823. }
  824. return false;
  825. }
  826. /**
  827. * Checks if the video conference server is running.
  828. * Function currently disabled (always returns 1)
  829. * @return bool True if server is running, false otherwise
  830. * @assert () === false
  831. */
  832. public function isServerRunning()
  833. {
  834. return true;
  835. //return BigBlueButtonBN::isServerRunning($this->protocol.$this->url);
  836. }
  837. /**
  838. * Get active session in the all platform
  839. */
  840. public function getActiveSessionsCount()
  841. {
  842. $meetingList = Database::select(
  843. 'count(id) as count',
  844. $this->table,
  845. array('where' => array('status = ?' => array(1))),
  846. 'first'
  847. );
  848. return $meetingList['count'];
  849. }
  850. /**
  851. * @param string $url
  852. */
  853. public function redirectToBBB($url)
  854. {
  855. if (file_exists(__DIR__ . '/../config.vm.php')) {
  856. // Using VM
  857. echo Display::url(get_lang('ClickToContinue'), $url);
  858. exit;
  859. } else {
  860. // Classic
  861. header("Location: $url");
  862. exit;
  863. }
  864. }
  865. /**
  866. * @return string
  867. */
  868. public function getUrlParams()
  869. {
  870. $courseInfo = api_get_course_info();
  871. if (empty($courseInfo)) {
  872. if ($this->isGlobalConference()) {
  873. return 'global=1';
  874. }
  875. return '';
  876. }
  877. return api_get_cidreq();
  878. }
  879. /**
  880. * @return string
  881. */
  882. public function getCurrentVideoConferenceName()
  883. {
  884. if ($this->isGlobalConference()) {
  885. return 'url_'.api_get_current_access_url_id();
  886. }
  887. if ($this->hasGroupSupport()) {
  888. return api_get_course_id().'-'.api_get_session_id().'-'.api_get_group_id();
  889. }
  890. return api_get_course_id().'-'.api_get_session_id();
  891. }
  892. /**
  893. * @return string
  894. */
  895. public function getConferenceUrl()
  896. {
  897. return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.$this->getUrlParams();
  898. }
  899. /**
  900. * @return string
  901. */
  902. public function getListingUrl()
  903. {
  904. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams();
  905. }
  906. /**
  907. * @param array $meeting
  908. * @return string
  909. */
  910. public function endUrl($meeting)
  911. {
  912. if (!isset($meeting['id'])) {
  913. return '';
  914. }
  915. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=end&id='.$meeting['id'];
  916. }
  917. /**
  918. * @param array $meeting
  919. * @param array $record
  920. * @return string
  921. */
  922. public function addToCalendarUrl($meeting, $record = [])
  923. {
  924. $url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
  925. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=add_to_calendar&id='.$meeting['id'].'&start='.api_strtotime($meeting['created_at']).'&url='.$url;
  926. }
  927. /**
  928. * @param array $meeting
  929. * @return string
  930. */
  931. public function publishUrl($meeting)
  932. {
  933. if (!isset($meeting['id'])) {
  934. return '';
  935. }
  936. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=publish&id='.$meeting['id'];
  937. }
  938. /**
  939. * @param array $meeting
  940. * @return string
  941. */
  942. public function unPublishUrl($meeting)
  943. {
  944. if (!isset($meeting['id'])) {
  945. return '';
  946. }
  947. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=unpublish&id='.$meeting['id'];
  948. }
  949. /**
  950. * @param array $meeting
  951. * @return string
  952. */
  953. public function deleteRecordUrl($meeting)
  954. {
  955. if (!isset($meeting['id'])) {
  956. return '';
  957. }
  958. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=delete_record&id='.$meeting['id'];
  959. }
  960. /**
  961. * @param array $meeting
  962. * @return string
  963. */
  964. public function copyToRecordToLinkTool($meeting)
  965. {
  966. if (!isset($meeting['id'])) {
  967. return '';
  968. }
  969. return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.$this->getUrlParams().'&action=copy_record_to_link_tool&id='.$meeting['id'];
  970. }
  971. }