public static function ProcessLogEventEditPOST($arPOST, $entityTypeID, $entityID, &$arResult) { $arEntityData = array(); $errors = array(); $enableTitle = isset($arPOST['ENABLE_POST_TITLE']) && strtoupper($arPOST['ENABLE_POST_TITLE']) === 'Y'; $title = $enableTitle && isset($arPOST['POST_TITLE']) ? $arPOST['POST_TITLE'] : ''; $message = isset($arPOST['MESSAGE']) ? htmlspecialcharsback($arPOST['MESSAGE']) : ''; $arResult['EVENT']['MESSAGE'] = $message; $arResult['EVENT']['TITLE'] = $title; $arResult['ENABLE_TITLE'] = $enableTitle; $attachedFiles = array(); $webDavFileFieldName = $arResult['WEB_DAV_FILE_FIELD_NAME']; if ($webDavFileFieldName !== '' && isset($GLOBALS[$webDavFileFieldName]) && is_array($GLOBALS[$webDavFileFieldName])) { foreach ($GLOBALS[$webDavFileFieldName] as $fileID) { if ($fileID === '') { continue; } //fileID: "888|165|16" $attachedFiles[] = $fileID; } if (!empty($attachedFiles) && is_array($arResult['WEB_DAV_FILE_FIELD'])) { $arResult['WEB_DAV_FILE_FIELD']['VALUE'] = $attachedFiles; } } $allowToAll = COption::GetOptionString('socialnetwork', 'allow_livefeed_toall', 'Y') === 'Y'; if ($allowToAll) { $arToAllRights = unserialize(COption::GetOptionString("socialnetwork", "livefeed_toall_rights", 'a:1:{i:0;s:2:"AU";}')); if (!$arToAllRights) { $arToAllRights = array('AU'); } $arUserGroupCode = array_merge(array('AU'), CAccess::GetUserCodesArray($arResult['USER_ID'])); if (count(array_intersect($arToAllRights, $arUserGroupCode)) <= 0) { $allowToAll = false; } } $arSocnetRights = array(); if (!empty($arPOST['SPERM'])) { foreach ($arPOST['SPERM'] as $v => $k) { if (strlen($v) > 0 && is_array($k) && !empty($k)) { foreach ($k as $vv) { if (strlen($vv) > 0) { $arSocnetRights[] = $vv; } } } } } if (in_array('UA', $arSocnetRights) && !$allowToAll) { foreach ($arSocnetRights as $key => $value) { if ($value == 'UA') { unset($arSocnetRights[$key]); break; } } } foreach ($arSocnetRights as $key => $value) { if ($value == 'UA') { $arSocnetRights[] = 'AU'; unset($arSocnetRights[$key]); break; } } $arSocnetRights = array_unique($arSocnetRights); $allFeedEtityTypes = CCrmLiveFeedEntity::GetAll(); $userPerms = CCrmPerms::GetCurrentUserPermissions(); foreach ($arSocnetRights as $key => $value) { $groupCodeData = array(); if (CCrmLiveFeed::TryParseGroupCode($value, $groupCodeData) && in_array($groupCodeData['ENTITY_TYPE'], $allFeedEtityTypes, true)) { $groupCodeEntityType = $groupCodeData['ENTITY_TYPE']; $groupCodeEntityID = $groupCodeData['ENTITY_ID']; if (!CCrmLiveFeed::CheckCreatePermission($groupCodeEntityType, $groupCodeEntityID, $userPerms)) { $canonicalEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($groupCodeEntityType); $errors[] = GetMessage('CRM_SL_EVENT_EDIT_PERMISSION_DENIED', array('#TITLE#' => CCrmOwnerType::GetCaption($canonicalEntityTypeID, $groupCodeEntityID, false))); } else { $arEntityData[] = array('ENTITY_TYPE' => $groupCodeEntityType, 'ENTITY_ID' => $groupCodeEntityID); } } } if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) && !empty($arEntityData)) { $entityData = $arEntityData[0]; $entityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']); $entityID = $entityData['ENTITY_ID']; } if (!empty($arEntityData)) { $arResult['ENTITY_DATA'] = $arEntityData; } if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0)) { $errors[] = GetMessage('CRM_SL_EVENT_EDIT_ENTITY_NOT_DEFINED'); } if ($message === '') { $errors[] = GetMessage('CRM_SL_EVENT_EDIT_EMPTY_MESSAGE'); } if (empty($errors)) { $fields = array('ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_ID' => $entityID, 'USER_ID' => $arResult['USER_ID'], 'TITLE' => $title, 'MESSAGE' => $message, 'RIGHTS' => $arSocnetRights); $parents = array(); CCrmOwnerType::TryGetOwnerInfos($entityTypeID, $entityID, $parents, array('ENABLE_MAPPING' => true)); foreach ($arEntityData as $entityData) { $curEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']); $curEntityID = $entityData['ENTITY_ID']; $entityKey = "{$curEntityTypeID}_{$curEntityID}"; if (!isset($parents[$entityKey]) && !($curEntityTypeID === $entityTypeID && $curEntityID === $entityID)) { $parents[$entityKey] = array('ENTITY_TYPE_ID' => $curEntityTypeID, 'ENTITY_ID' => $curEntityID); } } if (!empty($parents)) { $fields['PARENTS'] = array_values($parents); } if (!empty($attachedFiles)) { $fields['WEB_DAV_FILES'] = array($webDavFileFieldName => $attachedFiles); } $messageID = CCrmLiveFeed::CreateLogMessage($fields); if (!(is_int($messageID) && $messageID > 0)) { $errors[] = isset($fields['ERROR']) ? $fields['ERROR'] : 'UNKNOWN ERROR'; } else { preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/is" . BX_UTF_PCRE_MODIFIER, $message, $arMention); if (!empty($arMention) && !empty($arMention[1]) && CModule::IncludeModule("im")) { $arMention = $arMention[1]; $arMention = array_unique($arMention); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => "", "FROM_USER_ID" => $arResult['USER_ID'], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "NOTIFY_EVENT" => "mention"); $genderSuffix = ""; $dbUser = CUser::GetByID($arResult['USER_ID']); if ($arUser = $dbUser->Fetch()) { switch ($arUser["PERSONAL_GENDER"]) { case "M": $genderSuffix = "_M"; break; case "F": $genderSuffix = "_F"; break; default: $genderSuffix = ""; } } $strIMMessageTitle = str_replace(array("\r\n", "\n"), " ", strlen($title) > 0 ? $title : $message); if (CModule::IncludeModule("blog")) { $strIMMessageTitle = trim(blogTextParser::killAllTags($strIMMessageTitle)); } $strIMMessageTitle = TruncateText($strIMMessageTitle, 100); $strIMMessageTitleOut = TruncateText($strIMMessageTitle, 255); $strLogEntryURL = COption::GetOptionString("socialnetwork", "log_entry_page", SITE_DIR . "company/personal/log/#log_id#/", SITE_ID); $strLogEntryURL = CComponentEngine::MakePathFromTemplate($strLogEntryURL, array("log_id" => $messageID)); $strLogEntryCrmURL = CComponentEngine::MakePathFromTemplate(SITE_DIR . "crm/stream/?log_id=#log_id#", array("log_id" => $messageID)); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); foreach ($arMention as $val) { $val = IntVal($val); if ($val > 0 && $val != $arResult['USER_ID']) { $bHasAccess = false; if (in_array('U' . $val, $arSocnetRights)) { $url = $strLogEntryURL; $bHasAccess = true; } if (!$bHasAccess) { $arAccessCodes = array(); $dbAccess = CAccess::GetUserCodes($val); while ($arAccess = $dbAccess->Fetch()) { $arAccessCodes[] = $arAccess["ACCESS_CODE"]; } $arTmp = array_intersect($arAccess, $arSocnetRights); if (!empty($arTmp)) { $url = $strLogEntryURL; $bHasAccess = true; } } if (!$bHasAccess) { $userPermissions = CCrmPerms::GetUserPermissions($val); foreach ($arEntityData as $arEntity) { if (CCrmAuthorizationHelper::CheckReadPermission(CCrmOwnerType::ResolveName(CCrmLiveFeedEntity::ResolveEntityTypeID($arEntity['ENTITY_TYPE'])), $arEntity['ENTITY_ID'], $userPermissions)) { $url = $strLogEntryCrmURL; $bHasAccess = true; break; } } } if ($bHasAccess) { $arMessageFields["TO_USER_ID"] = $val; $arMessageFields["NOTIFY_TAG"] = "CRM|MESSAGE_MENTION|" . $messageID; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($strIMMessageTitle) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => htmlspecialcharsbx($strIMMessageTitleOut))) . " (" . $serverName . $url . ")"; CIMNotify::Add($arMessageFields); } } } } return $messageID; } } return $errors; }