start.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * This script initiates a videoconference session, calling the BigBlueButton API
  4. * @package chamilo.plugin.bigbluebutton
  5. */
  6. /**
  7. * Initialization
  8. */
  9. require_once '../../main/inc/global.inc.php';
  10. require_once 'bbb.lib.php';
  11. //The script receives the course_code (cidReq), which allows it to get the corresponding data
  12. $cid = api_get_real_course_id();
  13. $ccode = api_get_course_id();
  14. // initialize conference settings from course settings
  15. $meeting_name = api_get_course_setting('big_blue_button_meeting_name',$ccode);
  16. if (empty($meeting_name) or $meeting_name==-1) { $meeting_name = $ccode; }
  17. $meeting_att_pw = api_get_course_setting('big_blue_button_meeting_attendee_pw',$ccode);
  18. if (empty($meeting_att_pw) or $meeting_att_pw==-1) { $meeting_att_pw = $ccode; }
  19. $meeting_mod_pw = api_get_course_setting('big_blue_button_meeting_moderator_pw',$ccode);
  20. if (empty($meeting_mod_pw) or $meeting_mod_pw==-1) { $meeting_mod_pw = $ccode.'mod'; }
  21. $meeting_wel_ms = api_get_course_setting('big_blue_button_meeting_welcome_message',$ccode);
  22. if (empty($meeting_wel_ms) or $meeting_wel_ms==-1) { $meeting_wel_ms = ''; }
  23. // initialize video server settings from global settings
  24. $settings = api_get_settings('Extra','list',api_get_current_access_url_id());
  25. $bbb_settings = array();
  26. foreach ($settings as $setting) {
  27. if (substr($setting['variable'],0,4)==='bbb_') {
  28. $bbb_settings[$setting['variable']] = $setting['selected_value'];
  29. }
  30. }
  31. $bbb_plugin = $bbb_settings['bbb_plugin'] === 'true';
  32. $bbb_host = $bbb_settings['bbb_plugin_host'];
  33. $bbb_salt = $bbb_settings['bbb_plugin_salt'];
  34. if (!$bbb_plugin) {
  35. //the BigBlueButton plugin is not enabled (strangely), return to course homepage
  36. header('location: '.api_get_path(WEB_COURSE_PATH).'/'.$ccode);
  37. }
  38. $teacher = api_is_course_admin() || api_is_coach() || api_is_platform_admin();
  39. $user_info = api_get_user_info(api_get_user_id());
  40. $full_user_name = api_get_person_name($user_info['firstname'],$user_info['lastname']);
  41. $user_id = api_get_user_id();
  42. $is_running = wc_isMeetingRunning($bbb_host,$bbb_salt,$meeting_name);
  43. if ($is_running == 'true') {
  44. // The conference is running, everything is fine, join
  45. header('location: '.wc_joinMeetingURL($bbb_host,$bbb_salt,$full_user_name,$meeting_name,($teacher?$meeting_mod_pw:$meeting_att_pw),$user_id));
  46. exit;
  47. } else { //$is_running = false or 'false'
  48. // The conference room does not seem to be running...
  49. // First, try harder and ignore the "running" status
  50. $meetings = wc_getRunningMeetings($bbb_host,$bbb_salt);
  51. $found = false;
  52. foreach ($meetings as $meeting) {
  53. //Try to find our meeting room in the list...
  54. if ($meeting['meetingID'] == $meeting_name) {
  55. $meeting_info = wc_getMeetingInfo($bbb_host,$bbb_salt,$meeting_name,$meeting_mod_pw);
  56. error_log('Found passive meeting created '.($meeting_info['createTime']).' seconds ago with '.count($meeting_info['attendees']).' attendees - joining as '.($teacher?'teacher':'student'));
  57. //if the user is a teacher, or if there are already attendees in
  58. // the conference room, then allow joining it
  59. if ($teacher or count($meeting_info['attendees'])>0) {
  60. header('location: '.wc_joinMeetingURL($bbb_host,$bbb_salt,$full_user_name,$meeting_name,($teacher?$meeting_mod_pw:$meeting_att_pw),$user_id));
  61. exit;
  62. }
  63. }
  64. }
  65. // That conference room is really not running or it has no
  66. // accompanying moderator subscribed
  67. if ($teacher) {
  68. // The user is a teacher, so he has the right to create the
  69. // room, so create it and join it
  70. wc_createMeeting($bbb_host,$bbb_salt,$meeting_name,$meeting_name,$meeting_att_pw,$meeting_mod_pw,$meeting_wel_ms,api_get_path(WEB_COURSE_PATH).'/'.$ccode);
  71. header('location: '.wc_joinMeetingURL($bbb_host,$bbb_salt,$full_user_name,$meeting_name,($teacher?$meeting_mod_pw:$meeting_att_pw),$user_id));
  72. exit;
  73. } else {
  74. // There is no conference room for this course and the user
  75. // is a mere student, so he cannot start a conference room by
  76. // himself: a teacher has to launch it first
  77. header('location: '.api_get_path(WEB_COURSE_PATH).'/'.$ccode);
  78. exit;
  79. }
  80. }