示例#1
0
 public function DeleteUser($chatId, $userId, $checkPermission = true)
 {
     global $DB;
     $chatId = intval($chatId);
     $userId = intval($userId);
     if ($chatId <= 0 || $userId <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_OR_CHAT"), "EMPTY_USER_OR_CHAT");
         return false;
     }
     $strSql = "\n\t\t\tSELECT R.CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID, C.EXTRANET CHAT_EXTRANET, C.TYPE CHAT_TYPE\n\t\t\tFROM b_im_relation R LEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\tWHERE R.USER_ID = " . $userId . " AND R.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "') AND R.CHAT_ID = " . $chatId;
     $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if ($arRes = $dbRes->Fetch()) {
         $extranetFlag = $arRes["CHAT_EXTRANET"] == "" ? "" : ($arRes["CHAT_EXTRANET"] == "Y" ? true : false);
         $chatTitle = $arRes['CHAT_TITLE'];
         $chatType = $arRes['CHAT_TYPE'];
         $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']);
         if ($chatAuthorId == $userId) {
             $strSql = "\n\t\t\t\t\tSELECT R.USER_ID\n\t\t\t\t\tFROM b_im_relation R\n\t\t\t\t\tWHERE R.CHAT_ID = " . $chatId . " AND R.USER_ID <> " . $chatAuthorId;
             $strSql = $DB->TopSql($strSql, 1);
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($arRes = $dbRes->Fetch()) {
                 $strSql = "UPDATE b_im_chat SET AUTHOR_ID = " . $arRes['USER_ID'] . " WHERE ID = " . $chatId;
                 $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
         }
         $bSelf = true;
         $arUsers = array($userId);
         if (is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->GetId() != $userId) {
             if ($checkPermission && $chatAuthorId != $GLOBALS["USER"]->GetId()) {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_KICK"), "IM_ERROR_KICK");
                 return false;
             }
             $bSelf = false;
             $arUsers[] = $GLOBALS["USER"]->GetId();
         }
         $arOldRelation = CIMChat::GetRelationById($chatId);
         $arUsers = CIMContactList::GetUserData(array('ID' => array_keys($arOldRelation), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N'));
         $arUsers = $arUsers['users'];
         if ($bSelf) {
             $message = GetMessage("IM_CHAT_LEAVE_" . $arUsers[$userId]['gender'], array('#USER_NAME#' => htmlspecialcharsback($arUsers[$userId]['name'])));
         } else {
             $message = GetMessage("IM_CHAT_KICK_" . $arUsers[$GLOBALS["USER"]->GetId()]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$GLOBALS["USER"]->GetId()]['name']), '#USER_2_NAME#' => htmlspecialcharsback($arUsers[$userId]['name'])));
         }
         $CIMChat = new CIMChat($userId);
         $CIMChat->SetReadMessage($chatId);
         CIMContactList::CleanChatCache($userId);
         $publicPullWatch = false;
         if ($chatType == IM_MESSAGE_OPEN && CModule::IncludeModule("pull")) {
             $publicPullWatch = true;
         }
         $relationList = IM\RelationTable::getList(array("select" => array("ID", "USER_ID"), "filter" => array("=CHAT_ID" => $chatId, "=USER_ID" => $userId)));
         while ($relation = $relationList->fetch()) {
             if ($publicPullWatch && !$arUsers[$relation["USER_ID"]]['extranet']) {
                 CPullWatch::Add($relation["USER_ID"], 'IM_PUBLIC_' . $chatId, true);
             }
             Im\RelationTable::delete($relation["ID"]);
             CIMContactList::DeleteRecent($chatId, true, $relation["USER_ID"]);
             if ($extranetFlag !== false) {
                 $isExtranet = false;
                 foreach ($arUsers as $userData) {
                     if ($userData['id'] == $userId) {
                         continue;
                     }
                     if ($userData['extranet']) {
                         $isExtranet = true;
                         break;
                     }
                 }
                 if (!$isExtranet || $extranetFlag === "") {
                     IM\ChatTable::update($chatId, array('EXTRANET' => $isExtranet ? "Y" : "N"));
                 }
                 $extranetFlag = $isExtranet;
             }
         }
         CIMDisk::ChangeFolderMembers($chatId, $userId, false);
         self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y'));
         foreach ($arOldRelation as $rel) {
             CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserLeave', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'userId' => $userId, 'message' => $bSelf ? '' : htmlspecialcharsbx($message))));
         }
         return true;
     }
     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_USER_NOT_FOUND"), "USER_NOT_FOUND");
     return false;
 }
