Esempio n. 1
0
 public static function OnGetNotifySchema()
 {
     $arResult = array("socialnetwork" => array("invite_group" => array("NAME" => GetMessage("SONET_NS_INVITE_GROUP")), "inout_group" => array("NAME" => GetMessage("SONET_NS_INOUT_GROUP")), "moderators_group" => array("NAME" => GetMessage("SONET_NS_MODERATORS_GROUP")), "owner_group" => array("NAME" => GetMessage("SONET_NS_OWNER_GROUP")), "sonet_group_event" => array("NAME" => GetMessage("SONET_NS_SONET_GROUP_EVENT"))));
     if (CSocNetUser::IsFriendsAllowed()) {
         /*
         			$arResult["socialnetwork"]["invite_user"] = Array(
         				"NAME" => GetMessage("SONET_NS_INVITE_USER")
         			);
         */
         $arResult["socialnetwork"]["inout_user"] = array("NAME" => GetMessage("SONET_NS_FRIEND"));
     }
     return $arResult;
 }
Esempio n. 2
0
	public static function Invite($arParams)
	{
		$arConfig['CHAT_ID'] = intval($arParams['CHAT_ID']);
		if ($arConfig['CHAT_ID'] <= 0)
			return false;

		global $DB, $USER;

		$arConfig['RECIPIENT_ID'] = intval($arParams['RECIPIENT_ID']);
		$arConfig['USER_ID'] = intval($arParams['USER_ID']) > 0? intval($arParams['USER_ID']): IntVal($USER->GetID());
		$arConfig['VIDEO'] = isset($arParams['VIDEO']) && $arParams['VIDEO'] == 'N'? 'N': 'Y';

		$arChat = CIMChat::GetChatData(Array('ID' => $arConfig['CHAT_ID']));
		if (empty($arChat['chat']))
			return false;

		$arConfig['CALL_TO_GROUP'] = $arChat['chat'][$arConfig['CHAT_ID']]['type'] == IM_MESSAGE_GROUP;
		$arConfig['STATUS_TYPE'] = intval($arChat['chat'][$arConfig['CHAT_ID']]['call']);

		if (!$arConfig['CALL_TO_GROUP'] && !IsModuleInstalled('intranet') && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CALL, $arConfig['RECIPIENT_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT
			&& CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arConfig['USER_ID'], $arConfig['RECIPIENT_ID']))
		{
			$GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_CALL_PRIVACY'), "ERROR_FROM_PRIVACY");
			return false;
		}

		if ($arConfig['STATUS_TYPE'] != IM_CALL_NONE)
		{
			if ($arConfig['CALL_TO_GROUP'])
				self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_START_", $arConfig['USER_ID'], true);

			$strSql = "UPDATE b_im_relation SET CALL_STATUS = ".IM_CALL_STATUS_ANSWER." WHERE CHAT_ID = ".$arConfig['CHAT_ID']." AND USER_ID = ".$arConfig['USER_ID'];
			$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			$arUserData = CIMContactList::GetUserData(Array('ID' => $arChat['userInChat'][$arConfig['CHAT_ID']], 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y'));
			$arConfig['USER_DATA']['USERS'] = $arUserData['users'];
			$arConfig['USER_DATA']['HR_PHOTO'] = $arUserData['hrphoto'];

			foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus)
			{
				if ($userId != $arConfig['USER_ID'] && in_array($callStatus, Array(IM_CALL_STATUS_WAIT, IM_CALL_STATUS_ANSWER)))
					$arUserToConnect[$userId] = $callStatus;
			}
			$arConfig['USERS_CONNECT'] = $arUserToConnect;
			
			$arSend['users'] = $arUserData['users'];
			$arSend['hrphoto'] = $arUserData['hrphoto'];
			$arSend['video'] = $arConfig['VIDEO'] == 'Y'? true: false;
			$arSend['callToGroup'] = $arConfig['CALL_TO_GROUP'];
			$arSend['chat'] = $arChat['chat'];
			$arSend['userInChat'] = $arChat['userInChat'];
			foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus)
				if ($userId != $arConfig['USER_ID'] && !in_array($callStatus, Array(IM_CALL_STATUS_DECLINE)))
					self::Command($arConfig['CHAT_ID'], $userId, 'invite_join', $arSend);
		}
		else
		{
			if ($arConfig['CALL_TO_GROUP'])
				self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_INIT_", $arConfig['USER_ID'], true);

			$strSql = "UPDATE b_im_chat SET CALL_TYPE = ".($arConfig['VIDEO'] == 'Y'? IM_CALL_VIDEO: IM_CALL_AUDIO)." WHERE ID = ".$arConfig['CHAT_ID'];
			$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			$strSql = "UPDATE b_im_relation SET CALL_STATUS = ".IM_CALL_STATUS_ANSWER." WHERE CHAT_ID = ".$arConfig['CHAT_ID']." AND USER_ID = ".$arConfig['USER_ID'];
			$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			$arUserToConnect = Array();
			foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus)
			{
				if ($userId != $arConfig['USER_ID'])
					$arUserToConnect[$userId] = $callStatus;
			}

			$arUserData = CIMContactList::GetUserData(Array('ID' => $arChat['userInChat'][$arConfig['CHAT_ID']], 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y'));
			$arSend['users'] = $arUserData['users'];
			$arSend['hrphoto'] = $arUserData['hrphoto'];
			$arSend['video'] = $arConfig['VIDEO'] == 'Y'? true: false;
			$arSend['callToGroup'] = $arConfig['CALL_TO_GROUP'];
			$arSend['chat'] = $arChat['chat'];
			$arSend['userInChat'] = $arChat['userInChat'];
			foreach ($arUserToConnect as $userId => $callStatus)
				self::Command($arConfig['CHAT_ID'], $userId, 'invite', $arSend);

			$arConfig['USER_DATA']['USERS'] = $arUserData['users'];
			$arConfig['USER_DATA']['HR_PHOTO'] = $arUserData['hrphoto'];
		}
		foreach(GetModuleEvents("im", "OnCallStart", true) as $arEvent)
			ExecuteModuleEventEx($arEvent, array($arConfig));

		return $arConfig;
	}
Esempio n. 3
0
 public function AddUser($chatId, $userId)
 {
     global $DB;
     $chatId = intval($chatId);
     if ($chatId <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_CHAT_ID"), "EMPTY_CHAT_ID");
         return false;
     }
     $arUserId = array();
     if (is_array($userId)) {
         foreach ($userId as $value) {
             $arUserId[] = intval($value);
         }
     } else {
         $arUserId[] = intval($userId);
     }
     if (count($arUserId) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID"), "EMPTY_USER_ID");
         return false;
     }
     if (!IsModuleInstalled('intranet') && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) {
         global $USER;
         $arFriendUsers = array();
         $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $USER->GetID(), "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID", "DATE_CREATE", "DATE_UPDATE", "INITIATED_BY"));
         while ($arFriends = $dbFriends->Fetch()) {
             $friendId = $USER->GetID() == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
             $arFriendUsers[$friendId] = $friendId;
         }
         foreach ($arUserId as $id => $userId) {
             if ($userId == $USER->GetID()) {
                 continue;
             }
             if (!isset($arFriendUsers[$userId]) && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CHAT, $userId) == CIMSettings::PRIVACY_RESULT_CONTACT) {
                 unset($arUserId[$id]);
             }
         }
         if (count($arUserId) <= 0) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID_BY_PRIVACY"), "EMPTY_USER_ID_BY_PRIVACY");
             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 = " . $this->user_id . " 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']);
         $arRelation = self::GetRelationById($chatId);
         $arExistUser = array();
         foreach ($arRelation as $relation) {
             $arExistUser[] = $relation['USER_ID'];
         }
         if (count($arRelation) + count($arUserId) > 100) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MAX_USER", array('#COUNT#' => 100)), "MAX_USER");
             return false;
         }
         $arUserId = array_diff($arUserId, $arExistUser);
         if (empty($arUserId)) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_NOTHING_TO_ADD"), "NOTHING_TO_ADD");
             return false;
         }
         $arUserSelect = $arUserId;
         $arUserSelect[] = $this->user_id;
         $arUsers = CIMContactList::GetUserData(array('ID' => array_values($arUserSelect), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N'));
         $arUsers = $arUsers['users'];
         $maxId = 0;
         $strSql = "SELECT MAX(ID) ID FROM b_im_message WHERE CHAT_ID = " . $chatId . " GROUP BY CHAT_ID";
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($arRes = $dbRes->Fetch()) {
             $maxId = $arRes['ID'];
         }
         $fileMaxId = CIMDisk::GetMaxFileId($chatId);
         $arUsersName = array();
         foreach ($arUserId as $userId) {
             $arUsersName[] = htmlspecialcharsback($arUsers[$userId]['name']);
             CIMContactList::SetRecent($chatId, $maxId, true, $userId);
             $strSql = "INSERT INTO b_im_relation (CHAT_ID, MESSAGE_TYPE, USER_ID, START_ID, LAST_ID, LAST_SEND_ID, LAST_FILE_ID) VALUES (" . $chatId . ",'" . IM_MESSAGE_GROUP . "'," . $userId . "," . ($maxId + 1) . "," . $maxId . "," . $maxId . ", " . $fileMaxId . ")";
             $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             CIMContactList::CleanChatCache($userId);
         }
         CIMDisk::ChangeFolderMembers($chatId, $arUserId);
         $message = GetMessage("IM_CHAT_JOIN_" . $arUsers[$this->user_id]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$this->user_id]['name']), '#USER_2_NAME#' => implode(', ', $arUsersName)));
         if (CModule::IncludeModule("pull")) {
             foreach ($arRelation as $ar) {
                 CPullStack::AddByUser($ar['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserAdd', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'chatOwner' => $chatAuthorId, 'users' => $arUsers, 'newUsers' => $arUserId)));
             }
         }
         self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y'));
         return true;
     }
     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_AUTHORIZE_ERROR"), "AUTHORIZE_ERROR");
     return false;
 }
Esempio n. 4
0
	public function UpdateCodes($USER_ID)
	{
		global $DB;
		if(CSocNetUser::IsFriendsAllowed())
		{
			$USER_ID = intval($USER_ID);
			
			$dbFriends = CSocNetUserRelations::GetRelatedUsers($USER_ID, SONET_RELATIONS_FRIEND);
			while ($arFriends = $dbFriends->Fetch())
			{
				$friendID = (($USER_ID == $arFriends["FIRST_USER_ID"]) ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"]);
				$DB->Query("INSERT INTO b_user_access (USER_ID, PROVIDER_ID, ACCESS_CODE) VALUES 
					(".$friendID.", '".$DB->ForSQL($this->id)."', 'SU".$USER_ID."_".SONET_RELATIONS_TYPE_FRIENDS."')");

				$arFriends2Exist = array();
				$dbRes = $DB->Query("SELECT USER_ID FROM b_user_access WHERE PROVIDER_ID = '".$DB->ForSQL($this->id)."' AND ACCESS_CODE = 'SU".$USER_ID."_".SONET_RELATIONS_TYPE_FRIENDS2."'");
				while ($arRes = $dbRes->Fetch())
					$arFriends2Exist[] = $arRes["USER_ID"];

				$dbFriends2 = CSocNetUserRelations::GetRelatedUsers($friendID, SONET_RELATIONS_FRIEND);
				while ($arFriends2 = $dbFriends2->Fetch())
				{
					$friendID2 = (($friendID == $arFriends2["FIRST_USER_ID"]) ? $arFriends2["SECOND_USER_ID"] : $arFriends2["FIRST_USER_ID"]);
					if ($friendID2 != $USER_ID && !in_array($friendID2, $arFriends2Exist))
						$DB->Query("INSERT INTO b_user_access (USER_ID, PROVIDER_ID, ACCESS_CODE) VALUES 
							(".$friendID2.", '".$DB->ForSQL($this->id)."', 'SU".$USER_ID."_".SONET_RELATIONS_TYPE_FRIENDS2."')");
				}
			}	
		}
	}
Esempio n. 5
0
 public function AddUser($chatId, $userId)
 {
     global $DB;
     $chatId = intval($chatId);
     if ($chatId <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_CHAT_ID"), "EMPTY_CHAT_ID");
         return false;
     }
     $arUserId = array();
     if (is_array($userId)) {
         $arUserId = \CIMContactList::PrepareUserIds($userId);
     } else {
         if (intval($userId) > 0) {
             $arUserId[intval($userId)] = intval($userId);
         }
     }
     if ($this->user_id > 0) {
         $arUserId[$this->user_id] = $this->user_id;
     }
     if (count($arUserId) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID"), "EMPTY_USER_ID");
         return false;
     }
     if ($this->user_id > 0 && !IsModuleInstalled('intranet') && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) {
         $arFriendUsers = array();
         $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $this->user_id, "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID", "DATE_CREATE", "DATE_UPDATE", "INITIATED_BY"));
         while ($arFriends = $dbFriends->Fetch()) {
             $friendId = $this->user_id == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
             $arFriendUsers[$friendId] = $friendId;
         }
         foreach ($arUserId as $id => $userId) {
             if ($userId == $this->user_id) {
                 continue;
             }
             if (!isset($arFriendUsers[$userId]) && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CHAT, $userId) == CIMSettings::PRIVACY_RESULT_CONTACT) {
                 unset($arUserId[$id]);
             }
         }
         if (count($arUserId) <= 0) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_EMPTY_USER_ID_BY_PRIVACY"), "EMPTY_USER_ID_BY_PRIVACY");
             return false;
         }
     }
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tR.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\n\t\t\tLEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID\n\t\t\tWHERE\n\t\t\t\t" . ($this->user_id > 0 ? "R.USER_ID = " . $this->user_id . " AND " : "") . "\n\t\t\t\tR.MESSAGE_TYPE IN ('" . IM_MESSAGE_OPEN . "','" . IM_MESSAGE_CHAT . "')\n\t\t\t\tAND R.CHAT_ID = " . $chatId . "\n\t\t";
     $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'];
         $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']);
         $chatType = intval($arRes['CHAT_TYPE']);
         $arRelation = self::GetRelationById($chatId);
         $arExistUser = array();
         foreach ($arRelation as $relation) {
             $arExistUser[] = $relation['USER_ID'];
         }
         if (count($arRelation) + count($arUserId) > 500) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MAX_USER", array('#COUNT#' => 500)), "MAX_USER");
             return false;
         }
         $arUserId = array_diff($arUserId, $arExistUser);
         if (empty($arUserId)) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_NOTHING_TO_ADD"), "NOTHING_TO_ADD");
             return false;
         }
         $arUserSelect = $arUserId;
         if ($this->user_id > 0) {
             $arUserSelect[] = $this->user_id;
         }
         $arUsers = CIMContactList::GetUserData(array('ID' => array_values($arUserSelect), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N'));
         $arUsers = $arUsers['users'];
         if ($extranetFlag !== true) {
             $isExtranet = false;
             foreach ($arUsers as $userData) {
                 if ($userData['extranet']) {
                     $isExtranet = true;
                     break;
                 }
             }
             if ($isExtranet || $extranetFlag === "") {
                 IM\ChatTable::update($chatId, array('EXTRANET' => $isExtranet ? "Y" : "N"));
             }
             $extranetFlag = $isExtranet;
         }
         $arUsersName = array();
         foreach ($arUserId as $userId) {
             $arUsersName[] = htmlspecialcharsback($arUsers[$userId]['name']);
         }
         if ($this->user_id > 0) {
             $message = GetMessage("IM_CHAT_JOIN_" . $arUsers[$this->user_id]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$this->user_id]['name']), '#USER_2_NAME#' => implode(', ', $arUsersName)));
         } else {
             if (count($arUsersName) > 1) {
                 $message = GetMessage("IM_CHAT_SELF_JOIN", array('#USERS_NAME#' => implode(', ', $arUsersName)));
             } else {
                 $arUserList = array_values($arUserId);
                 $message = GetMessage("IM_CHAT_SELF_JOIN_" . $arUsers[$arUserList[0]]['gender'], array('#USER_NAME#' => implode(', ', $arUsersName)));
             }
         }
         $fileMaxId = CIMDisk::GetMaxFileId($chatId);
         $maxId = 0;
         $strSql = "SELECT MAX(ID) ID FROM b_im_message WHERE CHAT_ID = " . $chatId . " GROUP BY CHAT_ID";
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($arMax = $dbRes->Fetch()) {
             $maxId = $arMax['ID'];
         }
         $update = array();
         $publicPullWatch = false;
         if ($chatType == IM_MESSAGE_OPEN && CModule::IncludeModule("pull")) {
             $publicPullWatch = true;
         }
         foreach ($arUserId as $userId) {
             if ($publicPullWatch) {
                 CPullWatch::Delete($userId, 'IM_PUBLIC_' . $chatId);
             }
             CIMContactList::SetRecent(array('ENTITY_ID' => $chatId, 'MESSAGE_ID' => $maxId, 'CHAT_TYPE' => $arRes['CHAT_TYPE'], 'USER_ID' => $userId));
             $hideHistory = CIMSettings::GetStartChatMessage() == CIMSettings::START_MESSAGE_LAST && $arRes['CHAT_TYPE'] == IM_MESSAGE_CHAT;
             if ($arRes['CHAT_TYPE'] != IM_MESSAGE_PRIVATE && $arUsers[$userId]['extranet']) {
                 $hideHistory = true;
             }
             $orm = IM\RelationTable::add(array("CHAT_ID" => $chatId, "MESSAGE_TYPE" => $arRes['CHAT_TYPE'], "USER_ID" => $userId, "START_ID" => $hideHistory ? $maxId + 1 : 0, "LAST_ID" => $maxId, "LAST_SEND_ID" => $maxId, "LAST_FILE_ID" => $hideHistory ? $fileMaxId : 0));
             $update[] = $orm->getId();
             CIMContactList::CleanChatCache($userId);
         }
         CIMDisk::ChangeFolderMembers($chatId, $arUserId);
         if (CModule::IncludeModule("pull")) {
             foreach ($arRelation as $ar) {
                 CPullStack::AddByUser($ar['USER_ID'], array('module_id' => 'im', 'command' => 'chatUserAdd', 'params' => array('chatId' => $chatId, 'chatTitle' => $chatTitle, 'chatOwner' => $chatAuthorId, 'chatExtranet' => $extranetFlag, 'users' => $arUsers, 'newUsers' => $arUserId)));
             }
         }
         $lastId = self::AddMessage(array("TO_CHAT_ID" => $chatId, "MESSAGE" => $message, "FROM_USER_ID" => $this->user_id, "SYSTEM" => 'Y'));
         if (IsModuleInstalled('replica')) {
             if ($lastId && CIMSettings::GetStartChatMessage() == CIMSettings::START_MESSAGE_LAST && $arRes['CHAT_TYPE'] == IM_MESSAGE_CHAT) {
                 foreach ($update as $relId) {
                     IM\RelationTable::update($relId, array('START_ID' => $lastId));
                 }
             }
         }
         return true;
     }
     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_AUTHORIZE_ERROR"), "AUTHORIZE_ERROR");
     return false;
 }
