/**
  * Calls $chatroom->disconnectUsers for every given user in every
  * given scope ($usersByScope), sends corresponding status messages to
  * chatroom and adds event in history.
  *
  * @param array $usersByScope
  */
 private function disconnectedUsers($usersByScope)
 {
     require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     foreach ($usersByScope as $scope => $users) {
         $users = explode(',', $users);
         $chatroom = ilChatroom::byRoomId($scope);
         if ($chatroom instanceof ilChatroom && is_array($users)) {
             $users = array_filter($users);
             $userDetails = $this->getUserInformation($users);
             $message = json_encode(array('type' => 'disconnected', 'users' => $userDetails, 'timestamp' => date('c')));
             $chatroom->disconnectUsers($users);
             $this->getConnector()->sendMessage($chatroom->getRoomId(), $message);
             if (true || $chatroom->getSetting('enable_history')) {
                 $messageObject = array('type' => 'disconnected', 'users' => $userDetails, 'timestamp' => date('c'));
                 $chatroom->addHistoryEntry($messageObject);
             }
         }
     }
 }
 /**
  * Last step of chat invitations
  * check access for every selected user and send invitation
  */
 public function submitInvitation()
 {
     /**
      * @var $ilUser ilObjUser
      * @var $ilCtrl ilCtrl
      * @var $lng    ilLanguage
      */
     global $ilUser, $ilCtrl, $lng;
     if (!$_POST['addr_ids']) {
         ilUtil::sendFailure($lng->txt('select_one'), true);
         $ilCtrl->redirect($this, 'showAddressbook');
     }
     if (!$_POST['room_id']) {
         ilUtil::sendFailure($lng->txt('select_one'));
         $_POST['addr_id'] = explode(',', $_POST['addr_ids']);
         $this->inviteToChat();
         return;
     }
     // get selected users (comma seperated user id list)
     $ids = explode(',', $_POST['addr_ids']);
     // get selected chatroom from POST-String, format: "room_id , scope"
     $room_ids = explode(',', $_POST['room_id']);
     $room_id = (int) $room_ids[0];
     $scope = 0;
     if (count($room_ids) > 0) {
         $scope = (int) $room_ids[1];
     }
     include_once 'Modules/Chatroom/classes/class.ilChatroom.php';
     $room = ilChatroom::byRoomId((int) $room_id, true);
     $no_access = array();
     $no_login = array();
     $valid_users = array();
     $valid_user_to_login_map = array();
     foreach ($ids as $id) {
         $entry = $this->abook->getEntry($id);
         if ($entry['login']) {
             $user_id = $ilUser->getUserIdByLogin($entry['login']);
             if (!$user_id) {
                 $no_login[] = $id;
                 continue;
             }
             $ref_id = $room->getRefIdByRoomId($room_id);
             if (!ilChatroom::checkPermissionsOfUser($user_id, 'read', $ref_id) || $room->isUserBanned($user_id)) {
                 $no_access[] = $id;
             } else {
                 $valid_users[] = $user_id;
                 $valid_user_to_login_map[$user_id] = $entry['login'];
             }
         } else {
             $no_login[] = $id;
         }
     }
     if (count($no_access) || count($no_login)) {
         $message = '';
         if (count($no_access)) {
             $message .= $lng->txt('chat_users_without_permission') . ':<br>';
             $list = '';
             foreach ($no_access as $e) {
                 $list .= '<li>' . $this->abook->entryToString($e) . '</li>';
             }
             $message .= '<ul>';
             $message .= $list;
             $message .= '</ul>';
         }
         if (count($no_login)) {
             $message .= $lng->txt('chat_users_without_login') . ':<br>';
             $list = '';
             foreach ($no_login as $e) {
                 $list .= '<li>' . $this->abook->entryToString($e) . '</li>';
             }
             $message .= '<ul>';
             $message .= $list;
             $message .= '</ul>';
         }
         ilUtil::sendFailure($message);
         $_POST['addr_id'] = $ids;
         $this->inviteToChat();
         return;
     }
     $ref_id = $room->getRefIdByRoomId($room_id);
     $url = '';
     include_once 'Services/Link/classes/class.ilLink.php';
     if ($scope) {
         $url = ilLink::_getStaticLink($ref_id, 'chta', true, '_' . $scope);
     } else {
         $url = ilLink::_getStaticLink($ref_id, 'chta');
     }
     $link = '<p><a target="chatframe" href="' . $url . '" title="' . $lng->txt('goto_invitation_chat') . '">' . $lng->txt('goto_invitation_chat') . '</a></p>';
     $userlist = array();
     foreach ($valid_users as $id) {
         $room->inviteUserToPrivateRoom($id, $scope);
         $room->sendInvitationNotification(null, $ilUser->getId(), $id, (int) $scope, $url);
         $userlist[] = '<li>' . $valid_user_to_login_map[$id] . '</li>';
     }
     if ($userlist) {
         ilUtil::sendSuccess($lng->txt('chat_users_have_been_invited') . '<ul>' . implode('', $userlist) . '</ul>' . $link, true);
     }
     $ilCtrl->redirect($this, 'showAddressbook');
 }