public static function notify($arParams) { global $USER; $arParams = array_change_key_case($arParams, CASE_UPPER); $arMessageFields = array("TO_USER_ID" => $arParams['TO'], "FROM_USER_ID" => $USER->GetID(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "rest", "NOTIFY_EVENT" => "rest_notify", "NOTIFY_MESSAGE" => $arParams['MESSAGE']); return CIMNotify::Add($arMessageFields); }
public static function notify($arParams, $n, $server) { global $USER; $arParams = array_change_key_case($arParams, CASE_UPPER); if (!isset($arParams['TYPE']) || !in_array($arParams['TYPE'], array('USER', 'SYSTEM'))) { $arParams['TYPE'] = 'USER'; } if ($arParams['TYPE'] == 'SYSTEM') { $result = \CBitrix24App::getList(array(), array('APP_ID' => $server->getAppId())); $result = $result->fetch(); $moduleName = isset($result['APP_NAME']) ? $result['APP_NAME'] : $result['CODE']; $fromUserId = 0; $notifyType = IM_NOTIFY_SYSTEM; $message = $moduleName . "#BR#" . $arParams['MESSAGE']; } else { $fromUserId = $USER->GetID(); $notifyType = IM_NOTIFY_FROM; $message = $arParams['MESSAGE']; } $message = trim($message); if (strlen($message) <= 0) { return false; } $arMessageFields = array("TO_USER_ID" => $arParams['TO'], "FROM_USER_ID" => $fromUserId, "NOTIFY_TYPE" => $notifyType, "NOTIFY_MODULE" => "rest", "NOTIFY_EVENT" => "rest_notify", "NOTIFY_MESSAGE" => $message); return CIMNotify::Add($arMessageFields); }
public static function Notify($addresseeID, $internalMessage, $externalMessage, $schemeTypeID, $tag = '') { self::ClearErrors(); if (!(IsModuleInstalled('im') && CModule::IncludeModule('im'))) { self::RegisterError('IM module is not installed.'); return false; } if ($addresseeID <= 0) { self::RegisterError('Addressee is not assigned.'); return false; } $arMessage = array('TO_USER_ID' => $addresseeID, 'FROM_USER_ID' => 0, 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM, 'NOTIFY_MODULE' => 'crm', 'NOTIFY_MESSAGE' => strval($internalMessage), 'NOTIFY_MESSAGE_OUT' => strval($externalMessage)); $schemeTypeName = CCrmNotifierSchemeType::ResolveName($schemeTypeID); if ($schemeTypeName !== '') { $arMessage['NOTIFY_EVENT'] = $schemeTypeName; } $tag = strval($tag); if ($tag !== '') { $arMessage['NOTIFY_TAG'] = $tag; } $msgID = CIMNotify::Add($arMessage); if (!$msgID) { $e = $GLOBALS['APPLICATION']->GetException(); $errorMessage = $e ? $e->GetString() : 'Unknown sending error. message not send.'; self::RegisterError($errorMessage); return false; } return true; }
function Add($arFields) { global $DB; if (IsModuleInstalled("im") && CModule::IncludeModule("im")) { if ($arFields["MESSAGE_TYPE"] == SONET_MESSAGE_SYSTEM) { if (!(isset($arFields["EMAIL_TEMPLATE"]) && strlen($arFields["EMAIL_TEMPLATE"]) > 0)) { $arFields["EMAIL_TEMPLATE"] = "SONET_NEW_MESSAGE"; } $ID = CIMNotify::Add($arFields); return $ID; } else { CIMMessenger::SpeedFileDelete($arFields['TO_USER_ID'], IM_SPEED_MESSAGE); } } if (defined("INTASK_SKIP_SOCNET_MESSAGES1") && INTASK_SKIP_SOCNET_MESSAGES1) { $arFields["=DATE_VIEW"] = $DB->CurrentTimeFunction(); } $arFields1 = array(); foreach ($arFields as $key => $value) { if (substr($key, 0, 1) == "=") { $arFields1[substr($key, 1)] = $value; unset($arFields[$key]); } } if (!CSocNetMessages::CheckFields("ADD", $arFields)) { return false; } $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetMessagesAdd"); while ($arEvent = $db_events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { return false; } } $arInsert = $DB->PrepareInsert("b_sonet_messages", $arFields); foreach ($arFields1 as $key => $value) { if (strlen($arInsert[0]) > 0) { $arInsert[0] .= ", "; } $arInsert[0] .= $key; if (strlen($arInsert[1]) > 0) { $arInsert[1] .= ", "; } $arInsert[1] .= $value; } $ID = false; if (strlen($arInsert[0]) > 0) { $strSql = "INSERT INTO b_sonet_messages(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")"; $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); $events = GetModuleEvents("socialnetwork", "OnSocNetMessagesAdd"); while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID, $arFields)); } //CSocNetMessages::SendEvent($ID, "SONET_NEW_MESSAGE"); CSocNetMessages::__SpeedFileCreate($arFields["TO_USER_ID"]); } return $ID; }
/** * Method will be invoked after new database record inserted. * * @param array $newRecord All fields of inserted record. * * @return void */ public function afterInsertTrigger(array $newRecord) { $id = intval($newRecord['MESSAGE_ID']); if (!\Bitrix\Main\Loader::includeModule('pull')) { return; } $message = \CIMMessenger::GetById($id, array('WITH_FILES' => 'Y')); if (!$message) { return; } if ($newRecord['PARAM_NAME'] === 'LIKE' && $newRecord["PARAM_VALUE"]) { $like = $message['PARAMS']['LIKE']; $result = \Bitrix\IM\ChatTable::getList(array('filter' => array('=ID' => $message['CHAT_ID']))); $chat = $result->fetch(); $relations = \CIMMessenger::GetRelationById($id); if (!isset($relations[$newRecord["PARAM_VALUE"]])) { return; } if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $newRecord["PARAM_VALUE"]) { $CCTP = new \CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $message['MESSAGE'] = str_replace('<br />', ' ', $CCTP->convertText($message['MESSAGE'])); $message['MESSAGE'] = preg_replace("/\\[s\\].*?\\[\\/s\\]/i", "", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/\\[[bui]\\](.*?)\\[\\/[bui]\\]/i", "\$1", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/\\[USER=([0-9]{1,})\\](.*?)\\[\\/USER\\]/i", "\$2", $message['MESSAGE']); $message['MESSAGE'] = preg_replace("/------------------------------------------------------(.*)------------------------------------------------------/mi", " [" . GetMessage('IM_QUOTE') . "] ", str_replace(array("#BR#"), array(" "), $message['MESSAGE'])); if (count($message['FILES']) > 0 && strlen($message['MESSAGE']) < 200) { foreach ($message['FILES'] as $file) { $file = " [" . GetMessage('IM_MESSAGE_FILE') . ": " . $file['name'] . "]"; if (strlen($message['MESSAGE'] . $file) > 200) { break; } $message['MESSAGE'] .= $file; } $message['MESSAGE'] = trim($message['MESSAGE']); } $isChat = $chat && strlen($chat['TITLE']) > 0; $dot = strlen($message['MESSAGE']) >= 200 ? '...' : ''; $message['MESSAGE'] = substr($message['MESSAGE'], 0, 199) . $dot; $message['MESSAGE'] = strlen($message['MESSAGE']) > 0 ? $message['MESSAGE'] : '-'; $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $newRecord["PARAM_VALUE"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|" . ($isChat ? 'G' : 'P') . "|" . ($isChat ? $chat['ID'] : $newRecord["PARAM_VALUE"]) . "|" . $id, "NOTIFY_MESSAGE" => GetMessage($isChat ? 'IM_MESSAGE_LIKE' : 'IM_MESSAGE_LIKE_PRIVATE', array('#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE']))); \CIMNotify::Add($arMessageFields); } $arPullMessage = array('id' => $id, 'chatId' => $relations[$newRecord["PARAM_VALUE"]]['CHAT_ID'], 'senderId' => $newRecord["PARAM_VALUE"], 'users' => $like); foreach ($relations as $rel) { \CPullStack::AddByUser($rel['USER_ID'], array('module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage)); } } }
public static function notify($arParams) { global $USER; $arMessageFields = array( "TO_USER_ID" => $arParams['to'], "FROM_USER_ID" => $USER->GetID(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "rest", "NOTIFY_EVENT" => "rest_notify",// - get it from the oauth module "NOTIFY_MESSAGE" => $arParams['message'], ); return CIMNotify::Add($arMessageFields); }
/** * Sends notifications to IM. * * @param $fromUserID * @param $arRecipientsIDs * @param $message * @param int $taskID * @param null $message_email * @param array $arEventData * @return bool|null */ public static function SendMessage($fromUserID, $arRecipientsIDs, $message, $taskID = 0, $message_email = null, $arEventData = array(), $taskAssignedTo = null) { if (!(IsModuleInstalled("im") && CModule::IncludeModule("im"))) { return false; } $message_email = is_null($message_email) ? $message : $message_email; if (!($fromUserID && $arRecipientsIDs && $message)) { return false; } CTaskAssert::assert(is_array($arEventData)); $arEventData['fromUserID'] =& $fromUserID; $arEventData['arRecipientsIDs'] =& $arRecipientsIDs; $arEventData['message'] =& $message; $arEventData['message_email'] =& $message_email; foreach (GetModuleEvents('tasks', 'OnBeforeTaskNotificationSend', true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($arEventData)) === false) { return false; } } $arSites = array(); if (CModule::IncludeModule("extranet")) { $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { $type = $arSite["ID"] == CExtranet::GetExtranetSiteID() ? "EXTRANET" : "INTRANET"; if ($type === 'INTRANET' && isset($arSites['INTRANET']) && $arSite['DEF'] !== 'Y') { // Don't overwrite INTRANET site data by not default site continue; } $arSites[$type] = array('SITE_ID' => $arSite['ID'], "DIR" => strlen(trim($arSite["DIR"])) > 0 ? $arSite["DIR"] : "/", "SERVER_NAME" => strlen(trim($arSite["SERVER_NAME"])) > 0 ? $arSite["SERVER_NAME"] : COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"])); } } if (is_array($arRecipientsIDs) && count($arRecipientsIDs)) { $arRecipientsIDs = array_unique($arRecipientsIDs); $rsUser = CUser::GetList($by = 'ID', $order = 'ASC', array('ID' => implode('|', $arRecipientsIDs)), array('FIELDS' => array('ID'))); while ($arUser = $rsUser->Fetch()) { $notifyEvent = 'manage'; if ($taskAssignedTo !== null) { if ($arUser['ID'] == $taskAssignedTo) { $notifyEvent = 'task_assigned'; } } $pathToTask = CTaskNotifications::GetNotificationPath($arUser, $taskID, true, $arSites); $arMessageFields = array("TO_USER_ID" => $arUser['ID'], "FROM_USER_ID" => $fromUserID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => $notifyEvent, "NOTIFY_MESSAGE" => str_replace("#PATH_TO_TASK#", $pathToTask, $message), "NOTIFY_MESSAGE_OUT" => strip_tags(str_replace("#PATH_TO_TASK#", $pathToTask, $message_email))); CIMNotify::Add($arMessageFields); } } return null; }
public static function onAfterTimeManagerDayStart($arData) { if (!(isset($arData['USER_ID'], $arData['MODIFIED_BY']) && $arData['USER_ID'] > 0 && $arData['MODIFIED_BY'] > 0 && $arData['MODIFIED_BY'] == $arData['USER_ID'] && IsModuleInstalled("im") && CModule::IncludeModule("im"))) { return; } $recipientId = (int) $arData['USER_ID']; try { $tasksCounter = CTaskListCtrl::getMainCounterForUser($recipientId); if ($tasksCounter <= 0) { return; } /** @noinspection PhpDeprecationInspection */ CIMNotify::Add(array('FROM_USER_ID' => 0, 'TO_USER_ID' => $recipientId, 'NOTIFY_MODULE' => 'tasks', 'NOTIFY_EVENT' => 'notice', 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM, 'NOTIFY_TAG' => 'TASKS|COUNTERS_NOTICE|' . $recipientId, 'MESSAGE' => CTasksTools::getMessagePlural($tasksCounter, 'TASKS_COUNTERS_NOTICE_CONTENT_V2', array('#TASKS_COUNT#' => $tasksCounter, '#HREF#' => self::getTasksListLink($recipientId))), 'TITLE' => GetMessage('TASKS_COUNTERS_NOTICE_TITLE'))); } catch (Exception $e) { CTaskAssert::logWarning('[0xb83d6845] unexpected exception in CTaskCountersNotifier::onAfterTimeManagerDayStart()' . ', file: ' . $e->getFile() . ', line: ' . $e->getLine() . ', code: ' . $e->getCode() . ', message: ' . $e->getMessage()); } }
public function Execute() { if (!CModule::IncludeModule("im")) { return CBPActivityExecutionStatus::Closed; } $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $arMessageUserFrom = CBPHelper::ExtractUsers($this->MessageUserFrom, $documentId, true); $arMessageUserTo = CBPHelper::ExtractUsers($this->MessageUserTo, $documentId, false); $arMessageFields = array("FROM_USER_ID" => $arMessageUserFrom, "NOTIFY_TYPE" => intval($this->MessageType), "NOTIFY_MESSAGE" => $this->MessageSite, "NOTIFY_MESSAGE_OUT" => $this->MessageOut, "NOTIFY_MODULE" => "bizproc", "NOTIFY_EVENT" => "activity"); $ar = array(); foreach ($arMessageUserTo as $userTo) { if (in_array($userTo, $ar)) { continue; } $ar[] = $userTo; $arMessageFields["TO_USER_ID"] = $userTo; CIMNotify::Add($arMessageFields); } return CBPActivityExecutionStatus::Closed; }
public static function SendMentionNotification($arCommentFields) { if (!CModule::IncludeModule("im")) { return false; } switch ($arCommentFields["EVENT_ID"]) { case "forum": $arTitleRes = self::OnSendMentionGetEntityFields_Forum($arCommentFields); break; default: $db_events = GetModuleEvents("socialnetwork", "OnSendMentionGetEntityFields"); while ($arEvent = $db_events->Fetch()) { $arTitleRes = ExecuteModuleEventEx($arEvent, array($arCommentFields)); if ($arTitleRes) { break; } } } if ($arTitleRes && is_array($arTitleRes) && !empty($arTitleRes["NOTIFY_MESSAGE"])) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $arCommentFields["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => !empty($arTitleRes["NOTIFY_MODULE"]) ? $arTitleRes["NOTIFY_MODULE"] : "socialnetwork", "NOTIFY_EVENT" => "mention", "NOTIFY_TAG" => !empty($arTitleRes["NOTIFY_TAG"]) ? $arTitleRes["NOTIFY_TAG"] : "LOG_COMMENT|COMMENT_MENTION|" . $arCommentFields["ID"]); preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/ies" . BX_UTF_PCRE_MODIFIER, $arCommentFields["MESSAGE"], $arMention); if (!empty($arMention)) { $arMention = $arMention[1]; $arExcludeUsers = array(); if (!empty($arCommentFields["LOG_ID"])) { $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . $arCommentFields["LOG_ID"], "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arExcludeUsers[] = $arUnFollower["USER_ID"]; } } $arSourceURL = array("URL" => $arTitleRes["URL"]); if (!empty($arTitleRes["CRM_URL"])) { $arSourceURL["CRM_URL"] = $arTitleRes["CRM_URL"]; } foreach ($arMention as $mentionUserID) { $bHaveRights = CSocNetLogRights::CheckForUserOnly($arCommentFields["LOG_ID"], $mentionUserID); if (!$bHaveRights && $arTitleRes["IS_CRM"] == "Y") { $dbLog = CSocNetLog::GetList(array(), array("ID" => $arCommentFields["LOG_ID"], "ENTITY_TYPE" => $arCommentFields["ENTITY_TYPE"]), false, false, array("ID"), array("IS_CRM" => "Y", "CHECK_CRM_RIGHTS" => "Y", "USER_ID" => $mentionUserID, "USE_SUBSCRIBE" => "N")); if ($arLog = $dbLog->Fetch()) { $bHaveCrmRights = true; } } if (in_array($mentionUserID, $arExcludeUsers) || !$bHaveRights && !$bHaveCrmRights) { continue; } $url = false; if (!empty($arSourceURL["URL"]) || !empty($arSourceURL["CRM_URL"])) { $arTmp = CSocNetLogTools::ProcessPath($arSourceURL, $mentionUserID); if ($arTitleRes["IS_CRM"] == "Y" && !$bHaveRights && !empty($arTmp["URLS"]["CRM_URL"])) { $url = $arTmp["URLS"]["CRM_URL"]; } else { $url = $arTmp["URLS"]["URL"]; } $serverName = strpos($url, "http://") === 0 || strpos($url, "https://") === 0 ? "" : $arTmp["SERVER_NAME"]; } $arMessageFields["TO_USER_ID"] = $mentionUserID; $arMessageFields["NOTIFY_MESSAGE"] = str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE"]); $arMessageFields["NOTIFY_MESSAGE_OUT"] = !empty($arTitleRes["NOTIFY_MESSAGE_OUT"]) ? str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE_OUT"]) : ""; CIMNotify::Add($arMessageFields); } $arMentionedDestCode = array(); foreach ($arMention as $val) { $arMentionedDestCode[] = "U" . $val; } \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "mention", "CODE" => array_unique($arMentionedDestCode))); } } }
private static function SynchronizeLiveFeedEvent($activityID, $params) { if (!is_array($params)) { $params = array(); } $processBindings = isset($params['PROCESS_BINDINGS']) ? (bool) $params['PROCESS_BINDINGS'] : false; $bindings = isset($params['BINDINGS']) && is_array($params['BINDINGS']) ? $params['BINDINGS'] : array(); $hasBindings = !empty($bindings); if ($processBindings) { CCrmSonetRelation::UnRegisterRelationsByEntity(CCrmOwnerType::Activity, $activityID, array('QUICK' => $hasBindings)); } $arOwners = $hasBindings ? $bindings : self::GetBindings($activityID); $slEntities = CCrmLiveFeed::GetLogEvents(array(), array('ENTITY_TYPE_ID' => CCrmOwnerType::Activity, 'ENTITY_ID' => $activityID), array('ID', 'EVENT_ID')); if (empty($slEntities)) { return false; } global $DB; foreach ($slEntities as &$slEntity) { $slID = intval($slEntity['ID']); $slEventType = $slEntity['EVENT_ID']; if (isset($params['REFRESH_DATE']) ? (bool) $params['REFRESH_DATE'] : false) { //Update LOG_UPDATE for force event to rise in global feed //Update LOG_DATE for force event to rise in entity feed CCrmLiveFeed::UpdateLogEvent($slID, array('=LOG_UPDATE' => $DB->CurrentTimeFunction(), '=LOG_DATE' => $DB->CurrentTimeFunction())); } else { //HACK: FAKE UPDATE FOR INVALIDATE CACHE CCrmLiveFeed::UpdateLogEvent($slID, array('ENTITY_TYPE_ID' => CCrmOwnerType::Activity, 'ENTITY_ID' => $activityID)); } /* 'START_RESPONSIBLE_ID' => $arPrevEntity['RESPONSIBLE_ID'], 'FINAL_RESPONSIBLE_ID' => $responsibleID */ $userID = intval($params['EDITOR_ID']) > 0 ? $params['EDITOR_ID'] : CCrmSecurityHelper::GetCurrentUserID(); if (intval($params['START_RESPONSIBLE_ID']) != intval($params['FINAL_RESPONSIBLE_ID']) && CModule::IncludeModule("im")) { switch ($params['TYPE_ID']) { case CCrmActivityType::Call: $type = 'CALL'; break; case CCrmActivityType::Meeting: $type = 'MEETING'; break; default: $type = false; } if ($type) { $url = "/crm/stream/?log_id=#log_id#"; $url = str_replace(array("#log_id#"), array($slID), $url); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $userID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $slID, "NOTIFY_EVENT" => "activity_add", "NOTIFY_TAG" => "CRM|ACTIVITY|" . $activityID); if (intval($params['START_RESPONSIBLE_ID']) != $userID) { $bHasPermissions = false; $perms = CCrmPerms::GetUserPermissions($params['START_RESPONSIBLE_ID']); foreach ($arOwners as $arOwner) { if (CCrmActivity::CheckReadPermission($arOwner["OWNER_TYPE_ID"], $arOwner["OWNER_ID"], $perms)) { $bHasPermissions = true; break; } } if ($bHasPermissions) { $arMessageFields["TO_USER_ID"] = $params['START_RESPONSIBLE_ID']; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_ACTIVITY_" . $type . "_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => '<a href="' . $url . '">' . htmlspecialcharsbx($params['SUBJECT']) . '</a>')); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_" . $type . "_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($params['SUBJECT']))) . " (" . $serverName . $url . ")"; CIMNotify::Add($arMessageFields); } } if (intval($params['FINAL_RESPONSIBLE_ID']) != $userID) { $bHasPermissions = false; $perms = CCrmPerms::GetUserPermissions($params['FINAL_RESPONSIBLE_ID']); foreach ($arOwners as $arOwner) { if (CCrmActivity::CheckReadPermission($arOwner["OWNER_TYPE_ID"], $arOwner["OWNER_ID"], $perms)) { $bHasPermissions = true; break; } } if ($bHasPermissions) { $arMessageFields["TO_USER_ID"] = $params['FINAL_RESPONSIBLE_ID']; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_ACTIVITY_" . $type . "_RESPONSIBLE_IM_NOTIFY", array("#title#" => '<a href="' . $url . '">' . htmlspecialcharsbx($params['SUBJECT']) . '</a>')); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_" . $type . "_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($params['SUBJECT']))) . " (" . $serverName . $url . ")"; CIMNotify::Add($arMessageFields); } } } } if ($processBindings && $hasBindings) { CCrmSonetRelation::RegisterRelationBundle($slID, $slEventType, CCrmOwnerType::Activity, $activityID, $bindings, array('ENTITY_TYPE_ID_KEY' => 'OWNER_TYPE_ID', 'ENTITY_ID_KEY' => 'OWNER_ID', 'TYPE_ID' => CCrmSonetRelationType::Ownership)); } } unset($slEntity); return true; }
static function AddComment_Wiki($arFields) { if (!CModule::IncludeModule('iblock')) { return false; } if (!CModule::IncludeModule('socialnetwork')) { return false; } $ufFileID = array(); $ufDocID = array(); $dbResult = CSocNetLog::GetList(array('ID' => 'DESC'), array('TMP_ID' => $arFields['LOG_ID']), false, false, array('ID', 'SOURCE_ID', 'PARAMS', 'URL')); $bFound = false; if ($arLog = $dbResult->Fetch()) { if (strlen($arLog['PARAMS']) > 0) { $arFieldsParams = explode('&', $arLog['PARAMS']); if (is_array($arFieldsParams) && count($arFieldsParams) > 0) { foreach ($arFieldsParams as $tmp) { list($key, $value) = explode('=', $tmp); if ($key == 'forum_id') { $FORUM_ID = intval($value); break; } } } } if ($FORUM_ID > 0 && intval($arLog['SOURCE_ID']) > 0) { $bFound = true; } } if ($bFound) { $arElement = false; $arFilter = array('ID' => $arLog['SOURCE_ID']); $arSelectedFields = array('IBLOCK_ID', 'ID', 'NAME', 'TAGS', 'CODE', 'IBLOCK_SECTION_ID', 'DETAIL_PAGE_URL', 'CREATED_BY', 'PREVIEW_PICTURE', 'PREVIEW_TEXT', 'PROPERTY_FORUM_TOPIC_ID', 'PROPERTY_FORUM_MESSAGE_CNT'); $db_res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelectedFields); if ($db_res && ($res = $db_res->GetNext())) { $arElement = $res; } if ($arElement) { // check iblock properties CSocNetLogTools::AddComment_Review_CheckIBlock($arElement); $dbMessage = CForumMessage::GetList(array(), array('PARAM2' => $arElement['ID'])); if (!($arMessage = $dbMessage->Fetch())) { // Add Topic and Root Message $TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot($arElement, $FORUM_ID, false); $bNewTopic = true; } else { $TOPIC_ID = $arMessage['TOPIC_ID']; } if (intval($TOPIC_ID) > 0) { // Add comment $messageID = false; $arFieldsMessage = array('POST_MESSAGE' => $arFields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PARAM2' => $arElement['ID'], 'APPROVED' => 'Y'); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsMessage["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id); } } } $messageID = ForumAddMessage('REPLY', $FORUM_ID, $TOPIC_ID, 0, $arFieldsMessage, $sError, $sNote); if (!$messageID) { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } else { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID); CSocNetLogTools::AddComment_Review_UpdateElement($arElement, $TOPIC_ID, $bNewTopic); $userID = $GLOBALS["USER"]->GetID(); if (CModule::IncludeModule("im") && intval($arElement["CREATED_BY"]) > 0 && $arElement["CREATED_BY"] != $userID) { $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arElement["CREATED_BY"], "CODE" => "L" . $arLog["ID"], "TYPE" => "N"), array("USER_ID")); $arUnFollower = $rsUnFollower->Fetch(); if (!$arUnFollower) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arElement["CREATED_BY"], "FROM_USER_ID" => $userID, "LOG_ID" => $arLog["ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "wiki", "NOTIFY_EVENT" => "comment"); $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arElement["NAME"]); $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100); $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255); $arTmp = CSocNetLogTools::ProcessPath(array("ELEMENT_URL" => $arLog["URL"]), $arElement["CREATED_BY"]); $serverName = $arTmp["SERVER_NAME"]; $url = $arTmp["URLS"]["ELEMENT_URL"]; $arMessageFields["NOTIFY_TAG"] = "WIKI|COMMENT|" . $arElement['ID']; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("WIKI_SONET_FROM_LOG_IM_COMMENT", array("#title#" => strlen($url) > 0 ? "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>" : htmlspecialcharsbx($arParams["TITLE"]))); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("WIKI_SONET_FROM_LOG_IM_COMMENT", array("#title#" => htmlspecialcharsbx($arParams["TITLE"]))) . (strlen($url) > 0 ? " (" . $serverName . $url . ")" : "") . "#BR##BR#" . $arFields["TEXT_MESSAGE"]; CIMNotify::Add($arMessageFields); } } } } else { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } } else { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } } else { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } return array('SOURCE_ID' => $messageID, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => $messageID, 'ERROR' => $strError, 'NOTES' => '', "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID)); }
public static function NotifyComment($eventID, $arComment) { if (!CModule::IncludeModule("im")) { return; } if (intval($eventID) <= 0) { return; } if ($arCalendarEvent = CCalendarEvent::GetById($eventID)) { $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => intval($arComment["USER_ID"])), array('FIELDS' => array('PERSONAL_GENDER'))); $strMsgAddComment = GetMessage("EC_LF_COMMENT_MESSAGE_ADD"); $strMsgEditComment = GetMessage("EC_LF_COMMENT_MESSAGE_ADD"); if ($arUser = $rsUser->fetch()) { switch ($arUser['PERSONAL_GENDER']) { case "F": case "M": $strMsgAddComment = GetMessage("EC_LF_COMMENT_MESSAGE_ADD" . '_' . $arUser['PERSONAL_GENDER']); break; default: break; } } $arMessageFields = array("FROM_USER_ID" => $arComment["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "calendar", "NOTIFY_EVENT" => "event_comment", "NOTIFY_MESSAGE" => str_replace(array("#EVENT_TITLE#"), array(strlen($arComment["URL"]) > 0 ? "<a href=\"" . $arComment["URL"] . "\" class=\"bx-notifier-item-action\">" . $arCalendarEvent["NAME"] . "</a>" : $arCalendarEvent["NAME"]), $strMsgAddComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#EVENT_TITLE#"), array($arCalendarEvent["NAME"]), $strMsgAddComment) . (strlen($arComment["URL"]) > 0 ? " (" . $arComment["URL"] . ")" : "") . "#BR##BR#" . $arComment["MESSAGE"]); if (is_array($arCalendarEvent["~ATTENDEES"])) { foreach ($arCalendarEvent["~ATTENDEES"] as $arAttendee) { if ($arAttendee["USER_ID"] == $arComment["USER_ID"]) { continue; } $arMessageFields1 = array_merge($arMessageFields, array("TO_USER_ID" => $arAttendee["USER_ID"])); CIMNotify::Add($arMessageFields1); } } } }
function NotifyIm($arParams) { if (!CModule::IncludeModule("im")) { return; } $arUsers = array(); if (!empty($arParams["TO_USER_ID"])) { foreach ($arParams["TO_USER_ID"] as $val) { $val = IntVal($val); if ($val > 0 && $val != $arParams["FROM_USER_ID"]) { $arUsers[] = $val; } } } if (!empty($arParams["TO_SOCNET_RIGHTS"])) { foreach ($arParams["TO_SOCNET_RIGHTS"] as $v) { if (substr($v, 0, 1) == "U") { $u = IntVal(substr($v, 1)); if ($u > 0 && !in_array($u, $arUsers) && empty($arParams["TO_SOCNET_RIGHTS_OLD"][$u]) && $u != $arParams["FROM_USER_ID"]) { $arUsers[] = $u; } } } } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => "", "FROM_USER_ID" => $arParams["FROM_USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "blog"); if (CModule::IncludeModule("socialnetwork")) { $rsLog = CSocNetLog::GetList(array(), array("EVENT_ID" => array("blog_post", "blog_post_micro"), "SOURCE_ID" => $arParams["ID"]), false, false, array("ID")); if ($arLog = $rsLog->Fetch()) { $arMessageFields["LOG_ID"] = $arLog["ID"]; } } $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arParams["TITLE"]); $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100); $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255); $dbSite = CSite::GetByID(SITE_ID); $arSite = $dbSite->Fetch(); $serverName = htmlspecialcharsEx($arSite["SERVER_NAME"]); if (strlen($serverName) <= 0) { if (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0) { $serverName = SITE_SERVER_NAME; } else { $serverName = COption::GetOptionString("main", "server_name", ""); } } $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . $serverName; if ($arParams["TYPE"] == "POST") { $arMessageFields["NOTIFY_EVENT"] = "post"; $arMessageFields["NOTIFY_TAG"] = "BLOG|POST|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_1", array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_1", array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $serverName . $arParams["URL"] . ")"; } elseif ($arParams["TYPE"] == "COMMENT") { $arMessageFields["NOTIFY_EVENT"] = "comment"; $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_4", array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_4", array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $serverName . $arParams["URL"] . ")"; $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage("BLG_GP_IM_5", array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage("BLG_GP_IM_5", array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $serverName . $arParams["URL"] . ")"; } foreach ($arUsers as $v) { if (!empty($arParams["EXCLUDE_USERS"]) && IntVal($arParams["EXCLUDE_USERS"][$v]) > 0) { continue; } $arMessageFieldsTmp = $arMessageFields; if ($arParams["TYPE"] == "COMMENT") { if ($arParams["AUTHOR_ID"] == $v) { $arMessageFieldsTmp["NOTIFY_MESSAGE"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR"]; $arMessageFieldsTmp["NOTIFY_MESSAGE_OUT"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"]; } } $arMessageFieldsTmp["TO_USER_ID"] = $v; $ID = CIMNotify::Add($arMessageFieldsTmp); } if (!empty($arParams["MENTION_ID"])) { if (!is_array($arParams["MENTION_ID_OLD"])) { $arParams["MENTION_ID_OLD"] = array(); } foreach ($arParams["MENTION_ID"] as $val) { $val = IntVal($val); if (IntVal($val) > 0 && !in_array($val, $arUsers) && !in_array($val, $arParams["MENTION_ID_OLD"]) && $val != $arParams["FROM_USER_ID"]) { if (CBlogPost::GetSocNetPostPerms($arParams["ID"], false, $val) >= BLOG_PERMS_READ) { $arMessageFields["TO_USER_ID"] = $val; $arMessageFields["NOTIFY_EVENT"] = "mention"; if ($arParams["TYPE"] == "POST") { $arMessageFields["NOTIFY_TAG"] = "BLOG|POST_MENTION|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_6", array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_6", array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $arParams["URL"] . ")"; } elseif ($arParams["TYPE"] == "COMMENT") { $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT_MENTION|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_7", array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_7", array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $arParams["URL"] . ")"; } $ID = CIMNotify::Add($arMessageFields); if (intval($ID) > 0 && intval($arMessageFields["LOG_ID"]) > 0) { $db_events = GetModuleEvents("blog", "OnBlogPostMentionNotifyIm"); while ($arEvent = $db_events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID, $arMessageFields)); } } } } } } }
public static function NotifyGroup($arFields) { if (!CModule::IncludeModule("im")) { return; } if (!is_array($arFields["GROUP_ID"])) { $arFields["GROUP_ID"] = array($arFields["GROUP_ID"]); } if (empty($arFields["GROUP_ID"])) { return; } if (empty($arFields["EXCLUDE_USERS"])) { $arFields["EXCLUDE_USERS"] = array(); } if (intval($arFields["LOG_ID"]) > 0) { $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . intval($arFields["LOG_ID"]), "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arFields["EXCLUDE_USERS"][] = $arUnFollower["USER_ID"]; } $arFields["EXCLUDE_USERS"] = array_unique($arFields["EXCLUDE_USERS"]); } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "socialnetwork", "NOTIFY_EVENT" => "sonet_group_event", "NOTIFY_TAG" => "SONET|EVENT|" . (intval($arFields["LOG_ID"]) > 0 ? $arFields["LOG_ID"] : rand())); if (intval($arFields["FROM_USER_ID"]) > 0) { $arMessageFields["FROM_USER_ID"] = $arFields["FROM_USER_ID"]; } $arUserToSend = array(); $arUserIDToSend = array(); $arGroupID = array(); $arCodes = array(); foreach ($arFields["GROUP_ID"] as $group_id) { $arCodes[] = "SG" . $group_id; } $rsSubscriber = CSocNetSubscription::GetList(array(), array("CODE" => $arCodes), false, false, array("USER_ID", "CODE")); while ($arSubscriber = $rsSubscriber->Fetch()) { if (!in_array($arSubscriber["USER_ID"], $arFields["EXCLUDE_USERS"]) && !in_array($arSubscriber["USER_ID"], $arUserIDToSend)) { if (preg_match('/^SG(\\d+)$/', $arSubscriber["CODE"], $matches)) { $arUserToSend[] = array("USER_ID" => $arSubscriber["USER_ID"], "GROUP_ID" => $matches[1]); $arUserIDToSend[] = $arSubscriber["USER_ID"]; $arGroupID[] = $matches[1]; } } } $rsGroup = CSocNetGroup::GetList(array(), array("ID" => $arGroupID), false, false, array("ID", "NAME", "OWNER_ID")); while ($arGroup = $rsGroup->GetNext()) { $arGroups[$arGroup["ID"]] = $arGroup; } $workgroupsPage = COption::GetOptionString("socialnetwork", "workgroups_page", "/workgroups/", SITE_ID); $groupUrlTemplate = COption::GetOptionString("socialnetwork", "group_path_template", "/workgroups/group/#group_id#/", SITE_ID); $groupUrlTemplate = "#GROUPS_PATH#" . substr($groupUrlTemplate, strlen($workgroupsPage), strlen($groupUrlTemplate) - strlen($workgroupsPage)); foreach ($arUserToSend as $arUser) { $arMessageFields["TO_USER_ID"] = $arUser["USER_ID"]; $arTmp = CSocNetLogTools::ProcessPath(array("URL" => $arFields["URL"], "GROUP_URL" => str_replace(array("#group_id#", "#GROUP_ID#"), $arUser["GROUP_ID"], $groupUrlTemplate)), $arUser["USER_ID"]); $url = $arTmp["URLS"]["URL"]; if (strpos($url, "http://") === 0 || strpos($url, "https://") === 0) { $serverName = ""; } else { $serverName = $arTmp["SERVER_NAME"]; } $groupUrl = $serverName . $arTmp["URLS"]["GROUP_URL"]; $group_name = array_key_exists($arUser["GROUP_ID"], $arGroups) ? $arGroups[$arUser["GROUP_ID"]]["NAME"] : ""; $arMessageFields["NOTIFY_MESSAGE"] = str_replace(array("#URL#", "#url#", "#group_name#", "#GROUP_ID#", "#group_id#"), array($url, $url, "<a href=\"" . $groupUrl . "\" class=\"bx-notifier-item-action\">" . $group_name . "</a>", $arUser["GROUP_ID"], $arUser["GROUP_ID"]), $arFields["MESSAGE"]); $arMessageFields["NOTIFY_MESSAGE_OUT"] = str_replace(array("#URL#", "#url#", "#group_name#"), array($serverName . $url, $serverName . $url, $group_name), $arFields["MESSAGE_OUT"]); $arMessageFields2Send = $arMessageFields; if (!is_set($arMessageFields2Send["FROM_USER_ID"]) || intval($arMessageFields2Send["FROM_USER_ID"]) <= 0) { $arMessageFields2Send["NOTIFY_TYPE"] = IM_NOTIFY_SYSTEM; $arMessageFields2Send["FROM_USER_ID"] = 0; } CIMNotify::Add($arMessageFields2Send); } }
public static function Like($id, $action = 'auto') { global $USER; if (!CModule::IncludeModule('pull')) return false; $action = in_array($action, Array('plus', 'minus'))? $action: 'auto'; $message = self::GetById($id, Array('WITH_FILES' => 'Y')); if (!$message) return false; $relations = CIMMessenger::GetRelationById($id); if (!isset($relations[$USER->GetId()])) return false; $isLike = false; if (isset($message['PARAMS']['LIKE'])) { $isLike = in_array($USER->GetId(), $message['PARAMS']['LIKE']); } if ($isLike && $action == 'plus') { return false; } else if (!$isLike && $action == 'minus') { return false; } $isLike = true; if (isset($message['PARAMS']['LIKE'])) { $like = $message['PARAMS']['LIKE']; $selfLike = array_search($USER->GetId(), $like); if ($selfLike !== false) { $isLike = false; unset($like[$selfLike]); } else { $like[] = $USER->GetId(); } } else { $like = Array($USER->GetId()); } sort($like); CIMMessageParam::Set($id, Array('LIKE' => $like)); $result = IM\ChatTable::getList(Array( 'filter'=>Array( '=ID' => $message['CHAT_ID'] ) )); $chat = $result->fetch(); if ($message['AUTHOR_ID'] > 0 && $message['AUTHOR_ID'] != $USER->GetId() && $isLike) { $CCTP = new CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $message['MESSAGE'] = str_replace('<br />', ' ', $CCTP->convertText($message['MESSAGE'])); if (count($message['FILES']) > 0 && strlen($message['MESSAGE']) < 200) { foreach ($message['FILES'] as $file) { $file = " [".GetMessage('IM_MESSAGE_FILE').": ".$file['name']."]"; if (strlen($message['MESSAGE'].$file) > 200) break; $message['MESSAGE'] .= $file; } $message['MESSAGE'] = trim($message['MESSAGE']); } $isChat = $chat && strlen($chat['TITLE']) > 0; $arMessageFields = array( "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $message['AUTHOR_ID'], "FROM_USER_ID" => $USER->GetId(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|IM|".($isChat? 'G':'P')."|".($isChat? $chat['ID']: $USER->GetId())."|".$id, "NOTIFY_MESSAGE" => GetMessage($isChat? 'IM_MESSAGE_LIKE': 'IM_MESSAGE_LIKE_PRIVATE', Array( '#MESSAGE#' => $message['MESSAGE'], '#TITLE#' => $chat['TITLE'] )) ); CIMNotify::Add($arMessageFields); } $arPullMessage = Array( 'id' => $id, 'chatId' => $relations[$USER->GetId()]['CHAT_ID'], 'senderId' => $USER->GetId(), 'users' => $like ); foreach ($relations as $rel) { CPullStack::AddByUser($rel['USER_ID'], Array( 'module_id' => 'im', 'command' => 'messageLike', 'params' => $arPullMessage )); } return $like; }
public function merge($seedID, $targID, Integrity\DuplicateCriterion $targCriterion) { if (!is_int($seedID)) { $seedID = (int) $seedID; } if (!is_int($targID)) { $targID = (int) $targID; } $entityTypeID = $this->entityTypeID; if ($this->enablePermissionCheck && !$this->userIsAdmin) { $userPermissions = $this->getUserPermissions(); if (!$this->checkEntityReadPermission($seedID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $seedID, self::ROLE_SEED, EntityMergerException::READ_DENIED); } if (!$this->checkEntityDeletePermission($seedID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $seedID, self::ROLE_SEED, EntityMergerException::DELETE_DENIED); } if (!$this->checkEntityReadPermission($targID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $targID, self::ROLE_TARG, EntityMergerException::READ_DENIED); } if (!$this->checkEntityUpdatePermission($targID, $userPermissions)) { throw new EntityMergerException($entityTypeID, $targID, self::ROLE_TARG, EntityMergerException::UPDATE_DENIED); } } $collisions = self::getMergeCollisions($seedID, $targID); $seed = $this->getEntityFields($seedID, self::ROLE_SEED); $targ = $this->getEntityFields($targID, self::ROLE_TARG); $entityFieldInfos = $this->getEntityFieldsInfo(); $userFieldInfos = $this->getEntityUserFieldsInfo(); EntityMerger::mergeEntityFields($seed, $targ, $entityFieldInfos); EntityMerger::mergeUserFields($seed, $targ, $userFieldInfos); $seedMultiFields = $this->getEntityMultiFields($seedID, self::ROLE_SEED); $targMultiFields = $this->getEntityMultiFields($targID, self::ROLE_TARG); EntityMerger::mergeMultiFields($seedMultiFields, $targMultiFields); if (!empty($targMultiFields)) { $targ['FM'] = $targMultiFields; } //$recoveryData = self::prepareRecoveryData($seed, $entityFieldInfos, $userFieldInfos); //$recoveryData->setEntityTypeID($entityTypeID); //$recoveryData->setEntityID($seedID); //$this->setupRecoveryData($recoveryData, $seed); //if(!empty($seedMultiFields)) //{ // $recoveryData->setDataItem('MULTI_FIELDS', $seedMultiFields); //} //$activityIDs = \CCrmActivity::GetBoundIDs($entityTypeID, $seedID); //if(!empty($activityIDs)) //{ // $recoveryData->setDataItem('ACTIVITY_IDS', $activityIDs); //} //$eventIDs = array(); //$result = \CCrmEvent::GetListEx( // array('EVENT_REL_ID' => 'ASC'), // array( // 'ENTITY_TYPE' => $entityTypeName, // 'ENTITY_ID' => $seedID, // 'EVENT_TYPE' => 0, // 'CHECK_PERMISSIONS' => 'N' // ), // false, // false, // array('EVENT_REL_ID') //); //if(is_object($result)) //{ // while($eventFields = $result->Fetch()) // { // $eventIDs[] = (int)$eventFields['EVENT_REL_ID']; // } //} //if(!empty($eventIDs)) //{ // $recoveryData->setDataItem('EVENT_IDS', $eventIDs); //} //$recoveryData->setUserID($this->userID); //$recoveryData->save(); $this->updateEntity($targID, $targ, self::ROLE_TARG); $this->rebind($seedID, $targID); $matches = $this->getRegisteredEntityMatches($entityTypeID, $seedID); $targIndexTypeID = $targCriterion->getIndexTypeID(); if (!isset($matches[$targIndexTypeID])) { $matches[$targIndexTypeID] = array(); } $targetMatchHash = $targCriterion->getMatchHash(); if (!isset($matches[$targIndexTypeID][$targetMatchHash])) { $matches[$targIndexTypeID][$targetMatchHash] = $targCriterion->getMatches(); } $this->deleteEntity($seedID, self::ROLE_SEED, array('ENABLE_DUP_INDEX_INVALIDATION' => false)); if (!empty($matches)) { $this->processEntityDeletion($entityTypeID, $seedID, $matches); } Integrity\DuplicateIndexBuilder::markAsJunk($entityTypeID, $seedID); if (!empty($collisions)) { $messageFields = $this->prepareCollisionMessageFields($collisions, $seed, $targ); if (is_array($messageFields) && !empty($messageFields) && Main\Loader::includeModule('im')) { $messageFields['FROM_USER_ID'] = $this->userID; $messageFields['MESSAGE_TYPE'] = IM_MESSAGE_SYSTEM; $messageFields['NOTIFY_TYPE'] = IM_NOTIFY_FROM; $messageFields['NOTIFY_MODULE'] = 'crm'; $messageFields['NOTIFY_EVENT'] = 'merge'; $messageFields['NOTIFY_TAG'] = 'CRM|MERGE|COLLISION'; \CIMNotify::Add($messageFields); } } }
public static function NotifyComment($comment) { if (!Loader::includeModule("im")) { return; } if ($comment["TO_USER_ID"] == $comment["FROM_USER_ID"]) { return; } $siteDir = rtrim(SITE_DIR, '/'); $url = str_replace('#SITE_DIR#', $siteDir, $comment["URL"]); $url .= '' . $comment['LOG_ID'] . '/'; $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD", array("#PROCESS#" => '<a href="' . $url . '" class="bx-notifier-item-action">' . $comment["TITLE"] . '</a>')); $userQuery = CUser::getList($by = "id", $order = "asc", array("ID_EQUAL_EXACT" => intval($comment["TO_USER_ID"])), array("FIELDS" => array("PERSONAL_GENDER"))); if ($user = $userQuery->fetch()) { switch ($user["PERSONAL_GENDER"]) { case "F": case "M": $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD" . '_' . $user["PERSONAL_GENDER"], array("#PROCESS#" => '<a href="' . $url . '" class="bx-notifier-item-action">' . $comment["TITLE"] . '</a>')); break; default: break; } } $messageFields = array("TO_USER_ID" => $comment["TO_USER_ID"], "FROM_USER_ID" => $comment["FROM_USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "lists", "NOTIFY_TAG" => "SONET|EVENT|" . $comment["LOG_ID"], "NOTIFY_EVENT" => "event_lists_comment_add", "NOTIFY_MESSAGE" => $messageAddComment); CIMNotify::Add($messageFields); }
public static function NotifyIm($arParams) { if (!CModule::IncludeModule("im") || intval($arParams["PHOTO_AUTHOR_ID"]) <= 0 || $arParams["PHOTO_AUTHOR_ID"] == intval($arParams["COMMENT_AUTHOR_ID"])) { return; } if (!array_key_exists("SECTION_NAME", $arParams)) { $arParams["SECTION_NAME"] = ""; } if (!array_key_exists("SECTION_URL", $arParams)) { $arParams["SECTION_URL"] = 0; } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arParams["PHOTO_AUTHOR_ID"], "FROM_USER_ID" => $arParams["COMMENT_AUTHOR_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "photogallery", "NOTIFY_EVENT" => "comment"); $rsLog = CSocNetLog::GetList(array(), array("EVENT_ID" => array("photo_photo"), "SOURCE_ID" => $arParams["ID"]), false, false, array("ID")); if ($arLog = $rsLog->Fetch()) { $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arParams["PHOTO_AUTHOR_ID"], "CODE" => "L" . $arLog["ID"], "TYPE" => "N"), array("USER_ID")); if ($arUnFollower = $rsUnFollower->Fetch()) { return; } $arMessageFields["LOG_ID"] = $arLog["ID"]; } $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arParams["TITLE"]); $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100); $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255); $arTmp = CSocNetLogTools::ProcessPath(array("PHOTO_URL" => $arParams["URL"], "SECTION_URL" => $arParams["SECTION_URL"]), $arParams["PHOTO_AUTHOR_ID"]); $serverName = $arTmp["SERVER_NAME"]; $arParams["URL"] = $arTmp["URLS"]["PHOTO_URL"]; $arParams["SECTION_URL"] = $arTmp["URLS"]["SECTION_URL"]; $arMessageFields["NOTIFY_TAG"] = "PHOTO|COMMENT|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("SONET_PHOTO_IM_COMMENT", array("#photo_title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>", "#album_title#" => "<a href=\"" . $arParams["SECTION_URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["SECTION_NAME"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("SONET_PHOTO_IM_COMMENT", array("#photo_title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]), "#album_title#" => htmlspecialcharsbx($arParams["SECTION_NAME"]))) . " (" . $serverName . $arParams["URL"] . ")#BR##BR#" . $arParams["MESSAGE"]; $ID = CIMNotify::Add($arMessageFields); if (!empty($arParams["COMMENT_MENTION_ID"])) { // } }
/** * WARNING! This method is transitional and can be changed without * any notifications! Don't use it. * * @deprecated */ public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional) { global $DB; if (is_array($arTask)) { if (!array_key_exists('~TITLE', $arTask)) { $arTmpTask = $arTask; foreach ($arTmpTask as $key => $value) { if (substr($key, 0, 1) !== '~') { $arTask['~' . $key] = $arTmpTask[$key]; } } } } $MID = 0; $TID = 0; if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) { $forumTopicId = false; } if ($forumTopicId <= 0) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim(CUser::FormatName($nameTemplate, $res)) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arFields); if (intVal($TID) <= 0) { $arErrorCodes[] = array('code' => 'topic is not created'); } else { $arFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arFields); } if (!empty($arErrorCodes)) { $DB->Rollback(); return false; } else { $DB->Commit(); } } $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions); // UF_* forwarding if (is_array($arFieldsAdditional)) { foreach ($arFieldsAdditional as $field => $value) { if (strlen($field) && substr($field, 0, 3) == 'UF_') { $arFieldsG[$field] = $value; $GLOBALS[$field] = $value; // strange behaviour required for ForumMessageAdd() to handle UF_* properly } } } if (!empty($_FILES["REVIEW_ATTACH_IMG"])) { $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"]; } else { $arFiles = array(); if (!empty($_REQUEST["FILES"])) { foreach ($_REQUEST["FILES"] as $key) { $arFiles[$key] = array("FILE_ID" => $key); if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) { $arFiles[$key]["del"] = "Y"; } } } if (!empty($_FILES)) { $res = array(); foreach ($_FILES as $key => $val) { if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) { $arFiles[] = $_FILES[$key]; } } } if (!empty($arFiles)) { $arFieldsG["FILES"] = $arFiles; } } $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID; $MESSAGE_ID = 0; $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW"; if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) { $MESSAGE_TYPE = "EDIT"; } $strErrorMessage = ''; $strOKMessage = ''; $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate); if ($MID <= 0 || !empty($strErrorMessage)) { $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage); } else { $arMessage = CForumMessage::GetByID($MID); if ($forumTopicId <= 0) { $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]); } $outForumTopicId = intVal($forumTopicId); if ($componentName !== null) { ForumClearComponentCache($componentName); } // NOTIFICATION $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array(); $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"])); while ($arMember = $rsMembers->Fetch()) { if ($arMember["TYPE"] == "A") { $arTask["ACCOMPLICES"][] = $arMember["USER_ID"]; } elseif ($arMember["TYPE"] == "U") { $arTask["AUDITORS"][] = $arMember["USER_ID"]; } } $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]); $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"])); $currentUserPos = array_search($givenUserId, $arEmailUserIDs); if ($currentUserPos !== false) { unset($arEmailUserIDs[$currentUserPos]); } $parser = new CTextParser(); $parser->imageWidth = $imageWidth; $parser->imageHeight = $imageHeight; $parser->smiles = $arSmiles; $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y"); $arAllow = NULL; $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow)); // remove [ url] for socialnetwork log $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE); $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y"); $message_notify = $parser->convertText($commentText); $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); // Instant Messages if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { $pageNumber = CForumMessage::GetMessagePage($MID, $messagesPerPage, $arUserGroupArray); // There are different links for extranet users $isExtranetEnabled = false; if (CModule::IncludeModule("extranet")) { $isExtranetEnabled = true; } if ($isExtranetEnabled) { $arSites = array(); $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { if (strlen(trim($arSite["DIR"])) > 0) { $arSites[$arSite['ID']]['DIR'] = $arSite['DIR']; } else { $arSites[$arSite['ID']]['DIR'] = '/'; } if (strlen(trim($arSite["SERVER_NAME"])) > 0) { $arSites[$arSite['ID']]['SERVER_NAME'] = $arSite["SERVER_NAME"]; } else { $arSites[$arSite['ID']]['SERVER_NAME'] = COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"]); } $arSites[$arSite['ID']]['urlPrefix'] = $arSites[$arSite['ID']]['SERVER_NAME'] . $arSites[$arSite['ID']]['DIR']; // remove last '/' if (strlen($arSites[$arSite['ID']]['urlPrefix']) > 0 && substr($arSites[$arSite['ID']]['urlPrefix'], -1) === '/') { $arSites[$arSite['ID']]['urlPrefix'] = substr($arSites[$arSite['ID']]['urlPrefix'], 0, -1); } } $extranet_site_id = CExtranet::GetExtranetSiteID(); $intranet_site_id = CSite::GetDefSite(); $arIntranetUsers = CExtranet::GetIntranetUsers(); } else { if ($arTask["GROUP_ID"]) { $pathTemplateWoExtranet = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"])); } else { $pathTemplateWoExtranet = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"]); } } foreach ($arRecipientsIDs as $userID) { $urlPrefixForUser = tasksServerName(); if ($isExtranetEnabled) { if (!in_array($userID, $arIntranetUsers) && $extranet_site_id) { $userSiteId = $extranet_site_id; } else { $userSiteId = $intranet_site_id; } if (isset($arSites[$userSiteId]['SERVER_NAME'])) { $urlPrefixForUser = tasksServerName($arSites[$userSiteId]['SERVER_NAME']); } if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace('#group_id#', $arTask['GROUP_ID'], CTasksTools::GetOptionPathTaskGroupEntry($userSiteId, '')); } else { $pathTemplate = CTasksTools::GetOptionPathTaskUserEntry($userSiteId, ''); } } else { $pathTemplate = $pathTemplateWoExtranet; } $NOTIFY_MESSAGE_TITLE_TEMPLATE = ''; $messageUrl = ''; if (strlen($pathTemplate) > 0) { $groupId = 0; if (isset($arTask['GROUP_ID'])) { $groupId = (int) $arTask['GROUP_ID']; } $messageUrl = $urlPrefixForUser . CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $userID, "task_id" => $arTask["ID"], "action" => "view", "USER_ID" => $userID, "TASK_ID" => $arTask["ID"], "ACTION" => "view", 'GROUP_ID' => $groupId, 'group_id' => $groupId)); if ($pageNumber > 1) { $messageUrl .= (strpos($messageUrl, "?") === false ? "?" : "&") . "MID=" . $MID; } $NOTIFY_MESSAGE_TITLE_TEMPLATE = '[URL=' . $messageUrl . "#message" . $MID . ']' . $arTask["~TITLE"] . '[/URL]'; } else { $NOTIFY_MESSAGE_TITLE_TEMPLATE = $arTask["~TITLE"]; } $MESSAGE_SITE = trim(htmlspecialcharsbx(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($message_notify))))); $MESSAGE_EMAIL = $MESSAGE_SITE; // full message to email if (strlen($MESSAGE_SITE) >= 100) { $dot = '...'; $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99); if (($lastLinkPosition = strrpos($MESSAGE_SITE, 'http://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'https://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftp://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftps://')) !== false) { if (strpos($MESSAGE_SITE, ' ', $lastLinkPosition) === false) { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, $lastLinkPosition); } } $MESSAGE_SITE .= $dot; } $arMessageFields = array("TO_USER_ID" => $userID, "FROM_USER_ID" => $givenUserId, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($NOTIFY_MESSAGE_TITLE_TEMPLATE, '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($arTask["~TITLE"], $MESSAGE_EMAIL . ' #BR# ' . $messageUrl . "#message" . $MID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment)); CIMNotify::Add($arMessageFields); } } $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result")); $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false); $outStrUrl = $strURL; // sonet log if (CModule::IncludeModule("socialnetwork")) { $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID")); if ($arRes = $dbRes->Fetch()) { $log_id = $arRes["TMP_ID"]; $entity_type = $arRes["ENTITY_TYPE"]; $entity_id = $arRes["ENTITY_ID"]; } else { $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER; $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"]; $rsUser = CUser::GetByID($arTask["CREATED_BY"]); if ($arUser = $rsUser->Fetch()) { $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create"))); $log_id = CSocNetLog::Add($arSoFields, false); if (intval($log_id) > 0) { CSocNetLog::Update($log_id, array("TMP_ID" => $log_id)); $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false)); if ($arTask["GROUP_ID"]) { $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"]; } CSocNetLogRights::Add($log_id, $arRights); } } } if (intval($log_id) > 0) { $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]; CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID); if ($MESSAGE_TYPE == "EDIT") { $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID")); while ($arRes = $dbRes->Fetch()) { CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet); } } else { $arFieldsForSocnet['USER_ID'] = $givenUserId; $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction(); $ufFileID = array(); $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } if (count($ufFileID) > 0) { $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID); if ($ufDocID) { $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID; } $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID); if ($ufDocVer) { $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer; } $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); CSocNetLog::CounterIncrement($comment_id, false, false, "LC"); } } } $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1; } // Tasks log $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID); $log = new CTaskLog(); $log->Add($arLogFields); } return $MID; // Message id }
public static function OnAddRatingVote($id, $arParams) { $bSocialnetworkInstalled = CModule::IncludeModule("socialnetwork"); if ($arParams['ENTITY_TYPE_ID'] == 'LISTS_NEW_ELEMENT' && CModule::IncludeModule("socialnetwork")) { $rsLog = CSocNetLog::GetList(array(), array("RATING_TYPE_ID" => $arParams['ENTITY_TYPE_ID'], "RATING_ENTITY_ID" => $arParams['ENTITY_ID']), false, false, array("ID", "USER_ID", "TITLE_TEMPLATE", "TITLE")); if ($arLog = $rsLog->Fetch()) { if ($arLog['USER_ID'] != $arParams['USER_ID']) { $url = COption::GetOptionString("socialnetwork", "log_entry_page", $arSites[$user_site_id]["DIR"] . "company/personal/log/#log_id#/", SITE_ID); $url = str_replace("#log_id#", $arLog["ID"], $url); $arParams['ENTITY_LINK'] = $url; $arParams['ENTITY_TITLE'] = htmlspecialcharsback($arLog["TITLE"]); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => intval($arLog['USER_ID']), "FROM_USER_ID" => intval($arParams['USER_ID']), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|" . ($arParams['VALUE'] >= 0 ? "" : "DL|") . $arParams['ENTITY_TYPE_ID'] . "|" . $arParams['ENTITY_ID'], "NOTIFY_MESSAGE" => self::GetMessageRatingVote($arParams), "NOTIFY_MESSAGE_OUT" => self::GetMessageRatingVote($arParams, true)); CIMNotify::Add($arMessageFields); } } } elseif ($arParams['ENTITY_TYPE_ID'] == 'LOG_COMMENT') { if ($arComment = CSocNetLogComments::GetByID($arParams['ENTITY_ID'])) { preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/ies" . BX_UTF_PCRE_MODIFIER, $arComment["TEXT_MESSAGE"], $arMention); if (!empty($arMention)) { $arMentionedUserID = $arMention[1]; } if ($arComment['USER_ID'] == $arParams['USER_ID'] && empty($arMentionedUserID)) { return false; } $arEventTmp = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]); if ($arEventTmp && array_key_exists("CLASS_FORMAT", $arEventTmp) && array_key_exists("METHOD_FORMAT", $arEventTmp)) { $arComment["MESSAGE"] = preg_replace(array('|\\[DISK\\sFILE\\sID=[n]*\\d+\\]|', '|\\[DOCUMENT\\sID=[n]*\\d+\\]|'), '', $arComment["MESSAGE"]); $arComment["MESSAGE"] = preg_replace('|\\[QUOTE\\](.+?)\\[\\/QUOTE\\]|is' . BX_UTF_PCRE_MODIFIER, '"\\1"', $arComment["MESSAGE"]); $arFIELDS_FORMATTED = call_user_func(array($arEventTmp["CLASS_FORMAT"], $arEventTmp["METHOD_FORMAT"]), $arComment, array("IM" => "Y")); $CCTP = new CTextParser(); $CCTP->MaxStringLen = 200; $CCTP->allow = array("HTML" => "N", "ANCHOR" => "Y", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "Y", "NL2BR" => "Y", "VIDEO" => "N", "TABLE" => "N", "CUT_ANCHOR" => "N", "ALIGN" => "N"); $arComment["MESSAGE"] = $CCTP->convertText($arFIELDS_FORMATTED["EVENT_FORMATTED"]["MESSAGE"]); } $arComment["MESSAGE"] = preg_replace(array('|\\[DISK\\sFILE\\sID=[n]*\\d+\\]|', '|\\[DOCUMENT\\sID=[n]*\\d+\\]|'), '', $arComment["MESSAGE"]); $arParams["ENTITY_TITLE"] = strip_tags(str_replace(array("<br>", "<br/>", "<br />", "#BR#"), array(" ", " ", " ", " "), htmlspecialcharsback($arComment["MESSAGE"]))); $bExtranetInstalled = CModule::IncludeModule("extranet"); if ($bExtranetInstalled) { $arSites = array(); $extranet_site_id = CExtranet::GetExtranetSiteID(); $intranet_site_id = CSite::GetDefSite(); $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { $arSites[$arSite["ID"]] = array("DIR" => strlen(trim($arSite["DIR"])) > 0 ? $arSite["DIR"] : "/", "SERVER_NAME" => strlen(trim($arSite["SERVER_NAME"])) > 0 ? $arSite["SERVER_NAME"] : COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"])); } } if ($arComment['USER_ID'] != $arParams['USER_ID']) { $followValue = "Y"; if ($bSocialnetworkInstalled) { $followValue = CSocNetLogFollow::GetExactValueByRating($arComment['USER_ID'], trim($arParams["ENTITY_TYPE_ID"]), intval($arParams["ENTITY_ID"])); } if ($followValue != "N") { $arParams['ENTITY_LINK'] = self::GetMessageRatingLogCommentURL($arComment, intval($arComment['USER_ID']), $arSites, $intranet_site_id, $extranet_site_id); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => intval($arComment['USER_ID']), "FROM_USER_ID" => intval($arParams['USER_ID']), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|" . ($arParams['VALUE'] >= 0 ? "" : "DL|") . $arParams['ENTITY_TYPE_ID'] . "|" . $arParams['ENTITY_ID'], "NOTIFY_MESSAGE" => self::GetMessageRatingVote($arParams), "NOTIFY_MESSAGE_OUT" => self::GetMessageRatingVote($arParams, true)); CIMNotify::Add($arMessageFields); } } if (!empty($arMentionedUserID) && is_array($arMentionedUserID)) { $arParams["MENTION"] = true; // for self::GetMessageRatingVote() foreach ($arMentionedUserID as $mentioned_user_id) { if ($mentioned_user_id != $arParams['USER_ID'] && CSocNetLogRights::CheckForUserOnly($arComment["LOG_ID"], $mentioned_user_id)) { $followValue = "Y"; if ($bSocialnetworkInstalled) { $followValue = CSocNetLogFollow::GetExactValueByRating(intval($mentioned_user_id), trim($arParams["ENTITY_TYPE_ID"]), intval($arParams["ENTITY_ID"])); } if ($followValue != "N") { $arParams['ENTITY_LINK'] = self::GetMessageRatingLogCommentURL($arComment, intval($mentioned_user_id), $arSites, $intranet_site_id, $extranet_site_id); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => intval($mentioned_user_id), "FROM_USER_ID" => intval($arParams['USER_ID']), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote_mentioned", "NOTIFY_TAG" => "RATING_MENTION|" . ($arParams['VALUE'] >= 0 ? "" : "DL|") . $arParams['ENTITY_TYPE_ID'] . "|" . $arParams['ENTITY_ID'], "NOTIFY_MESSAGE" => self::GetMessageRatingVote($arParams), "NOTIFY_MESSAGE_OUT" => self::GetMessageRatingVote($arParams, true)); CIMNotify::Add($arMessageFields); } } } } } } else { if (!CModule::IncludeModule("search") || BX_SEARCH_VERSION <= 1) { return false; } $CSI = new CSearchItem(); $arFSearch = array('=ENTITY_TYPE_ID' => $arParams['ENTITY_TYPE_ID'], '=ENTITY_ID' => $arParams['ENTITY_ID']); if (defined("SITE_ID") && strlen(SITE_ID) > 0) { $arFSearch["=SITE_ID"] = SITE_ID; } $res = $CSI->GetList(array(), $arFSearch, array('ID', 'URL', 'TITLE', 'BODY', 'PARAM1')); if ($arItem = $res->GetNext(true, false)) { // notify mentioned users $arSearchItemParams = CSearch::GetContentItemParams($arItem['ID'], 'mentioned_user_id'); if (is_array($arSearchItemParams) && array_key_exists('mentioned_user_id', $arSearchItemParams) && is_array($arSearchItemParams['mentioned_user_id'])) { $arMentionedUserID = $arSearchItemParams['mentioned_user_id']; } // send to author if ($arParams['OWNER_ID'] != $arParams['USER_ID'] || $arMentionedUserID) { $arParams["ENTITY_LINK"] = $arItem['URL']; $arParams["ENTITY_PARAM"] = $arItem['PARAM1']; $arParams["ENTITY_TITLE"] = trim(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($arItem['TITLE'])))); $arParams["ENTITY_MESSAGE"] = trim(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($arItem['BODY'])))); if ((strlen($arParams["ENTITY_TITLE"]) > 0 || strlen($arParams["ENTITY_MESSAGE"]) > 0) && strlen($arParams["ENTITY_LINK"]) > 0) { $originalLink = $arParams["ENTITY_LINK"]; $bExtranetInstalled = CModule::IncludeModule("extranet"); if ($bExtranetInstalled) { $arSites = array(); $extranet_site_id = CExtranet::GetExtranetSiteID(); $intranet_site_id = CSite::GetDefSite(); $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { $arSites[$arSite["ID"]] = array("DIR" => strlen(trim($arSite["DIR"])) > 0 ? $arSite["DIR"] : "/", "SERVER_NAME" => strlen(trim($arSite["SERVER_NAME"])) > 0 ? $arSite["SERVER_NAME"] : COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"])); } } if ($arParams['OWNER_ID'] != $arParams['USER_ID']) { $followValue = "Y"; if ($bSocialnetworkInstalled) { $followValue = CSocNetLogFollow::GetExactValueByRating(intval($arParams['OWNER_ID']), trim($arParams["ENTITY_TYPE_ID"]), intval($arParams["ENTITY_ID"])); } if ($followValue != "N") { $arParams['ENTITY_LINK'] = self::GetMessageRatingEntityURL($originalLink, intval($arParams['OWNER_ID']), $arSites, $intranet_site_id, $extranet_site_id); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => intval($arParams['OWNER_ID']), "FROM_USER_ID" => intval($arParams['USER_ID']), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote", "NOTIFY_TAG" => "RATING|" . ($arParams['VALUE'] >= 0 ? "" : "DL|") . $arParams['ENTITY_TYPE_ID'] . "|" . $arParams['ENTITY_ID'], "NOTIFY_MESSAGE" => self::GetMessageRatingVote($arParams), "NOTIFY_MESSAGE_OUT" => self::GetMessageRatingVote($arParams, true)); CIMNotify::Add($arMessageFields); } } if (is_array($arMentionedUserID) && $bSocialnetworkInstalled) { if (in_array($arParams['ENTITY_TYPE_ID'], array("BLOG_COMMENT", "FORUM_POST"))) { $rsLogComment = CSocNetLogComments::GetList(array(), array("RATING_TYPE_ID" => $arParams['ENTITY_TYPE_ID'], "RATING_ENTITY_ID" => $arParams['ENTITY_ID']), false, false, array("LOG_ID")); if ($arLogComment = $rsLogComment->Fetch()) { $log_id = $arLogComment["LOG_ID"]; } } elseif (in_array($arParams['ENTITY_TYPE_ID'], array("BLOG_POST"))) { $rsLog = CSocNetLog::GetList(array(), array("RATING_TYPE_ID" => $arParams['ENTITY_TYPE_ID'], "RATING_ENTITY_ID" => $arParams['ENTITY_ID']), false, false, array("ID")); if ($arLog = $rsLog->Fetch()) { $log_id = $arLog["ID"]; } } if (intval($log_id) > 0) { $arParams["MENTION"] = true; // for self::GetMessageRatingVote() foreach ($arMentionedUserID as $mentioned_user_id) { if ($mentioned_user_id != $arParams['USER_ID'] && CSocNetLogRights::CheckForUserOnly($log_id, $mentioned_user_id)) { $followValue = "Y"; if ($bSocialnetworkInstalled) { $followValue = CSocNetLogFollow::GetExactValueByRating(intval($mentioned_user_id), trim($arParams["ENTITY_TYPE_ID"]), intval($arParams["ENTITY_ID"])); } if ($followValue != "N") { $arParams['ENTITY_LINK'] = self::GetMessageRatingEntityURL($originalLink, intval($mentioned_user_id), $arSites, $intranet_site_id, $extranet_site_id); $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => intval($mentioned_user_id), "FROM_USER_ID" => intval($arParams['USER_ID']), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "main", "NOTIFY_EVENT" => "rating_vote_mentioned", "NOTIFY_TAG" => "RATING_MENTION|" . ($arParams['VALUE'] >= 0 ? "" : "DL|") . $arParams['ENTITY_TYPE_ID'] . "|" . $arParams['ENTITY_ID'], "NOTIFY_MESSAGE" => self::GetMessageRatingVote($arParams), "NOTIFY_MESSAGE_OUT" => self::GetMessageRatingVote($arParams, true)); CIMNotify::Add($arMessageFields); } } } } } } } } } }
public static function AddCommentToIM($arFields) { if (CModule::IncludeModule("im") && intval($arFields["USER_ID"]) > 0) { $date_text = ""; $dbReport = CTimeManReportFull::GetByID($arFields["REPORT_ID"]); if ($arReport = $dbReport->Fetch()) { $date_from = FormatDate("j F", MakeTimeStamp($arReport["DATE_FROM"], CSite::GetDateFormat("FULL", SITE_ID))); $date_to = FormatDate("j F", MakeTimeStamp($arReport["DATE_TO"], CSite::GetDateFormat("FULL", SITE_ID))); if ($date_from == $date_to) { $date_text = $date_to; } else { $date_text = $date_from . " - " . $date_to; } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $arFields["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "timeman", "NOTIFY_EVENT" => "report_comment", "NOTIFY_TAG" => "TIMEMAN|REPORT|" . $arFields["REPORT_ID"]); $arUserIDToSend = array($arReport["USER_ID"]); $gender_suffix = ""; $dbUser = CUser::GetByID($arFields["USER_ID"]); if ($arUser = $dbUser->Fetch()) { switch ($arUser["PERSONAL_GENDER"]) { case "M": $gender_suffix = "_M"; break; case "F": $gender_suffix = "_F"; break; default: $gender_suffix = ""; } } $arManagers = CTimeMan::GetUserManagers($arReport["USER_ID"]); if (is_array($arManagers)) { $arUserIDToSend = array_merge($arUserIDToSend, $arManagers); } $reports_page = COption::GetOptionString("timeman", "WORK_REPORT_PATH", "/company/work_report.php"); $arUnFollowers = array(); $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arUserIDToSend, "CODE" => "L" . $arFields["LOG_ID"], "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arUnFollowers[] = $arUnFollower["USER_ID"]; } $arUserIDToSend = array_diff($arUserIDToSend, $arUnFollowers); foreach ($arUserIDToSend as $user_id) { if ($arFields["USER_ID"] == $user_id) { continue; } $arMessageFields["TO_USER_ID"] = $user_id; $arTmp = CSocNetLogTools::ProcessPath(array("REPORTS_PAGE" => $reports_page), $user_id); $sender_type = $arReport["USER_ID"] == $user_id ? "1" : ($arReport["USER_ID"] == $arFields["USER_ID"] ? "2" : "3"); $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("REPORT_FULL_IM_COMMENT_" . $sender_type . $gender_suffix, array("#period#" => "<a href=\"" . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $arReport["ID"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($date_text) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("REPORT_FULL_IM_COMMENT_" . $sender_type . $gender_suffix, array("#period#" => htmlspecialcharsbx($date_text))) . " ( " . $arTmp["SERVER_NAME"] . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $arReport["ID"] . " )#BR##BR#" . $arFields["MESSAGE"]; CIMNotify::Add($arMessageFields); } } } }
public static function NotifyIm($arParams) { if (!CModule::IncludeModule("im")) { return; } $arUsers = array(); $arUserIDSent = array(); if (!empty($arParams["TO_USER_ID"])) { foreach ($arParams["TO_USER_ID"] as $val) { $val = IntVal($val); if ($val > 0 && $val != $arParams["FROM_USER_ID"]) { $arUsers[] = $val; } } } if (!empty($arParams["TO_SOCNET_RIGHTS"])) { foreach ($arParams["TO_SOCNET_RIGHTS"] as $v) { if (substr($v, 0, 1) == "U") { $u = IntVal(substr($v, 1)); if ($u > 0 && !in_array($u, $arUsers) && (!array_key_exists("U", $arParams["TO_SOCNET_RIGHTS_OLD"]) || empty($arParams["TO_SOCNET_RIGHTS_OLD"]["U"][$u])) && $u != $arParams["FROM_USER_ID"]) { $arUsers[] = $u; } } } } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => "", "FROM_USER_ID" => $arParams["FROM_USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "blog"); $aditGM = ""; if (IntVal($arParams["FROM_USER_ID"]) > 0) { $dbUser = CUser::GetByID($arParams["FROM_USER_ID"]); if ($arUser = $dbUser->Fetch()) { if ($arUser["PERSONAL_GENDER"] == "F") { $aditGM = "_FEMALE"; } } } if (CModule::IncludeModule("socialnetwork")) { $rsLog = CSocNetLog::GetList(array(), array("EVENT_ID" => array("blog_post", "blog_post_important", "blog_post_micro"), "SOURCE_ID" => $arParams["ID"]), false, false, array("ID")); if ($arLog = $rsLog->Fetch()) { $arMessageFields["LOG_ID"] = $arLog["ID"]; } } $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arParams["TITLE"]); $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100); $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); if (IsModuleInstalled("extranet")) { $user_path = COption::GetOptionString("socialnetwork", "user_page", false, SITE_ID); if (strpos($arParams["URL"], $user_path) === 0) { $arParams["URL"] = str_replace($user_path, "#USER_PATH#", $arParams["URL"]); } } if ($arParams["TYPE"] == "POST") { $arMessageFields["NOTIFY_EVENT"] = "post"; $arMessageFields["NOTIFY_TAG"] = "BLOG|POST|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_1" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_1" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . ""; } elseif ($arParams["TYPE"] == "COMMENT") { $arMessageFields["NOTIFY_EVENT"] = "comment"; $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_4" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_4" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . "\n\n" . $arParams["BODY"]; $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage("BLG_GP_IM_5" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage("BLG_GP_IM_5" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . "\n\n" . $arParams["BODY"]; } elseif ($arParams["TYPE"] == "SHARE") { $arMessageFields["NOTIFY_EVENT"] = "share"; $arMessageFields["NOTIFY_TAG"] = "BLOG|SHARE|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_8" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_8" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . ""; } elseif ($arParams["TYPE"] == "SHARE2USERS") { $arMessageFields["NOTIFY_EVENT"] = "share2users"; $arMessageFields["NOTIFY_TAG"] = "BLOG|SHARE2USERS|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_9" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_9" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . ""; } foreach ($arUsers as $v) { if (!empty($arParams["EXCLUDE_USERS"]) && IntVal($arParams["EXCLUDE_USERS"][$v]) > 0) { continue; } if (IsModuleInstalled("extranet")) { $arTmp = CSocNetLogTools::ProcessPath(array("URL" => $arParams["URL"]), $v); $url = $arTmp["URLS"]["URL"]; if (strpos($url, "http://") === 0 || strpos($url, "https://") === 0) { $serverName = ""; } else { $serverName = $arTmp["SERVER_NAME"]; } if ($arParams["TYPE"] == "POST") { $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_1" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_1" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $serverName . $url . ")"; } elseif ($arParams["TYPE"] == "COMMENT") { $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_4" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_4" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $url . "\n\n" . $arParams["BODY"]; $arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage("BLG_GP_IM_5" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage("BLG_GP_IM_5" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $url . "\n\n" . $arParams["BODY"]; } elseif ($arParams["TYPE"] == "SHARE") { $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_8" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_8" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $url . ""; } elseif ($arParams["TYPE"] == "SHARE2USERS") { $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_9" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_9" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $url . ""; } } $arMessageFieldsTmp = $arMessageFields; if ($arParams["TYPE"] == "COMMENT") { if ($arParams["AUTHOR_ID"] == $v) { $arMessageFieldsTmp["NOTIFY_MESSAGE"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR"]; $arMessageFieldsTmp["NOTIFY_MESSAGE_OUT"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"]; } } $arMessageFieldsTmp["TO_USER_ID"] = $v; $ID = CIMNotify::Add($arMessageFieldsTmp); $arUserIDSent[] = $v; } if (!empty($arParams["MENTION_ID"])) { if (!is_array($arParams["MENTION_ID_OLD"])) { $arParams["MENTION_ID_OLD"] = array(); } foreach ($arParams["MENTION_ID"] as $val) { $val = IntVal($val); if (IntVal($val) > 0 && !in_array($val, $arUsers) && !in_array($val, $arParams["MENTION_ID_OLD"]) && $val != $arParams["FROM_USER_ID"]) { if (CBlogPost::GetSocNetPostPerms($arParams["ID"], false, $val) >= BLOG_PERMS_READ) { $arMessageFields["TO_USER_ID"] = $val; $arMessageFields["NOTIFY_EVENT"] = "mention"; if (IsModuleInstalled("extranet")) { $arTmp = CSocNetLogTools::ProcessPath(array("URL" => $arParams["URL"]), $val); $url = $arTmp["URLS"]["URL"]; if (strpos($url, "http://") === 0 || strpos($url, "https://") === 0) { $serverName = ""; } else { $serverName = $arTmp["SERVER_NAME"]; } if ($arParams["TYPE"] == "POST") { $arMessageFields["NOTIFY_TAG"] = "BLOG|POST_MENTION|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_6" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_6" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $url . ""; } elseif ($arParams["TYPE"] == "COMMENT") { $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT_MENTION|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_7" . $aditGM, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_7" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $url . ""; } } else { if ($arParams["TYPE"] == "POST") { $arMessageFields["NOTIFY_TAG"] = "BLOG|POST_MENTION|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_6" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_6" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . ""; } elseif ($arParams["TYPE"] == "COMMENT") { $arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT_MENTION|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_7" . $aditGM, array("#title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_7" . $aditGM, array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " " . $serverName . $arParams["URL"] . ""; } } $ID = CIMNotify::Add($arMessageFields); $arUserIDSent[] = $val; if (intval($ID) > 0 && intval($arMessageFields["LOG_ID"]) > 0) { foreach (GetModuleEvents("blog", "OnBlogPostMentionNotifyIm", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID, $arMessageFields)); } } } } } } if ($arParams["TYPE"] == "POST" && !empty($arParams["TO_SOCNET_RIGHTS"])) { $arGroupsId = array(); foreach ($arParams["TO_SOCNET_RIGHTS"] as $perm_tmp) { if (preg_match('/^SG(\\d+)_' . SONET_ROLES_USER . '$/', $perm_tmp, $matches) || preg_match('/^SG(\\d+)$/', $perm_tmp, $matches)) { $group_id_tmp = $matches[1]; if ($group_id_tmp > 0 && (!array_key_exists("SG", $arParams["TO_SOCNET_RIGHTS_OLD"]) || empty($arParams["TO_SOCNET_RIGHTS_OLD"]["SG"][$group_id_tmp]))) { $arGroupsId[] = $group_id_tmp; } } } if (!empty($arGroupsId)) { $title_tmp = str_replace(array("\r\n", "\n"), " ", $arParams["TITLE"]); $title = TruncateText($title_tmp, 100); $title_out = TruncateText($title_tmp, 255); $arNotifyParams = array("LOG_ID" => $arMessageFields["LOG_ID"], "GROUP_ID" => $arGroupsId, "NOTIFY_MESSAGE" => "", "FROM_USER_ID" => $arParams["FROM_USER_ID"], "URL" => $arParams["URL"], "MESSAGE" => GetMessage("SONET_IM_NEW_POST", array("#title#" => "<a href=\"#URL#\" class=\"bx-notifier-item-action\">" . $title . "</a>")), "MESSAGE_OUT" => GetMessage("SONET_IM_NEW_POST", array("#title#" => $title_out)) . " #URL#", "EXCLUDE_USERS" => array_merge(array($arParams["FROM_USER_ID"]), array($arUserIDSent))); CSocNetSubscription::NotifyGroup($arNotifyParams); } } }
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; }
public static function KeepVoting() { global $DB, $VOTING_LAMP, $USER_ALREADY_VOTE, $USER_GROUP_PERMISSION, $USER; $err_mess = CAllVote::err_mess() . "<br>Function: KeepVoting<br>Line: "; $VOTING_LAMP = "green"; $USER_ALREADY_VOTE = "N"; $PUBLIC_VOTE_ID = intval($_REQUEST["PUBLIC_VOTE_ID"]); $aMsg = array(); $VOTE_ID = 0; $arVote = array(); $arQuestions = array(); if (!(!empty($_REQUEST["vote"]) && $PUBLIC_VOTE_ID > 0 && check_bitrix_sessid())) { $aMsg[] = array("id" => "bad_params", "text" => GetMessage("VOTE_NOT_FOUND")); } elseif (($VOTE_ID = intVal(GetVoteDataByID($PUBLIC_VOTE_ID, $arChannel, $arVote, $arQuestions, $arAnswers, $arDropDown, $arMultiSelect, $arGroupAnswers, "N"))) && ($VOTE_ID <= 0 || $arVote["LAMP"] != "green")) { $VOTING_LAMP = "red"; if ($VOTE_ID <= 0) { $aMsg[] = array("id" => "VOTE_ID", "text" => GetMessage("VOTE_NOT_FOUND")); } else { $aMsg[] = array("id" => "LAMP", "text" => GetMessage("VOTE_RED_LAMP")); } } elseif ($arChannel["USE_CAPTCHA"] == "Y" && !$USER->IsAuthorized()) { include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/captcha.php"; $cpt = new CCaptcha(); if (!empty($_REQUEST["captcha_word"])) { $captchaPass = COption::GetOptionString("main", "captcha_password", ""); if (!$cpt->CheckCodeCrypt($_REQUEST["captcha_word"], $_REQUEST["captcha_code"], $captchaPass)) { $GLOBALS["BAD_CAPTCHA"] = "Y"; $aMsg[] = array("id" => "CAPTCHA", "text" => GetMessage("VOTE_BAD_CAPTCHA")); } } else { if (!$cpt->CheckCode($_REQUEST["captcha_word"], 0)) { $GLOBALS["NO_CAPTCHA"] = "Y"; $aMsg[] = array("id" => "CAPTCHA", "text" => GetMessage("VOTE_BAD_CAPTCHA")); } } } if (empty($aMsg)) { // get user id $_SESSION["VOTE_USER_ID"] = CVote::SetVoteUserID(); $GLOBALS["VOTING_ID"] = $VOTE_ID; // check: can user vote $UNIQUE_TYPE = $arVote["UNIQUE_TYPE"]; $KEEP_IP_SEC = $arVote["KEEP_IP_SEC"]; $CHANNEL_ID = $arVote["CHANNEL_ID"]; $StatusVote = CVote::UserAlreadyVote($VOTE_ID, $_SESSION["VOTE_USER_ID"], $UNIQUE_TYPE, $KEEP_IP_SEC, $USER->GetID()); $USER_ALREADY_VOTE = $StatusVote != false ? "Y" : "N"; $USER_GROUP_PERMISSION = CVote::UserGroupPermission($CHANNEL_ID); // if user can vote that if (($USER_ALREADY_VOTE == "N" || $StatusVote == 8 && $_REQUEST["REVOTE_ID"] == $VOTE_ID) && $USER_GROUP_PERMISSION >= 2) { $arSqlAnswers = array(); // check answers foreach ($arQuestions as $qID => $arQuestion) { $arSqlAnswers[$arQuestion["ID"]] = array(); $bIndicators = array(); foreach ($arQuestion["ANSWERS"] as $arAnswer) { switch ($arAnswer["FIELD_TYPE"]) { case 0: // radio // radio case 2: // dropdown list $fieldName = ($arAnswer["FIELD_TYPE"] == 0 ? "vote_radio_" : "vote_dropdown_") . $qID; $aID = intval($GLOBALS[$fieldName]); if (!isset($bIndicators[$fieldName]) && array_key_exists($aID, $arQuestion["ANSWERS"])) { if (!empty($arAnswer['MESSAGE'])) { $arSqlAnswers[$qID][$aID] = array("ANSWER_ID" => $aID); } $bIndicators[$fieldName] = "Y"; } break; case 1: // checkbox // checkbox case 3: // multiselect list $fieldName = ($arAnswer["FIELD_TYPE"] == 1 ? "vote_checkbox_" : "vote_multiselect_") . $qID; $res = $GLOBALS[$fieldName]; if (!isset($bIndicators[$fieldName]) && is_array($res) && !empty($res)) { reset($res); foreach ($res as $aID) { if (array_key_exists($aID, $arQuestion["ANSWERS"])) { $arSqlAnswers[$qID][$aID] = array("ANSWER_ID" => $aID); } } $bIndicators[$fieldName] = "Y"; } break; case 4: // field // field case 5: // text $aID = $arAnswer["ID"]; $fieldName = ($arAnswer["FIELD_TYPE"] == 4 ? "vote_field_" : "vote_memo_") . $aID; $MESSAGE = trim($GLOBALS[$fieldName]); if ($MESSAGE != "") { $arSqlAnswers[$qID][$aID] = array("ANSWER_ID" => $aID, "MESSAGE" => "'" . $DB->ForSql(trim($MESSAGE), 2000) . "'"); } break; } } if (empty($arSqlAnswers[$qID])) { unset($arSqlAnswers[$qID]); if ($arQuestion['REQUIRED'] == 'Y') { $aMsg[] = array("id" => "QUESTION_" . $qID, "text" => GetMessage("VOTE_REQUIRED_MISSING")); $GLOBALS["VOTE_REQUIRED_MISSING"] = "Y"; break; } } } if (!empty($aMsg)) { /* do nothing; */ } elseif (!empty($arSqlAnswers)) { // vote event $arFields = array("VOTE_ID" => $VOTE_ID, "VOTE_USER_ID" => intval($_SESSION["VOTE_USER_ID"]), "DATE_VOTE" => $DB->GetNowFunction(), "STAT_SESSION_ID" => intval($_SESSION["SESS_SESSION_ID"]), "IP" => "'" . $DB->ForSql($_SERVER["REMOTE_ADDR"], 15) . "'", "VALID" => "'Y'"); /***************** Event onBeforeVoting ****************************/ foreach (GetModuleEvents("vote", "onBeforeVoting", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields, &$arSqlAnswers)) === false) { return false; } } /***************** /Event ******************************************/ if ($StatusVote == 8 && $_REQUEST["REVOTE_ID"] == $VOTE_ID) { $strSql = "SELECT VE.ID, VEQ.QUESTION_ID, VEA.ANSWER_ID" . " FROM b_vote_event VE " . "\tLEFT JOIN b_vote_event_question VEQ ON (VEQ.EVENT_ID=VE.ID)" . "\tLEFT JOIN b_vote_event_answer VEA ON (VEA.EVENT_QUESTION_ID=VEQ.ID)" . "\tLEFT JOIN b_vote_user VU ON (VE.VOTE_USER_ID = VU.ID)" . " WHERE VE.VOTE_ID=" . $VOTE_ID . " AND VU.AUTH_USER_ID=" . intval($USER->GetID()) . " ORDER BY VE.ID ASC, VEQ.QUESTION_ID ASC"; $db_res = $DB->Query($strSql, false, $err_mess . __LINE__); if ($db_res && ($res = $db_res->Fetch())) { if ($USER->GetID() > 0 && CModule::IncludeModule("im")) { CIMNotify::DeleteByTag("VOTING|" . $VOTE_ID, $USER->GetID()); } $del = false; $delQ = false; do { if ($delQ !== $res["QUESTION_ID"]) { if ($del !== $res["ID"]) { CVoteEvent::Delete($res["ID"]); $del = $res["ID"]; $arVote["COUNTER"] = intval($arVote["COUNTER"]) - 1; } $delQ = $res["QUESTION_ID"]; $arQuestions[$res["QUESTION_ID"]]["COUNTER"] = intval($arQuestions[$res["QUESTION_ID"]]["COUNTER"]) - 1; } $arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["COUNTER"] = intval($arQuestions[$res["QUESTION_ID"]]["ANSWERS"][$res["ANSWER_ID"]]["COUNTER"]) - 1; } while ($res = $db_res->Fetch()); } $USER_ALREADY_VOTE = "N"; } unset($GLOBALS["VOTE_CACHE_VOTING"][$VOTE_ID]); unset($GLOBALS["VOTE_CACHE"]["VOTE"][$VOTE_ID]); $EVENT_ID = intval($DB->Insert("b_vote_event", $arFields, $err_mess . __LINE__)); if ($EVENT_ID > 0) { $arSqlQuestionsID = array(); $arSqlAnswersID = array(); foreach ($arSqlAnswers as $qID => $arSqlAnswer) { $arFields = array("EVENT_ID" => $EVENT_ID, "QUESTION_ID" => $qID); $EVENT_QUESTION_ID = intval($DB->Insert("b_vote_event_question", $arFields, $err_mess . __LINE__)); if ($EVENT_QUESTION_ID > 0) { $arSqlQuestionsID[] = $qID; $arQuestions[$qID]["COUNTER"] = intval($arQuestions[$qID]["COUNTER"]) + 1; foreach ($arSqlAnswer as $aID => $res) { $res["EVENT_QUESTION_ID"] = $EVENT_QUESTION_ID; if ($DB->Insert("b_vote_event_answer", $res, $err_mess . __LINE__)) { $arSqlAnswersID[$aID] = $qID; $arQuestions[$qID]["ANSWERS"][$aID]["COUNTER"] = intval($arQuestions[$qID]["ANSWERS"][$aID]["COUNTER"]) + 1; } } } } if (empty($arSqlQuestionsID) || empty($arSqlAnswersID)) { $DB->Query("DELETE FROM b_vote_event WHERE ID=" . $EVENT_ID, $arFields, $err_mess . __LINE__); } else { $arFields = array("COUNTER" => "COUNTER+1"); $DB->Update("b_vote", $arFields, "WHERE ID='" . $VOTE_ID . "'", $err_mess . __LINE__); $arVote["COUNTER"] = intval($arVote["COUNTER"]) + 1; $DB->Update("b_vote_question", $arFields, "WHERE ID in (" . implode(", ", $arSqlQuestionsID) . ")", $err_mess . __LINE__); $DB->Update("b_vote_answer", $arFields, "WHERE ID in (" . implode(", ", array_keys($arSqlAnswersID)) . ")", $err_mess . __LINE__); // increment user counter CVote::UpdateVoteUserID($_SESSION["VOTE_USER_ID"]); $GLOBALS["VOTING_OK"] = "Y"; $_SESSION["VOTE_ARRAY"][] = $VOTE_ID; if ($UNIQUE_TYPE & 8) { $_SESSION["VOTE"]["VOTES"][$VOTE_ID] = $EVENT_ID; } // statistic module if (CModule::IncludeModule("statistic")) { $event3 = $arVote["EVENT3"]; if (!empty($event3)) { $event3 = "http://" . $_SERVER["HTTP_HOST"] . "/bitrix/admin/vote_user_results.php?EVENT_ID=" . $EVENT_ID . "&lang=" . LANGUAGE_ID; } CStatEvent::AddCurrent($arVote["EVENT1"], $arVote["EVENT2"], $event3); } // notification if (!!$arVote["AUTHOR_ID"] && $arVote["AUTHOR_ID"] != $USER->GetID()) { if (empty($arVote["TITLE"])) { $arQuestion = reset($arQuestions); $arVote["TITLE"] = $arQuestion["QUESTION"]; } if ($arVote["NOTIFY"] == "I" && CModule::IncludeModule("im")) { $arVote["TOTAL_URL"] = ""; if (!empty($arVote["URL"])) { if (defined('SITE_SERVER_NAME')) { $arVote["TOTAL_URL"] = SITE_SERVER_NAME; } $arVote["TOTAL_URL"] = !empty($arVote["TOTAL_URL"]) ? $arVote["TOTAL_URL"] : COption::GetOptionString("main", "server_name", $GLOBALS["SERVER_NAME"]); if (!empty($arVote["TOTAL_URL"])) { $arVote["TOTAL_URL"] = (CMain::IsHTTPS() ? "https" : "http") . "://" . $arVote["TOTAL_URL"] . $arVote["URL"]; } } // send notification $gender = $USER->getParam("PERSONAL_GENDER") == "F" ? "_F" : ""; $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arVote["AUTHOR_ID"], "FROM_USER_ID" => $USER->GetID(), "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "vote", "NOTIFY_EVENT" => "voting", "NOTIFY_TAG" => "VOTING|" . $VOTE_ID, "NOTIFY_MESSAGE" => !empty($arVote["URL"]) ? GetMessage("V_NOTIFY_MESSAGE_HREF" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"], "#VOTE_URL#" => $arVote["URL"])) : GetMessage("V_NOTIFY_MESSAGE" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"])), "NOTIFY_MESSAGE_OUT" => !empty($arVote["TOTAL_URL"]) ? GetMessage("V_NOTIFY_MESSAGE_OUT_HREF" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"], "#VOTE_URL#" => $arVote["TOTAL_URL"])) : GetMessage("V_NOTIFY_MESSAGE" . $gender, array("#VOTE_TITLE#" => $arVote["TITLE"]))); CIMNotify::Add($arMessageFields); } else { if ($arVote["NOTIFY"] == "Y") { // send e-mail $db_user = CUser::GetById($arVote["AUTHOR_ID"]); if ($db_user && ($arUser = $db_user->Fetch()) && !empty($arUser["EMAIL"])) { $arEventFields = array("EMAIL_TO" => $arUser["EMAIL"], "VOTE_STATISTIC" => "", "ID" => $EVENT_ID, "TIME" => GetTime(time(), "FULL"), "VOTE_TITLE" => $arVote["TITLE"], "VOTE_DESCRIPTION" => $arVote["DESCRIPTION"], "VOTE_ID" => $arVote["ID"], "VOTE_COUNTER" => $arVote["COUNTER"], "URL" => $arVote["URL"], "CHANNEL" => $arChannel["TITLE"], "CHANNEL_ID" => $arChannel["ID"], "VOTER_ID" => $_SESSION["VOTE_USER_ID"], "USER_NAME" => $USER->GetFullName(), "LOGIN" => $USER->GetLogin(), "USER_ID" => $USER->GetID(), "STAT_GUEST_ID" => intval($_SESSION["SESS_GUEST_ID"]), "SESSION_ID" => intval($_SESSION["SESS_SESSION_ID"]), "IP" => $_SERVER["REMOTE_ADDR"]); $arEventFields["USER_NAME"] = !!$arEventFields["USER_NAME"] ? $arEventFields["USER_NAME"] : $arEventFields["LOGIN"]; // VOTE_STATISTIC $text = array(); foreach ($arSqlAnswersID as $aID => $qID) { $text[$qID] = is_array($text[$qID]) ? $text[$qID] : array(); if ($arQuestions[$qID]["ANSWERS"][$aID]["FIELD_TYPE"] == 4 || $arQuestions[$qID]["ANSWERS"][$aID]["FIELD_TYPE"] == 5) { if (!empty($arSqlAnswers[$qID][$aID]["MESSAGE"])) { $text[$qID][] = $arSqlAnswers[$qID][$aID]["MESSAGE"]; } } else { $text[$qID][] = $arQuestions[$qID]["ANSWERS"][$aID]["MESSAGE"]; } } foreach ($text as $qID => $txt) { $text[$qID] = " - " . $arQuestions[$qID]["QUESTION"] . "\n - " . implode(", ", $text[$qID]); } $arEventFields["VOTE_STATISTIC"] = "\n" . implode("\n\n", $text); $arrSites = CVoteChannel::GetSiteArray($arChannel["ID"]); CEvent::Send("VOTE_FOR", $arrSites, $arEventFields, "N"); } } } } } /***************** Event onAfterVoting *****************************/ foreach (GetModuleEvents("vote", "onAfterVoting", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($VOTE_ID, $EVENT_ID)); } /***************** /Event ******************************************/ } } else { $GLOBALS["USER_VOTE_EMPTY"] = "Y"; $aMsg[] = array("id" => "VOTE_ID", "text" => GetMessage("USER_VOTE_EMPTY")); } } else { $aMsg[] = array("id" => "VOTE_ID", "text" => $USER_GROUP_PERMISSION >= 2 ? GetMessage("VOTE_ALREADY_VOTE") : GetMessage("VOTE_ACCESS_DENIED")); } } if (!empty($aMsg)) { $e = new CAdminException($aMsg, "CVote::KeepVoting"); $GLOBALS["APPLICATION"]->ThrowException($e); $GLOBALS["VOTING_OK"] = "N"; return false; } return true; }
function RejectRequestToBeFriend($senderUserID, $relationID) { global $APPLICATION; $senderUserID = IntVal($senderUserID); if ($senderUserID <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_EMPTY_SENDER_USER_ID"), "ERROR_SENDER_USER_ID"); return false; } $relationID = IntVal($relationID); if ($relationID <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_EMPTY_TARGET_USER_ID"), "ERROR_RELATION_ID"); return false; } $dbResult = CSocNetUserRelations::GetList( array(), array( "ID" => $relationID, "SECOND_USER_ID" => $senderUserID, "RELATION" => SONET_RELATIONS_REQUEST ), false, false, array("ID", "FIRST_USER_ID") ); if ($arResult = $dbResult->Fetch()) { if (CSocNetUserRelations::Delete($arResult["ID"])) { if (CModule::IncludeModule("im")) { CIMNotify::DeleteByTag("SOCNET|INVITE_USER|".intval($senderUserID)."|".intval($arResult["ID"])); $arMessageFields = array( "MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arResult["FIRST_USER_ID"], "FROM_USER_ID" => $senderUserID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "socialnetwork", "NOTIFY_EVENT" => "invite_user", "NOTIFY_TAG" => "SOCNET|INVITE_USER_REJECT", "NOTIFY_MESSAGE" => GetMessage("SONET_UR_REJECT_FRIEND_MESSAGE"), ); CIMNotify::Add($arMessageFields); } else { $arMessageFields = array( "FROM_USER_ID" => $senderUserID, "TO_USER_ID" => $arResult["FIRST_USER_ID"], "MESSAGE" => GetMessage("SONET_UR_REJECT_FRIEND_MESSAGE"), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM ); CSocNetMessages::Add($arMessageFields); } } else { $errorMessage = ""; if ($e = $APPLICATION->GetException()) $errorMessage = $e->GetString(); if (StrLen($errorMessage) <= 0) $errorMessage = GetMessage("SONET_UR_RELATION_DELETE_ERROR"); $GLOBALS["APPLICATION"]->ThrowException($errorMessage, "ERROR_DELETE_RELATION"); return false; } } else { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_UR_NO_FRIEND_REQUEST"), "ERROR_NO_FRIEND_REQUEST"); return false; } CSocNetUserRelations::__SpeedFileCheckMessages($senderUserID); return true; }
function NotifyImToModerators($arNotifyParams) { if (!CModule::IncludeModule("im")) { return; } if (!is_array($arNotifyParams) || !array_key_exists("TYPE", $arNotifyParams) || !in_array($arNotifyParams["TYPE"], array("join", "unjoin", "exclude", "moderate", "unmoderate", "owner")) || !array_key_exists("USER_ID", $arNotifyParams) || intval($arNotifyParams["USER_ID"]) <= 0 || !array_key_exists("GROUP_ID", $arNotifyParams) || intval($arNotifyParams["GROUP_ID"]) <= 0 || !array_key_exists("RELATION_ID", $arNotifyParams) || intval($arNotifyParams["RELATION_ID"]) <= 0 || !array_key_exists("GROUP_NAME", $arNotifyParams) || strlen($arNotifyParams["GROUP_NAME"]) <= 0) { return; } switch ($arNotifyParams["TYPE"]) { case "join": $from_user_id = $arNotifyParams["USER_ID"]; $message_code = "SONET_UG_IM_JOIN"; $schema_code = "inout_group"; $notify_tag = "INOUT_GROUP"; break; case "unjoin": $from_user_id = $arNotifyParams["USER_ID"]; $message_code = "SONET_UG_IM_UNJOIN"; $schema_code = "inout_group"; $notify_tag = "INOUT_GROUP"; break; case "exclude": $from_user_id = $arNotifyParams["USER_ID"]; $message_code = "SONET_UG_IM_EXCLUDE"; $schema_code = "inout_group"; $notify_tag = "INOUT_GROUP"; break; case "moderate": $from_user_id = $arNotifyParams["USER_ID"]; $message_code = "SONET_UG_IM_MODERATE"; $schema_code = "moderators_group"; $notify_tag = "MOD_GROUP"; break; case "unmoderate": $from_user_id = $arNotifyParams["USER_ID"]; $message_code = "SONET_UG_IM_UNMODERATE"; $schema_code = "moderators_group"; $notify_tag = "MOD_GROUP"; break; case "owner": $from_user_id = $arNotifyParams["USER_ID"]; $message_code = "SONET_UG_IM_OWNER"; $schema_code = "owner_group"; $notify_tag = "OWNER_GROUP"; break; default: } $rsUser = CUser::GetByID($arNotifyParams["USER_ID"]); if ($arUser = $rsUser->Fetch()) { switch ($arUser["PERSONAL_GENDER"]) { case "M": $gender_suffix = "_M"; break; case "F": $gender_suffix = "_F"; break; default: $gender_suffix = ""; } } $arToUserID = array(); $rsUserToGroup = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $arNotifyParams["GROUP_ID"], "USER_ACTIVE" => "Y", "<=ROLE" => SONET_ROLES_MODERATOR), false, false, array("USER_ID")); while ($arUserToGroup = $rsUserToGroup->Fetch()) { $arToUserID[] = $arUserToGroup["USER_ID"]; } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $from_user_id, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "socialnetwork", "NOTIFY_EVENT" => $schema_code, "LOG_ID" => $arEntry["LOG_ID"], "NOTIFY_TAG" => "SOCNET|" . $notify_tag . "|" . intval($arNotifyParams["USER_ID"]) . "|" . intval($arNotifyParams["GROUP_ID"]) . "|" . intval($arNotifyParams["RELATION_ID"])); $groups_path = COption::GetOptionString("socialnetwork", "workgroups_page", SITE_DIR . "workgroups/"); $group_url_template = str_replace($groups_path, "#GROUPS_PATH#", COption::GetOptionString("socialnetwork", "group_path_template", SITE_DIR . "workgroups/group/#group_id#/")); $groupUrl = str_replace("#group_id#", $arNotifyParams["GROUP_ID"], $group_url_template); foreach ($arToUserID as $to_user_id) { if (is_array($arNotifyParams["EXCLUDE_USERS"]) && in_array($to_user_id, $arNotifyParams["EXCLUDE_USERS"]) || $to_user_id == $from_user_id) { continue; } $arMessageFields["TO_USER_ID"] = $to_user_id; $arTmp = CSocNetLogTools::ProcessPath(array("GROUP_PAGE" => $groupUrl), $to_user_id, SITE_ID); $arMessageFields["NOTIFY_MESSAGE"] = GetMessage($message_code . $gender_suffix, array("#group_name#" => "<a href=\"" . $arTmp["URLS"]["GROUP_PAGE"] . "\" class=\"bx-notifier-item-action\">" . $arNotifyParams["GROUP_NAME"] . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage($message_code . $gender_suffix, array("#group_name#" => $arNotifyParams["GROUP_NAME"])) . " (" . $arTmp["SERVER_NAME"] . $arTmp["URLS"]["GROUP_PAGE"] . ")"; CIMNotify::Add($arMessageFields); } }
public static function ReminderAgent($eventId = 0, $userId = 0, $viewPath = '', $calendarType = '', $ownerId = 0) { if ($eventId > 0 && $userId > 0 && $calendarType != '') { if (!CModule::IncludeModule("im")) { return false; } $skipReminding = false; global $USER; // Create tmp user if ($bTmpUser = !$USER || !is_object($USER)) { $USER = new CUser(); } // We have to use this to set timezone offset to local user's timezone self::SetOffset(false, self::GetOffset($userId)); $arEvents = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "DELETED" => "N", "FROM_LIMIT" => CCalendar::Date(time() - 3600, false), "TO_LIMIT" => CCalendar::Date(CCalendar::GetMaxTimestamp(), false)), 'parseRecursion' => true, 'maxInstanceCount' => 2, 'preciseLimits' => true, 'fetchAttendees' => true, 'checkPermissions' => false, 'setDefaultLimit' => false)); if ($arEvents && is_array($arEvents[0])) { $Event = $arEvents[0]; } if ($Event && $Event['IS_MEETING'] && is_array($Event['~ATTENDEES'])) { foreach ($Event['~ATTENDEES'] as $attendee) { // If current user is an attendee but his status is 'N' we don't take care about reminding if ($attendee['USER_ID'] == $userId && $attendee['STATUS'] == 'N') { $skipReminding = true; break; } } } if ($Event && $Event['DELETED'] != 'Y' && !$skipReminding) { // Get Calendar Info $Section = CCalendarSect::GetById($Event['SECT_ID'], false); if ($Section) { $arNotifyFields = array('FROM_USER_ID' => $userId, 'TO_USER_ID' => $userId, 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM, 'NOTIFY_MODULE' => "calendar", 'NOTIFY_EVENT' => "reminder", 'NOTIFY_TAG' => "CALENDAR|INVITE|" . $eventId . "|" . $userId . "|REMINDER", 'NOTIFY_SUB_TAG' => "CALENDAR|INVITE|" . $eventId); $arNotifyFields['MESSAGE'] = GetMessage('EC_EVENT_REMINDER', array('#EVENT_NAME#' => $Event["NAME"], '#DATE_FROM#' => CCalendar::CutZeroTime($Event["DT_FROM"]))); $sectionName = $Section['NAME']; $ownerName = CCalendar::GetOwnerName($calendarType, $ownerId); if ($calendarType == 'user' && $ownerId == $userId) { $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_PERSONAL', array('#CALENDAR_NAME#' => $sectionName)); } else { if ($calendarType == 'user') { $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_USER', array('#CALENDAR_NAME#' => $sectionName, '#USER_NAME#' => $ownerName)); } else { if ($calendarType == 'group') { $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_GROUP', array('#CALENDAR_NAME#' => $sectionName, '#GROUP_NAME#' => $ownerName)); } else { $arNotifyFields['MESSAGE'] .= ' ' . GetMessage('EC_EVENT_REMINDER_IN_COMMON', array('#CALENDAR_NAME#' => $sectionName, '#IBLOCK_NAME#' => $ownerName)); } } } if ($viewPath != '') { $arNotifyFields['MESSAGE'] .= "\n" . GetMessage('EC_EVENT_REMINDER_DETAIL', array('#URL_VIEW#' => $viewPath)); } CIMNotify::Add($arNotifyFields); foreach (GetModuleEvents("calendar", "OnRemindEvent", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(array('eventId' => $eventId, 'userId' => $userId, 'viewPath' => $viewPath, 'calType' => $calendarType, 'ownerId' => $ownerId))); } if (CCalendarEvent::CheckRecurcion($Event) && ($nextEvent = $arEvents[1])) { $remAgentParams = array('eventId' => $eventId, 'userId' => $userId, 'viewPath' => $viewPath, 'calendarType' => $calendarType, 'ownerId' => $ownerId); // 1. clean reminders CCalendar::RemoveAgent($remAgentParams); // 2. Set new reminders $startTs = $nextEvent['DT_FROM_TS']; $reminder = $nextEvent['REMIND'][0]; if ($reminder) { $delta = intVal($reminder['count']) * 60; //Minute if ($reminder['type'] == 'hour') { $delta = $delta * 60; } elseif ($reminder['type'] == 'day') { $delta = $delta * 60 * 24; } //Day if ($startTs - $delta >= time() - 60 * 10) { // Inaccuracy - 10 min CCalendar::AddAgent(CCalendar::Date($startTs - $delta), $remAgentParams); } } } } } self::$offset = null; if (isset($bTmpUser) && $bTmpUser) { unset($USER); } } }
protected function processActionNotifyAdmin() { $this->checkRequiredPostParams(array('userId')); if (!Loader::includeModule('im')) { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_CONNECTION_MODULE_IM')))); } if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $this->iblockId = intval($this->request->getPost('iblockId')); $this->iblockTypeId = COption::GetOptionString("lists", "livefeed_iblock_type_id"); $siteId = SITE_ID; if ($this->request->getPost('siteId')) { $siteId = $this->request->getPost('siteId'); } $siteDir = SITE_DIR; if ($this->request->getPost('siteId')) { $siteDir = $this->request->getPost('siteDir'); } $this->checkPermissionElement(); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $userIdFrom = intval($this->getUser()->getID()); $userIdTo = intval($this->request->getPost('userId')); $iblockName = $this->request->getPost('iblockName'); if (SITE_TEMPLATE_ID == 'bitrix24') { $urlForAdmin = '/?bp_setting=' . $this->iblockId; } else { $urlForAdmin = COption::GetOptionString('socialnetwork', 'user_page', false, $siteId); $urlForAdmin = $urlForAdmin ? $urlForAdmin : $siteDir . 'company/personal/'; $urlForAdmin = $urlForAdmin . 'log/?bp_setting=' . $this->iblockId; } $messageFields = array('TO_USER_ID' => $userIdTo, 'FROM_USER_ID' => $userIdFrom, 'NOTIFY_TYPE' => IM_NOTIFY_FROM, 'NOTIFY_MODULE' => 'lists', 'NOTIFY_TAG' => 'LISTS|NOTIFY_ADMIN|' . $userIdTo . '|' . $userIdFrom, 'NOTIFY_MESSAGE' => Loc::getMessage('LISTS_SEAC_NOTIFY_MESSAGE', array('#NAME_PROCESSES#' => $iblockName, '#URL#' => $urlForAdmin))); $messageId = CIMNotify::Add($messageFields); if ($messageId) { $this->sendJsonSuccessResponse(array('message' => Loc::getMessage('LISTS_SEAC_NOTIFY_SUCCESS'))); } else { $this->errorCollection->add(array(new Error(Loc::getMessage('LISTS_SEAC_NOTIFY_ERROR')))); $this->sendJsonErrorResponse(); } }
public function Update($ID, array &$arFields, $bCompare = true, $bUpdateSearch = true, $options = array()) { global $DB; $this->LAST_ERROR = ''; $ID = (int) $ID; if (!is_array($options)) { $options = array(); } $arFilterTmp = array('ID' => $ID); if (!$this->bCheckPermission) { $arFilterTmp['CHECK_PERMISSIONS'] = 'N'; } $obRes = self::GetListEx(array(), $arFilterTmp); if (!($arRow = $obRes->Fetch())) { return false; } $iUserId = CCrmSecurityHelper::GetCurrentUserID(); if (isset($arFields['DATE_CREATE'])) { unset($arFields['DATE_CREATE']); } if (isset($arFields['DATE_MODIFY'])) { unset($arFields['DATE_MODIFY']); } $arFields['~DATE_MODIFY'] = $DB->CurrentTimeFunction(); if (!isset($arFields['MODIFY_BY_ID']) || $arFields['MODIFY_BY_ID'] <= 0) { $arFields['MODIFY_BY_ID'] = $iUserId; } if (isset($arFields['ASSIGNED_BY_ID']) && $arFields['ASSIGNED_BY_ID'] <= 0) { unset($arFields['ASSIGNED_BY_ID']); } $assignedByID = (int) (isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']); $bResult = false; if (!$this->CheckFields($arFields, $ID, $options)) { $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; } else { if ($this->bCheckPermission && !CCrmAuthorizationHelper::CheckUpdatePermission(self::$TYPE_NAME, $ID, $this->cPerms)) { $this->LAST_ERROR = GetMessage('CRM_PERMISSION_DENIED'); $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; return false; } $beforeEvents = GetModuleEvents('crm', 'OnBeforeCrmDealUpdate'); while ($arEvent = $beforeEvents->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { if (isset($arFields['RESULT_MESSAGE'])) { $this->LAST_ERROR = $arFields['RESULT_MESSAGE']; } else { $this->LAST_ERROR = GetMessage('CRM_DEAL_UPDATE_CANCELED', array('#NAME#' => $arEvent['TO_NAME'])); $arFields['RESULT_MESSAGE'] =& $this->LAST_ERROR; } return false; } } $arAttr = array(); $arAttr['STAGE_ID'] = !empty($arFields['STAGE_ID']) ? $arFields['STAGE_ID'] : $arRow['STAGE_ID']; $arAttr['OPENED'] = !empty($arFields['OPENED']) ? $arFields['OPENED'] : $arRow['OPENED']; $arEntityAttr = self::BuildEntityAttr($assignedByID, $arAttr); $sEntityPerm = $this->cPerms->GetPermType('DEAL', 'WRITE', $arEntityAttr); $this->PrepareEntityAttrs($arEntityAttr, $sEntityPerm); //Prevent 'OPENED' field change by user restricted by BX_CRM_PERM_OPEN permission if ($sEntityPerm === BX_CRM_PERM_OPEN && isset($arFields['OPENED']) && $arFields['OPENED'] !== 'Y' && $assignedByID !== $iUserId) { $arFields['OPENED'] = 'Y'; } if (isset($arFields['ASSIGNED_BY_ID']) && $arRow['ASSIGNED_BY_ID'] != $arFields['ASSIGNED_BY_ID']) { CCrmEvent::SetAssignedByElement($arFields['ASSIGNED_BY_ID'], 'DEAL', $ID); } $sonetEventData = array(); if ($bCompare) { $arEvents = self::CompareFields($arRow, $arFields, $this->bCheckPermission); foreach ($arEvents as $arEvent) { $arEvent['ENTITY_TYPE'] = 'DEAL'; $arEvent['ENTITY_ID'] = $ID; $arEvent['EVENT_TYPE'] = 1; if (!isset($arEvent['USER_ID'])) { $arEvent['USER_ID'] = $iUserId; } $CCrmEvent = new CCrmEvent(); $eventID = $CCrmEvent->Add($arEvent, $this->bCheckPermission); if (is_int($eventID) && $eventID > 0) { $fieldID = isset($arEvent['ENTITY_FIELD']) ? $arEvent['ENTITY_FIELD'] : ''; if ($fieldID === '') { continue; } switch ($fieldID) { case 'STAGE_ID': $sonetEventData[CCrmLiveFeedEvent::Progress] = array('TYPE' => CCrmLiveFeedEvent::Progress, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_STAGE'), 'MESSAGE' => '', 'PARAMS' => array('START_STATUS_ID' => $arRow['STAGE_ID'], 'FINAL_STATUS_ID' => $arFields['STAGE_ID']))); break; case 'ASSIGNED_BY_ID': $sonetEventData[CCrmLiveFeedEvent::Responsible] = array('TYPE' => CCrmLiveFeedEvent::Responsible, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_ASSIGNED_BY'), 'MESSAGE' => '', 'PARAMS' => array('START_RESPONSIBLE_ID' => $arRow['ASSIGNED_BY_ID'], 'FINAL_RESPONSIBLE_ID' => $arFields['ASSIGNED_BY_ID']))); break; case 'CONTACT_ID': case 'COMPANY_ID': if (!isset($sonetEventData[CCrmLiveFeedEvent::Client])) { $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0; $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0; $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => $oldContactID, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : $oldContactID, 'START_CLIENT_COMPANY_ID' => $oldCompanyID, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : $oldCompanyID))); } break; case 'TITLE': $sonetEventData[CCrmLiveFeedEvent::Denomination] = array('TYPE' => CCrmLiveFeedEvent::Denomination, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_TITLE'), 'MESSAGE' => '', 'PARAMS' => array('START_TITLE' => $arRow['TITLE'], 'FINAL_TITLE' => $arFields['TITLE']))); break; } } } // CHECK IF COMPANY/CONTACT WAS ADDED/REMOVED if (!isset($sonetEventData[CCrmLiveFeedEvent::Client]) && (!isset($arRow['COMPANY_ID']) && isset($arFields['COMPANY_ID']) || isset($arRow['COMPANY_ID']) && !isset($arFields['COMPANY_ID']) || !isset($arRow['CONTACT_ID']) && isset($arFields['CONTACT_ID']) || isset($arRow['CONTACT_ID']) && !isset($arFields['CONTACT_ID']))) { $sonetEventData[CCrmLiveFeedEvent::Client] = array('CODE' => 'CLIENT', 'TYPE' => CCrmLiveFeedEvent::Client, 'FIELDS' => array('TITLE' => GetMessage('CRM_DEAL_EVENT_UPDATE_CLIENT'), 'MESSAGE' => '', 'PARAMS' => array('START_CLIENT_CONTACT_ID' => isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0, 'FINAL_CLIENT_CONTACT_ID' => isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0, 'START_CLIENT_COMPANY_ID' => isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0, 'FINAL_CLIENT_COMPANY_ID' => isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0))); } } // Calculation of Account Data $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['OPPORTUNITY']) ? $arFields['OPPORTUNITY'] : (isset($arRow['OPPORTUNITY']) ? $arRow['OPPORTUNITY'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null))); if (is_array($accData)) { $arFields['ACCOUNT_CURRENCY_ID'] = $accData['ACCOUNT_CURRENCY_ID']; $arFields['OPPORTUNITY_ACCOUNT'] = $accData['ACCOUNT_SUM']; } $accData = CCrmAccountingHelper::PrepareAccountingData(array('CURRENCY_ID' => isset($arFields['CURRENCY_ID']) ? $arFields['CURRENCY_ID'] : (isset($arRow['CURRENCY_ID']) ? $arRow['CURRENCY_ID'] : null), 'SUM' => isset($arFields['TAX_VALUE']) ? $arFields['TAX_VALUE'] : (isset($arRow['TAX_VALUE']) ? $arRow['TAX_VALUE'] : null), 'EXCH_RATE' => isset($arFields['EXCH_RATE']) ? $arFields['EXCH_RATE'] : (isset($arRow['EXCH_RATE']) ? $arRow['EXCH_RATE'] : null))); if (is_array($accData)) { $arFields['TAX_VALUE_ACCOUNT'] = $accData['ACCOUNT_SUM']; } $enableCloseDateSync = \Bitrix\Crm\Settings\DealSettings::isCloseDateSyncEnabled(); if (isset($arFields['STAGE_ID'])) { $now = ConvertTimeStamp(time(), 'SHORT', SITE_ID); $isFinalStage = self::GetStageSemantics($arFields['STAGE_ID']) !== 'process'; $isStageChanged = !isset($arRow['STAGE_ID']) || $arRow['STAGE_ID'] !== $arFields['STAGE_ID']; $arFields['CLOSED'] = $isFinalStage ? 'Y' : 'N'; if ($enableCloseDateSync && $isFinalStage && $isStageChanged) { $arFields['CLOSEDATE'] = $now; $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($now, 'SHORT', false); } elseif (isset($arFields['CLOSEDATE']) && $arFields['CLOSEDATE'] !== '') { $arFields['~CLOSEDATE'] = $DB->CharToDateFunction($arFields['CLOSEDATE'], 'SHORT', false); } } elseif ($enableCloseDateSync && self::GetStageSemantics($arRow['STAGE_ID']) !== 'process' && isset($arFields['CLOSEDATE'])) { unset($arFields['CLOSEDATE']); } if (isset($arFields['BEGINDATE']) && $arFields['BEGINDATE'] !== '') { $arFields['~BEGINDATE'] = $DB->CharToDateFunction($arFields['BEGINDATE'], 'SHORT', false); } if (isset($arFields['BEGINDATE'])) { $arFields['__BEGINDATE'] = $arFields['BEGINDATE']; unset($arFields['BEGINDATE']); } if (isset($arFields['CLOSEDATE'])) { $arFields['__CLOSEDATE'] = $arFields['CLOSEDATE']; unset($arFields['CLOSEDATE']); } unset($arFields['ID']); $sUpdate = $DB->PrepareUpdate('b_crm_deal', $arFields); if (strlen($sUpdate) > 0) { $DB->Query("UPDATE b_crm_deal SET {$sUpdate} WHERE ID = {$ID}", false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $bResult = true; } //Restore BEGINDATE and CLOSEDATE if (isset($arFields['__BEGINDATE'])) { $arFields['BEGINDATE'] = $arFields['__BEGINDATE']; unset($arFields['__BEGINDATE']); } if (isset($arFields['__CLOSEDATE'])) { $arFields['CLOSEDATE'] = $arFields['__CLOSEDATE']; unset($arFields['__CLOSEDATE']); } if (defined("BX_COMP_MANAGED_CACHE")) { static $arNameFields = array("TITLE"); $bClear = false; foreach ($arNameFields as $val) { if (isset($arFields[$val])) { $bClear = true; break; } } if ($bClear) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("crm_entity_name_" . CCrmOwnerType::Deal . "_" . $ID); } } CCrmPerms::UpdateEntityAttr('DEAL', $ID, $arEntityAttr); CCrmEntityHelper::NormalizeUserFields($arFields, self::$sUFEntityID, $GLOBALS['USER_FIELD_MANAGER'], array('IS_NEW' => false)); $GLOBALS['USER_FIELD_MANAGER']->Update(self::$sUFEntityID, $ID, $arFields); //Statistics & History --> $currentDbResult = \CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*')); $currentFields = $currentDbResult->Fetch(); Bitrix\Crm\Statistics\DealSumStatisticEntry::register($ID, $currentFields); Bitrix\Crm\History\DealStageHistoryEntry::synchronize($ID, $currentFields); Bitrix\Crm\Statistics\DealInvoiceStatisticEntry::synchronize($ID, $currentFields); Bitrix\Crm\Statistics\DealActivityStatisticEntry::synchronize($ID, $currentFields); if (isset($arFields['STAGE_ID'])) { Bitrix\Crm\History\DealStageHistoryEntry::register($ID, $arFields, array('IS_NEW' => false)); } //<-- Statistics & History if ($bUpdateSearch) { $arFilterTmp = array('ID' => $ID); if (!$this->bCheckPermission) { $arFilterTmp['CHECK_PERMISSIONS'] = 'N'; } CCrmSearch::UpdateSearch($arFilterTmp, 'DEAL', true); } $arFields['ID'] = $ID; if (isset($arFields['FM']) && is_array($arFields['FM'])) { $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmFieldMulti->SetFields('DEAL', $ID, $arFields['FM']); } // Responsible user sync //CCrmActivity::Synchronize(CCrmOwnerType::Deal, $ID); $registerSonetEvent = isset($options['REGISTER_SONET_EVENT']) && $options['REGISTER_SONET_EVENT'] === true; if ($bResult && isset($arFields['ASSIGNED_BY_ID'])) { CCrmSonetSubscription::ReplaceSubscriptionByEntity(CCrmOwnerType::Deal, $ID, CCrmSonetSubscriptionType::Responsibility, $arFields['ASSIGNED_BY_ID'], $arRow['ASSIGNED_BY_ID'], $registerSonetEvent); } if ($bResult && $bCompare && $registerSonetEvent && !empty($sonetEventData)) { //CONTACT $newContactID = isset($arFields['CONTACT_ID']) ? intval($arFields['CONTACT_ID']) : 0; $oldContactID = isset($arRow['CONTACT_ID']) ? intval($arRow['CONTACT_ID']) : 0; $contactID = $newContactID > 0 ? $newContactID : $oldContactID; //COMPANY $newCompanyID = isset($arFields['COMPANY_ID']) ? intval($arFields['COMPANY_ID']) : 0; $oldCompanyID = isset($arRow['COMPANY_ID']) ? intval($arRow['COMPANY_ID']) : 0; $companyID = $newCompanyID > 0 ? $newCompanyID : $oldCompanyID; $modifiedByID = intval($arFields['MODIFY_BY_ID']); foreach ($sonetEventData as &$sonetEvent) { $sonetEventType = $sonetEvent['TYPE']; $sonetEventCode = isset($sonetEvent['CODE']) ? $sonetEvent['CODE'] : ''; $sonetEventFields =& $sonetEvent['FIELDS']; $sonetEventFields['ENTITY_TYPE_ID'] = CCrmOwnerType::Deal; $sonetEventFields['ENTITY_ID'] = $ID; $sonetEventFields['USER_ID'] = $modifiedByID; //Register contact & company relations if ($sonetEventCode === 'CLIENT') { $sonetEventFields['PARENTS'] = array(); //If contact changed bind events to old and new contacts if ($oldContactID !== $newContactID) { if ($oldContactID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $oldContactID); } if ($newContactID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $newContactID); } } //If company changed bind events to old and new companies if ($oldCompanyID !== $newCompanyID) { if ($oldCompanyID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $oldCompanyID); } if ($newCompanyID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $newCompanyID); } } } elseif ($contactID > 0 || $companyID > 0) { $sonetEventFields['PARENTS'] = array(); if ($contactID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID); } if ($companyID > 0) { $sonetEventFields['PARENTS'][] = array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID); } } $logEventID = CCrmLiveFeed::CreateLogEvent($sonetEventFields, $sonetEventType); if ($logEventID && CModule::IncludeModule("im")) { $url = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $ID); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'] != $modifiedByID) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['FINAL_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")"); CIMNotify::Add($arMessageFields); } if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Responsible && $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'] != $modifiedByID) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $sonetEventFields['PARAMS']['START_RESPONSIBLE_ID'], "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_RESPONSIBLE|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>")), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']))) . " (" . $serverName . $url . ")"); CIMNotify::Add($arMessageFields); } if ($sonetEvent['TYPE'] == CCrmLiveFeedEvent::Progress && $sonetEventFields['PARAMS']['START_STATUS_ID'] && $sonetEventFields['PARAMS']['FINAL_STATUS_ID']) { $assignedByID = isset($arFields['ASSIGNED_BY_ID']) ? $arFields['ASSIGNED_BY_ID'] : $arRow['ASSIGNED_BY_ID']; $infos = CCrmStatus::GetStatus('DEAL_STAGE'); if ($assignedByID != $modifiedByID && array_key_exists($sonetEventFields['PARAMS']['START_STATUS_ID'], $infos) && array_key_exists($sonetEventFields['PARAMS']['FINAL_STATUS_ID'], $infos)) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $assignedByID, "FROM_USER_ID" => $modifiedByID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $logEventID, "NOTIFY_EVENT" => "deal_update", "NOTIFY_TAG" => "CRM|DEAL_PROGRESS|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arFields['TITLE']) . "</a>", "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_DEAL_PROGRESS_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['TITLE']), "#start_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['START_STATUS_ID']]['NAME']), "#final_status_title#" => htmlspecialcharsbx($infos[$sonetEventFields['PARAMS']['FINAL_STATUS_ID']]['NAME']))) . " (" . $serverName . $url . ")"); CIMNotify::Add($arMessageFields); } } } unset($sonetEventFields); } unset($sonetEvent); } if ($bResult) { $afterEvents = GetModuleEvents('crm', 'OnAfterCrmDealUpdate'); while ($arEvent = $afterEvents->Fetch()) { ExecuteModuleEventEx($arEvent, array(&$arFields)); } } self::PullChange('UPDATE', array('ID' => $ID)); } return $bResult; }