Esempio n. 6
0
         }
     }
     if (count($arResult["UserPropertiesMain"]["DATA"]) > 0) {
         $arResult["UserPropertiesMain"]["SHOW"] = "Y";
     }
     if (count($arResult["UserPropertiesContact"]["DATA"]) > 0) {
         $arResult["UserPropertiesContact"]["SHOW"] = "Y";
     }
     if (count($arResult["UserPropertiesPersonal"]["DATA"]) > 0) {
         $arResult["UserPropertiesPersonal"]["SHOW"] = "Y";
     }
 }
 if (!$arParams["SHORT_FORM"]) {
     // USER FRIENDS
     $arResult["Friends"] = false;
     if (CSocNetUser::IsFriendsAllowed() && $arResult["CurrentUserPerms"]["Operations"]["viewfriends"]) {
         $dbFriends = CSocNetUserRelations::GetRelatedUsers($arResult["User"]["ID"], SONET_RELATIONS_FRIEND, array("nTopCount" => $arParams["ITEMS_COUNT"]));
         if ($dbFriends) {
             $arResult["Friends"] = array();
             $arResult["Friends"]["Count"] = CSocNetUserRelations::GetList(array(), array("USER_ID" => $arResult["User"]["ID"], "RELATION" => SONET_RELATIONS_FRIEND), array());
             $arResult["Friends"]["List"] = false;
             while ($arFriends = $dbFriends->GetNext()) {
                 if ($arResult["Friends"]["List"] == false) {
                     $arResult["Friends"]["List"] = array();
                 }
                 $pref = IntVal($arResult["User"]["ID"]) == $arFriends["FIRST_USER_ID"] ? "SECOND" : "FIRST";
                 $pu = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arFriends[$pref . "_USER_ID"]));
                 $canViewProfile = CSocNetUserPerms::CanPerformOperation($GLOBALS["USER"]->GetID(), $arFriends[$pref . "_USER_ID"], "viewprofile", CSocNetUser::IsCurrentUserModuleAdmin());
                 if (intval($arParams["THUMBNAIL_LIST_SIZE"]) > 0) {
                     if (intval($arFriends[$pref . "_USER_PERSONAL_PHOTO"]) <= 0) {
                         switch ($arFriends[$pref . "_USER_PERSONAL_GENDER"]) {
	public static function Add($arFields)
	{
		global $DB;

		if (isset($arFields['TITLE']) && !isset($arFields['NOTIFY_TITLE']))
			$arFields['NOTIFY_TITLE'] = $arFields['TITLE'];

		if (isset($arFields['NOTIFY_MESSAGE']) && !isset($arFields['MESSAGE']))
			$arFields['MESSAGE'] = $arFields['NOTIFY_MESSAGE'];

		if (isset($arFields['NOTIFY_MESSAGE_OUT']) && !isset($arFields['MESSAGE_OUT']))
			$arFields['MESSAGE_OUT'] = $arFields['NOTIFY_MESSAGE_OUT'];

		$bConvert = false;
		if (isset($arFields['CONVERT']) && $arFields['CONVERT'] == 'Y')
			$bConvert = true;

		if (!isset($arFields['MESSAGE_OUT']))
			$arFields['MESSAGE_OUT'] = "";

		if (!isset($arFields['MESSAGE_TYPE']))
			$arFields['MESSAGE_TYPE'] = "";

		if (!isset($arFields['NOTIFY_MODULE']))
			$arFields['NOTIFY_MODULE'] = 'im';

		if (!isset($arFields['NOTIFY_EVENT']))
			$arFields['NOTIFY_EVENT'] = 'default';

		if (!isset($arFields['PARAMS']))
			$arFields['PARAMS'] = Array();

		if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM)
		{
			if (!isset($arFields['NOTIFY_TYPE']) && intval($arFields['FROM_USER_ID']) > 0)
				$arFields['NOTIFY_TYPE'] = IM_NOTIFY_FROM;
			else if (!isset($arFields['NOTIFY_TYPE']))
				$arFields['NOTIFY_TYPE'] = IM_NOTIFY_SYSTEM;
		}

		if (isset($arFields['NOTIFY_EMAIL_TEMPLATE']) && !isset($arFields['EMAIL_TEMPLATE']))
			$arFields['EMAIL_TEMPLATE'] = $arFields['NOTIFY_EMAIL_TEMPLATE'];

		if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE']))>0)
			$arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']);

		if (!isset($arFields['AUTHOR_ID']))
			$arFields['AUTHOR_ID'] = intval($arFields['FROM_USER_ID']);

		foreach(GetModuleEvents("im", "OnBeforeMessageNotifyAdd", true) as $arEvent)
		{
			$result = ExecuteModuleEventEx($arEvent, array(&$arFields));
			if($result===false || isset($result['result']) && $result['result'] === false)
			{
				if (isset($result['reason']))
				{
					$CBXSanitizer = new CBXSanitizer;
					$CBXSanitizer->AddTags(array(
						'a' => array('href','style', 'target'),
						'b' => array(), 'u' => array(),
						'i' => array(), 'br' => array(),
						'span' => array('style'),
					));
					$reason = $CBXSanitizer->SanitizeHtml($result['reason']);
				}
				else
				{
					$reason = $arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE? GetMessage("IM_ERROR_MESSAGE_CANCELED"): ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_GROUP? GetMessage("IM_ERROR_GROUP_CANCELED"): GetMessage("IM_ERROR_NOTIFY_CANCELED"));
				}

				$GLOBALS["APPLICATION"]->ThrowException($reason, "ERROR_FROM_OTHER_MODULE");

				return false;
			}
		}

		if (!self::CheckFields($arFields))
			return false;

		if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE)
		{
			if (isset($arFields['TO_CHAT_ID']))
			{
				$chatId = $arFields['TO_CHAT_ID'];
				$arRel = CIMChat::GetRelationById($chatId);
				foreach ($arRel as $rel)
				{
					if ($rel['USER_ID'] == $arFields['FROM_USER_ID'])
						continue;

					$arFields['TO_USER_ID'] = $rel['USER_ID'];
				}

				if (!IsModuleInstalled('intranet'))
				{
					if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']))
					{
						$GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY_SELF'), "ERROR_FROM_PRIVACY_SELF");
						return false;
					}
					else if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arFields['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']))
					{
						$GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY'), "ERROR_FROM_PRIVACY");
						return false;
					}
				}
			}
			else
			{
				$arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']);
				$arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']);

				if (!IsModuleInstalled('intranet'))
				{
					if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']))
					{
						$GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY_SELF'), "ERROR_FROM_PRIVACY_SELF");
						return false;
					}
					else if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arFields['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']))
					{
						$GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY'), "ERROR_FROM_PRIVACY");
						return false;
					}
				}
				$chatId = CIMMessage::GetChatId($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']);
			}

			if ($chatId > 0)
			{
				$arParams = Array();
				$arParams['CHAT_ID'] = $chatId;
				$arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']);
				$arParams['MESSAGE'] = trim($arFields['MESSAGE']);
				$arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']);
				$arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE'];
				$arParams['NOTIFY_EVENT'] = $arFields['SYSTEM'] == 'Y'? 'private_system': 'private';

				if (isset($arFields['IMPORT_ID']))
					$arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']);

				if (isset($arFields['MESSAGE_DATE']))
					$arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
				else
					$arParams['~DATE_CREATE'] = $DB->CurrentTimeFunction();


				$arFiles = Array();
				$arFields['FILES'] = Array();
				if (isset($arFields['PARAMS']['FILE_ID']))
				{
					foreach ($arFields['PARAMS']['FILE_ID'] as $fileId)
					{
						$arFiles[$fileId] = $fileId;
					}
				}
				$arFields['FILES'] = CIMDisk::GetFiles($chatId, $arFiles);

				$messageFiles = self::GetFormatFilesMessageOut($arFields['FILES']);
				if (strlen($messageFiles) > 0)
				{
					$arParams['MESSAGE_OUT'] = strlen($arParams['MESSAGE_OUT'])>0? $arParams['MESSAGE_OUT']."\n".$messageFiles: $messageFiles;
					$arFields['MESSAGE_OUT'] = $arParams['MESSAGE_OUT'];
				}

				$messageID = IntVal($DB->Add("b_im_message", $arParams, Array('MESSAGE','MESSAGE_OUT')));
				if ($messageID <= 0)
					return false;

				if (!empty($arFields['PARAMS']))
					CIMMessageParam::Set($messageID, $arFields['PARAMS']);

				//CUserCounter::Increment($arFields['TO_USER_ID'], 'im_message_v2', '**', false);
				CIMContactList::SetRecent($arFields['TO_USER_ID'], $messageID, false, $arFields['FROM_USER_ID']);
				CIMContactList::SetRecent($arFields['FROM_USER_ID'], $messageID, false, $arFields['TO_USER_ID']);

				CIMStatus::SetIdle($arFields['FROM_USER_ID'], false);

				if (!$bConvert)
				{
					$strSql = "
						UPDATE b_im_relation
						SET STATUS = (case when USER_ID = ".$arFields['TO_USER_ID']." then '".IM_STATUS_UNREAD."' else '".IM_STATUS_READ."' end),
						LAST_ID = (case when USER_ID = ".$arFields['TO_USER_ID']." then LAST_ID else ".$messageID." end),
						LAST_SEND_ID = (case when USER_ID = ".$arFields['TO_USER_ID']." then LAST_SEND_ID else ".$messageID." end),
						LAST_READ = (case when USER_ID = ".$arFields['TO_USER_ID']." then LAST_READ else ".$DB->CurrentTimeFunction()." end)
						WHERE CHAT_ID = ".$chatId;
					$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

					if (CModule::IncludeModule("pull"))
					{
						$arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID'];
						$arParams['TO_USER_ID'] = $arFields['TO_USER_ID'];

						$pushText = '';
						if (CPullOptions::GetPushStatus() && (!isset($arFields['PUSH']) || $arFields['PUSH'] == 'Y'))
						{
							$arSelect = Array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME");
							$dbUsers = CUser::GetList(($sort_by = false), ($dummy=''), array('ID' => $arParams['FROM_USER_ID']), array('FIELDS' => $arSelect));
							if ($arUser = $dbUsers->GetNext(true, false))
							{
								$sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
								$pushText = $sName.': '.$arParams['MESSAGE'];

								if (count($arFields['FILES']) > 0 && strlen($pushText) < 200)
								{
									foreach ($arFields['FILES'] as $file)
									{
										$file = " [".GetMessage('IM_MESSAGE_FILE').": ".$file['name']."]";
										if (strlen($pushText.$file) > 200)
											break;

										$pushText = trim($pushText).$file;
									}
								}
							}
						}

						$arPullTo = Array(
							'module_id' => 'im',
							'command' => 'message',
							'params' => CIMMessage::GetFormatMessage(Array(
								'ID' => $messageID,
								'CHAT_ID' => $chatId,
								'TO_USER_ID' => $arParams['TO_USER_ID'],
								'FROM_USER_ID' => $arParams['FROM_USER_ID'],
								'SYSTEM' => $arFields['SYSTEM'] == 'Y'? 'Y': 'N',
								'MESSAGE' => $arParams['MESSAGE'],
								'DATE_CREATE' => time(),
								'PARAMS' => $arFields['PARAMS'],
								'FILES' => $arFields['FILES'],
							)),
						);
						$arPullFrom = $arPullTo;

						$arPullTo['push_params'] = 'IM_MESS_'.$arParams['FROM_USER_ID'];
						$arPullTo['push_tag'] = 'IM_MESS_'.$arParams['FROM_USER_ID'];
						$arPullTo['push_sub_tag'] = 'IM_MESS';
						$arPullTo['push_app_id'] = 'Bitrix24';
						$arPullTo['push_text'] = preg_replace("/\[s\].*?\[\/s\]/i", "", $pushText);
						$arPullTo['push_text'] = preg_replace("/\[[bui]\](.*?)\[\/[bui]\]/i", "$1", $arPullTo['push_text']);
						$arPullTo['push_text'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [".GetMessage('IM_QUOTE')."] ", str_replace(array("#BR#"), Array(" "), $arPullTo['push_text']));

						CPullStack::AddByUser($arParams['TO_USER_ID'], $arPullTo);
						CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom);

						CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS');

						self::SendBadges($arParams['TO_USER_ID']);
					}
					foreach(GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent)
						ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
				}

				return $messageID;
			}
			else
			{
				$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
				return false;
			}
		}
		else if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_GROUP)
		{
			$arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']);
			$chatId = 0;
			$systemMessage = false;
			if (isset($arFields['SYSTEM']) && $arFields['SYSTEM'] == 'Y')
			{
				$strSql = "
					SELECT C.ID CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID
					FROM b_im_chat C
					WHERE C.ID = ".intval($arFields['TO_CHAT_ID'])."
				";
				$systemMessage = true;
			}
			else
			{
				$strSql = "
					SELECT R.CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID
					FROM b_im_relation R LEFT JOIN b_im_chat C ON R.CHAT_ID = C.ID
					WHERE R.USER_ID = ".$arFields['FROM_USER_ID']." AND R.CHAT_ID = ".intval($arFields['TO_CHAT_ID'])."
				";
			}
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			if ($arRes = $dbRes->Fetch())
			{
				$chatId = intval($arRes['CHAT_ID']);
				$chatTitle = htmlspecialcharsbx($arRes['CHAT_TITLE']);
				$chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']);
			}
			else
			{
				$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
				return false;
			}

			if ($chatId > 0)
			{
				$arParams = Array();
				$arParams['CHAT_ID'] = $chatId;
				$arParams['AUTHOR_ID'] = $systemMessage? 0: intval($arFields['AUTHOR_ID']);
				$arParams['MESSAGE'] = trim($arFields['MESSAGE']);
				$arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']);
				$arParams['NOTIFY_MODULE'] = 'im';
				$arParams['NOTIFY_EVENT'] = 'group';

				if (isset($arFields['MESSAGE_DATE']))
					$arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
				else
					$arParams['~DATE_CREATE'] = $DB->CurrentTimeFunction();

				$arFiles = Array();
				$arFields['FILES'] = Array();
				if (isset($arFields['PARAMS']['FILE_ID']))
				{
					foreach ($arFields['PARAMS']['FILE_ID'] as $fileId)
					{
						$arFiles[$fileId] = $fileId;
					}
				}
				$arFields['FILES'] = CIMDisk::GetFiles($chatId, $arFiles);

				$messageFiles = self::GetFormatFilesMessageOut($arFields['FILES']);
				if (strlen($messageFiles) > 0)
				{
					$arParams['MESSAGE_OUT'] = strlen($arParams['MESSAGE_OUT'])>0? $arParams['MESSAGE_OUT']."\n".$messageFiles: $messageFiles;
					$arFields['MESSAGE_OUT'] = $arParams['MESSAGE_OUT'];
				}

				$messageID = IntVal($DB->Add("b_im_message", $arParams, Array('MESSAGE','MESSAGE_OUT')));
				if ($messageID <= 0)
					return false;

				if (!empty($arFields['PARAMS']))
					CIMMessageParam::Set($messageID, $arFields['PARAMS']);

				$sqlCounter = "SELECT USER_ID as ID, 1 as CNT, '**' as SITE_ID, 'im_chat_v2' as CODE, 1 as SENT
								FROM b_im_relation R1
								WHERE CHAT_ID = ".$chatId." AND USER_ID <> ".$arFields['FROM_USER_ID'];
				//CUserCounter::IncrementWithSelect($sqlCounter, false);

				$arRel = CIMChat::GetRelationById($chatId);
				foreach ($arRel as $rel)
					CIMContactList::SetRecent($chatId, $messageID, true, $rel['USER_ID']);

				$strSql = "
					UPDATE b_im_relation
					SET STATUS = (case when USER_ID = ".$arFields['FROM_USER_ID']." then '".IM_STATUS_READ."' else '".IM_STATUS_UNREAD."' end),
					LAST_ID = (case when USER_ID = ".$arFields['FROM_USER_ID']." then ".$messageID." else LAST_ID end),
					LAST_SEND_ID = (case when USER_ID = ".$arFields['FROM_USER_ID']." then ".$messageID." else LAST_SEND_ID end),
					LAST_READ = (case when USER_ID = ".$arFields['FROM_USER_ID']." then ".$DB->CurrentTimeFunction()." else LAST_READ end)
					WHERE CHAT_ID = ".$chatId;
				$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

				CIMStatus::SetIdle($arFields['FROM_USER_ID'], false);

				if (CModule::IncludeModule("pull"))
				{
					$arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID'];
					$arParams['TO_CHAT_ID'] = $arFields['TO_CHAT_ID'];

					$arPullTo = Array(
						'module_id' => 'im',
						'command' => 'messageChat',
						'params' => CIMMessage::GetFormatMessage(Array(
							'ID' => $messageID,
							'CHAT_ID' => $chatId,
							'TO_CHAT_ID' => $arParams['TO_CHAT_ID'],
							'FROM_USER_ID' => $arParams['FROM_USER_ID'],
							'MESSAGE' => $arParams['MESSAGE'],
							'SYSTEM' => $arFields['SYSTEM'] == 'Y'? 'Y': 'N',
							'DATE_CREATE' => time(),
							'PARAMS' => $arFields['PARAMS'],
							'FILES' => $arFields['FILES'],
						)),
					);
					$arPullFrom = $arPullTo;
					unset($arPullFrom['push_text']);

					foreach ($arRel as $rel)
					{
						if ($rel['USER_ID'] == $arParams['FROM_USER_ID'])
						{
							CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom);
							CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS');
						}
					}

					$usersForBadges = Array();
					foreach ($arRel as $rel)
					{
						if ($rel['USER_ID'] != $arParams['FROM_USER_ID'])
						{
							CPullStack::AddByUser($rel['USER_ID'], $arPullTo);
							$usersForBadges[] = $rel['USER_ID'];
						}
					}
					self::SendBadges($usersForBadges);
				}
				foreach(GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent)
					ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));

				return $messageID;
			}
			else
			{
				$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
				return false;
			}

		}
		else if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM)
		{
			$arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']);
			$chatId = 0;
			$strSql = "
				SELECT CHAT_ID
				FROM b_im_relation
				WHERE USER_ID = ".$arFields['TO_USER_ID']." AND MESSAGE_TYPE = '".IM_MESSAGE_SYSTEM."'";
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			if ($arRes = $dbRes->Fetch())
				$chatId = intval($arRes['CHAT_ID']);
			else
			{
				$chatId = IntVal($DB->Add("b_im_chat", Array('AUTHOR_ID' => $arFields['TO_USER_ID']), Array()));
				if ($chatId <= 0)
				{
					$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
					return false;
				}

				$strSql = "INSERT INTO b_im_relation (CHAT_ID, MESSAGE_TYPE, USER_ID, STATUS) VALUES (".$chatId.",'".IM_MESSAGE_SYSTEM."',".intval($arFields['TO_USER_ID']).", ".($bConvert? 2: 0).")";
				$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			}

			if ($chatId > 0)
			{
				$arParams = Array();
				$arParams['CHAT_ID'] = $chatId;
				$arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']);
				$arParams['MESSAGE'] = trim($arFields['MESSAGE']);
				$arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']);
				$arParams['NOTIFY_TYPE'] = intval($arFields['NOTIFY_TYPE']);
				$arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE'];
				$arParams['NOTIFY_EVENT'] = $arFields['NOTIFY_EVENT'];

				//if (strlen($arParams['MESSAGE']) <= 0 && strlen($arParams['MESSAGE_OUT']) <= 0)
				//	return false;

				$sendToSite = true;
				if ($arParams['NOTIFY_TYPE'] != IM_NOTIFY_CONFIRM)
					$sendToSite = CIMSettings::GetNotifyAccess($arFields["TO_USER_ID"], $arFields["NOTIFY_MODULE"], $arFields["NOTIFY_EVENT"], CIMSettings::CLIENT_SITE);

				if (!$sendToSite)
					$arParams['NOTIFY_READ'] = 'Y';

				if (isset($arFields['IMPORT_ID']))
					$arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']);

				if (isset($arFields['MESSAGE_DATE']))
					$arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
				else
					$arParams['~DATE_CREATE'] = $DB->CurrentTimeFunction();

				if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE']))>0)
					$arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']);

				if (isset($arFields['NOTIFY_TAG']))
					$arParams['NOTIFY_TAG'] = $arFields['NOTIFY_TAG'];

				if (isset($arFields['NOTIFY_SUB_TAG']))
					$arParams['NOTIFY_SUB_TAG'] = $arFields['NOTIFY_SUB_TAG'];

				if (isset($arFields['NOTIFY_TITLE']) && strlen(trim($arFields['NOTIFY_TITLE']))>0)
					$arParams['NOTIFY_TITLE'] = trim($arFields['NOTIFY_TITLE']);

				if ($arParams['NOTIFY_TYPE'] == IM_NOTIFY_CONFIRM)
				{
					if (isset($arFields['NOTIFY_BUTTONS']))
					{
						foreach ($arFields['NOTIFY_BUTTONS'] as $key => $arButtons)
						{
							if (is_array($arButtons))
							{
								if (isset($arButtons['TITLE']) && strlen($arButtons['TITLE']) > 0
								&& isset($arButtons['VALUE']) && strlen($arButtons['VALUE']) > 0
								&& isset($arButtons['TYPE']) && strlen($arButtons['TYPE']) > 0)
								{
									$arButtons['TITLE'] = htmlspecialcharsbx($arButtons['TITLE']);
									$arButtons['VALUE'] = htmlspecialcharsbx($arButtons['VALUE']);
									$arButtons['TYPE'] = htmlspecialcharsbx($arButtons['TYPE']);
									$arFields['NOTIFY_BUTTONS'][$key] = $arButtons;
								}
								else
									unset($arFields['NOTIFY_BUTTONS'][$key]);
							}
							else
								unset($arFields['NOTIFY_BUTTONS'][$key]);
						}
					}
					else
					{
						$arFields['NOTIFY_BUTTONS'] = Array(
							Array('TITLE' => GetMessage('IM_ERROR_BUTTON_ACCEPT'), 'VALUE' => 'Y', 'TYPE' => 'accept'),
							Array('TITLE' => GetMessage('IM_ERROR_BUTTON_CANCEL'), 'VALUE' => 'N', 'TYPE' => 'cancel'),
						);
					}
					$arParams['NOTIFY_BUTTONS'] = serialize($arFields["NOTIFY_BUTTONS"]);

					if (isset($arParams['NOTIFY_TAG']) && strlen($arParams['NOTIFY_TAG'])>0)
						CIMNotify::DeleteByTag($arParams['NOTIFY_TAG']);
				}

				$messageID = IntVal($DB->Add("b_im_message", $arParams, Array('MESSAGE', 'MESSAGE_OUT', 'NOTIFY_BUTTONS')));
				if ($messageID <= 0)
					return false;

				if ($sendToSite)
					CIMMessenger::SpeedFileDelete($arFields['TO_USER_ID'], IM_SPEED_NOTIFY);

				if (!$bConvert)
				{
					//CUserCounter::Increment($arFields['TO_USER_ID'], 'im_notify_v2', '**', false);
					$strSql = "UPDATE b_im_relation SET STATUS = '".IM_STATUS_UNREAD."' WHERE USER_ID = ".intval($arFields['TO_USER_ID'])." AND MESSAGE_TYPE = '".IM_MESSAGE_SYSTEM."' AND CHAT_ID = ".$chatId;
					$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

					if (CModule::IncludeModule("pull"))
					{
						CPullStack::AddByUser(intval($arFields['TO_USER_ID']), Array(
							'module_id' => 'im',
							'command' => 'notify',
							'params' => CIMNotify::GetFormatNotify(Array(
								'ID' => $messageID,
								'DATE_CREATE' => time(),
								'FROM_USER_ID' => intval($arFields['FROM_USER_ID']),
								'MESSAGE' => $arParams['MESSAGE'],
								'NOTIFY_MODULE' => $arParams['NOTIFY_MODULE'],
								'NOTIFY_EVENT' => $arParams['NOTIFY_EVENT'],
								'NOTIFY_TAG' => $arParams['NOTIFY_TAG'],
								'NOTIFY_TYPE' => $arParams['NOTIFY_TYPE'],
								'NOTIFY_BUTTONS' => isset($arParams['NOTIFY_BUTTONS'])? $arParams['NOTIFY_BUTTONS']: serialize(Array()),
								'NOTIFY_TITLE' => isset($arParams['NOTIFY_TITLE'])? $arParams['NOTIFY_TITLE']: '',
								'NOTIFY_SILENT' => $sendToSite? false: true,
							)),
						));
						self::SendBadges($arFields['TO_USER_ID']);
					}
					foreach(GetModuleEvents("im", "OnAfterNotifyAdd", true) as $arEvent)
						ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
				}

				return $messageID;
			}
			else
			{
				$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
				return false;
			}
		}
		else
		{
			$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_TYPE"), "MESSAGE_TYPE");
			return false;
		}

		return false;
	}
