示例#1
0
 public function meeting($id = 1, $username = null, $password = null)
 {
     if ($id) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query = "SELECT * FROM `#__bigbluebutton_meetings` WHERE `id`=" . $id;
         $db->setQuery($query);
         $data = $db->loadObject();
         $paidId = 13;
         $user = JFactory::getUser();
         $startTimeInSeconds = $data->start_time / 1000;
         $endTimeInSeconds = $data->end_time / 1000;
         $allowedgroupsids = json_decode($data->allowed_groups);
         /*
         	If duration is zero it causes an audio error, 
         	so if ever a user sets the duration to zero, 
         	instead of passing a zero value, pass the default value of 120 to get out from the error.
         */
         $duration = $data->duration == 0 ? 120 : $data->duration;
         $goCreateParameters = true;
         $isUserAllowed = false;
         $countAllowedUser = 0;
         $allowedusers_ids = json_decode($data->allowed_users);
         /*
         	If a user is selected, only the selected users are allowed to enter the room.
         	If no user is selected, all users are allowed to enter the room.
         */
         if (!empty($allowedusers_ids) && $data->allowed_users != '') {
             foreach ($allowedusers_ids as $alloweduserid) {
                 if ($alloweduserid > 0) {
                     $countAllowedUser++;
                 }
                 if ($alloweduserid == $user->id) {
                     $isUserAllowed = true;
                     break;
                 }
             }
         }
         $isUserModerator = false;
         $moderators_ids = json_decode($data->event_moderators);
         foreach ($moderators_ids as $moderatorid) {
             if ($moderatorid == $user->id) {
                 $isUserModerator = true;
                 break;
             }
         }
         $isGroupAllowed = false;
         $countAllowedGroup = 0;
         $allowedgroups_ids = json_decode($data->allowed_groups);
         $allowedgroups_idsS = $allowedgroups_ids ? implode(', ', $allowedgroups_ids) : '0';
         $query = $db->getQuery(true);
         $query = "SELECT * FROM `#__user_usergroup_map` WHERE `user_id`=" . $user->id . " AND `group_id` IN (" . $allowedgroups_idsS . ")";
         $db->setQuery($query);
         $isUserIntheGroup = $db->loadObjectList();
         /*
         	If a Group is selected, only the selected Group(s) are allowed to enter the room.
         	If no Group is selected, all Group(s) are allowed to enter the room.
         */
         if (!empty($allowedgroups_ids) && $data->allowed_groups != '') {
             foreach ($allowedgroups_ids as $allowedgroupid) {
                 if ($allowedgroupid > 0) {
                     $countAllowedGroup++;
                 }
             }
             if ($isUserIntheGroup) {
                 $isGroupAllowed = true;
             }
         }
         if ($countAllowedGroup == 0 && $countAllowedUser == 0) {
             $isGroupAllowed = true;
             $isUserAllowed = true;
         }
         //Do the conditions whether the bbb event will go and join or not.
         if (!($data->attendeePW == $password || $data->moderatorPW == $password) || time() < $startTimeInSeconds || !(time() <= $endTimeInSeconds) || $startTimeInSeconds >= $endTimeInSeconds || $isUserAllowed == false && $isGroupAllowed == false && $isUserModerator == false) {
             //Conditions
             if (!($data->attendeePW == $password || $data->moderatorPW == $password)) {
                 $output = "Sorry password don't match";
             } else {
                 if ($startTimeInSeconds >= $endTimeInSeconds) {
                     $output = "Invalid Time Set.";
                 } else {
                     if (time() < $startTimeInSeconds) {
                         $output = "Event is not yet available";
                     } else {
                         if (time() > $endTimeInSeconds) {
                             $output = "Event is already finished";
                         } else {
                             $output = "BBB Creation Failed.";
                         }
                     }
                 }
             }
             if ($isUserAllowed == false && $countAllowedUser != 0) {
                 $output .= "<br/> User is not allowed to enter the room";
             }
             if ($isGroupAllowed == false && $countAllowedGroup != 0) {
                 $output .= "<br/> User's Group is not allowed to enter the room";
             }
             $goCreateParameters = false;
             $groupsOfUser = JAccess::getGroupsByUser($user->id);
             //If Group is paid, display the lesson.
             if (in_array($paidId, $allowedgroupsids)) {
                 $goCreateParameters = true;
             }
         }
         /*
         	User is allowed:
         	-A Super User.
         	-Add the ID of the group if you want a group that will always be allowed to enter the room.
         */
         $query = $db->getQuery(true);
         $query = "SELECT * FROM `#__user_usergroup_map` WHERE `user_id`=" . $user->id . " AND `group_id` IN (8)";
         $db->setQuery($query);
         $isSuperUser = $db->loadObjectList();
         //passed through the condition, and if event is open is checked.
         if ($goCreateParameters || $data->event_isopen == 1 || $isSuperUser) {
             $creationParams = array('meetingId' => $data->meeting_id, 'meetingName' => $data->meetingName, 'attendeePw' => $data->attendeePW, 'moderatorPw' => $data->moderatorPW, 'logoutUrl' => 'http://www.intenga.com/donations', 'welcomeMsg' => 'Welcome to ' . $data->meetingName, 'dialNumber' => $this->dialNumber, 'voiceBridge' => $data->voiceBridge, 'startTime' => $data->start_time, 'endTime' => $data->end_time, 'maxParticipants' => $data->maxParticipants, 'record' => $data->record, 'duration' => $duration);
             $goJoin = true;
             $bbb = new BBB($this->salt, $this->url);
             try {
                 $result = $bbb->createMeetingWithXmlResponseArray($creationParams);
             } catch (Exception $e) {
                 echo 'Caught exception: ', $e->getMessage(), "\n";
                 $goJoin = false;
             }
             $infoParams = array('meetingId' => $data->meeting_id, 'password' => $data->moderatorPW);
             try {
                 $meetingInfo = $bbb->getMeetingInfoWithXmlResponseArray($infoParams);
             } catch (Exception $e) {
                 echo 'Caught exception: ', $e->getMessage(), "\n";
             }
             //Start Free Users
             $query = $db->getQuery(true);
             $query = "SELECT * FROM `#__bigbluebutton_freeusers` WHERE `event_id`=" . $data->id;
             $db->setQuery($query);
             $eventWFreeUser = $db->loadObject();
             //if user count is equal or greater than 2 or if a user is a free user, and the user is not a returning user.
             //count($a)
             $free_users_id = json_decode($eventWFreeUser->users_id);
             $lessonIsPaid = false;
             $userReEntered = false;
             if (in_array($user->id, $free_users_id)) {
                 $userReEntered = true;
             }
             //if false means user is a paid user.
             $userIsFree = true;
             $groupsOfUser = JAccess::getGroupsByUser($user->id);
             //If Group is paid, display the lesson.
             if (in_array($paidId, $allowedgroupsids)) {
                 $goJoin = true;
                 $lessonIsPaid = true;
                 if (in_array($paidId, $groupsOfUser)) {
                     $userIsFree = false;
                 }
             }
             $countFree_users_id = count($free_users_id);
             if (($eventWFreeUser->users_count >= 2 || $countFree_users_id >= 2) && $lessonIsPaid == true && $userIsFree == true && $userReEntered == false && $isUserModerator == false) {
                 $goJoin = false;
                 $output = "We are sorry but only 2 free users can enter this room.";
             }
             //End Free Users
             $allowedParticipants = $meetingInfo['participantCount'] - $meetingInfo['moderatorCount'];
             if ($allowedParticipants >= $data->maxParticipants && $allowedParticipants > 0 && $data->maxParticipants > 0 && $isUserModerator == false) {
                 $goJoin = false;
                 $output = "We are sorry but this classroom is full. Why not join one of our other classes.";
             }
             if ($goJoin == true) {
                 if ($result == null) {
                     $output = "Failed to get any response. Maybe we can't contact the BBB server.";
                 } else {
                     if ($result['returncode'] == 'SUCCESS') {
                         $output = $this->getlink($id, $username, $password);
                         //if false means user is a paid user.
                         $userIsFree = true;
                         $groupsOfUser = JAccess::getGroupsByUser($user->id);
                         //If Group is paid, display the lesson.
                         if (in_array($paidId, $groupsOfUser)) {
                             $userIsFree = false;
                         }
                         if ($userIsFree == true) {
                             //Start Free Users
                             $query = $db->getQuery(true);
                             $query = "SELECT * FROM `#__bigbluebutton_freeusers` WHERE `event_id`=" . $data->id;
                             $db->setQuery($query);
                             $eventWithFreeUser = $db->loadObject();
                             $freeusers = array();
                             $freeusers[] = $user->id;
                             if (!$eventWithFreeUser) {
                                 $users_id = json_encode($freeusers);
                                 //Insert/Update BBB Allowed Free Users
                                 $bbbFreeUsers = new stdClass();
                                 $bbbFreeUsers->event_id = $data->id;
                                 $bbbFreeUsers->users_id = $users_id;
                                 $bbbFreeUsers->users_count = 1;
                                 // Insert the objects into the database.
                                 $result = $db->insertObject('#__bigbluebutton_freeusers', $bbbFreeUsers);
                                 $thisId = $db->insertid();
                             } else {
                                 $user_reenter = 0;
                                 $ex_users_id = json_decode($eventWithFreeUser->users_id);
                                 foreach ($ex_users_id as $exusrid) {
                                     if ($user->id == $exusrid) {
                                         $user_reenter = 1;
                                     }
                                     $freeusers[] = $exusrid;
                                 }
                                 if ($user_reenter == 0) {
                                     $users_id = json_encode($freeusers);
                                     $bbbFreeUsers = new stdClass();
                                     $bbbFreeUsers->id = (int) $eventWithFreeUser->id;
                                     $bbbFreeUsers->event_id = $data->id;
                                     $bbbFreeUsers->users_id = $users_id;
                                     $bbbFreeUsers->users_count = $eventWithFreeUser->users_count + 1;
                                     // Insert the objects into the database.
                                     $updateBbbMeeting = $db->updateObject('#__bigbluebutton_freeusers', $bbbFreeUsers, 'id');
                                 }
                             }
                             //End Free Users
                         }
                     } else {
                         $output = "Meeting creation failed";
                     }
                 }
             }
         }
     } else {
         $output = 'BBB ID not set';
     }
     return $output;
 }