Ejemplo n.º 1
0
 public static function Increment($log_id, $entity_type = false, $entity_id = false, $event_id = false, $created_by_id = false, $arOfEntities = false, $arAdmin = false, $transport = false, $visible = "Y", $type = "L")
 {
     global $DB;
     if (intval($log_id) <= 0) {
         return false;
     }
     $counter = new CSocNetLogCounter();
     $subSelect = $counter->GetSubSelect($log_id, $entity_type, $entity_id, $event_id, $created_by_id, $arOfEntities, $arAdmin, $transport, $visible, $type);
     if (strlen($subSelect) > 0) {
         $strSQL = "INSERT INTO b_sonet_log_counter (USER_ID, CNT, SITE_ID, CODE) (" . $subSelect . ") ON DUPLICATE KEY UPDATE CNT = CNT + 1";
         $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     }
     $subSelect = $counter->GetSubSelect($log_id, $entity_type, $entity_id, $event_id, $created_by_id, $arOfEntities, $arAdmin, $transport, $visible, "group");
     if (strlen($subSelect) > 0) {
         $strSQL = "INSERT INTO b_sonet_log_counter (USER_ID, CNT, SITE_ID, CODE) (" . $subSelect . ") ON DUPLICATE KEY UPDATE CNT = CNT + 1";
         $DB->Query($strSQL, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
     }
 }
Ejemplo n.º 2
0
	public static function CounterIncrement($log_id, $event_id = false, $arOfEntities = false, $type = "L")
	{
		if (intval($log_id) <= 0)
			return false;

		CUserCounter::IncrementWithSelect(
			CSocNetLogCounter::GetSubSelect(
				$log_id, false, false, false, false,
				$arOfEntities, false, false, "Y", $type
			)
		);

		if ($event_id == "blog_post_important")
		{
			CUserCounter::IncrementWithSelect(
				CSocNetLogCounter::GetSubSelect(
					$log_id, false, false, false, false,
					$arOfEntities, false, false, "Y", "L",
					array("CODE" => "'BLOG_POST_IMPORTANT'")
				)
			);
		}
	}
Ejemplo n.º 3
0
 function SendEvent($ID, $mailTemplate = "SONET_NEW_EVENT")
 {
     $ID = IntVal($ID);
     if ($ID <= 0) {
         return false;
     }
     $arFilter = array("ID" => $ID);
     $dbLogComments = CSocNetLogComments::GetList(array(), $arFilter, false, false, array("ID", "LOG_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "GROUP_NAME", "CREATED_BY_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_LOGIN", "LOG_SITE_ID", "SOURCE_ID", "LOG_SOURCE_ID"));
     $arLogComment = $dbLogComments->Fetch();
     if (!$arLogComment) {
         return false;
     }
     $arLog = array();
     if (intval($arLogComment["LOG_ID"]) > 0) {
         $dbLog = CSocNetLog::GetList(array(), array("ID" => $arLogComment["LOG_ID"]));
         $arLog = $dbLog->Fetch();
         if (!$arLog) {
             $arLog = array();
         }
     }
     $arEvent = CSocNetLogTools::FindLogCommentEventByID($arLogComment["EVENT_ID"]);
     if ($arEvent && array_key_exists("CLASS_FORMAT", $arEvent) && array_key_exists("METHOD_FORMAT", $arEvent) && strlen($arEvent["CLASS_FORMAT"]) > 0 && strlen($arEvent["METHOD_FORMAT"]) > 0) {
         $dbSiteCurrent = CSite::GetByID(SITE_ID);
         if ($arSiteCurrent = $dbSiteCurrent->Fetch()) {
             if ($arSiteCurrent["LANGUAGE_ID"] != LANGUAGE_ID) {
                 $arLogComment["MAIL_LANGUAGE_ID"] = $arSiteCurrent["LANGUAGE_ID"];
             }
         }
         $arLogComment["FIELDS_FORMATTED"] = call_user_func(array($arEvent["CLASS_FORMAT"], $arEvent["METHOD_FORMAT"]), $arLogComment, array(), true, $arLog);
     }
     if (array_key_exists($arLogComment["ENTITY_TYPE"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"]) && array_key_exists("HAS_MY", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]) && $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["HAS_MY"] == "Y" && array_key_exists("CLASS_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]) && array_key_exists("METHOD_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]) && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["CLASS_OF"]) > 0 && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["METHOD_OF"]) > 0 && method_exists($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["METHOD_OF"])) {
         $arOfEntities = call_user_func(array($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["METHOD_OF"]), $arLogComment["ENTITY_ID"]);
     }
     $arListParams = array("USE_SUBSCRIBE" => "Y", "ENTITY_TYPE" => $arLogComment["ENTITY_TYPE"], "ENTITY_ID" => $arLogComment["ENTITY_ID"], "EVENT_ID" => $arLogComment["EVENT_ID"], "USER_ID" => $arLogComment["USER_ID"], "OF_ENTITIES" => $arOfEntities, "TRANSPORT" => array("M", "X"));
     $arLogSites = array();
     $rsLogSite = CSocNetLog::GetSite($arLog["ID"]);
     while ($arLogSite = $rsLogSite->Fetch()) {
         $arLogSites[] = $arLogSite["LID"];
     }
     if (CModule::IncludeModule("extranet")) {
         if ($arLogComment["ENTITY_TYPE"] == SONET_ENTITY_GROUP) {
             $arSites = array();
             $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"]));
             }
             $intranet_site_id = CSite::GetDefSite();
         }
         $arIntranetUsers = CExtranet::GetIntranetUsers();
         $extranet_site_id = CExtranet::GetExtranetSiteID();
     }
     $dbSubscribers = CSocNetLogEvents::GetList(array("TRANSPORT" => "DESC"), array("USER_ACTIVE" => "Y", "SITE_ID" => array_merge($arLogSites, array(false))), false, false, array("USER_ID", "ENTITY_TYPE", "ENTITY_ID", "ENTITY_CB", "ENTITY_MY", "USER_NAME", "USER_LAST_NAME", "USER_LOGIN", "USER_LID", "USER_EMAIL", "TRANSPORT"), $arListParams);
     $arListParams = array("USE_SUBSCRIBE" => "Y", "ENTITY_TYPE" => $arLogComment["ENTITY_TYPE"], "ENTITY_ID" => $arLogComment["ENTITY_ID"], "EVENT_ID" => $arLogComment["EVENT_ID"], "USER_ID" => $arLogComment["USER_ID"], "OF_ENTITIES" => $arOfEntities, "TRANSPORT" => "N");
     $dbUnSubscribers = CSocNetLogEvents::GetList(array("TRANSPORT" => "DESC"), array("USER_ACTIVE" => "Y", "SITE_ID" => array_merge($arLogSites, array(false))), false, false, array("USER_ID", "SITE_ID", "ENTITY_TYPE", "ENTITY_ID", "ENTITY_CB", "ENTITY_MY", "TRANSPORT", "EVENT_ID"), $arListParams);
     $arUnSubscribers = array();
     while ($arUnSubscriber = $dbUnSubscribers->Fetch()) {
         $arUnSubscribers[] = $arUnSubscriber["USER_ID"] . "_" . $arUnSubscriber["ENTITY_TYPE"] . "_" . $arUnSubscriber["ENTITY_ID"] . "_" . $arUnSubscriber["ENTITY_MY"] . "_" . $arUnSubscriber["ENTITY_CB"] . "_" . $arUnSubscriber["EVENT_ID"];
     }
     $bHasAccessAll = CSocNetLogRights::CheckForUserAll($arLog["ID"] ? $arLog["ID"] : $arLogComment["LOG_ID"]);
     $arSentUserID = array("M" => array(), "X" => array());
     while ($arSubscriber = $dbSubscribers->Fetch()) {
         if (is_array($arIntranetUsers) && !in_array($arSubscriber["USER_ID"], $arIntranetUsers) && !in_array($extranet_site_id, $arLogSites)) {
             continue;
         }
         if (array_key_exists($arSubscriber["TRANSPORT"], $arSentUserID) && in_array($arSubscriber["USER_ID"], $arSentUserID[$arSubscriber["TRANSPORT"]])) {
             continue;
         }
         if (intval($arSubscriber["ENTITY_ID"]) != 0 && $arSubscriber["EVENT_ID"] == "all" && (in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arSubscriber["ENTITY_ID"] . "_N_" . $arSubscriber["ENTITY_CB"] . "_" . $arLogComment["EVENT_ID"], $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arSubscriber["ENTITY_ID"] . "_Y_" . $arSubscriber["ENTITY_CB"] . "_" . $arLogComment["EVENT_ID"], $arUnSubscribers))) {
             continue;
         } elseif (intval($arSubscriber["ENTITY_ID"]) == 0 && $arSubscriber["ENTITY_CB"] == "N" && $arSubscriber["EVENT_ID"] != "all" && (in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_Y_N_all", $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_N_N_all", $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_Y_N_" . $arLogComment["EVENT_ID"], $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_N_N_" . $arLogComment["EVENT_ID"], $arUnSubscribers))) {
             continue;
         }
         $arSentUserID[$arSubscriber["TRANSPORT"]][] = $arSubscriber["USER_ID"];
         if (!$bHasAccessAll) {
             $bHasAccess = CSocNetLogRights::CheckForUserOnly($arLog["ID"] ? $arLog["ID"] : $arLogComment["LOG_ID"], $arSubscriber["USER_ID"]);
             if (!$bHasAccess) {
                 continue;
             }
         }
         if ($arLogComment["ENTITY_TYPE"] == SONET_ENTITY_GROUP && is_array($arIntranetUsers) && CModule::IncludeModule("extranet")) {
             $server_name = $arSites[!in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id ? $extranet_site_id : $intranet_site_id]["SERVER_NAME"];
             $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] = str_replace(array("#SERVER_NAME#", "#GROUPS_PATH#"), array($server_name, COption::GetOptionString("socialnetwork", "workgroups_page", false, !in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id ? $extranet_site_id : $intranet_site_id)), $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]);
         } else {
             $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] = $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"];
         }
         switch ($arSubscriber["TRANSPORT"]) {
             case "X":
                 if (array_key_exists("URL_TO_SEND", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0) {
                     $link = GetMessage("SONET_GLC_SEND_EVENT_LINK") . $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"];
                 } else {
                     $link = "";
                 }
                 $arMessageFields = array("FROM_USER_ID" => intval($arLogComment["USER_ID"]) > 0 ? $arLogComment["USER_ID"] : 1, "TO_USER_ID" => $arSubscriber["USER_ID"], "MESSAGE" => $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["TITLE"] . " #BR# " . $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE"] . (strlen($link) > 0 ? "#BR# " . $link : ""), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM, "IS_LOG" => "Y");
                 CSocNetMessages::Add($arMessageFields);
                 break;
             case "M":
                 $arFields["SUBSCRIBER_ID"] = $arSubscriber["USER_ID"];
                 $arFields["SUBSCRIBER_NAME"] = $arSubscriber["USER_NAME"];
                 $arFields["SUBSCRIBER_LAST_NAME"] = $arSubscriber["USER_LAST_NAME"];
                 $arFields["SUBSCRIBER_LOGIN"] = $arSubscriber["USER_LOGIN"];
                 $arFields["SUBSCRIBER_EMAIL"] = $arSubscriber["USER_EMAIL"];
                 $arFields["EMAIL_TO"] = $arSubscriber["USER_EMAIL"];
                 $arFields["TITLE"] = str_replace("#BR#", "\n", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["TITLE"]);
                 $arFields["MESSAGE"] = str_replace("#BR#", "\n", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE"]);
                 $arFields["ENTITY"] = $arLogComment["FIELDS_FORMATTED"]["ENTITY"]["FORMATTED"];
                 $arFields["ENTITY_TYPE"] = $arLogComment["FIELDS_FORMATTED"]["ENTITY"]["TYPE_MAIL"];
                 if (array_key_exists("URL_TO_SEND", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0) {
                     $arFields["URL"] = $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"];
                 } else {
                     $arFields["URL"] = $arLogComment["URL"];
                 }
                 if (CModule::IncludeModule("extranet")) {
                     $arUserGroup = CUser::GetUserGroup($arSubscriber["USER_ID"]);
                 }
                 foreach ($arLogSites as $site_id_tmp) {
                     if (IsModuleInstalled("extranet")) {
                         if (CExtranet::IsExtranetSite($site_id_tmp) && in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup) || !CExtranet::IsExtranetSite($site_id_tmp) && !in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup)) {
                             $siteID = $site_id_tmp;
                             break;
                         } else {
                             continue;
                         }
                     } else {
                         $siteID = $site_id_tmp;
                         break;
                     }
                 }
                 if (!$siteID) {
                     $siteID = defined("SITE_ID") ? SITE_ID : $arSubscriber["SITE_ID"];
                 }
                 if (StrLen($siteID) <= 0) {
                     $siteID = $arSubscriber["USER_LID"];
                 }
                 if (StrLen($siteID) <= 0) {
                     continue;
                 }
                 $event = new CEvent();
                 $event->Send($mailTemplate, $siteID, $arFields, "N");
                 break;
             default:
         }
     }
     CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect($arLog["ID"], $arLog["ENTITY_TYPE"], $arLog["ENTITY_ID"], $arLogComment["EVENT_ID"], $arLogComment["USER_ID"], $arOfEntities, false, false, "Y", "LC"));
     return true;
 }