Esempio n. 8
0
$arParams["SET_NAV_CHAIN"] = $arParams["SET_NAV_CHAIN"] == "N" ? "N" : "Y";
if (strLen($arParams["USER_VAR"]) <= 0) {
    $arParams["USER_VAR"] = "user_id";
}
if (strLen($arParams["PAGE_VAR"]) <= 0) {
    $arParams["PAGE_VAR"] = "page";
}
$arParams["PATH_TO_USER"] = trim($arParams["PATH_TO_USER"]);
if (strlen($arParams["PATH_TO_USER"]) <= 0) {
    $arParams["PATH_TO_USER"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=user&" . $arParams["USER_VAR"] . "=#user_id#");
}
if (strlen($arParams["NAME_TEMPLATE"]) <= 0) {
    $arParams["NAME_TEMPLATE"] = CSite::GetNameFormat();
}
$bUseLogin = $arParams['SHOW_LOGIN'] != "N" ? true : false;
if (!CSocNetUser::IsFriendsAllowed()) {
    $arResult["FatalError"] = GetMessage("SONET_C35_NO_FR_FUNC") . ". ";
} else {
    if (!$GLOBALS["USER"]->IsAuthorized()) {
        $arResult["NEED_AUTH"] = "Y";
    } else {
        $dbUser = CUser::GetByID($arParams["ID"]);
        $arResult["User"] = $dbUser->GetNext();
        if (!is_array($arResult["User"])) {
            $arResult["FatalError"] = GetMessage("SONET_P_USER_NO_USER") . ". ";
        } else {
            $arResult["CurrentUserPerms"] = CSocNetUserPerms::InitUserPerms($GLOBALS["USER"]->GetID(), $arResult["User"]["ID"], CSocNetUser::IsCurrentUserModuleAdmin());
            if (!$arResult["CurrentUserPerms"]["IsCurrentUser"]) {
                $arResult["CurrentUserRelation"] = CSocNetUserRelations::GetRelation($GLOBALS["USER"]->GetID(), $arResult["User"]["ID"]);
            }
            $arResult["Urls"]["User"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arResult["User"]["ID"]));
Esempio n. 9
0
 public static function GetList($arParams = array())
 {
     if (!is_array($arParams)) {
         $arParams = array();
     }
     $arID = array();
     if (isset($arParams['ID']) && is_array($arParams['ID']) && !empty($arParams['ID'])) {
         foreach ($arParams['ID'] as $key => $value) {
             $arID[] = intval($value);
         }
     } else {
         if (isset($arParams['ID']) && intval($arParams['ID']) > 0) {
             $arID[] = intval($arParams['ID']);
         }
     }
     global $USER;
     if (!isset($arParams['ID']) && !IsModuleInstalled('intranet') && is_object($USER)) {
         $arID[] = $USER->GetID();
         if (CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) {
             $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $USER->GetID(), "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID"));
             if ($dbFriends) {
                 while ($arFriends = $dbFriends->GetNext(true, false)) {
                     $friendId = $pref = IntVal($USER->GetID()) == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
                     $arID[] = $friendId;
                 }
             }
         }
     }
     $enable = self::Enable();
     $arUsers = array();
     $query = new \Bitrix\Main\Entity\Query(\Bitrix\Main\UserTable::getEntity());
     if ($enable) {
         $query->registerRuntimeField('', new \Bitrix\Main\Entity\ReferenceField('ref', 'Bitrix\\Im\\StatusTable', array('=this.ID' => 'ref.USER_ID')));
     }
     $query->addSelect('ID');
     if ($enable) {
         $query->addSelect('ref.STATUS', 'STATUS')->addSelect('ref.IDLE', 'IDLE');
     }
     $query->addFilter('>LAST_ACTIVITY_DATE', new \Bitrix\Main\DB\SqlExpression(Bitrix\Main\Application::getConnection()->getSqlHelper()->addSecondsToDateTime('-180')));
     $result = $query->exec();
     while ($arUser = $result->fetch()) {
         if (!empty($arID) && !in_array($arUser["ID"], $arID)) {
             continue;
         }
         $arUsers[$arUser["ID"]] = array('id' => $arUser["ID"], 'status' => $enable && in_array($arUser['STATUS'], self::$AVAILABLE_STATUSES) ? $arUser['STATUS'] : 'online', 'idle' => $enable && is_object($arUser['IDLE']) ? $arUser['IDLE']->getTimestamp() : 0);
     }
     return array('users' => $arUsers);
 }
Esempio n. 10
0
 function IsMyUser($entity_id)
 {
     $is_my = false;
     if (CSocNetUser::IsFriendsAllowed() && CSocNetUserRelations::IsFriends($GLOBALS["USER"]->GetID(), $entity_id)) {
         $is_my = true;
     }
     return $is_my;
 }
Esempio n. 11
0
 public static function Add($arFields)
 {
     global $DB;
     if (isset($arFields['TITLE']) && !isset($arFields['NOTIFY_TITLE'])) {
         $arFields['NOTIFY_TITLE'] = $arFields['TITLE'];
     }
     if (isset($arFields['NOTIFY_MESSAGE']) && !isset($arFields['MESSAGE'])) {
         $arFields['MESSAGE'] = $arFields['NOTIFY_MESSAGE'];
     }
     if (isset($arFields['NOTIFY_MESSAGE_OUT']) && !isset($arFields['MESSAGE_OUT'])) {
         $arFields['MESSAGE_OUT'] = $arFields['NOTIFY_MESSAGE_OUT'];
     }
     $bConvert = false;
     if (isset($arFields['CONVERT']) && $arFields['CONVERT'] == 'Y') {
         $bConvert = true;
     }
     if (!isset($arFields['MESSAGE_OUT'])) {
         $arFields['MESSAGE_OUT'] = "";
     }
     if (!isset($arFields['MESSAGE_TYPE'])) {
         $arFields['MESSAGE_TYPE'] = "";
     }
     if (!isset($arFields['NOTIFY_MODULE'])) {
         $arFields['NOTIFY_MODULE'] = 'im';
     }
     if (!isset($arFields['NOTIFY_EVENT'])) {
         $arFields['NOTIFY_EVENT'] = 'default';
     }
     if (!isset($arFields['PARAMS'])) {
         $arFields['PARAMS'] = array();
     }
     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) {
         if (!isset($arFields['NOTIFY_TYPE']) && intval($arFields['FROM_USER_ID']) > 0) {
             $arFields['NOTIFY_TYPE'] = IM_NOTIFY_FROM;
         } else {
             if (!isset($arFields['NOTIFY_TYPE'])) {
                 $arFields['NOTIFY_TYPE'] = IM_NOTIFY_SYSTEM;
             }
         }
     }
     if (isset($arFields['NOTIFY_EMAIL_TEMPLATE']) && !isset($arFields['EMAIL_TEMPLATE'])) {
         $arFields['EMAIL_TEMPLATE'] = $arFields['NOTIFY_EMAIL_TEMPLATE'];
     }
     if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE'])) > 0) {
         $arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']);
     }
     if (!isset($arFields['AUTHOR_ID'])) {
         $arFields['AUTHOR_ID'] = intval($arFields['FROM_USER_ID']);
     }
     foreach (GetModuleEvents("im", "OnBeforeMessageNotifyAdd", true) as $arEvent) {
         $result = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($result === false || isset($result['result']) && $result['result'] === false) {
             if (isset($result['reason'])) {
                 $CBXSanitizer = new CBXSanitizer();
                 $CBXSanitizer->AddTags(array('a' => array('href', 'style', 'target'), 'b' => array(), 'u' => array(), 'i' => array(), 'br' => array(), 'span' => array('style')));
                 $reason = $CBXSanitizer->SanitizeHtml($result['reason']);
             } else {
                 if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) {
                     $reason = GetMessage("IM_ERROR_MESSAGE_CANCELED");
                 } else {
                     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) {
                         $reason = GetMessage("IM_ERROR_NOTIFY_CANCELED");
                     } else {
                         $reason = GetMessage("IM_ERROR_GROUP_CANCELED");
                     }
                 }
             }
             $GLOBALS["APPLICATION"]->ThrowException($reason, "ERROR_FROM_OTHER_MODULE");
             return false;
         }
     }
     if (!self::CheckFields($arFields)) {
         return false;
     }
     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) {
         if (isset($arFields['TO_CHAT_ID'])) {
             $chatId = $arFields['TO_CHAT_ID'];
             $arRel = CIMChat::GetRelationById($chatId);
             foreach ($arRel as $rel) {
                 if ($rel['USER_ID'] == $arFields['FROM_USER_ID']) {
                     continue;
                 }
                 $arFields['TO_USER_ID'] = $rel['USER_ID'];
             }
             if (!IsModuleInstalled('intranet')) {
                 if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY_SELF'), "ERROR_FROM_PRIVACY_SELF");
                     return false;
                 } else {
                     if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arFields['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY'), "ERROR_FROM_PRIVACY");
                         return false;
                     }
                 }
             }
         } else {
             $arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']);
             $arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']);
             if (!IsModuleInstalled('intranet')) {
                 if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY_SELF'), "ERROR_FROM_PRIVACY_SELF");
                     return false;
                 } else {
                     if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arFields['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY'), "ERROR_FROM_PRIVACY");
                         return false;
                     }
                 }
             }
             $chatId = CIMMessage::GetChatId($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']);
         }
         if ($chatId > 0) {
             $arParams = array();
             $arParams['CHAT_ID'] = $chatId;
             $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']);
             $arParams['MESSAGE'] = trim($arFields['MESSAGE']);
             $arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']);
             $arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE'];
             $arParams['NOTIFY_EVENT'] = $arFields['SYSTEM'] == 'Y' ? 'private_system' : 'private';
             if (isset($arFields['IMPORT_ID'])) {
                 $arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']);
             }
             if (isset($arFields['MESSAGE_DATE'])) {
                 $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
             }
             $arFiles = array();
             $arFields['FILES'] = array();
             if (isset($arFields['PARAMS']['FILE_ID'])) {
                 foreach ($arFields['PARAMS']['FILE_ID'] as $fileId) {
                     $arFiles[$fileId] = $fileId;
                 }
             }
             $arFields['FILES'] = CIMDisk::GetFiles($chatId, $arFiles);
             $messageFiles = self::GetFormatFilesMessageOut($arFields['FILES']);
             if (strlen($messageFiles) > 0) {
                 $arParams['MESSAGE_OUT'] = strlen($arParams['MESSAGE_OUT']) > 0 ? $arParams['MESSAGE_OUT'] . "\n" . $messageFiles : $messageFiles;
                 $arFields['MESSAGE_OUT'] = $arParams['MESSAGE_OUT'];
             }
             $result = IM\MessageTable::add($arParams);
             $messageID = IntVal($result->getId());
             if ($messageID <= 0) {
                 return false;
             }
             IM\ChatTable::update($chatId, array('LAST_MESSAGE_ID' => $messageID));
             if (!empty($arFields['PARAMS'])) {
                 CIMMessageParam::Set($messageID, $arFields['PARAMS']);
             }
             //CUserCounter::Increment($arFields['TO_USER_ID'], 'im_message_v2', '**', false);
             CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['TO_USER_ID'], 'MESSAGE_ID' => $messageID, 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['FROM_USER_ID']));
             CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['FROM_USER_ID'], 'MESSAGE_ID' => $messageID, 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['TO_USER_ID']));
             CIMStatus::SetIdle($arFields['FROM_USER_ID'], false);
             if (!$bConvert) {
                 $arRel = CIMChat::GetRelationById($chatId);
                 foreach ($arRel as $relation) {
                     if ($relation["USER_ID"] == $arFields["TO_USER_ID"]) {
                         if ($relation['STATUS'] != IM_STATUS_UNREAD) {
                             IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_UNREAD));
                         }
                     } else {
                         IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_READ, "LAST_ID" => $messageID, "LAST_SEND_ID" => $messageID, "LAST_READ" => new Bitrix\Main\Type\DateTime()));
                     }
                 }
                 if (CModule::IncludeModule("pull")) {
                     $arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID'];
                     $arParams['TO_USER_ID'] = $arFields['TO_USER_ID'];
                     $arPullTo = array('module_id' => 'im', 'command' => 'message', 'params' => CIMMessage::GetFormatMessage(array('ID' => $messageID, 'CHAT_ID' => $chatId, 'TO_USER_ID' => $arParams['TO_USER_ID'], 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'SYSTEM' => $arFields['SYSTEM'] == 'Y' ? 'Y' : 'N', 'MESSAGE' => $arParams['MESSAGE'], 'DATE_CREATE' => time(), 'PARAMS' => $arFields['PARAMS'], 'FILES' => $arFields['FILES'])));
                     $arPullFrom = $arPullTo;
                     $pushText = '';
                     if (CPullOptions::GetPushStatus() && (!isset($arFields['PUSH']) || $arFields['PUSH'] == 'Y')) {
                         $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME");
                         $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => $arParams['FROM_USER_ID']), array('FIELDS' => $arSelect));
                         if ($arUser = $dbUsers->GetNext(true, false)) {
                             $sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
                             $pushText = $sName . ': ' . $arParams['MESSAGE'];
                             if (count($arFields['FILES']) > 0 && strlen($pushText) < 200) {
                                 foreach ($arFields['FILES'] as $file) {
                                     $file = " [" . GetMessage('IM_MESSAGE_FILE') . ": " . $file['name'] . "]";
                                     if (strlen($pushText . $file) > 200) {
                                         break;
                                     }
                                     $pushText = trim($pushText) . $file;
                                 }
                             }
                         }
                         if (CIMSettings::GetNotifyAccess($arParams["TO_USER_ID"], 'im', 'message', CIMSettings::CLIENT_PUSH)) {
                             $arPullTo['push_params'] = array('TAG' => 'IM_MESS_' . $arParams['FROM_USER_ID'], 'CATEGORY' => 'ANSWER', 'URL' => SITE_DIR . 'mobile/ajax.php?mobile_action=im_answer', 'PARAMS' => array('RECIPIENT_ID' => $arParams['FROM_USER_ID']));
                             $arPullTo['push_tag'] = 'IM_MESS_' . $arParams['FROM_USER_ID'];
                             $arPullTo['push_sub_tag'] = 'IM_MESS';
                             $arPullTo['push_app_id'] = 'Bitrix24';
                             $arPullTo['push_text'] = preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $pushText);
                             $arPullTo['push_text'] = preg_replace("/\\[[bui]\\](.*?)\\[\\/[bui]\\]/i", "\$1", $arPullTo['push_text']);
                             $arPullTo['push_text'] = preg_replace("/\\[PCH=([0-9]{1,})\\](.*?)\\[\\/PCH\\]/i", "\$2", $arPullTo['push_text']);
                             $arPullTo['push_text'] = preg_replace("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", "\$2", $arPullTo['push_text']);
                             $arPullTo['push_text'] = preg_replace('#\\-{54}.+?\\-{54}#s', " [" . GetMessage('IM_QUOTE') . "] ", str_replace(array("#BR#"), array(" "), $arPullTo['push_text']));
                         }
                     }
                     CPullStack::AddByUser($arParams['TO_USER_ID'], $arPullTo);
                     CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom);
                     CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS');
                     self::SendBadges($arParams['TO_USER_ID']);
                 }
                 foreach (GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) {
                     ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
                 }
             }
             return $messageID;
         } else {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
             return false;
         }
     } else {
         if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_CHAT || $arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) {
             $arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']);
             $chatId = 0;
             $systemMessage = false;
             if (isset($arFields['SYSTEM']) && $arFields['SYSTEM'] == 'Y') {
                 $strSql = "\n\t\t\t\t\tSELECT C.ID CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID, C.TYPE CHAT_TYPE, '1' RID\n\t\t\t\t\tFROM b_im_chat C\n\t\t\t\t\tWHERE C.ID = " . intval($arFields['TO_CHAT_ID']) . "\n\t\t\t\t";
                 $systemMessage = true;
             } else {
                 $strSql = "\n\t\t\t\t\tSELECT C.ID CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID, C.TYPE CHAT_TYPE, R.USER_ID RID\n\t\t\t\t\tFROM b_im_chat C\n\t\t\t\t\tLEFT JOIN b_im_relation R ON R.CHAT_ID = C.ID AND R.USER_ID = " . $arFields['FROM_USER_ID'] . "\n\t\t\t\t\tWHERE C.ID = " . intval($arFields['TO_CHAT_ID']) . "\n\t\t\t\t";
             }
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($arRes = $dbRes->Fetch()) {
                 $chatId = intval($arRes['CHAT_ID']);
                 $chatTitle = htmlspecialcharsbx($arRes['CHAT_TITLE']);
                 $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']);
                 $arFields['MESSAGE_TYPE'] = $arRes['CHAT_TYPE'];
                 if ($arRes['CHAT_TYPE'] == IM_MESSAGE_OPEN) {
                     if (intval($arRes['RID']) <= 0) {
                         if (IM\User::getInstance($arFields['FROM_USER_ID'])->isExtranet()) {
                             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                             return false;
                         } else {
                             $chat = new CIMChat(0);
                             $chat->AddUser($chatId, $arFields['FROM_USER_ID']);
                         }
                     }
                 } else {
                     if (intval($arRes['RID']) <= 0) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                         return false;
                     }
                 }
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                 return false;
             }
             if ($chatId > 0) {
                 $arParams = array();
                 $arParams['CHAT_ID'] = $chatId;
                 $arParams['AUTHOR_ID'] = $systemMessage ? 0 : intval($arFields['AUTHOR_ID']);
                 $arParams['MESSAGE'] = trim($arFields['MESSAGE']);
                 $arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']);
                 $arParams['NOTIFY_MODULE'] = 'im';
                 $arParams['NOTIFY_EVENT'] = 'group';
                 if (isset($arFields['MESSAGE_DATE'])) {
                     $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
                 }
                 $arFiles = array();
                 $arFields['FILES'] = array();
                 if (isset($arFields['PARAMS']['FILE_ID'])) {
                     foreach ($arFields['PARAMS']['FILE_ID'] as $fileId) {
                         $arFiles[$fileId] = $fileId;
                     }
                 }
                 $arFields['FILES'] = CIMDisk::GetFiles($chatId, $arFiles);
                 $messageFiles = self::GetFormatFilesMessageOut($arFields['FILES']);
                 if (strlen($messageFiles) > 0) {
                     $arParams['MESSAGE_OUT'] = strlen($arParams['MESSAGE_OUT']) > 0 ? $arParams['MESSAGE_OUT'] . "\n" . $messageFiles : $messageFiles;
                     $arFields['MESSAGE_OUT'] = $arParams['MESSAGE_OUT'];
                 }
                 $result = IM\MessageTable::add($arParams);
                 $messageID = IntVal($result->getId());
                 if ($messageID <= 0) {
                     return false;
                 }
                 IM\ChatTable::update($chatId, array('LAST_MESSAGE_ID' => $messageID));
                 if (!empty($arFields['PARAMS'])) {
                     CIMMessageParam::Set($messageID, $arFields['PARAMS']);
                 }
                 //$sqlCounter = "SELECT USER_ID as ID, 1 as CNT, '**' as SITE_ID, 'im_chat_v2' as CODE, 1 as SENT
                 //				FROM b_im_relation R1
                 //				WHERE CHAT_ID = ".$chatId." AND USER_ID <> ".$arFields['FROM_USER_ID'];
                 //CUserCounter::IncrementWithSelect($sqlCounter, false);
                 $arRel = CIMChat::GetRelationById($chatId);
                 foreach ($arRel as $relation) {
                     CIMContactList::SetRecent(array('ENTITY_ID' => $chatId, 'MESSAGE_ID' => $messageID, 'CHAT_TYPE' => $arFields['MESSAGE_TYPE'], 'USER_ID' => $relation['USER_ID']));
                     if ($relation["USER_ID"] == $arFields["FROM_USER_ID"]) {
                         IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_READ, "LAST_ID" => $messageID, "LAST_SEND_ID" => $messageID, "LAST_READ" => new Bitrix\Main\Type\DateTime()));
                     } else {
                         if ($relation['STATUS'] != IM_STATUS_UNREAD) {
                             IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_UNREAD));
                         }
                     }
                 }
                 CIMStatus::SetIdle($arFields['FROM_USER_ID'], false);
                 if (CModule::IncludeModule("pull")) {
                     $arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID'];
                     $arParams['TO_CHAT_ID'] = $arFields['TO_CHAT_ID'];
                     $arPullTo = array('module_id' => 'im', 'command' => 'messageChat', 'params' => CIMMessage::GetFormatMessage(array('ID' => $messageID, 'CHAT_ID' => $chatId, 'TO_CHAT_ID' => $arParams['TO_CHAT_ID'], 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'MESSAGE' => $arParams['MESSAGE'], 'SYSTEM' => $arFields['SYSTEM'] == 'Y' ? 'Y' : 'N', 'DATE_CREATE' => time(), 'PARAMS' => $arFields['PARAMS'], 'FILES' => $arFields['FILES'])));
                     $pushText = '';
                     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_CHAT && CPullOptions::GetPushStatus() && (!isset($arFields['PUSH']) || $arFields['PUSH'] == 'Y')) {
                         if ($arFields['SYSTEM'] == 'Y') {
                             $pushText = substr(htmlspecialcharsback($chatTitle), 0, 32) . ': ' . $arParams['MESSAGE'];
                         } else {
                             $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME");
                             $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => $arParams['FROM_USER_ID']), array('FIELDS' => $arSelect));
                             if ($arUser = $dbUsers->GetNext(true, false)) {
                                 $sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
                                 $pushText = GetMessage('IM_PUSH_GROUP_TITLE', array('#USER#' => $sName, '#GROUP#' => substr(htmlspecialcharsback($chatTitle), 0, 32))) . ': ' . $arParams['MESSAGE'];
                             }
                         }
                         if (count($arFields['FILES']) > 0 && strlen($pushText) < 200 && strlen($pushText) > 0) {
                             foreach ($arFields['FILES'] as $file) {
                                 $file = " [" . GetMessage('IM_MESSAGE_FILE') . ": " . $file['name'] . "]";
                                 if (strlen($pushText . $file) > 200) {
                                     break;
                                 }
                                 $pushText = trim($pushText) . $file;
                             }
                         }
                         $arPullTo['push_params'] = array('TAG' => 'IM_CHAT_' . $chatId, 'CATEGORY' => 'ANSWER', 'URL' => SITE_DIR . 'mobile/ajax.php?mobile_action=im_answer', 'PARAMS' => array('RECIPIENT_ID' => 'chat' . $chatId));
                         $arPullTo['push_tag'] = 'IM_CHAT_' . $chatId;
                         $arPullTo['push_sub_tag'] = 'IM_MESS';
                         $arPullTo['push_app_id'] = 'Bitrix24';
                         $arPullTo['push_text'] = preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "-", $pushText);
                         $arPullTo['push_text'] = preg_replace("/\\[[bui]\\](.*?)\\[\\/[bui]\\]/i", "\$1", $arPullTo['push_text']);
                         $arPullTo['push_text'] = preg_replace("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", "\$2", $arPullTo['push_text']);
                         $arPullTo['push_text'] = preg_replace("/\\[PCH=([0-9]{1,})\\](.*?)\\[\\/PCH\\]/i", "\$2", $arPullTo['push_text']);
                         $arPullTo['push_text'] = preg_replace('#\\-{54}.+?\\-{54}#s', " [" . GetMessage('IM_QUOTE') . "] ", str_replace(array("#BR#"), array(" "), $arPullTo['push_text']));
                     }
                     $arPullFrom = $arPullTo;
                     unset($arPullFrom['push_text']);
                     foreach ($arRel as $rel) {
                         if ($rel['USER_ID'] == $arParams['FROM_USER_ID']) {
                             CPullStack::AddByUser($arParams['FROM_USER_ID'], $arPullFrom);
                             CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS');
                         } else {
                             $arPullUser = $arPullTo;
                             if ($rel['NOTIFY_BLOCK'] == 'Y' || !CIMSettings::GetNotifyAccess($rel['USER_ID'], 'im', 'chat', CIMSettings::CLIENT_PUSH)) {
                                 unset($arPullUser['push_text']);
                             }
                             CPullStack::AddByUser($rel['USER_ID'], $arPullUser);
                             //$usersForBadges[] = $rel['USER_ID'];
                         }
                     }
                     if ($arRes['CHAT_TYPE'] == IM_MESSAGE_OPEN) {
                         CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $arPullFrom);
                         $forUsers = array();
                         if (preg_match_all("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", $arParams['MESSAGE'], $matches)) {
                             foreach ($matches[1] as $userId) {
                                 if (!isset($arRel[$userId])) {
                                     $forUsers[$userId] = $userId;
                                 }
                             }
                         }
                         if (count($forUsers)) {
                             $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME");
                             $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => $arParams['FROM_USER_ID']), array('FIELDS' => $arSelect));
                             if ($arUser = $dbUsers->GetNext(true, false)) {
                                 $sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
                                 $notifyMail = GetMessage('IM_MESSAGE_MENTION', array('#TITLE#' => substr(htmlspecialcharsback($chatTitle), 0, 32)));
                                 $notifyText = GetMessage('IM_MESSAGE_MENTION', array('#TITLE#' => '[CHAT=' . $chatId . ']' . substr(htmlspecialcharsback($chatTitle), 0, 32) . '[/CHAT]'));
                                 $pushText = GetMessage('IM_MESSAGE_MENTION_PUSH', array('#USER#' => $sName, '#TITLE#' => substr(htmlspecialcharsback($chatTitle), 0, 32)));
                             }
                             if (strlen($notifyText) > 0) {
                                 $arMessageFields = array("TO_USER_ID" => $userId, "FROM_USER_ID" => $arParams['FROM_USER_ID'], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "im", "NOTIFY_EVENT" => "mention", "NOTIFY_TAG" => 'IM|MENTION|' . $chatId, "NOTIFY_SUB_TAG" => "IM_MESS", "NOTIFY_MESSAGE" => $notifyText, "NOTIFY_MESSAGE_OUT" => $notifyMail, "PUSH_MESSAGE" => $pushText, "PUSH_PARAMS" => array('TAG' => 'IM_CHAT_' . $chatId, 'CATEGORY' => 'ANSWER', 'URL' => SITE_DIR . 'mobile/ajax.php?mobile_action=im_answer', 'PARAMS' => array('RECIPIENT_ID' => 'chat' . $chatId)), "PUSH_APP_ID" => 'Bitirx24');
                                 CIMNotify::Add($arMessageFields);
                             }
                         }
                     }
                     //self::SendBadges($usersForBadges);
                 }
                 foreach (GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) {
                     ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
                 }
                 return $messageID;
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
                 return false;
             }
         } else {
             if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) {
                 $arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']);
                 $chatId = 0;
                 $strSql = "\n\t\t\t\tSELECT CHAT_ID\n\t\t\t\tFROM b_im_relation\n\t\t\t\tWHERE USER_ID = " . $arFields['TO_USER_ID'] . " AND MESSAGE_TYPE = '" . IM_MESSAGE_SYSTEM . "'";
                 $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 if ($arRes = $dbRes->Fetch()) {
                     $chatId = intval($arRes['CHAT_ID']);
                 } else {
                     $result = IM\ChatTable::add(array('TYPE' => IM_MESSAGE_SYSTEM, 'AUTHOR_ID' => $arFields['TO_USER_ID']));
                     $chatId = $result->getId();
                     if ($chatId <= 0) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
                         return false;
                     }
                     IM\RelationTable::add(array("CHAT_ID" => $chatId, "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "USER_ID" => intval($arFields['TO_USER_ID']), "STATUS" => $bConvert ? 2 : 0));
                 }
                 if ($chatId > 0) {
                     $arParams = array();
                     $arParams['CHAT_ID'] = $chatId;
                     $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']);
                     $arParams['MESSAGE'] = trim($arFields['MESSAGE']);
                     $arParams['MESSAGE_OUT'] = trim($arFields['MESSAGE_OUT']);
                     $arParams['NOTIFY_TYPE'] = intval($arFields['NOTIFY_TYPE']);
                     $arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE'];
                     $arParams['NOTIFY_EVENT'] = $arFields['NOTIFY_EVENT'];
                     //if (strlen($arParams['MESSAGE']) <= 0 && strlen($arParams['MESSAGE_OUT']) <= 0)
                     //	return false;
                     $sendToSite = true;
                     if ($arParams['NOTIFY_TYPE'] != IM_NOTIFY_CONFIRM) {
                         $sendToSite = CIMSettings::GetNotifyAccess($arFields["TO_USER_ID"], $arFields["NOTIFY_MODULE"], $arFields["NOTIFY_EVENT"], CIMSettings::CLIENT_SITE);
                     }
                     if (!$sendToSite) {
                         $arParams['NOTIFY_READ'] = 'Y';
                     }
                     if (isset($arFields['IMPORT_ID'])) {
                         $arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']);
                     }
                     if (isset($arFields['MESSAGE_DATE'])) {
                         $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
                     }
                     if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE'])) > 0) {
                         $arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']);
                     }
                     $arParams['NOTIFY_TAG'] = isset($arFields['NOTIFY_TAG']) ? $arFields['NOTIFY_TAG'] : '';
                     $arParams['NOTIFY_SUB_TAG'] = isset($arFields['NOTIFY_SUB_TAG']) ? $arFields['NOTIFY_SUB_TAG'] : '';
                     if (isset($arFields['NOTIFY_TITLE']) && strlen(trim($arFields['NOTIFY_TITLE'])) > 0) {
                         $arParams['NOTIFY_TITLE'] = trim($arFields['NOTIFY_TITLE']);
                     }
                     if ($arParams['NOTIFY_TYPE'] == IM_NOTIFY_CONFIRM) {
                         if (isset($arFields['NOTIFY_BUTTONS'])) {
                             foreach ($arFields['NOTIFY_BUTTONS'] as $key => $arButtons) {
                                 if (is_array($arButtons)) {
                                     if (isset($arButtons['TITLE']) && strlen($arButtons['TITLE']) > 0 && isset($arButtons['VALUE']) && strlen($arButtons['VALUE']) > 0 && isset($arButtons['TYPE']) && strlen($arButtons['TYPE']) > 0) {
                                         $arButtons['TITLE'] = htmlspecialcharsbx($arButtons['TITLE']);
                                         $arButtons['VALUE'] = htmlspecialcharsbx($arButtons['VALUE']);
                                         $arButtons['TYPE'] = htmlspecialcharsbx($arButtons['TYPE']);
                                         $arFields['NOTIFY_BUTTONS'][$key] = $arButtons;
                                     } else {
                                         unset($arFields['NOTIFY_BUTTONS'][$key]);
                                     }
                                 } else {
                                     unset($arFields['NOTIFY_BUTTONS'][$key]);
                                 }
                             }
                         } else {
                             $arFields['NOTIFY_BUTTONS'] = array(array('TITLE' => GetMessage('IM_ERROR_BUTTON_ACCEPT'), 'VALUE' => 'Y', 'TYPE' => 'accept'), array('TITLE' => GetMessage('IM_ERROR_BUTTON_CANCEL'), 'VALUE' => 'N', 'TYPE' => 'cancel'));
                         }
                         $arParams['NOTIFY_BUTTONS'] = serialize($arFields["NOTIFY_BUTTONS"]);
                         if (isset($arParams['NOTIFY_TAG']) && strlen($arParams['NOTIFY_TAG']) > 0) {
                             CIMNotify::DeleteByTag($arParams['NOTIFY_TAG']);
                         }
                     }
                     if (!$bConvert) {
                         if (isset($arFields['PUSH_MESSAGE']) && CIMSettings::GetNotifyAccess($arFields["TO_USER_ID"], $arFields['NOTIFY_MODULE'], $arFields['NOTIFY_EVENT'], CIMSettings::CLIENT_PUSH) && CModule::IncludeModule('pull')) {
                             $CPushManager = new CPushManager();
                             $CPushManager->AddQueue(array('USER_ID' => $arFields['TO_USER_ID'], 'MESSAGE' => str_replace("\n", " ", trim($arFields['PUSH_MESSAGE'])), 'PARAMS' => isset($arFields['PUSH_PARAMS']) ? $arFields['PUSH_PARAMS'] : '', 'TAG' => $arParams['NOTIFY_TAG'], 'SUB_TAG' => $arParams['NOTIFY_SUB_TAG'], 'APP_ID' => isset($arParams['PUSH_APP_ID']) ? $arParams['PUSH_APP_ID'] : ''));
                         }
                         foreach (GetModuleEvents("im", "OnAfterNotifyAdd", true) as $arEvent) {
                             ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
                         }
                     }
                     if (!$sendToSite) {
                         return 0;
                     }
                     $result = IM\MessageTable::add($arParams);
                     $messageID = IntVal($result->getId());
                     if ($messageID <= 0) {
                         return false;
                     }
                     IM\ChatTable::update($chatId, array('LAST_MESSAGE_ID' => $messageID));
                     CIMMessenger::SpeedFileDelete($arFields['TO_USER_ID'], IM_SPEED_NOTIFY);
                     if (!$bConvert) {
                         //CUserCounter::Increment($arFields['TO_USER_ID'], 'im_notify_v2', '**', false);
                         $strSql = "UPDATE b_im_relation SET STATUS = '" . IM_STATUS_UNREAD . "' WHERE USER_ID = " . intval($arFields['TO_USER_ID']) . " AND MESSAGE_TYPE = '" . IM_MESSAGE_SYSTEM . "' AND CHAT_ID = " . $chatId;
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if (CModule::IncludeModule("pull")) {
                             CPullStack::AddByUser(intval($arFields['TO_USER_ID']), array('module_id' => 'im', 'command' => 'notify', 'params' => CIMNotify::GetFormatNotify(array('ID' => $messageID, 'DATE_CREATE' => time(), 'FROM_USER_ID' => intval($arFields['FROM_USER_ID']), 'MESSAGE' => $arParams['MESSAGE'], 'NOTIFY_MODULE' => $arParams['NOTIFY_MODULE'], 'NOTIFY_EVENT' => $arParams['NOTIFY_EVENT'], 'NOTIFY_TAG' => $arParams['NOTIFY_TAG'], 'NOTIFY_TYPE' => $arParams['NOTIFY_TYPE'], 'NOTIFY_BUTTONS' => isset($arParams['NOTIFY_BUTTONS']) ? $arParams['NOTIFY_BUTTONS'] : serialize(array()), 'NOTIFY_TITLE' => isset($arParams['NOTIFY_TITLE']) ? $arParams['NOTIFY_TITLE'] : ''))));
                             self::SendBadges($arFields['TO_USER_ID']);
                         }
                     }
                     return $messageID;
                 } else {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
                     return false;
                 }
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_TYPE"), "MESSAGE_TYPE");
                 return false;
             }
         }
     }
 }