示例#2
0
文件: im_chat.php 项目: vim84/b-markt
 public function DeleteUser($chatId, $userId, $checkPermission = true)
 {
     global $DB;
     $chatId = intval($chatId);
     $userId = intval($userId);
     if ($chatId <= 0 || $userId <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_OR_CHAT"), "EMPTY_USER_OR_CHAT");
         return false;
     }
     $strSql = "\n\t\t\tSELECT R.CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID\n\t\t\tFROM b_im_relation R LEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\tWHERE R.USER_ID = " . $userId . " AND R.MESSAGE_TYPE = '" . IM_MESSAGE_GROUP . "' AND R.CHAT_ID = " . $chatId;
     $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if ($arRes = $dbRes->Fetch()) {
         $chatTitle = $arRes['CHAT_TITLE'];
         $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']);
         if ($chatAuthorId == $userId) {
             $strSql = "\n\t\t\t\t\tSELECT R.USER_ID\n\t\t\t\t\tFROM b_im_relation R\n\t\t\t\t\tWHERE R.CHAT_ID = " . $chatId . " AND R.USER_ID <> " . $chatAuthorId;
             $strSql = $DB->TopSql($strSql, 1);
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($arRes = $dbRes->Fetch()) {
                 $strSql = "UPDATE b_im_chat SET AUTHOR_ID = " . $arRes['USER_ID'] . " WHERE ID = " . $chatId;
                 $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
         }
         $bSelf = true;
         $arUsers = array($userId);
         if (is_object($GLOBALS["USER"]) && $GLOBALS["USER"]->GetId() != $userId) {
             if ($checkPermission && $chatAuthorId != $GLOBALS["USER"]->GetId()) {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_KICK"), "IM_ERROR_KICK");
                 return false;
             }
             $bSelf = false;
             $arUsers[] = $GLOBALS["USER"]->GetId();
         }
         $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME", "PERSONAL_GENDER");
         $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => implode('|', $arUsers)), array('FIELDS' => $arSelect));
         $arUsers = array();
         while ($arUser = $dbUsers->Fetch()) {
             $arUsers[$arUser['ID']]['NAME'] = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
             $arUsers[$arUser['ID']]['GENDER'] = $arUser["PERSONAL_GENDER"] == 'F' ? 'F' : 'M';
         }
         if ($bSelf) {
             $message = GetMessage("IM_CHAT_LEAVE_" . $arUsers[$userId]['GENDER'], array('#USER_NAME#' => $arUsers[$userId]['NAME']));
         } else {
             $message = GetMessage("IM_CHAT_KICK_" . $arUsers[$GLOBALS["USER"]->GetId()]['GENDER'], array('#USER_1_NAME#' => $arUsers[$GLOBALS["USER"]->GetId()]['NAME'], '#USER_2_NAME#' => $arUsers[$userId]['NAME']));
         }
         $arOldRelation = array();
         if (CModule::IncludeModule("pull")) {
             $arOldRelation = CIMChat::GetRelationById($chatId);
         }
         $CIMChat = new CIMChat($userId);
         $CIMChat->SetReadMessage($chatId);
         CIMContactList::CleanChatCache($userId);
         $strSql = "DELETE FROM b_im_relation WHERE CHAT_ID = " . $chatId . " AND USER_ID = " . $userId;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         CIMDisk::ChangeFolderMembers($chatId, $userId, false);
         self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y'));
         foreach ($arOldRelation as $rel) {
             CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserLeave', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'userId' => $userId, 'message' => $bSelf ? '' : htmlspecialcharsbx($message))));
         }
         CIMContactList::DeleteRecent($chatId, true, $userId);
         return true;
     }
     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_USER_NOT_FOUND"), "USER_NOT_FOUND");
     return false;
 }