Ejemplo n.º 4
0
 public static function MessageUpdate($REPORT_ID, $arReport = array(), $arFields = array())
 {
     global $DB, $USER;
     $curUser = $USER->GetID();
     if (CModule::IncludeModule("socialnetwork")) {
         $dbLog = CSocNetLog::GetList(array(), array("SOURCE_ID" => $REPORT_ID, "EVENT_ID" => "report"));
         if (!($arLog = $dbLog->Fetch())) {
             $LOG_ID = CReportNotifications::SendMessage($REPORT_ID, false);
         } else {
             $LOG_ID = $arLog["ID"];
             CSocNetLog::Update($LOG_ID, array("USER_ID" => $curUser, "=LOG_DATE" => $DB->CurrentTimeFunction(), "=LOG_UPDATE" => $DB->CurrentTimeFunction()));
             CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect($LOG_ID, $arLog["ENTITY_TYPE"], $arLog["ENTITY_ID"], $arLog["EVENT_ID"], $arLog["USER_ID"]));
         }
         if (CModule::IncludeModule("im") && is_array($arFields) && is_array($arReport) && intval($arReport["USER_ID"]) > 0 && $arReport["USER_ID"] != $curUser) {
             $date_text = "";
             $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, "TO_USER_ID" => $arReport["USER_ID"], "FROM_USER_ID" => $curUser, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "timeman", "NOTIFY_EVENT" => "report_approve", "NOTIFY_TAG" => "TIMEMAN|REPORT|" . $arReport["ID"] . "_" . $arFields["MARK"]);
             $gender_suffix = "";
             $dbUser = CUser::GetByID($curUser);
             if ($arUser = $dbUser->Fetch()) {
                 switch ($arUser["PERSONAL_GENDER"]) {
                     case "M":
                         $gender_suffix = "_M";
                         break;
                     case "F":
                         $gender_suffix = "_F";
                         break;
                     default:
                         $gender_suffix = "";
                 }
             }
             $reports_page = COption::GetOptionString("timeman", "WORK_REPORT_PATH", "/company/work_report.php");
             $arTmp = CSocNetLogTools::ProcessPath(array("REPORTS_PAGE" => $reports_page), $arReport["USER_ID"]);
             switch ($arFields["MARK"]) {
                 case "G":
                     $mark = "G";
                     break;
                 case "B":
                     $mark = "B";
                     break;
                 case "X":
                     $mark = "X";
                     break;
                 default:
                     $mark = "N";
             }
             $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("REPORT_FULL_IM_APPROVE" . $gender_suffix . "_" . $mark, array("#period#" => "<a href=\"" . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $REPORT_ID . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($date_text) . "</a>"));
             $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("REPORT_FULL_IM_APPROVE" . $gender_suffix . "_" . $mark, array("#period#" => htmlspecialcharsbx($date_text))) . " ( " . $arTmp["SERVER_NAME"] . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $REPORT_ID . " )";
             CIMNotify::Add($arMessageFields);
         }
         $dbLogRights = CSocNetLogRights::GetList(array(), array("LOG_ID" => $LOG_ID));
         while ($arRight = $dbLogRights->Fetch()) {
             $arRights[] = $arRight["GROUP_CODE"];
         }
         if (!in_array("U" . $curUser, $arRights)) {
             CSocNetLogRights::Add($LOG_ID, "U" . $curUser);
         }
         return $LOG_ID;
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 public static function CounterDecrement($log_id, $event_id = false, $type = "L", $bForAllAccess = false)
 {
     if (intval($log_id) <= 0) {
         return false;
     }
     CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect2($log_id, array("TYPE" => $type, "DECREMENT" => true, "FOR_ALL_ACCESS" => $bForAllAccess)));
     if ($event_id == "blog_post_important") {
         CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect2($log_id, array("TYPE" => "L", "CODE" => "'BLOG_POST_IMPORTANT'", "DECREMENT" => true, "FOR_ALL_ACCESS" => $bForAllAccess)));
     }
 }