Esempio n. 12
0
 public static function GetList($arParams = array())
 {
     if (!is_array($arParams)) {
         $arParams = array();
     }
     $arID = array();
     if (isset($arParams['ID']) && is_array($arParams['ID']) && !empty($arParams['ID'])) {
         foreach ($arParams['ID'] as $key => $value) {
             $arID[] = intval($value);
         }
     } else {
         if (isset($arParams['ID']) && intval($arParams['ID']) > 0) {
             $arID[] = intval($arParams['ID']);
         }
     }
     $arParams['GET_OFFLINE'] = !empty($arID) && isset($arParams['GET_OFFLINE']) && $arParams['GET_OFFLINE'] == 'Y' ? 'Y' : 'N';
     global $USER;
     $userId = is_object($USER) ? intval($USER->GetID()) : 0;
     $bBusShowAll = !IsModuleInstalled('intranet') && COption::GetOptionInt('im', 'contact_list_show_all_bus');
     if (!$bBusShowAll && !isset($arParams['ID']) && $userId > 0 && !isset($arParams['SKIP_CHECK'])) {
         if (isset(self::$FRIENDS_USERS[$userId])) {
             $arID = self::$FRIENDS_USERS[$userId];
         } else {
             if (CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) {
                 $arID = array($userId);
                 $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $userId, "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID"));
                 if ($dbFriends) {
                     while ($arFriends = $dbFriends->Fetch()) {
                         $arID[] = $userId == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
                     }
                 }
                 self::$FRIENDS_USERS[$userId] = $arID;
             }
         }
     }
     $arUsers = array();
     if (self::$ONLINE_USERS && $arParams['GET_OFFLINE'] == 'N') {
         $arUsers = self::$ONLINE_USERS;
     } else {
         if (!self::$ONLINE_USERS || $arParams['GET_OFFLINE'] == 'Y') {
             $enable = self::Enable();
             $arUsers = array();
             $query = new \Bitrix\Main\Entity\Query(\Bitrix\Main\UserTable::getEntity());
             $query->registerRuntimeField('', new \Bitrix\Main\Entity\ReferenceField('ref', 'Bitrix\\Im\\StatusTable', array('=this.ID' => 'ref.USER_ID')));
             $query->addSelect('ID')->addSelect('ref.COLOR', 'COLOR')->addSelect('PERSONAL_GENDER');
             if ($enable) {
                 $query->addSelect('ref.STATUS', 'STATUS')->addSelect('ref.IDLE', 'IDLE')->addSelect('ref.MOBILE_LAST_DATE', 'MOBILE_LAST_DATE');
             }
             if ($arParams['GET_OFFLINE'] == 'N') {
                 $query->addFilter('>LAST_ACTIVITY_DATE', new \Bitrix\Main\DB\SqlExpression(Bitrix\Main\Application::getConnection()->getSqlHelper()->addSecondsToDateTime('-180')));
             } else {
                 $sago = Bitrix\Main\Application::getConnection()->getSqlHelper()->addSecondsToDateTime('-180');
                 $query->registerRuntimeField('', new \Bitrix\Main\Entity\ExpressionField('IS_ONLINE_CUSTOM', 'CASE WHEN LAST_ACTIVITY_DATE > ' . $sago . ' THEN \'Y\' ELSE \'N\' END'));
                 $query->addSelect('IS_ONLINE_CUSTOM');
                 $query->addFilter('=ID', $arID);
             }
             $result = $query->exec();
             while ($arUser = $result->fetch()) {
                 $color = null;
                 if (isset($arUser['COLOR']) && strlen($arUser['COLOR']) > 0) {
                     $color = IM\Color::getColor($arUser['COLOR']);
                 }
                 if (!$color) {
                     $color = \CIMContactList::GetUserColor($arUser["ID"], $arUser['PERSONAL_GENDER'] == 'M' ? 'M' : 'F');
                 }
                 $arUsers[$arUser["ID"]] = array('id' => $arUser["ID"], 'status' => $enable && in_array($arUser['STATUS'], self::$AVAILABLE_STATUSES) ? $arUser['STATUS'] : 'online', 'color' => $color, 'idle' => $enable && is_object($arUser['IDLE']) ? $arUser['IDLE']->getTimestamp() : 0, 'mobileLastDate' => $enable && is_object($arUser['MOBILE_LAST_DATE']) ? $arUser['MOBILE_LAST_DATE']->getTimestamp() : 0);
                 if ($arParams['GET_OFFLINE'] == 'Y' && $arUser['IS_ONLINE_CUSTOM'] == 'N') {
                     $arUsers[$arUser["ID"]]['status'] = 'offline';
                     $arUsers[$arUser["ID"]]['idle'] = 0;
                     $arUsers[$arUser["ID"]]['mobileLastDate'] = 0;
                 }
             }
             if ($arParams['GET_OFFLINE'] == 'N') {
                 self::$ONLINE_USERS = $arUsers;
             }
         }
     }
     $arResult = array();
     if (empty($arID)) {
         $arResult = $arUsers;
     } else {
         foreach ($arID as $userId) {
             if (isset($arUsers[$userId])) {
                 $arResult[$userId] = $arUsers[$userId];
             }
         }
     }
     return array('users' => $arResult);
 }
Esempio n. 13
0
		if (IsModuleInstalled("bizproc"))
			$arSocNetFeaturesSettings["files"]["operations"]["bizproc"] = array();

		$arSocNetFeaturesSettings["files"]["operations"]["write"] = array();

		if (COption::GetOptionString("socialnetwork", "allow_files_user", "Y") == "Y")
		{
			$arSocNetFeaturesSettings["files"]["subscribe_events"]["files"]["ENTITIES"][SONET_SUBSCRIBE_ENTITY_USER] = array(
					"TITLE" => GetMessage("SOCNET_LOG_FILES_USER"),
					"TITLE_SETTINGS" => GetMessage("SOCNET_LOG_FILES_USER_SETTINGS"),
					"TITLE_SETTINGS_1" => GetMessage("SOCNET_LOG_FILES_USER_SETTINGS_1"),
					"TITLE_SETTINGS_2" => GetMessage("SOCNET_LOG_FILES_USER_SETTINGS_2"),
				);

			$arSocNetFeaturesSettings["files"]["allowed"][] = SONET_ENTITY_USER;
			$arSocNetFeaturesSettings["files"]["operations"]["view"][SONET_ENTITY_USER] = COption::GetOptionString("socialnetwork", "default_files_operation_view_user", (CSocNetUser::IsFriendsAllowed() ? SONET_RELATIONS_TYPE_FRIENDS : SONET_RELATIONS_TYPE_ALL));
			$arSocNetFeaturesSettings["files"]["operations"]["write_limited"][SONET_ENTITY_USER] = COption::GetOptionString("socialnetwork", "default_files_operation_write_limited_user", SONET_RELATIONS_TYPE_NONE);
			$arSocNetFeaturesSettings["files"]["operations"]["write"][SONET_ENTITY_USER] = COption::GetOptionString("socialnetwork", "default_files_operation_write_user", SONET_RELATIONS_TYPE_NONE);
		}

		if (COption::GetOptionString("socialnetwork", "allow_files_group", "Y") == "Y")
		{
			$arSocNetFeaturesSettings["files"]["subscribe_events"]["files"]["ENTITIES"][SONET_SUBSCRIBE_ENTITY_GROUP] = array(
					"TITLE" => GetMessage("SOCNET_LOG_FILES_GROUP"),
					"TITLE_SETTINGS" => GetMessage("SOCNET_LOG_FILES_GROUP_SETTINGS"),
					"TITLE_SETTINGS_1" => GetMessage("SOCNET_LOG_FILES_GROUP_SETTINGS_1"),
					"TITLE_SETTINGS_2" => GetMessage("SOCNET_LOG_FILES_GROUP_SETTINGS_2"),
				);

			$arSocNetFeaturesSettings["files"]["allowed"][] = SONET_ENTITY_GROUP;
			$arSocNetFeaturesSettings["files"]["operations"]["view"][SONET_ENTITY_GROUP] = COption::GetOptionString("socialnetwork", "default_files_operation_view_group", SONET_ROLES_USER);
Esempio n. 14
0
 public static function Add($arFields)
 {
     global $DB;
     if (isset($arFields['TITLE']) && !isset($arFields['NOTIFY_TITLE'])) {
         $arFields['NOTIFY_TITLE'] = $arFields['TITLE'];
     }
     if (isset($arFields['NOTIFY_MESSAGE']) && !isset($arFields['MESSAGE'])) {
         $arFields['MESSAGE'] = $arFields['NOTIFY_MESSAGE'];
     }
     if (isset($arFields['NOTIFY_MESSAGE_OUT']) && !isset($arFields['MESSAGE_OUT'])) {
         $arFields['MESSAGE_OUT'] = $arFields['NOTIFY_MESSAGE_OUT'];
     }
     if (isset($arFields['MESSAGE'])) {
         $arFields['MESSAGE'] = trim($arFields['MESSAGE']);
     }
     $arFields['MESSAGE_OUT'] = isset($arFields['MESSAGE_OUT']) ? trim($arFields['MESSAGE_OUT']) : "";
     $bConvert = false;
     if (isset($arFields['CONVERT']) && $arFields['CONVERT'] == 'Y') {
         $bConvert = true;
     }
     if (!isset($arFields['MESSAGE_TYPE'])) {
         $arFields['MESSAGE_TYPE'] = "";
     }
     if (!isset($arFields['NOTIFY_MODULE'])) {
         $arFields['NOTIFY_MODULE'] = 'im';
     }
     if (!isset($arFields['NOTIFY_EVENT'])) {
         $arFields['NOTIFY_EVENT'] = 'default';
     }
     if (!isset($arFields['PARAMS'])) {
         $arFields['PARAMS'] = array();
     }
     if (isset($arFields['ATTACH']) || isset($arFields['PARAMS']['ATTACH'])) {
         $attach = isset($arFields['ATTACH']) ? $arFields['ATTACH'] : $arFields['PARAMS']['ATTACH'];
         if (is_object($attach)) {
             $arFields['PARAMS']['ATTACH'] = array($attach);
         } else {
             if (is_array($attach)) {
                 $arFields['PARAMS']['ATTACH'] = $attach;
             } else {
                 $arFields['PARAMS']['ATTACH'] = array();
             }
         }
     }
     if (isset($arFields['FOR_USER_ID'])) {
         $arFields['PARAMS']['FOR_USER_ID'] = $arFields['FOR_USER_ID'];
     }
     $arFields['URL_ATTACH'] = array();
     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) {
         if (!isset($arFields['NOTIFY_TYPE']) && intval($arFields['FROM_USER_ID']) > 0) {
             $arFields['NOTIFY_TYPE'] = IM_NOTIFY_FROM;
         } else {
             if (!isset($arFields['NOTIFY_TYPE'])) {
                 $arFields['NOTIFY_TYPE'] = IM_NOTIFY_SYSTEM;
             }
         }
         if (isset($arFields['NOTIFY_ANSWER']) && $arFields['NOTIFY_ANSWER'] == 'Y') {
             $arFields['PARAMS']['CAN_ANSWER'] = 'Y';
         }
         /*
         $urlPrepare = self::PrepareUrl($arFields['MESSAGE']);
         if ($urlPrepare['RESULT'])
         {
         	if (empty($arFields['MESSAGE_OUT']))
         	{
         		$arFields['MESSAGE_OUT'] = $arFields['MESSAGE'];
         	}
         	$arFields['MESSAGE'] = $urlPrepare['MESSAGE'];
         	$arFields['PARAMS']['ATTACH'] = array_merge($arFields['PARAMS']['ATTACH'], $urlPrepare['ATTACH']);
         }
         */
     } else {
         $link = new CIMMessageLink();
         $urlPrepare = $link->prepareInsert($arFields['MESSAGE']);
         if ($urlPrepare['RESULT']) {
             if (empty($arFields['MESSAGE_OUT'])) {
                 $arFields['MESSAGE_OUT'] = $arFields['MESSAGE'];
             }
             $arFields['MESSAGE'] = $urlPrepare['MESSAGE'];
             if (isset($arFields['PARAMS']['URL_ID'])) {
                 $arFields['PARAMS']['URL_ID'] = array_merge($arFields['PARAMS']['URL_ID'], $urlPrepare['URL_ID']);
             } else {
                 $arFields['PARAMS']['URL_ID'] = $urlPrepare['URL_ID'];
             }
             $arFields['URL_ATTACH'] = $urlPrepare['ATTACH'];
         }
     }
     if (isset($arFields['NOTIFY_EMAIL_TEMPLATE']) && !isset($arFields['EMAIL_TEMPLATE'])) {
         $arFields['EMAIL_TEMPLATE'] = $arFields['NOTIFY_EMAIL_TEMPLATE'];
     }
     if (!isset($arFields['AUTHOR_ID'])) {
         $arFields['AUTHOR_ID'] = intval($arFields['FROM_USER_ID']);
     }
     foreach (GetModuleEvents("im", "OnBeforeMessageNotifyAdd", true) as $arEvent) {
         $result = ExecuteModuleEventEx($arEvent, array(&$arFields));
         if ($result === false || isset($result['result']) && $result['result'] === false) {
             if (isset($result['reason'])) {
                 $CBXSanitizer = new CBXSanitizer();
                 $CBXSanitizer->AddTags(array('a' => array('href', 'style', 'target'), 'b' => array(), 'u' => array(), 'i' => array(), 'br' => array(), 'span' => array('style')));
                 $reason = $CBXSanitizer->SanitizeHtml($result['reason']);
             } else {
                 if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) {
                     $reason = GetMessage("IM_ERROR_MESSAGE_CANCELED");
                 } else {
                     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) {
                         $reason = GetMessage("IM_ERROR_NOTIFY_CANCELED");
                     } else {
                         $reason = GetMessage("IM_ERROR_GROUP_CANCELED");
                     }
                 }
             }
             $GLOBALS["APPLICATION"]->ThrowException($reason, "ERROR_FROM_OTHER_MODULE");
             return false;
         }
     }
     if (!self::CheckFields($arFields)) {
         return false;
     }
     if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_PRIVATE) {
         if (isset($arFields['TO_CHAT_ID'])) {
             $chatId = $arFields['TO_CHAT_ID'];
             $arRel = CIMChat::GetRelationById($chatId);
             foreach ($arRel as $rel) {
                 if ($rel['USER_ID'] == $arFields['FROM_USER_ID']) {
                     continue;
                 }
                 $arFields['TO_USER_ID'] = $rel['USER_ID'];
             }
             if (!IsModuleInstalled('intranet')) {
                 if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY_SELF'), "ERROR_FROM_PRIVACY_SELF");
                     return false;
                 } else {
                     if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arFields['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY'), "ERROR_FROM_PRIVACY");
                         return false;
                     }
                 }
             }
         } else {
             $arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']);
             $arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']);
             if (!IsModuleInstalled('intranet')) {
                 if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY_SELF'), "ERROR_FROM_PRIVACY_SELF");
                     return false;
                 } else {
                     if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arFields['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arFields['FROM_USER_ID'], $arFields['TO_USER_ID'])) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_MESSAGE_PRIVACY'), "ERROR_FROM_PRIVACY");
                         return false;
                     }
                 }
             }
             $chatId = CIMMessage::GetChatId($arFields['FROM_USER_ID'], $arFields['TO_USER_ID']);
         }
         if ($chatId > 0) {
             $arParams = array();
             $arParams['CHAT_ID'] = $chatId;
             $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']);
             $arParams['MESSAGE'] = $arFields['MESSAGE'];
             $arParams['MESSAGE_OUT'] = $arFields['MESSAGE_OUT'];
             $arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE'];
             $arParams['NOTIFY_EVENT'] = $arFields['SYSTEM'] == 'Y' ? 'private_system' : 'private';
             if (isset($arFields['IMPORT_ID'])) {
                 $arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']);
             }
             if (isset($arFields['MESSAGE_DATE'])) {
                 $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
             }
             $arFiles = array();
             $arFields['FILES'] = array();
             if (isset($arFields['PARAMS']['FILE_ID'])) {
                 foreach ($arFields['PARAMS']['FILE_ID'] as $fileId) {
                     $arFiles[$fileId] = $fileId;
                 }
             }
             $arFields['FILES'] = CIMDisk::GetFiles($chatId, $arFiles);
             $messageFiles = self::GetFormatFilesMessageOut($arFields['FILES']);
             if (strlen($messageFiles) > 0) {
                 $arParams['MESSAGE_OUT'] = strlen($arParams['MESSAGE_OUT']) > 0 ? $arParams['MESSAGE_OUT'] . "\n" . $messageFiles : $messageFiles;
                 $arFields['MESSAGE_OUT'] = $arParams['MESSAGE_OUT'];
             }
             $result = IM\MessageTable::add($arParams);
             $messageID = IntVal($result->getId());
             if ($messageID <= 0) {
                 return false;
             }
             IM\ChatTable::update($chatId, array('LAST_MESSAGE_ID' => $messageID));
             if (!empty($arFields['PARAMS'])) {
                 CIMMessageParam::Set($messageID, $arFields['PARAMS']);
             }
             if (!empty($arFields['URL_ATTACH'])) {
                 if (isset($arFields['PARAMS']['ATTACH'])) {
                     $arFields['PARAMS']['ATTACH'] = array_merge($arFields['PARAMS']['ATTACH'], $arFields['URL_ATTACH']);
                 } else {
                     $arFields['PARAMS']['ATTACH'] = $arFields['URL_ATTACH'];
                 }
             }
             //CUserCounter::Increment($arFields['TO_USER_ID'], 'im_message_v2', '**', false);
             CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['TO_USER_ID'], 'MESSAGE_ID' => $messageID, 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['FROM_USER_ID']));
             CIMContactList::SetRecent(array('ENTITY_ID' => $arFields['FROM_USER_ID'], 'MESSAGE_ID' => $messageID, 'CHAT_TYPE' => IM_MESSAGE_PRIVATE, 'USER_ID' => $arFields['TO_USER_ID']));
             CIMStatus::SetIdle($arFields['FROM_USER_ID'], false);
             if (!$bConvert) {
                 $arRel = CIMChat::GetRelationById($chatId);
                 foreach ($arRel as $relation) {
                     if ($relation["USER_ID"] == $arFields["TO_USER_ID"]) {
                         if ($relation['STATUS'] != IM_STATUS_UNREAD) {
                             IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_UNREAD));
                         }
                     } else {
                         IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_READ, "LAST_ID" => $messageID, "LAST_SEND_ID" => $messageID, "LAST_READ" => new Bitrix\Main\Type\DateTime()));
                     }
                 }
                 if (CModule::IncludeModule("pull")) {
                     $arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID'];
                     $arParams['TO_USER_ID'] = $arFields['TO_USER_ID'];
                     $pullMessage = array('module_id' => 'im', 'command' => 'message', 'params' => CIMMessage::GetFormatMessage(array('ID' => $messageID, 'CHAT_ID' => $chatId, 'TO_USER_ID' => $arParams['TO_USER_ID'], 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'SYSTEM' => $arFields['SYSTEM'] == 'Y' ? 'Y' : 'N', 'MESSAGE' => $arParams['MESSAGE'], 'DATE_CREATE' => time(), 'PARAMS' => self::PrepareParamsForPull($arFields['PARAMS']), 'FILES' => $arFields['FILES'])));
                     $pullMessageTo = $pullMessage;
                     if (CPullOptions::GetPushStatus() && (!isset($arFields['PUSH']) || $arFields['PUSH'] == 'Y')) {
                         if (CIMSettings::GetNotifyAccess($arParams["TO_USER_ID"], 'im', 'message', CIMSettings::CLIENT_PUSH)) {
                             $pushParams = self::PreparePushForPrivate(array('FROM_USER_ID' => $arParams['FROM_USER_ID'], 'MESSAGE' => $arParams['MESSAGE'], 'SYSTEM' => $arFields['SYSTEM'], 'FILES' => $arFields['FILES'], 'ATTACH' => isset($arFields['PARAMS']['ATTACH']) ? true : false));
                             $pullMessageTo = array_merge($pullMessage, $pushParams);
                         }
                     }
                     CPullStack::AddByUser($arParams['TO_USER_ID'], $pullMessageTo);
                     CPullStack::AddByUser($arParams['FROM_USER_ID'], $pullMessage);
                     CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS');
                     //self::SendBadges($arParams['TO_USER_ID']);
                 }
                 foreach (GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) {
                     ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
                 }
             }
             return $messageID;
         } else {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
             return false;
         }
     } else {
         if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_CHAT || $arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN) {
             $arFields['FROM_USER_ID'] = intval($arFields['FROM_USER_ID']);
             $chatId = 0;
             $systemMessage = false;
             if (isset($arFields['SYSTEM']) && $arFields['SYSTEM'] == 'Y') {
                 $strSql = "\n\t\t\t\t\tSELECT C.ID CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID, C.TYPE CHAT_TYPE, '1' RID\n\t\t\t\t\tFROM b_im_chat C\n\t\t\t\t\tWHERE C.ID = " . intval($arFields['TO_CHAT_ID']) . "\n\t\t\t\t";
                 $systemMessage = true;
             } else {
                 $strSql = "\n\t\t\t\t\tSELECT C.ID CHAT_ID, C.TITLE CHAT_TITLE, C.AUTHOR_ID CHAT_AUTHOR_ID, C.TYPE CHAT_TYPE, R.USER_ID RID\n\t\t\t\t\tFROM b_im_chat C\n\t\t\t\t\tLEFT JOIN b_im_relation R ON R.CHAT_ID = C.ID AND R.USER_ID = " . $arFields['FROM_USER_ID'] . "\n\t\t\t\t\tWHERE C.ID = " . intval($arFields['TO_CHAT_ID']) . "\n\t\t\t\t";
             }
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($arRes = $dbRes->Fetch()) {
                 $chatId = intval($arRes['CHAT_ID']);
                 $chatTitle = htmlspecialcharsbx($arRes['CHAT_TITLE']);
                 $chatAuthorId = intval($arRes['CHAT_AUTHOR_ID']);
                 $arRes['CHAT_TYPE'] = trim($arRes['CHAT_TYPE']);
                 $arFields['MESSAGE_TYPE'] = $arRes['CHAT_TYPE'];
                 if ($arRes['CHAT_TYPE'] == IM_MESSAGE_OPEN) {
                     if (!CIMMessenger::CheckEnableOpenChat()) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                         return false;
                     } else {
                         if (intval($arRes['RID']) <= 0) {
                             if (IM\User::getInstance($arFields['FROM_USER_ID'])->isExtranet()) {
                                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                                 return false;
                             } else {
                                 $chat = new CIMChat(0);
                                 $chat->AddUser($chatId, $arFields['FROM_USER_ID']);
                             }
                         }
                     }
                 } else {
                     if (intval($arRes['RID']) <= 0) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                         return false;
                     }
                 }
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_GROUP_CANCELED"), "CANCELED");
                 return false;
             }
             if ($chatId > 0) {
                 $arParams = array();
                 $arParams['CHAT_ID'] = $chatId;
                 $arParams['AUTHOR_ID'] = $systemMessage ? 0 : intval($arFields['AUTHOR_ID']);
                 $arParams['MESSAGE'] = $arFields['MESSAGE'];
                 $arParams['MESSAGE_OUT'] = $arFields['MESSAGE_OUT'];
                 $arParams['NOTIFY_MODULE'] = 'im';
                 $arParams['NOTIFY_EVENT'] = 'group';
                 if (isset($arFields['MESSAGE_DATE'])) {
                     $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
                 }
                 $arFiles = array();
                 $arFields['FILES'] = array();
                 if (isset($arFields['PARAMS']['FILE_ID'])) {
                     foreach ($arFields['PARAMS']['FILE_ID'] as $fileId) {
                         $arFiles[$fileId] = $fileId;
                     }
                 }
                 $arFields['FILES'] = CIMDisk::GetFiles($chatId, $arFiles);
                 $messageFiles = self::GetFormatFilesMessageOut($arFields['FILES']);
                 if (strlen($messageFiles) > 0) {
                     $arParams['MESSAGE_OUT'] = strlen($arParams['MESSAGE_OUT']) > 0 ? $arParams['MESSAGE_OUT'] . "\n" . $messageFiles : $messageFiles;
                     $arFields['MESSAGE_OUT'] = $arParams['MESSAGE_OUT'];
                 }
                 $result = IM\MessageTable::add($arParams);
                 $messageID = IntVal($result->getId());
                 if ($messageID <= 0) {
                     return false;
                 }
                 IM\ChatTable::update($chatId, array('LAST_MESSAGE_ID' => $messageID));
                 if (!empty($arFields['PARAMS'])) {
                     CIMMessageParam::Set($messageID, $arFields['PARAMS']);
                 }
                 if (!empty($arFields['URL_ATTACH'])) {
                     if (isset($arFields['PARAMS']['ATTACH'])) {
                         $arFields['PARAMS']['ATTACH'] = array_merge($arFields['PARAMS']['ATTACH'], $arFields['URL_ATTACH']);
                     } else {
                         $arFields['PARAMS']['ATTACH'] = $arFields['URL_ATTACH'];
                     }
                 }
                 //$sqlCounter = "SELECT USER_ID as ID, 1 as CNT, '**' as SITE_ID, 'im_chat_v2' as CODE, 1 as SENT
                 //				FROM b_im_relation R1
                 //				WHERE CHAT_ID = ".$chatId." AND USER_ID <> ".$arFields['FROM_USER_ID'];
                 //CUserCounter::IncrementWithSelect($sqlCounter, false);
                 $arRel = CIMChat::GetRelationById($chatId);
                 foreach ($arRel as $relation) {
                     CIMContactList::SetRecent(array('ENTITY_ID' => $chatId, 'MESSAGE_ID' => $messageID, 'CHAT_TYPE' => $arFields['MESSAGE_TYPE'], 'USER_ID' => $relation['USER_ID']));
                     if ($relation["USER_ID"] == $arFields["FROM_USER_ID"]) {
                         IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_READ, "LAST_ID" => $messageID, "LAST_SEND_ID" => $messageID, "LAST_READ" => new Bitrix\Main\Type\DateTime()));
                     } else {
                         if ($relation['STATUS'] != IM_STATUS_UNREAD) {
                             IM\RelationTable::update($relation["ID"], array("STATUS" => IM_STATUS_UNREAD));
                         }
                     }
                 }
                 CIMStatus::SetIdle($arFields['FROM_USER_ID'], false);
                 if (CModule::IncludeModule("pull")) {
                     $arParams['FROM_USER_ID'] = $arFields['FROM_USER_ID'];
                     $arParams['TO_CHAT_ID'] = $arFields['TO_CHAT_ID'];
                     $pullMessage = array('module_id' => 'im', 'command' => 'messageChat', 'params' => CIMMessage::GetFormatMessage(array('ID' => $messageID, 'CHAT_ID' => $chatId, 'TO_CHAT_ID' => $arParams['TO_CHAT_ID'], 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'MESSAGE' => $arParams['MESSAGE'], 'SYSTEM' => $arFields['SYSTEM'] == 'Y' ? 'Y' : 'N', 'DATE_CREATE' => time(), 'PARAMS' => self::PrepareParamsForPull($arFields['PARAMS']), 'FILES' => $arFields['FILES'])));
                     if (CPullOptions::GetPushStatus() && (!isset($arFields['PUSH']) || $arFields['PUSH'] == 'Y')) {
                         $pushParams = self::PreparePushForChat(array('CHAT_ID' => $chatId, 'CHAT_TITLE' => $chatTitle, 'FROM_USER_ID' => $arParams['FROM_USER_ID'], 'MESSAGE' => $arParams['MESSAGE'], 'SYSTEM' => $arFields['SYSTEM'], 'FILES' => $arFields['FILES'], 'ATTACH' => isset($arFields['PARAMS']['ATTACH']) ? true : false));
                         $pullMessage = array_merge($pullMessage, $pushParams);
                     }
                     $pullUsers = array();
                     $pullUsersSkip = array();
                     foreach ($arRel as $rel) {
                         $pullUsers[] = $rel['USER_ID'];
                         if ($rel['USER_ID'] == $arParams['FROM_USER_ID']) {
                             $pullUsersSkip[] = $rel['USER_ID'];
                             CPushManager::DeleteFromQueueBySubTag($arParams['FROM_USER_ID'], 'IM_MESS');
                         } else {
                             if ($rel['NOTIFY_BLOCK'] == 'Y' || !CIMSettings::GetNotifyAccess($rel['USER_ID'], 'im', $arFields['MESSAGE_TYPE'] == IM_MESSAGE_OPEN ? 'openChat' : 'chat', CIMSettings::CLIENT_PUSH)) {
                                 $pullUsersSkip[] = $rel['USER_ID'];
                             }
                         }
                     }
                     $pullMessage['push']['skip_users'] = $pullUsersSkip;
                     CPullStack::AddByUsers($pullUsers, $pullMessage);
                     if ($arRes['CHAT_TYPE'] == IM_MESSAGE_OPEN) {
                         $pullMessageToWatch = $pullMessage;
                         unset($pullMessageToWatch['push']);
                         CPullWatch::AddToStack('IM_PUBLIC_' . $chatId, $pullMessageToWatch);
                     }
                     self::SendMention(array('CHAT_ID' => $chatId, 'CHAT_TITLE' => $chatTitle, 'CHAT_RELATION' => $arRel, 'CHAT_TYPE' => $arFields['MESSAGE_TYPE'], 'MESSAGE' => $arParams['MESSAGE'], 'FILES' => $arFields['FILES'], 'FROM_USER_ID' => $arParams['FROM_USER_ID']));
                     //self::SendBadges($usersForBadges);
                 }
                 foreach (GetModuleEvents("im", "OnAfterMessagesAdd", true) as $arEvent) {
                     ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
                 }
                 return $messageID;
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
                 return false;
             }
         } else {
             if ($arFields['MESSAGE_TYPE'] == IM_MESSAGE_SYSTEM) {
                 $arFields['TO_USER_ID'] = intval($arFields['TO_USER_ID']);
                 $orm = \Bitrix\Main\UserTable::getById($arFields['TO_USER_ID']);
                 $userData = $orm->fetch();
                 if (!$userData || $userData['ACTIVE'] == 'N' || $userData['EXTERNAL_AUTH_ID'] == 'email') {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "TO_USER_ID");
                     return false;
                 }
                 $chatId = 0;
                 $strSql = "\n\t\t\t\tSELECT C.ID CHAT_ID\n\t\t\t\tFROM b_im_chat C\n\t\t\t\tWHERE C.AUTHOR_ID = " . $arFields['TO_USER_ID'] . " AND C.TYPE = '" . IM_MESSAGE_SYSTEM . "'\n\t\t\t";
                 $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 if ($arRes = $dbRes->Fetch()) {
                     $chatId = intval($arRes['CHAT_ID']);
                 } else {
                     $result = IM\ChatTable::add(array('TYPE' => IM_MESSAGE_SYSTEM, 'AUTHOR_ID' => $arFields['TO_USER_ID']));
                     $chatId = $result->getId();
                     if ($chatId <= 0) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
                         return false;
                     }
                     IM\RelationTable::add(array("CHAT_ID" => $chatId, "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "USER_ID" => intval($arFields['TO_USER_ID']), "STATUS" => $bConvert ? 2 : 0));
                 }
                 if ($chatId > 0) {
                     $arParams = array();
                     $arParams['CHAT_ID'] = $chatId;
                     $arParams['AUTHOR_ID'] = intval($arFields['AUTHOR_ID']);
                     $arParams['MESSAGE'] = $arFields['MESSAGE'];
                     $arParams['MESSAGE_OUT'] = $arFields['MESSAGE_OUT'];
                     $arParams['NOTIFY_TYPE'] = intval($arFields['NOTIFY_TYPE']);
                     $arParams['NOTIFY_MODULE'] = $arFields['NOTIFY_MODULE'];
                     $arParams['NOTIFY_EVENT'] = $arFields['NOTIFY_EVENT'];
                     //if (strlen($arParams['MESSAGE']) <= 0 && strlen($arParams['MESSAGE_OUT']) <= 0)
                     //	return false;
                     $sendToSite = true;
                     if ($arParams['NOTIFY_TYPE'] != IM_NOTIFY_CONFIRM) {
                         $sendToSite = CIMSettings::GetNotifyAccess($arFields["TO_USER_ID"], $arFields["NOTIFY_MODULE"], $arFields["NOTIFY_EVENT"], CIMSettings::CLIENT_SITE);
                     }
                     if (!$sendToSite) {
                         $arParams['NOTIFY_READ'] = 'Y';
                     }
                     if (isset($arFields['IMPORT_ID'])) {
                         $arParams['IMPORT_ID'] = intval($arFields['IMPORT_ID']);
                     }
                     if (isset($arFields['MESSAGE_DATE'])) {
                         $arParams['DATE_CREATE'] = $arFields['MESSAGE_DATE'];
                     }
                     if (isset($arFields['EMAIL_TEMPLATE']) && strlen(trim($arFields['EMAIL_TEMPLATE'])) > 0) {
                         $arParams['EMAIL_TEMPLATE'] = trim($arFields['EMAIL_TEMPLATE']);
                     }
                     $arParams['NOTIFY_TAG'] = isset($arFields['NOTIFY_TAG']) ? $arFields['NOTIFY_TAG'] : '';
                     $arParams['NOTIFY_SUB_TAG'] = isset($arFields['NOTIFY_SUB_TAG']) ? $arFields['NOTIFY_SUB_TAG'] : '';
                     if (isset($arFields['NOTIFY_TITLE']) && strlen(trim($arFields['NOTIFY_TITLE'])) > 0) {
                         $arParams['NOTIFY_TITLE'] = trim($arFields['NOTIFY_TITLE']);
                     }
                     if ($arParams['NOTIFY_TYPE'] == IM_NOTIFY_CONFIRM) {
                         if (isset($arFields['NOTIFY_BUTTONS'])) {
                             foreach ($arFields['NOTIFY_BUTTONS'] as $key => $arButtons) {
                                 if (is_array($arButtons)) {
                                     if (isset($arButtons['TITLE']) && strlen($arButtons['TITLE']) > 0 && isset($arButtons['VALUE']) && strlen($arButtons['VALUE']) > 0 && isset($arButtons['TYPE']) && strlen($arButtons['TYPE']) > 0) {
                                         $arButtons['TITLE'] = htmlspecialcharsbx($arButtons['TITLE']);
                                         $arButtons['VALUE'] = htmlspecialcharsbx($arButtons['VALUE']);
                                         $arButtons['TYPE'] = htmlspecialcharsbx($arButtons['TYPE']);
                                         $arFields['NOTIFY_BUTTONS'][$key] = $arButtons;
                                     } else {
                                         unset($arFields['NOTIFY_BUTTONS'][$key]);
                                     }
                                 } else {
                                     unset($arFields['NOTIFY_BUTTONS'][$key]);
                                 }
                             }
                         } else {
                             $arFields['NOTIFY_BUTTONS'] = array(array('TITLE' => GetMessage('IM_ERROR_BUTTON_ACCEPT'), 'VALUE' => 'Y', 'TYPE' => 'accept'), array('TITLE' => GetMessage('IM_ERROR_BUTTON_CANCEL'), 'VALUE' => 'N', 'TYPE' => 'cancel'));
                         }
                         $arParams['NOTIFY_BUTTONS'] = serialize($arFields["NOTIFY_BUTTONS"]);
                         if (isset($arParams['NOTIFY_TAG']) && strlen($arParams['NOTIFY_TAG']) > 0) {
                             CIMNotify::DeleteByTag($arParams['NOTIFY_TAG']);
                         }
                     }
                     if ($sendToSite) {
                         $result = IM\MessageTable::add($arParams);
                         $messageID = IntVal($result->getId());
                         if ($messageID <= 0) {
                             return false;
                         }
                     } else {
                         $messageID = time();
                     }
                     if (!$bConvert) {
                         if (CModule::IncludeModule('pull')) {
                             $CPushManager = new CPushManager();
                             if (isset($arFields['PUSH_MESSAGE']) && CIMSettings::GetNotifyAccess($arFields["TO_USER_ID"], $arFields['NOTIFY_MODULE'], $arFields['NOTIFY_EVENT'], CIMSettings::CLIENT_PUSH) && CModule::IncludeModule('pull')) {
                                 $CPushManager->AddQueue(array('USER_ID' => $arFields['TO_USER_ID'], 'MESSAGE' => str_replace("\n", " ", trim($arFields['PUSH_MESSAGE'])), 'PARAMS' => isset($arFields['PUSH_PARAMS']) ? $arFields['PUSH_PARAMS'] : '', 'TAG' => $arParams['NOTIFY_TAG'], 'SUB_TAG' => $arParams['NOTIFY_SUB_TAG'], 'APP_ID' => isset($arParams['PUSH_APP_ID']) ? $arParams['PUSH_APP_ID'] : ''));
                             } else {
                                 $CPushManager->AddQueue(array('USER_ID' => $arFields['TO_USER_ID'], 'APP_ID' => isset($arParams['PUSH_APP_ID']) ? $arParams['PUSH_APP_ID'] : ''));
                             }
                         }
                         foreach (GetModuleEvents("im", "OnAfterNotifyAdd", true) as $arEvent) {
                             ExecuteModuleEventEx($arEvent, array(intval($messageID), $arFields));
                         }
                     }
                     if (!$sendToSite) {
                         return false;
                     }
                     if (!empty($arFields['PARAMS'])) {
                         CIMMessageParam::Set($messageID, $arFields['PARAMS']);
                     }
                     IM\ChatTable::update($chatId, array('LAST_MESSAGE_ID' => $messageID));
                     CIMMessenger::SpeedFileDelete($arFields['TO_USER_ID'], IM_SPEED_NOTIFY);
                     if (!$bConvert) {
                         //CUserCounter::Increment($arFields['TO_USER_ID'], 'im_notify_v2', '**', false);
                         $strSql = "UPDATE b_im_relation SET STATUS = '" . IM_STATUS_UNREAD . "' WHERE USER_ID = " . intval($arFields['TO_USER_ID']) . " AND MESSAGE_TYPE = '" . IM_MESSAGE_SYSTEM . "' AND CHAT_ID = " . $chatId;
                         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         if (CModule::IncludeModule("pull")) {
                             CPullStack::AddByUser(intval($arFields['TO_USER_ID']), array('module_id' => 'im', 'command' => 'notify', 'params' => CIMNotify::GetFormatNotify(array('ID' => $messageID, 'DATE_CREATE' => time(), 'FROM_USER_ID' => intval($arFields['FROM_USER_ID']), 'MESSAGE' => $arParams['MESSAGE'], 'PARAMS' => self::PrepareParamsForPull($arFields['PARAMS']), 'NOTIFY_MODULE' => $arParams['NOTIFY_MODULE'], 'NOTIFY_EVENT' => $arParams['NOTIFY_EVENT'], 'NOTIFY_TAG' => $arParams['NOTIFY_TAG'], 'NOTIFY_TYPE' => $arParams['NOTIFY_TYPE'], 'NOTIFY_BUTTONS' => isset($arParams['NOTIFY_BUTTONS']) ? $arParams['NOTIFY_BUTTONS'] : serialize(array()), 'NOTIFY_TITLE' => isset($arParams['NOTIFY_TITLE']) ? $arParams['NOTIFY_TITLE'] : ''))));
                             self::SendBadges($arFields['TO_USER_ID']);
                         }
                     }
                     return $messageID;
                 } else {
                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_CREATE"), "CHAT_ID");
                     return false;
                 }
             } else {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MESSAGE_TYPE"), "MESSAGE_TYPE");
                 return false;
             }
         }
     }
 }