Ejemplo n.º 6
0
 function GetSubSelect($entityId, $entity_type = false, $entity_id = false, $event_id = false, $created_by_id = false, $arOfEntities = false, $arAdmin = false, $transport = false, $visible = "Y", $type = "L", $params = array(), $bDecrement = false, $bForAllAccess = false)
 {
     global $DB;
     if (is_array($entityId) && isset($entityId["LOG_ID"])) {
         $arFields = $entityId;
         $entityId = intval($arFields["LOG_ID"]);
         $entity_type = isset($arFields["ENTITY_TYPE"]) ? $arFields["ENTITY_TYPE"] : false;
         $entity_id = isset($arFields["ENTITY_ID"]) ? $arFields["ENTITY_ID"] : false;
         $event_id = isset($arFields["EVENT_ID"]) ? $arFields["EVENT_ID"] : false;
         $created_by_id = isset($arFields["CREATED_BY_ID"]) ? $arFields["CREATED_BY_ID"] : false;
         $arOfEntities = isset($arFields["ENTITIES"]) ? $arFields["ENTITIES"] : false;
         $transport = isset($arFields["TRANSPORT"]) ? $arFields["TRANSPORT"] : false;
         $visible = isset($arFields["VISIBLE"]) ? $arFields["VISIBLE"] : "Y";
         $type = isset($arFields["TYPE"]) ? $arFields["TYPE"] : "L";
         $code = isset($arFields["CODE"]) ? $arFields["CODE"] : false;
         $params = isset($arFields["PARAMS"]) ? $arFields["PARAMS"] : array();
         $bDecrement = isset($arFields["DECREMENT"]) ? $arFields["DECREMENT"] : false;
         $bMultiple = isset($arFields["MULTIPLE"]) && $arFields["MULTIPLE"] == "Y";
         $IsForAllAccessOnly = false;
         if (isset($arFields["FOR_ALL_ACCESS_ONLY"])) {
             $IsForAllAccessOnly = $arFields["FOR_ALL_ACCESS_ONLY"] ? "Y" : "N";
         }
         $bForAllAccess = $IsForAllAccessOnly == "Y" ? true : (isset($arFields["FOR_ALL_ACCESS"]) ? $arFields["FOR_ALL_ACCESS"] : false);
         $tagSet = isset($arFields["TAG_SET"]) ? $arFields["TAG_SET"] : false;
     }
     if (intval($entityId) <= 0) {
         return false;
     }
     $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
     $bGroupCounters = $type === "group";
     $params = is_array($params) ? $params : array();
     $params['CODE'] = !empty($params['CODE']) ? $params['CODE'] : ($code ? $code : ($bGroupCounters ? "SLR0.GROUP_CODE" : "'**" . ($bMultiple ? $type . $entityId : "") . "'"));
     if ($type == "L" && ($arLog = CSocNetLog::GetByID($entityId))) {
         $logId = $entityId;
         $entity_type = $arLog["ENTITY_TYPE"];
         $entity_id = $arLog["ENTITY_ID"];
         $event_id = $arLog["EVENT_ID"];
         $created_by_id = $arLog["USER_ID"];
         $log_user_id = $arLog["USER_ID"];
     } elseif ($type == "LC" && ($arLogComment = CSocNetLogComments::GetByID($entityId))) {
         $entity_type = $arLogComment["ENTITY_TYPE"];
         $entity_id = $arLogComment["ENTITY_ID"];
         $event_id = $arLogComment["EVENT_ID"];
         $created_by_id = $arLogComment["USER_ID"];
         $logId = $arLogComment["LOG_ID"];
         // recalculate log_id
         $log_user_id = $arLogComment["LOG_USER_ID"];
     } else {
         $logId = $entityId;
     }
     if (!in_array($entity_type, CSocNetAllowed::GetAllowedEntityTypes()) || intval($entity_id) <= 0 || strlen($event_id) <= 0) {
         return false;
     }
     if (!$arOfEntities) {
         if (array_key_exists($entity_type, $arSocNetAllowedSubscribeEntityTypesDesc) && array_key_exists("HAS_MY", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["HAS_MY"] == "Y" && array_key_exists("CLASS_OF", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && array_key_exists("METHOD_OF", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && strlen($arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["CLASS_OF"]) > 0 && strlen($arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["METHOD_OF"]) > 0 && method_exists($arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["CLASS_OF"], $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["METHOD_OF"])) {
             $arOfEntities = call_user_func(array($arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["CLASS_OF"], $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["METHOD_OF"]), $entity_id);
         } else {
             $arOfEntities = array();
         }
     }
     if ((!defined("DisableSonetLogVisibleSubscr") || DisableSonetLogVisibleSubscr !== true) && $visible && strlen($visible) > 0) {
         $key_res = CSocNetGroup::GetFilterOperation($visible);
         $strField = $key_res["FIELD"];
         $strNegative = $key_res["NEGATIVE"];
         $strOperation = $key_res["OPERATION"];
         $visibleFilter = "AND (" . ($strNegative == "Y" ? " SLE.VISIBLE IS NULL OR NOT " : "") . "(SLE.VISIBLE " . $strOperation . " '" . $DB->ForSql($strField) . "'))";
         $transportFilter = "";
     } else {
         $visibleFilter = "";
         if ($transport && strlen($transport) > 0) {
             $key_res = CSocNetGroup::GetFilterOperation($transport);
             $strField = $key_res["FIELD"];
             $strNegative = $key_res["NEGATIVE"];
             $strOperation = $key_res["OPERATION"];
             $transportFilter = "AND (" . ($strNegative == "Y" ? " SLE.TRANSPORT IS NULL OR NOT " : "") . "(SLE.TRANSPORT " . $strOperation . " '" . $DB->ForSql($strField) . "'))";
         } else {
             $transportFilter = "";
         }
     }
     if ($type == "LC" && (!defined("DisableSonetLogFollow") || DisableSonetLogFollow !== true)) {
         $default_follow = COption::GetOptionString("socialnetwork", "follow_default_type", "Y");
         if ($default_follow == "Y") {
             $followJoin = " LEFT JOIN b_sonet_log_follow LFW ON LFW.USER_ID = U.ID AND (LFW.CODE = 'L" . $logId . "' OR LFW.CODE = '**') ";
             $followWhere = "AND (LFW.USER_ID IS NULL OR LFW.TYPE = 'Y')";
         } else {
             $followJoin = " \n\t\t\t\t\tINNER JOIN b_sonet_log_follow LFW ON LFW.USER_ID = U.ID AND (LFW.CODE = 'L" . $logId . "' OR LFW.CODE = '**')\n\t\t\t\t\tLEFT JOIN b_sonet_log_follow LFW2 ON LFW2.USER_ID = U.ID AND (LFW2.CODE = 'L" . $logId . "' AND LFW2.TYPE = 'N')\n\t\t\t\t";
             $followWhere = "\n\t\t\t\t\tAND (LFW.USER_ID IS NOT NULL AND LFW.TYPE = 'Y')\n\t\t\t\t\tAND LFW2.USER_ID IS NULL\n\t\t\t\t";
         }
     }
     $strOfEntities = is_array($arOfEntities) && count($arOfEntities) > 0 ? "U.ID IN (" . implode(",", $arOfEntities) . ")" : "";
     $strSQL = "\n\t\tSELECT DISTINCT\n\t\t\tU.ID as ID\n\t\t\t," . ($bDecrement ? "-1" : "1") . " as CNT\n\t\t\t," . $DB->IsNull("SLS.SITE_ID", "'**'") . " as SITE_ID\n\t\t\t," . $params['CODE'] . " as CODE,\n\t\t\t0 as SENT\n\t\t\t" . ($tagSet ? ", '" . $DB->ForSQL($tagSet) . "' as TAG" : "") . "\n\t\tFROM\n\t\t\tb_user U \n\t\t\tINNER JOIN b_sonet_log_right SLR ON SLR.LOG_ID = " . $logId . "\n\t\t\t" . ($bGroupCounters ? "INNER JOIN b_sonet_log_right SLR0 ON SLR0.LOG_ID = SLR.LOG_ID " : "") . "\n\t\t\t" . (!$bForAllAccess ? "INNER JOIN b_user_access UA ON UA.USER_ID = U.ID" : "") . "\n\t\t\tLEFT JOIN b_sonet_log_site SLS ON SLS.LOG_ID = SLR.LOG_ID\n\t\t\t" . (strlen($followJoin) > 0 ? $followJoin : "") . "\n\t\t\t" . (!$bGroupCounters && !IsModuleInstalled("intranet") ? "LEFT JOIN b_sonet_log_smartfilter SLSF ON SLSF.USER_ID = U.ID " : "") . "\n\t\t\t\n\t\tWHERE\n\t\t\tU.ACTIVE = 'Y'\n\t\t\tAND U.LAST_ACTIVITY_DATE IS NOT NULL\n\t\t\tAND\tU.LAST_ACTIVITY_DATE > " . CSocNetLogCounter::dbWeeksAgo(2) . "\n\t\t\t" . (($type == "LC" || array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y") && intval($created_by_id) > 0 ? "AND U.ID <> " . $created_by_id : "") . "\n\t\t\t" . ($bGroupCounters ? "AND (SLR0.GROUP_CODE like 'SG%' AND SLR0.GROUP_CODE NOT LIKE 'SG%\\_%')" : "") . (!$bGroupCounters && !IsModuleInstalled("intranet") ? COption::GetOptionString("socialnetwork", "sonet_log_smart_filter", "N") == "Y" ? "\n\t\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\t\t0=1 \n\t\t\t\t\t\t\t\t\tOR (\n\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\tSLSF.USER_ID IS NULL \n\t\t\t\t\t\t\t\t\t\t\tOR SLSF.TYPE = 'Y'\n\t\t\t\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\t\t\t\t" . (!$bForAllAccess ? "AND (UA.ACCESS_CODE = SLR.GROUP_CODE)" : "") . "\n\t\t\t\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\t\t\t\tSLR.GROUP_CODE LIKE 'SG%'\n\t\t\t\t\t\t\t\t\t\t\tOR SLR.GROUP_CODE = 'U" . $log_user_id . "' \n\t\t\t\t\t\t\t\t\t\t\tOR SLR.GROUP_CODE = " . $DB->Concat("'U'", $DB->type == "MSSQL" ? "CAST(U.ID as varchar(17))" : "U.ID") . " \n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tOR (\n\t\t\t\t\t\t\t\t\t\tSLSF.TYPE <> 'Y'\n\t\t\t\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\t\t\t\tSLR.GROUP_CODE IN ('AU', 'G2')\n\t\t\t\t\t\t\t\t\t\t\t" . (!$bForAllAccess ? "OR (UA.ACCESS_CODE = SLR.GROUP_CODE)" : "") . "\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\t\t0=1 \n\t\t\t\t\t\t\t\t\tOR (\n\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\tSLSF.USER_ID IS NULL \n\t\t\t\t\t\t\t\t\t\t\tOR SLSF.TYPE <> 'Y'\n\t\t\t\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\t\t\t\tSLR.GROUP_CODE IN ('AU', 'G2')\n\t\t\t\t\t\t\t\t\t\t\t" . ($bForAllAccess ? "" : " OR (UA.ACCESS_CODE = SLR.GROUP_CODE)") . "\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tOR (\n\t\t\t\t\t\t\t\t\t\tSLSF.TYPE = 'Y' \n\t\t\t\t\t\t\t\t\t\t" . ($bForAllAccess ? "" : "AND (UA.ACCESS_CODE = SLR.GROUP_CODE)") . "\n\t\t\t\t\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t\t\t\t\tSLR.GROUP_CODE LIKE 'SG%'\n\t\t\t\t\t\t\t\t\t\t\tOR SLR.GROUP_CODE = 'U" . $log_user_id . "'\n\t\t\t\t\t\t\t\t\t\t\tOR SLR.GROUP_CODE = " . $DB->Concat("'U'", $DB->type == "MSSQL" ? "CAST(U.ID as varchar(17))" : "U.ID") . " \n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\tAND (\n\t\t\t\t\t\t\t0=1\n\t\t\t\t\t\t\t" . ($IsForAllAccessOnly != "N" || $bForAllAccess ? "OR (SLR.GROUP_CODE IN ('AU', 'G2'))" : "") . "\n\t\t\t\t\t\t\t" . (!$bForAllAccess && $IsForAllAccessOnly != "Y" ? " OR (UA.ACCESS_CODE = SLR.GROUP_CODE) " : "") . "\n\t\t\t\t\t\t)\n\t\t\t\t\t") . " " . (strlen($followWhere) > 0 ? $followWhere : "") . "\n\t\t";
     if ($bGroupCounters) {
         return $strSQL;
     }
     if (strlen($visibleFilter) > 0 || strlen($transportFilter) > 0) {
         $strSQL .= "\n\t\t\t\tAND\t\n\t\t\t\t(\n\t\t\t\t\tEXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'N'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $entity_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t)";
         if (array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y" && intval($created_by_id) > 0) {
             $strSQL .= "\n\t\t\t\tOR\n\t\t\t\t(\n\t\t\t\t\tEXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'Y'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $created_by_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t)\n\t\t\t\t)";
         }
         $strSQL .= "\n\t\t\tOR\n\t\t\t(\n\t\t\t\t(\n\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'N'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $entity_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t)\n\t\t\t\t\tOR\n\t\t\t\t\tEXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'N'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $entity_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t)\n\t\t\t\t)";
         if (array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y" && intval($created_by_id) > 0) {
             $strSQL .= "\n\t\t\t\tAND\n\t\t\t\t(\n\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'Y'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $created_by_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t)\n\t\t\t\t\tOR\n\t\t\t\t\tEXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'Y'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $created_by_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t)\n\n\t\t\t\t)";
         }
         $strSQL .= "\n\t\t\t\tAND\n\t\t\t\t(\n\t\t\t\t\tEXISTS(\n\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'N'\n\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $entity_id . "\n\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t)";
         if (array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y" && intval($created_by_id) > 0) {
             $strSQL .= "\n\t\t\t\t\tOR\n\t\t\t\t\t(\n\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'Y'\n\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $created_by_id . "\n\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t\t)\n\t\t\t\t\t)";
         }
         $strSQL .= "\n\t\t\t\t\tOR\n\t\t\t\t\t(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'N'\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $entity_id . "\n\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'N'\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $entity_id . "\n\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND ";
         if (array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y" && intval($created_by_id) > 0) {
             $strSQL .= "\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'Y'\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $created_by_id . "\n\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_CB = 'Y'\n\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = " . $created_by_id . "\n\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tAND\n\t\t\t\t\t\t(\n\t\t\t\t\t\t";
         }
         if (strlen($strOfEntities) > 0) {
             $strSQL .= "\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t" . $strOfEntities . "\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'Y'\n\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'Y'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'Y'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'Y'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t";
         }
         $strSQL .= "\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'N'\n\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'N'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'N'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'N'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t\t\t" . $transportFilter . "\n\t\t\t\t\t\t\t\t\t\t" . $visibleFilter . "\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\tEXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'N'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t\t\t\t\tAND " . ($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'") . "\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\tNOT EXISTS(\n\t\t\t\t\t\t\t\t\t\t\tSELECT ID\n\t\t\t\t\t\t\t\t\t\t\tFROM b_sonet_log_events SLE\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\tSLE.USER_ID = U.ID\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_ID = 0\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.ENTITY_MY = 'N'\n\t\t\t\t\t\t\t\t\t\t\t\tAND SLE.EVENT_ID = 'all'\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t)";
         if (array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y" && intval($created_by_id) > 0) {
             $strSQL .= "\n\t\t\t\t\t\t)";
         }
         $strSQL .= "\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\n\t\t\t)";
     }
     return $strSQL;
 }