Esempio n. 15
0
 /**
  * <p>Метод инициализирует массив прав пользователя на операции над профайлом заданного пользователя.</p>
  *
  *
  * @param int $currentUserID  Код пользователя, права которого проверяются.
  *
  * @param int $userID  Код пользователя, к профайлу которого осуществляется доступ.
  *
  * @param bool $bCurrentUserIsAdmin  Флаг, является ли администратором пользователь, права которого
  * проверяются.
  *
  * @return array <p>Массив с ключами:<br><b>IsCurrentUser</b> - флаг, осуществляется ли доступ к
  * собственному профайлу,<br><b>Relation</b> - отношения между
  * пользователями,<br><b>Operations</b> - массив операций: <br> modifyuser - право на
  * изменение профайла, если в главном модуле разрешено
  * редактировать профиль,<br> modifyuser_main - право на изменение
  * профайла,<br> viewcontacts - право на просмотр контактной информации,<br>
  * invitegroup - приглашение в группу, <br> message - отправка персонального
  * сообщения, <br> viewfriends - просмотр друзей, <br> viewgroups - просмотр групп,
  * <br> viewprofile - просмотр профиля. </p> <a name="examples"></a>
  *
  * <h4>Example</h4> 
  * <pre>
  * Array 
  * ( 
  *  [Operations] =&gt; Array 
  * 	 ( 
  * 		 [modifyuser] =&gt; 1 
  * 		 [viewcontacts] =&gt; 1 
  * 		 [invitegroup] =&gt; 1 
  * 		 [message] =&gt; 1 
  * 		 [viewfriends] =&gt; 1 
  * 		 [viewgroups] =&gt; 1 
  * 		 [viewprofile] =&gt; 1 
  * 		 [modifyuser_main] =&gt; 
  * 	 ) 
  * 
  *  [IsCurrentUser] =&gt; 
  *  [Relation] =&gt; 
  * )
  * </pre>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/socialnetwork/classes/csocnetuserperms/inituserperms.php
  * @author Bitrix
  */
 public static function InitUserPerms($currentUserID, $userID, $bCurrentUserIsAdmin)
 {
     global $arSocNetUserOperations, $USER;
     $arReturn = array();
     $currentUserID = IntVal($currentUserID);
     $userID = IntVal($userID);
     if ($userID <= 0) {
         return false;
     }
     $arReturn["Operations"] = array();
     if ($currentUserID <= 0) {
         $arReturn["IsCurrentUser"] = false;
         $arReturn["Relation"] = false;
         $arReturn["Operations"]["modifyuser"] = false;
         $arReturn["Operations"]["viewcontacts"] = false;
         foreach ($arSocNetUserOperations as $operation => $defPerm) {
             $arReturn["Operations"][$operation] = CSocNetUserPerms::CanPerformOperation($currentUserID, $userID, $operation, false);
         }
     } else {
         $arReturn["IsCurrentUser"] = $currentUserID == $userID;
         if ($arReturn["IsCurrentUser"]) {
             $arReturn["Relation"] = false;
         } else {
             $arReturn["Relation"] = CSocNetUserRelations::GetRelation($currentUserID, $userID);
         }
         if ($bCurrentUserIsAdmin || $arReturn["IsCurrentUser"]) {
             $arReturn["Operations"]["modifyuser"] = true;
             $arReturn["Operations"]["viewcontacts"] = true;
             foreach ($arSocNetUserOperations as $operation => $defPerm) {
                 $arReturn["Operations"][$operation] = true;
             }
         } else {
             $arReturn["Operations"]["modifyuser"] = false;
             if (CSocNetUser::IsFriendsAllowed()) {
                 $arReturn["Operations"]["viewcontacts"] = $arReturn["Relation"] == SONET_RELATIONS_FRIEND;
             } else {
                 $arReturn["Operations"]["viewcontacts"] = true;
             }
             foreach ($arSocNetUserOperations as $operation => $defPerm) {
                 $arReturn["Operations"][$operation] = CSocNetUserPerms::CanPerformOperation($currentUserID, $userID, $operation, false);
             }
         }
         $arReturn["Operations"]["modifyuser_main"] = false;
         if ($arReturn["IsCurrentUser"]) {
             if ($USER->CanDoOperation('edit_own_profile')) {
                 $arReturn["Operations"]["modifyuser_main"] = true;
             }
         } elseif ($USER->CanDoOperation('edit_all_users') || $USER->CanDoOperation('edit_subordinate_users') && count(array_diff(CUser::GetUserGroup($userID), CSocNetTools::GetSubordinateGroups($currentUserID))) <= 0) {
             $arReturn["Operations"]["modifyuser_main"] = true;
         }
     }
     return $arReturn;
 }
Esempio n. 16
0
 public static function Invite($arParams)
 {
     $arConfig['CHAT_ID'] = intval($arParams['CHAT_ID']);
     if ($arConfig['CHAT_ID'] <= 0) {
         return false;
     }
     global $DB, $USER;
     $arConfig['RECIPIENT_ID'] = intval($arParams['RECIPIENT_ID']);
     $arConfig['USER_ID'] = intval($arParams['USER_ID']) > 0 ? intval($arParams['USER_ID']) : IntVal($USER->GetID());
     $arConfig['VIDEO'] = isset($arParams['VIDEO']) && $arParams['VIDEO'] == 'N' ? 'N' : 'Y';
     $arChat = CIMChat::GetChatData(array('ID' => $arConfig['CHAT_ID']));
     if (empty($arChat['chat'])) {
         return false;
     }
     $arConfig['CALL_TO_GROUP'] = $arChat['chat'][$arConfig['CHAT_ID']]['type'] == IM_MESSAGE_GROUP;
     $arConfig['STATUS_TYPE'] = intval($arChat['chat'][$arConfig['CHAT_ID']]['call']);
     if (!$arConfig['CALL_TO_GROUP'] && !IsModuleInstalled('intranet') && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CALL, $arConfig['RECIPIENT_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($arConfig['USER_ID'], $arConfig['RECIPIENT_ID'])) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage('IM_ERROR_CALL_PRIVACY'), "ERROR_FROM_PRIVACY");
         return false;
     }
     if ($arConfig['STATUS_TYPE'] != IM_CALL_NONE) {
         if ($arConfig['CALL_TO_GROUP']) {
             self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_START_", $arConfig['USER_ID'], true);
         }
         $strSql = "UPDATE b_im_relation SET CALL_STATUS = " . IM_CALL_STATUS_ANSWER . " WHERE CHAT_ID = " . $arConfig['CHAT_ID'] . " AND USER_ID = " . $arConfig['USER_ID'];
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $arUserData = CIMContactList::GetUserData(array('ID' => $arChat['userInChat'][$arConfig['CHAT_ID']], 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y'));
         $arConfig['USER_DATA']['USERS'] = $arUserData['users'];
         $arConfig['USER_DATA']['HR_PHOTO'] = $arUserData['hrphoto'];
         foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) {
             if ($userId != $arConfig['USER_ID'] && in_array($callStatus, array(IM_CALL_STATUS_WAIT, IM_CALL_STATUS_ANSWER))) {
                 $arUserToConnect[$userId] = $callStatus;
             }
         }
         $arConfig['USERS_CONNECT'] = $arUserToConnect;
         $arSend['users'] = $arUserData['users'];
         $arSend['hrphoto'] = $arUserData['hrphoto'];
         $arSend['video'] = $arConfig['VIDEO'] == 'Y' ? true : false;
         $arSend['callToGroup'] = $arConfig['CALL_TO_GROUP'];
         $arSend['chat'] = $arChat['chat'];
         $arSend['userChatBlockStatus'] = $arChat['userChatBlockStatus'];
         $arSend['userInChat'] = $arChat['userInChat'];
         foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) {
             if ($userId != $arConfig['USER_ID'] && !in_array($callStatus, array(IM_CALL_STATUS_DECLINE))) {
                 self::Command($arConfig['CHAT_ID'], $userId, 'invite_join', $arSend);
             }
         }
     } else {
         if ($arConfig['CALL_TO_GROUP']) {
             self::MessageToChat($arConfig['CHAT_ID'], "IM_CALL_CHAT_INIT_", $arConfig['USER_ID'], true);
         }
         $strSql = "UPDATE b_im_chat SET CALL_TYPE = " . ($arConfig['VIDEO'] == 'Y' ? IM_CALL_VIDEO : IM_CALL_AUDIO) . " WHERE ID = " . $arConfig['CHAT_ID'];
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "UPDATE b_im_relation SET CALL_STATUS = " . IM_CALL_STATUS_ANSWER . " WHERE CHAT_ID = " . $arConfig['CHAT_ID'] . " AND USER_ID = " . $arConfig['USER_ID'];
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $arUserToConnect = array();
         foreach ($arChat['userCallStatus'][$arConfig['CHAT_ID']] as $userId => $callStatus) {
             if ($userId != $arConfig['USER_ID']) {
                 $arUserToConnect[$userId] = $callStatus;
             }
         }
         $arUserData = CIMContactList::GetUserData(array('ID' => $arChat['userInChat'][$arConfig['CHAT_ID']], 'DEPARTMENT' => 'N', 'HR_PHOTO' => 'Y'));
         $arSend['users'] = $arUserData['users'];
         $arSend['hrphoto'] = $arUserData['hrphoto'];
         $arSend['video'] = $arConfig['VIDEO'] == 'Y' ? true : false;
         $arSend['callToGroup'] = $arConfig['CALL_TO_GROUP'];
         $arSend['chat'] = $arChat['chat'];
         $arSend['userChatBlockStatus'] = $arChat['userChatBlockStatus'];
         $arSend['userInChat'] = $arChat['userInChat'];
         foreach ($arUserToConnect as $userId => $callStatus) {
             self::Command($arConfig['CHAT_ID'], $userId, 'invite', $arSend);
         }
         $arConfig['USER_DATA']['USERS'] = $arUserData['users'];
         $arConfig['USER_DATA']['HR_PHOTO'] = $arUserData['hrphoto'];
         if (!$arConfig['CALL_TO_GROUP'] && CModule::IncludeModule('pull') && CPullOptions::GetPushStatus()) {
             $arSelect = array("ID", "LAST_NAME", "NAME", "LOGIN", "SECOND_NAME");
             $dbUsers = CUser::GetList($sort_by = false, $dummy = '', array('ID' => $USER->GetID()), array('FIELDS' => $arSelect));
             if ($arUser = $dbUsers->GetNext(true, false)) {
                 $sName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
                 $pushText = GetMessage('IM_CALL_INVITE', array('#USER_NAME#' => $sName));
             } else {
                 $pushText = GetMessage('IM_CALL_INVITE', array('#USER_NAME#' => GetMessage('IM_CALL_INVITE_NA')));
             }
             $CPushManager = new CPushManager();
             foreach ($arUserToConnect as $sendTouserId => $callStatus) {
                 $CPushManager->AddQueue(array('USER_ID' => $sendTouserId, 'MESSAGE' => $pushText, 'EXPIRY' => 0, 'PARAMS' => 'IMINV_' . $USER->GetID() . "_" . time(), 'APP_ID' => 'Bitrix24', 'SOUND' => 'call.aif', 'SEND_IMMEDIATELY' => 'Y'));
             }
         }
     }
     foreach (GetModuleEvents("im", "OnCallStart", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($arConfig));
     }
     return $arConfig;
 }
Esempio n. 17
0
             $suffix = "male";
             break;
         case "F":
             $suffix = "female";
             break;
         default:
             $suffix = "unknown";
     }
     $arUser["PERSONAL_PHOTO"] = COption::GetOptionInt("socialnetwork", "default_user_picture_" . $suffix, false, SITE_ID);
 }
 $arImage = CSocNetTools::InitImage($arUser["PERSONAL_PHOTO"], $iSize, "/bitrix/images/socialnetwork/nopic_user_" . $iSize . ".gif", $iSize, $arUser["URL"], $arUser["SHOW_PROFILE_LINK"]);
 $arUser["IMAGE_FILE"] = $arImage["FILE"];
 $arUser["IMAGE_IMG"] = $arImage["IMG"];
 $arUser["NAME_FORMATED"] = CUser::FormatName($arParams['NAME_TEMPLATE'], $arUser, $bUseLogin);
 $arUser["IS_ONLINE"] = $arUser["IS_ONLINE"] == "Y";
 if ($GLOBALS["USER"]->IsAuthorized() && $GLOBALS["USER"]->GetID() != $arUser["ID"] && CSocNetUser::IsFriendsAllowed()) {
     $rel = CSocNetUserRelations::GetRelation($GLOBALS["USER"]->GetID(), $arUser["ID"]);
     $arUser["CAN_ADD2FRIENDS"] = !$rel && $arUser["ID"] != $GLOBALS["USER"]->GetID() ? true : false;
 } else {
     $arUser["CAN_ADD2FRIENDS"] = false;
 }
 $arUser["ADD_TO_FRIENDS_LINK"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER_FRIENDS_ADD"], array("user_id" => $arUser["ID"]));
 $arUser["MESSAGE_FORM_LINK"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_MESSAGE_FORM"], array("user_id" => $arUser["ID"]));
 $arUser["MESSAGE_LINK"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_MESSAGES_CHAT"], array("user_id" => $arUser["ID"]));
 $arUser["UserFieldsMain"] = array("SHOW" => "N", "DATA" => array());
 if (count($arParams["USER_FIELDS_LIST"]) > 0) {
     foreach ($arUser as $userFieldName => $userFieldValue) {
         if (in_array($userFieldName, $arParams["USER_FIELDS_LIST"])) {
             $val = $userFieldValue;
             switch ($userFieldName) {
                 case 'EMAIL':
Esempio n. 18
0
$dbResultTmp = CSocNetFeatures::GetList(array(), array("ENTITY_ID" => $arParams["ENTITY_ID"], "ENTITY_TYPE" => $arParams["ENTITY_TYPE"]));
while ($arResultTmp = $dbResultTmp->GetNext()) {
    $arFeaturesTmp[$arResultTmp["FEATURE"]] = $arResultTmp;
}
$arCustomFeatures = array();
$events = GetModuleEvents("socialnetwork", "OnFillSocNetMenu");
while ($arEvent = $events->Fetch()) {
    ExecuteModuleEventEx($arEvent, array(&$arCustomFeatures, $arParams));
}
if ($arParams["ENTITY_TYPE"] == SONET_ENTITY_USER && $USER->IsAuthorized() && $USER->GetID() == $arParams["ENTITY_ID"]) {
    $arResult["ALL_FEATURES"]["log"] = array("FeatureName" => $arParams["LogName"], "Active" => true, "Operations" => array(), "NOPARAMS" => true, "Url" => $arParams["arResult"]["Urls"]["Log"]);
}
if ($arParams["ENTITY_TYPE"] == SONET_ENTITY_USER || $arParams["ENTITY_TYPE"] == SONET_ENTITY_GROUP) {
    $arResult["ALL_FEATURES"]["general"] = array("FeatureName" => $arParams["GeneralName"], "Active" => true, "Operations" => array(), "NOPARAMS" => true, "Url" => $arParams["ENTITY_TYPE"] == SONET_ENTITY_GROUP ? $arParams["arResult"]["Urls"]["View"] : $arParams["arResult"]["Urls"]["Main"]);
}
if ($arParams["ENTITY_TYPE"] == SONET_ENTITY_USER && CSocNetUser::IsFriendsAllowed() && $arParams["arResult"]["CurrentUserPerms"]["Operations"]["viewfriends"]) {
    $arResult["ALL_FEATURES"]["friends"] = array("FeatureName" => $arParams["FriendsName"], "Active" => true, "Operations" => array(), "NOPARAMS" => true, "Url" => $arParams["arResult"]["Urls"]["Friends"]);
}
if ($arParams["ENTITY_TYPE"] == SONET_ENTITY_USER && $arParams["arResult"]["CurrentUserPerms"]["Operations"]["viewgroups"]) {
    $arResult["ALL_FEATURES"]["groups"] = array("FeatureName" => $arParams["GroupsName"], "Active" => true, "Operations" => array(), "NOPARAMS" => true, "Url" => $arParams["arResult"]["Urls"]["Groups"]);
}
foreach ($arSocNetFeaturesSettings as $feature => $arFeature) {
    if (!array_key_exists("allowed", $arFeature) || !in_array($arParams["ENTITY_TYPE"], $arFeature["allowed"])) {
        continue;
    }
    if (is_array($arCustomFeatures) && count($arCustomFeatures) > 0 && array_key_exists($feature, $arCustomFeatures["CanView"]) && !$arCustomFeatures["CanView"][$feature]) {
        continue;
    } elseif (is_array($arCustomFeatures) && count($arCustomFeatures) > 0 && array_key_exists($feature, $arCustomFeatures["CanView"])) {
        if (!array_key_exists($feature, $arFeaturesTmp) || !array_key_exists("FEATURE_NAME", $arFeaturesTmp[$feature]) || strlen($arFeaturesTmp[$feature]["FEATURE_NAME"]) <= 0) {
            $arFeaturesTmp[$feature]["FEATURE_NAME"] = $arCustomFeatures["Title"][$feature];
        }
Esempio n. 19
0
 public function UpdateCodes($USER_ID)
 {
     global $DB;
     if (CSocNetUser::IsFriendsAllowed()) {
         $USER_ID = intval($USER_ID);
         $dbFriends = CSocNetUserRelations::GetRelatedUsers($USER_ID, SONET_RELATIONS_FRIEND);
         while ($arFriends = $dbFriends->Fetch()) {
             $friendID = $USER_ID == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
             $DB->Query("INSERT INTO b_user_access (USER_ID, PROVIDER_ID, ACCESS_CODE) VALUES \n\t\t\t\t\t(" . $friendID . ", '" . $DB->ForSQL($this->id) . "', 'SU" . $USER_ID . "_" . SONET_RELATIONS_TYPE_FRIENDS . "')");
             $dbFriends2 = CSocNetUserRelations::GetRelatedUsers($friendID, SONET_RELATIONS_FRIEND);
             while ($arFriends2 = $dbFriends2->Fetch()) {
                 $friendID2 = $friendID == $arFriends2["FIRST_USER_ID"] ? $arFriends2["SECOND_USER_ID"] : $arFriends2["FIRST_USER_ID"];
                 if ($friendID2 != $USER_ID) {
                     $DB->Query("INSERT INTO b_user_access (USER_ID, PROVIDER_ID, ACCESS_CODE) VALUES \n\t\t\t\t\t\t\t(" . $friendID2 . ", '" . $DB->ForSQL($this->id) . "', 'SU" . $USER_ID . "_" . SONET_RELATIONS_TYPE_FRIENDS2 . "')");
                 }
             }
         }
     }
 }
Esempio n. 20
0
 static function AllowToSend($arParams)
 {
     $bResult = false;
     if (isset($arParams['TO_USER_ID'])) {
         global $USER;
         $toUserId = intval($arParams['TO_USER_ID']);
         $bResult = true;
         if (IsModuleInstalled('intranet') && CModule::IncludeModule('extranet') && !CExtranet::IsIntranetUser()) {
             $bResult = false;
             if (CModule::IncludeModule("socialnetwork")) {
                 global $USER, $CACHE_MANAGER;
                 if (defined("BX_COMP_MANAGED_CACHE")) {
                     $ttl = 2592000;
                 } else {
                     $ttl = 600;
                 }
                 $cache_id = 'im_user_sg_' . $USER->GetID();
                 $obSGCache = new CPHPCache();
                 $cache_dir = '/bx/imc/sonet';
                 if ($obSGCache->InitCache($ttl, $cache_id, $cache_dir)) {
                     $tmpVal = $obSGCache->GetVars();
                     $bResult = in_array($toUserId, $tmpVal['EXTRANET_USERS']);
                 } else {
                     if (defined("BX_COMP_MANAGED_CACHE")) {
                         $CACHE_MANAGER->StartTagCache($cache_dir);
                     }
                     $dbUsersInGroup = CSocNetUserToGroup::GetList(array(), array("USER_ID" => $USER->GetID(), "<=ROLE" => SONET_ROLES_USER, "GROUP_SITE_ID" => CExtranet::GetExtranetSiteID(), "GROUP_ACTIVE" => "Y", "GROUP_CLOSED" => "N"), false, false, array("ID", "GROUP_ID", "GROUP_NAME"));
                     $arUserSocNetGroups = array();
                     $arUserSG = array();
                     while ($ar = $dbUsersInGroup->GetNext(true, false)) {
                         $arUserSocNetGroups[] = $ar["GROUP_ID"];
                         $arUserSG['SG' . $ar['GROUP_ID']] = array('id' => 'SG' . $ar['GROUP_ID'], 'status' => 'close', 'name' => GetMessage('IM_CL_GROUP_SG') . $ar['GROUP_NAME']);
                         if (defined("BX_COMP_MANAGED_CACHE")) {
                             $CACHE_MANAGER->RegisterTag('sonet_group_' . $ar['GROUP_ID']);
                             $CACHE_MANAGER->RegisterTag('sonet_user2group_G' . $ar['GROUP_ID']);
                         }
                     }
                     $arExtranetUsers = array();
                     $arUserInGroup = array();
                     $arWoUserInGroup = array();
                     if (count($arUserSocNetGroups) > 0) {
                         $dbUsersInGroup = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $arUserSocNetGroups, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y", "USER_CONFIRM_CODE" => false), false, false, array("ID", "USER_ID", "GROUP_ID"));
                         while ($ar = $dbUsersInGroup->GetNext(true, false)) {
                             if ($USER->GetID() != $ar["USER_ID"]) {
                                 $arExtranetUsers[$ar["USER_ID"]] = $ar["USER_ID"];
                                 if (isset($arUserInGroup["SG" . $ar["GROUP_ID"]])) {
                                     $arUserInGroup["SG" . $ar["GROUP_ID"]]['users'][] = $ar["USER_ID"];
                                 } else {
                                     $arUserInGroup["SG" . $ar["GROUP_ID"]] = array('id' => "SG" . $ar["GROUP_ID"], 'users' => array($ar["USER_ID"]));
                                 }
                                 if (isset($arWoUserInGroup["extranet"])) {
                                     $arWoUserInGroup["extranet"]['users'][] = $ar["USER_ID"];
                                 } else {
                                     $arWoUserInGroup["extranet"] = array('id' => "extranet", 'users' => array($ar["USER_ID"]));
                                 }
                             }
                         }
                         if (isset($arWoUserInGroup['extranet']) && isset($arWoUserInGroup['extranet']['users'])) {
                             $arWoUserInGroup['extranet']['users'] = array_values(array_unique($arWoUserInGroup['extranet']['users']));
                         }
                     }
                     if (defined("BX_COMP_MANAGED_CACHE")) {
                         $CACHE_MANAGER->EndTagCache();
                     }
                     if ($obSGCache->StartDataCache()) {
                         $obSGCache->EndDataCache(array('USER_SG' => $arUserSG, 'EXTRANET_USERS' => $arExtranetUsers, 'USER_IN_GROUP' => $arUserInGroup, 'WO_USER_IN_GROUP' => $arWoUserInGroup));
                     }
                     $bResult = in_array($toUserId, $arExtranetUsers);
                 }
                 unset($obSGCache);
             }
         } else {
             if (!IsModuleInstalled('intranet')) {
                 if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($USER->GetID(), $arParams['TO_USER_ID'])) {
                     $bResult = false;
                 } else {
                     if (CIMSettings::GetPrivacy(CIMSettings::PRIVACY_MESSAGE, $arParams['TO_USER_ID']) == CIMSettings::PRIVACY_RESULT_CONTACT && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed() && !CSocNetUserRelations::IsFriends($USER->GetID(), $arParams['TO_USER_ID'])) {
                         $bResult = false;
                     }
                 }
             }
         }
     } else {
         if (isset($arParams['TO_CHAT_ID'])) {
             global $DB, $USER;
             $toChatId = intval($arParams['TO_CHAT_ID']);
             $fromUserId = intval($USER->GetID());
             $strSql = "\n\t\t\t\tSELECT R.CHAT_ID\n\t\t\t\tFROM b_im_relation R\n\t\t\t\tWHERE R.USER_ID = " . $fromUserId . "\n\t\t\t\t\tAND R.MESSAGE_TYPE IN ('" . IM_MESSAGE_CHAT . "', '" . IM_MESSAGE_OPEN . "')\n\t\t\t\t\tAND R.CHAT_ID = " . $toChatId . "";
             $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             if ($arRes = $dbRes->Fetch()) {
                 $bResult = true;
             } else {
                 $bResult = false;
             }
         }
     }
     return $bResult;
 }
Esempio n. 21
0
	public static function GetStatus($arParams = Array())
	{
		if (!is_array($arParams))
			$arParams = Array();

		$arID = Array();
		if (isset($arParams['ID']) && is_array($arParams['ID']) && !empty($arParams['ID']))
		{
			foreach ($arParams['ID'] as $key => $value)
				$arID[] = intval($value);
		}
		else if (isset($arParams['ID']) && intval($arParams['ID']) > 0)
		{
			$arID[] = intval($arParams['ID']);
		}

		global $USER;
		if(!isset($arParams['ID']) && !IsModuleInstalled('intranet') && is_object($USER))
		{
			$arID[] = $USER->GetID();
			if (CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed())
			{
				$dbFriends = CSocNetUserRelations::GetList(array(),array("USER_ID" => $USER->GetID(), "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID"));
				if ($dbFriends)
				{
					while ($arFriends = $dbFriends->GetNext(true, false))
					{
						$friendId = $pref = (IntVal($USER->GetID()) == $arFriends["FIRST_USER_ID"]) ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
						$arID[] = $friendId;
					}
				}
			}
		}

		$arUsers = Array();
		$dbUsers = CUser::GetList(($sort_by = 'ID'), ($sort_dir = 'asc'), array('LAST_ACTIVITY' => '180'), array('FIELDS' => array("ID")));
		while ($arUser = $dbUsers->GetNext(false, false))
		{
			if (!empty($arID) && !in_array($arUser["ID"], $arID))
				continue;

			$arUsers[$arUser["ID"]] = Array(
				'id' => $arUser["ID"],
				'status' => 'online',
			);
		}

		return Array('users' => $arUsers);
	}
Esempio n. 22
0
{
	$arAllOptionsUsers[] = array("allow_files_user", GetMessage("SONET_ALLOW_FILES_USER"), "Y", Array("checkbox"));
	$arAllOptionsUsers[] = array("allow_tasks_user", GetMessage("SONET_ALLOW_TASKS_USER"), "Y", Array("checkbox"));
}

if ($bCalendar)
	$arAllOptionsUsers[] = array("allow_calendar_user", GetMessage("SONET_ALLOW_CALENDAR_USER"), "Y", Array("checkbox"));

if (IsModuleInstalled('search'))
	$arAllOptionsUsers[] = array("allow_search_user", GetMessage("SONET_ALLOW_SEARCH_USER"), "N", Array("checkbox"));

$arAllOptionsUsersBlocks = array();

$arAllOptionsUsersBlocks["forum"][] = array("default_forum_operation_full_user", GetMessage("SONET_FORUM_OPERATION_FULL_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
$arAllOptionsUsersBlocks["forum"][] = array("default_forum_operation_newtopic_user", GetMessage("SONET_FORUM_OPERATION_NEWTOPIC_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
$arAllOptionsUsersBlocks["forum"][] = array("default_forum_operation_answer_user", GetMessage("SONET_FORUM_OPERATION_ANSWER_USER"), (CSocNetUser::IsFriendsAllowed() ? SONET_RELATIONS_TYPE_FRIENDS : SONET_RELATIONS_TYPE_AUTHORIZED), Array("select_user"));
$arAllOptionsUsersBlocks["forum"][] = array("default_forum_operation_view_user", GetMessage("SONET_FORUM_OPERATION_VIEW_USER"), SONET_RELATIONS_TYPE_ALL, Array("select_user"));

$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_view_post_user", GetMessage("SONET_BLOG_OPERATION_VIEW_POST_USER"), SONET_RELATIONS_TYPE_ALL, Array("select_user"));
//$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_premoderate_post_user", GetMessage("SONET_BLOG_OPERATION_PREMODERATE_POST_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
//$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_write_post_user", GetMessage("SONET_BLOG_OPERATION_WRITE_POST_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
//$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_moderate_post_user", GetMessage("SONET_BLOG_OPERATION_MODERATE_POST_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
//$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_full_post_user", GetMessage("SONET_BLOG_OPERATION_FULL_POST_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_view_comment_user", GetMessage("SONET_BLOG_OPERATION_VIEW_COMMENT_USER"), SONET_RELATIONS_TYPE_ALL, Array("select_user"));
$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_premoderate_comment_user", GetMessage("SONET_BLOG_OPERATION_PREMODERATE_COMMENT_USER"), SONET_RELATIONS_TYPE_ALL, Array("select_user"));
$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_write_comment_user", GetMessage("SONET_BLOG_OPERATION_WRITE_COMMENT_USER"), SONET_RELATIONS_TYPE_ALL, Array("select_user"));
//$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_moderate_comment_user", GetMessage("SONET_BLOG_OPERATION_MODERATE_COMMENT_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
//$arAllOptionsUsersBlocks["blog"][] = array("default_blog_operation_full_comment_user", GetMessage("SONET_BLOG_OPERATION_FULL_COMMENT_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));

$arAllOptionsUsersBlocks["photo"][]	= array("default_photo_operation_write_user", GetMessage("SONET_PHOTO_OPERATION_WRITE_USER"), SONET_RELATIONS_TYPE_NONE, Array("select_user"));
$arAllOptionsUsersBlocks["photo"][]	= array("default_photo_operation_view_user", GetMessage("SONET_PHOTO_OPERATION_VIEW_USER"), SONET_RELATIONS_TYPE_ALL, Array("select_user"));
Esempio n. 23
0
             $arTmpUser = array("NAME" => $arUser["~NAME"], "LAST_NAME" => $arUser["~LAST_NAME"], "SECOND_NAME" => $arUser["~SECOND_NAME"], "LOGIN" => $arUser["~LOGIN"]);
             $strNameFormatted = CUser::FormatName($arParams['NAME_TEMPLATE'], $arTmpUser, $bUseLogin);
             $arStructureUser = array("USER_ID" => $arUser["ID"], "USER_NAME" => $arUser["NAME"], "USER_LAST_NAME" => $arUser["LAST_NAME"], "USER_SECOND_NAME" => $arUser["SECOND_NAME"], "USER_LOGIN" => $arUser["LOGIN"], "USER_NAME_FORMATTED" => $strNameFormatted, "USER_PROFILE_URL" => $pu, "SHOW_PROFILE_LINK" => $canViewProfile, "PATH_TO_MESSAGES_CHAT" => str_replace("#user_id#", $arUser["ID"], $arParams["PATH_TO_MESSAGES_CHAT"]), "IS_ONLINE" => $arUser["IS_ONLINE"] == "Y");
             if (is_array($arUser["UF_DEPARTMENT"]) && !empty($arUser["UF_DEPARTMENT"])) {
                 foreach ($arUser["UF_DEPARTMENT"] as $dep_id) {
                     $arResult["UsersInStructure"][$dep_id][] = $arStructureUser;
                 }
             } else {
                 $arResult["UsersInStructure"]["others"][] = $arStructureUser;
             }
         }
     }
 }
 //Friends
 $arResult["Friends"] = false;
 if (CSocNetUser::IsFriendsAllowed() && (!CModule::IncludeModule('extranet') || !CExtranet::IsExtranetSite())) {
     $dbFriends = CSocNetUserRelations::GetRelatedUsers($arResult["UserSelf"]["ID"], SONET_RELATIONS_FRIEND);
     if ($dbFriends) {
         $arResult["Friends"] = array();
         while ($arFriends = $dbFriends->GetNext()) {
             $pref = IntVal($arResult["UserSelf"]["ID"]) == $arFriends["FIRST_USER_ID"] ? "SECOND" : "FIRST";
             $pu = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arFriends[$pref . "_USER_ID"]));
             $canViewProfile = CSocNetUserPerms::CanPerformOperation($arResult["UserSelf"]["ID"], $arFriends[$pref . "_USER_ID"], "viewprofile", CSocNetUser::IsCurrentUserModuleAdmin());
             $arTmpUser = array("NAME" => $arFriends["~" . $pref . "_USER_NAME"], "LAST_NAME" => $arFriends["~" . $pref . "_USER_LAST_NAME"], "SECOND_NAME" => $arFriends["~" . $pref . "_USER_SECOND_NAME"], "LOGIN" => $arFriends["~" . $pref . "_USER_LOGIN"]);
             $strNameFormatted = CUser::FormatName($arParams['NAME_TEMPLATE'], $arTmpUser, $bUseLogin);
             $arResult["Friends"][] = array("USER_ID" => $arFriends[$pref . "_USER_ID"], "USER_NAME" => $arFriends[$pref . "_USER_NAME"], "USER_LAST_NAME" => $arFriends[$pref . "_USER_LAST_NAME"], "USER_SECOND_NAME" => $arFriends[$pref . "_USER_SECOND_NAME"], "USER_LOGIN" => $arFriends[$pref . "_USER_LOGIN"], "USER_NAME_FORMATTED" => $strNameFormatted, "USER_PROFILE_URL" => $pu, "SHOW_PROFILE_LINK" => $canViewProfile, "PATH_TO_MESSAGES_CHAT" => str_replace("#user_id#", $arFriends[$pref . "_USER_ID"], $arParams["PATH_TO_MESSAGES_CHAT"]), "IS_ONLINE" => $arFriends[$pref . "_USER_IS_ONLINE"] == "Y");
         }
     }
 } elseif (CModule::IncludeModule('extranet') && CExtranet::IsExtranetSite()) {
     $arResult["Friends"] = array();
     $arUsersInListID = array();
Esempio n. 24
0
 function InitUserPerms($currentUserID, $userID, $bCurrentUserIsAdmin)
 {
     global $arSocNetUserOperations, $USER;
     $arReturn = array();
     $currentUserID = IntVal($currentUserID);
     $userID = IntVal($userID);
     if ($userID <= 0) {
         return false;
     }
     $arReturn["Operations"] = array();
     if ($currentUserID <= 0) {
         $arReturn["IsCurrentUser"] = false;
         $arReturn["Relation"] = false;
         $arReturn["Operations"]["modifyuser"] = false;
         $arReturn["Operations"]["viewcontacts"] = false;
         foreach ($arSocNetUserOperations as $operation => $defPerm) {
             $arReturn["Operations"][$operation] = CSocNetUserPerms::CanPerformOperation($currentUserID, $userID, $operation, false);
         }
     } else {
         $arReturn["IsCurrentUser"] = $currentUserID == $userID;
         if ($arReturn["IsCurrentUser"]) {
             $arReturn["Relation"] = false;
         } else {
             $arReturn["Relation"] = CSocNetUserRelations::GetRelation($currentUserID, $userID);
         }
         if ($bCurrentUserIsAdmin || $arReturn["IsCurrentUser"]) {
             $arReturn["Operations"]["modifyuser"] = true;
             $arReturn["Operations"]["viewcontacts"] = true;
             foreach ($arSocNetUserOperations as $operation => $defPerm) {
                 $arReturn["Operations"][$operation] = true;
             }
         } else {
             $arReturn["Operations"]["modifyuser"] = false;
             if (CSocNetUser::IsFriendsAllowed()) {
                 $arReturn["Operations"]["viewcontacts"] = $arReturn["Relation"] == SONET_RELATIONS_FRIEND;
             } else {
                 $arReturn["Operations"]["viewcontacts"] = true;
             }
             foreach ($arSocNetUserOperations as $operation => $defPerm) {
                 $arReturn["Operations"][$operation] = CSocNetUserPerms::CanPerformOperation($currentUserID, $userID, $operation, false);
             }
         }
         $arReturn["Operations"]["modifyuser_main"] = false;
         if ($arReturn["IsCurrentUser"]) {
             if ($USER->CanDoOperation('edit_own_profile')) {
                 $arReturn["Operations"]["modifyuser_main"] = true;
             }
         } elseif ($USER->CanDoOperation('edit_all_users')) {
             $arReturn["Operations"]["modifyuser_main"] = true;
         } elseif ($USER->CanDoOperation('edit_subordinate_users')) {
             $arUserGroups = CUser::GetUserGroup($userID);
             if (array_key_exists("SONET_SUBORD_GROUPS_BY_USER_ID", $GLOBALS) && !array_key_exists("SONET_ALLOW_FRIENDS_CACHE", $_REQUEST)) {
                 $arUserSubordinateGroups = $GLOBALS["SONET_SUBORD_GROUPS_BY_USER_ID"][$currentUserID];
             } else {
                 $arUserSubordinateGroups = array(2);
                 $arUserGroups_u = CUser::GetUserGroup($currentUserID);
                 for ($j = 0, $len = count($arUserGroups_u); $j < $len; $j++) {
                     $arSubordinateGroups = CGroup::GetSubordinateGroups($arUserGroups_u[$j]);
                     $arUserSubordinateGroups = array_merge($arUserSubordinateGroups, $arSubordinateGroups);
                 }
                 $arUserSubordinateGroups = array_unique($arUserSubordinateGroups);
                 if (!array_key_exists("SONET_SUBORD_GROUPS_BY_USER_ID", $GLOBALS)) {
                     $GLOBALS["SONET_SUBORD_GROUPS_BY_USER_ID"] = array();
                 }
                 $GLOBALS["SONET_SUBORD_GROUPS_BY_USER_ID"][$currentUserID] = $arUserSubordinateGroups;
             }
             if (count(array_diff($arUserGroups, $arUserSubordinateGroups)) <= 0) {
                 $arReturn["Operations"]["modifyuser_main"] = true;
             }
         }
     }
     return $arReturn;
 }
Esempio n. 25
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$arComponentProps = CComponentUtil::GetComponentProps("bitrix:socialnetwork.log.ex", $arCurrentValues);
$arEntityType = array("" => GetMessage("GD_LOG_P_ENTITY_TYPE_VALUE_ALL"), SONET_ENTITY_USER => GetMessage("GD_LOG_P_ENTITY_TYPE_VALUE_USER"), SONET_ENTITY_GROUP => GetMessage("GD_LOG_P_ENTITY_TYPE_VALUE_GROUP"));
$arEventID = array("" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_ALL"), "system" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_SYSTEM"), "system_groups" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_SYSTEM_GROUPS"), "forum" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_FORUM"), "blog" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_BLOG"), "photo" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_PHOTO"), "calendar" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_CALENDAR"), "files" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_FILES"), "tasks" => GetMessage("GD_LOG_P_EVENT_ID_VALUE_TASKS"));
if (CModule::IncludeModule("socialnetwork") && CSocNetUser::IsFriendsAllowed()) {
    $arEventID["system_friends"] = GetMessage("GD_LOG_P_EVENT_ID_VALUE_SYSTEM_FRIENDS");
}
$arParameters = array("PARAMETERS" => array("USER_VAR" => $arComponentProps["PARAMETERS"]["USER_VAR"], "GROUP_VAR" => $arComponentProps["PARAMETERS"]["GROUP_VAR"], "PAGE_VAR" => $arComponentProps["PARAMETERS"]["PAGE_VAR"], "PATH_TO_USER" => $arComponentProps["PARAMETERS"]["PATH_TO_USER"], "PATH_TO_GROUP" => $arComponentProps["PARAMETERS"]["PATH_TO_GROUP"], "LIST_URL" => array("NAME" => GetMessage("GD_LOG_P_URL"), "TYPE" => "STRING", "MULTIPLE" => "N", "DEFAULT" => "/company/personal/log/")), "USER_PARAMETERS" => array("LOG_CNT" => array("NAME" => GetMessage("GD_LOG_P_LOG_CNT"), "TYPE" => "STRING", "DEFAULT" => "7"), "ENTITY_TYPE" => array("NAME" => GetMessage("GD_LOG_P_ENTITY_TYPE"), "TYPE" => "LIST", "VALUES" => $arEntityType, "MULTIPLE" => "N", "DEFAULT" => ""), "EVENT_ID" => array("NAME" => GetMessage("GD_LOG_P_EVENT_ID"), "TYPE" => "LIST", "VALUES" => $arEventID, "MULTIPLE" => "Y", "DEFAULT" => ""), "AVATAR_SIZE" => array("NAME" => GetMessage("GD_LOG_AVATAR_SIZE"), "TYPE" => "STRING", "MULTIPLE" => "N", "DEFAULT" => "", "COLS" => 3), "AVATAR_SIZE_COMMENT" => array("NAME" => GetMessage("GD_LOG_AVATAR_SIZE_COMMENT"), "TYPE" => "STRING", "MULTIPLE" => "N", "DEFAULT" => "", "COLS" => 3)));
$arParameters["PARAMETERS"]["USER_VAR"]["DEFAULT"] = "user_id";
$arParameters["PARAMETERS"]["GROUP_VAR"]["DEFAULT"] = "group_id";
$arParameters["PARAMETERS"]["PAGE_VAR"]["DEFAULT"] = "page";
$arParameters["PARAMETERS"]["PATH_TO_USER"]["DEFAULT"] = "/company/personal/user/#user_id#/";
$arParameters["PARAMETERS"]["PATH_TO_GROUP"]["DEFAULT"] = "/workgroups/group/#group_id#/";
Esempio n. 26
0
    return false;
}
$arGadgetParams["TEMPLATE_NAME"] = $arGadgetParams["TEMPLATE_NAME"] ? $arGadgetParams["TEMPLATE_NAME"] : "main";
$arGadgetParams["SHOW_TITLE"] = $arGadgetParams["SHOW_TITLE"] ? $arGadgetParams["SHOW_TITLE"] : "N";
$arGadgetParams["GROUP_ID"] = $arGadgetParams["GROUP_ID"] ? $arGadgetParams["GROUP_ID"] : false;
$arGadgetParams["ENTITY_TYPE"] = $arGadgetParams["ENTITY_TYPE"] == SONET_ENTITY_USER ? SONET_ENTITY_USER : ($arGadgetParams["ENTITY_TYPE"] == SONET_ENTITY_GROUP ? SONET_ENTITY_GROUP : "");
if (!is_array($arGadgetParams["EVENT_ID"])) {
    $arGadgetParams["EVENT_ID"] = array($arGadgetParams["EVENT_ID"]);
}
if (in_array("", $arGadgetParams["EVENT_ID"]) || empty($arGadgetParams["EVENT_ID"])) {
    $arGadgetParams["EVENT_ID"] = array("all");
} else {
    foreach ($arGadgetParams["EVENT_ID"] as $i => $event_id_tmp) {
        if (!in_array($event_id_tmp, array("system", "system_groups", "system_friends", "forum", "photo", "blog", "tasks", "files", "calendar"))) {
            unset($arGadgetParams["EVENT_ID"][$i]);
        } elseif (!CSocNetUser::IsFriendsAllowed() && $event_id_tmp == "system_friends") {
            unset($arGadgetParams["EVENT_ID"][$i]);
        } elseif ($arGadgetParams["ENTITY_TYPE"] == SONET_ENTITY_GROUP && in_array($event_id_tmp, array("system_groups", "system_friends"))) {
            unset($arGadgetParams["EVENT_ID"][$i]);
        }
    }
}
if ($arGadgetParams["ENTITY_TYPE"] == SONET_ENTITY_GROUP) {
    $sTitle_1 = GetMessage('GD_LOG_GROUP');
} elseif ($arGadgetParams["ENTITY_TYPE"] == SONET_ENTITY_USER) {
    $sTitle_1 = GetMessage('GD_LOG_USER');
} else {
    $sTitle_1 = GetMessage('GD_LOG_ALL');
}
$sTitle_2 = "";
$arTitle_2 = array();