function Delete($ID)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GLC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
         return false;
     }
     $arComment = CSocNetLogComments::GetByID($ID);
     $bSuccess = True;
     if ($bSuccess) {
         $bSuccess = $DB->Query("DELETE FROM b_sonet_log_comment WHERE ID = " . $ID . "", true);
     }
     if ($bSuccess && intval($arComment["LOG_ID"]) > 0) {
         CSocNetLogComments::UpdateLogData($arComment["LOG_ID"], false, true);
     }
     if ($bSuccess && defined("BX_COMP_MANAGED_CACHE")) {
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_COMMENT_" . $ID);
     }
     return $bSuccess;
 }
Beispiel #2
0
							$arResult["commentText"] = $comment_text;
						}
					}
					else
						$arResult["strMessage"] = GetMessage("SONET_LOG_COMMENT_EMPTY");
				}
				else
					$arResult["strMessage"] = GetMessage("SONET_LOG_COMMENT_NO_PERMISSIONS");
			}
		}
	}
	elseif ($action == "get_comment")
	{
		$comment_id = $_REQUEST["cid"];

		if ($arComment = CSocNetLogComments::GetByID($comment_id))
		{
			$arResult["arComment"] = $arComment;

			$dateFormated = FormatDate(
				$GLOBALS['DB']->DateFormatToPHP(FORMAT_DATE),
				MakeTimeStamp(array_key_exists("LOG_DATE_FORMAT", $arComment) ? $arComment["LOG_DATE_FORMAT"] : $arComment["LOG_DATE"])
			);

			$timeFormat = (isset($_REQUEST["dtf"]) ? $_REQUEST["dtf"] : CSite::GetTimeFormat());

			$timeFormated = FormatDateFromDB(
				(array_key_exists("LOG_DATE_FORMAT", $arComment) ? $arComment["LOG_DATE_FORMAT"] : $arComment["LOG_DATE"]),
				(stripos($timeFormat, 'a') || ($timeFormat == 'FULL' && IsAmPmMode()) !== false ? 'H:MI T' : 'HH:MI')
			);
Beispiel #3
0
 public static function Delete($ID, $bSetSource = false)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GLC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
         return false;
     }
     $bSuccess = false;
     if ($arComment = CSocNetLogComments::GetByID($ID)) {
         if ($bSetSource) {
             if (strlen($arComment["EVENT_ID"]) > 0) {
                 $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
                 if (!$arCommentEvent || !array_key_exists("DELETE_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["DELETE_CALLBACK"])) {
                     $bSetSource = false;
                 }
             }
         }
         $bSuccess = true;
         if ($bSetSource) {
             $arSource = CSocNetLogComments::SetSource($arComment, "DELETE");
         }
         if (!$bSetSource || is_array($arSource) && (!isset($arSource["ERROR"]) || empty($arSource["ERROR"]))) {
             if ($bSuccess) {
                 $bSuccess = $DB->Query("DELETE FROM b_sonet_log_comment WHERE ID = " . $ID . "", true);
             }
             if ($bSuccess) {
                 $GLOBALS["USER_FIELD_MANAGER"]->Delete("SONET_COMMENT", $ID);
                 $db_events = GetModuleEvents("socialnetwork", "OnSocNetLogCommentDelete");
                 while ($arEvent = $db_events->Fetch()) {
                     ExecuteModuleEventEx($arEvent, array($ID));
                 }
                 if (intval($arComment["LOG_ID"]) > 0) {
                     CSocNetLogComments::UpdateLogData($arComment["LOG_ID"], false, true);
                     $cache = new CPHPCache();
                     $cache->CleanDir("/sonet/log/" . intval(intval($arComment["LOG_ID"]) / 1000) . "/" . $arComment["LOG_ID"] . "/comments/");
                 }
             }
         } elseif (is_array($arSource) && isset($arSource["ERROR"]) && is_string($arSource["ERROR"]) && !empty($arSource["ERROR"])) {
             $GLOBALS["APPLICATION"]->ThrowException($arSource["ERROR"], "ERROR_DELETE_SOURCE");
             $bSuccess = false;
         }
     }
     return $bSuccess;
 }
Beispiel #4
0
 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, '&quot;\\1&quot;', $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);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #5
0
 public static function Delete($ID, $bSetSource = false)
 {
     global $DB;
     $ID = IntVal($ID);
     if ($ID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_GLC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
         return false;
     }
     $bSuccess = false;
     if ($arComment = CSocNetLogComments::GetByID($ID)) {
         if ($bSetSource) {
             if (strlen($arComment["EVENT_ID"]) > 0) {
                 $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
                 if (!$arCommentEvent || !array_key_exists("DELETE_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["DELETE_CALLBACK"])) {
                     $bSetSource = false;
                 }
             }
         }
         $bSuccess = true;
         if ($bSetSource) {
             $arSource = CSocNetLogComments::SetSource($arComment, "DELETE");
         }
         if (!$bSetSource || is_array($arSource) && (!isset($arSource["ERROR"]) || empty($arSource["ERROR"]))) {
             if ($bSuccess) {
                 $bSuccess = $DB->Query("DELETE FROM b_sonet_log_comment WHERE ID = " . $ID . "", true);
             }
             if ($bSuccess) {
                 $GLOBALS["USER_FIELD_MANAGER"]->Delete("SONET_COMMENT", $ID);
             }
             if ($bSuccess && intval($arComment["LOG_ID"]) > 0) {
                 CSocNetLogComments::UpdateLogData($arComment["LOG_ID"], false, true);
             }
             if ($bSuccess && defined("BX_COMP_MANAGED_CACHE")) {
                 $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_COMMENT_" . $ID);
             }
         } elseif (is_array($arSource) && isset($arSource["ERROR"]) && is_string($arSource["ERROR"]) && !empty($arSource["ERROR"])) {
             $GLOBALS["APPLICATION"]->ThrowException($arSource["ERROR"], "ERROR_DELETE_SOURCE");
             $bSuccess = false;
         }
     }
     return $bSuccess;
 }
Beispiel #6
0
 function __SLMAjaxGetComment($comment_id, $arParams, $bCheckRights = false)
 {
     if ($arComment = CSocNetLogComments::GetByID($comment_id)) {
         if ($bCheckRights) {
             if (strpos($arComment["ENTITY_TYPE"], "CRM") === 0 && IsModuleInstalled("crm")) {
                 $arListParams = array("IS_CRM" => "Y", "CHECK_CRM_RIGHTS" => "Y");
             } else {
                 $arListParams = array("CHECK_RIGHTS" => "Y", "USE_SUBSCRIBE" => "N");
             }
             if (intval($arComment["LOG_ID"]) <= 0 || !($rsLog = CSocNetLog::GetList(array(), array("ID" => $arComment["LOG_ID"]), false, false, array("ID"), $arListParams)) || !($arLog = $rsLog->Fetch())) {
                 return false;
             }
         }
         $arParams["DATE_TIME_FORMAT"] = $_REQUEST["dtf"];
         $dateFormated = FormatDate($GLOBALS['DB']->DateFormatToPHP(FORMAT_DATE), MakeTimeStamp($arComment["LOG_DATE"]));
         $timeFormated = FormatDateFromDB($arComment["LOG_DATE"], stripos($arParams["DATE_TIME_FORMAT"], 'a') || ($arParams["DATE_TIME_FORMAT"] == 'FULL' && IsAmPmMode()) !== false ? 'H:MI T' : 'HH:MI');
         $dateTimeFormated = FormatDate(!empty($arParams['DATE_TIME_FORMAT']) ? $arParams['DATE_TIME_FORMAT'] == 'FULL' ? $GLOBALS['DB']->DateFormatToPHP(str_replace(':SS', '', FORMAT_DATETIME)) : $arParams['DATE_TIME_FORMAT'] : $GLOBALS['DB']->DateFormatToPHP(FORMAT_DATETIME), MakeTimeStamp($arComment["LOG_DATE"]));
         if (strcasecmp(LANGUAGE_ID, 'EN') !== 0 && strcasecmp(LANGUAGE_ID, 'DE') !== 0) {
             $dateFormated = ToLower($dateFormated);
             $dateTimeFormated = ToLower($dateTimeFormated);
         }
         // strip current year
         if (!empty($arParams['DATE_TIME_FORMAT']) && ($arParams['DATE_TIME_FORMAT'] == 'j F Y G:i' || $arParams['DATE_TIME_FORMAT'] == 'j F Y g:i a')) {
             $dateTimeFormated = ltrim($dateTimeFormated, '0');
             $curYear = date('Y');
             $dateTimeFormated = str_replace(array('-' . $curYear, '/' . $curYear, ' ' . $curYear, '.' . $curYear), '', $dateTimeFormated);
         }
         if (intval($arComment["USER_ID"]) > 0) {
             $arParams = array("PATH_TO_USER" => $_REQUEST["p_user"], "NAME_TEMPLATE" => $_REQUEST["nt"], "SHOW_LOGIN" => $_REQUEST["sl"], "AVATAR_SIZE" => $as, "PATH_TO_SMILE" => $_REQUEST["p_smile"]);
             $arUser = array("ID" => $arComment["USER_ID"], "NAME" => $arComment["~CREATED_BY_NAME"], "LAST_NAME" => $arComment["~CREATED_BY_LAST_NAME"], "SECOND_NAME" => $arComment["~CREATED_BY_SECOND_NAME"], "LOGIN" => $arComment["~CREATED_BY_LOGIN"], "PERSONAL_PHOTO" => $arComment["~CREATED_BY_PERSONAL_PHOTO"], "PERSONAL_GENDER" => $arComment["~CREATED_BY_PERSONAL_GENDER"]);
             $bUseLogin = $arParams["SHOW_LOGIN"] != "N" ? true : false;
             $arCreatedBy = array("FORMATTED" => CUser::FormatName($arParams["NAME_TEMPLATE"], $arUser, $bUseLogin), "URL" => CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_USER"], array("user_id" => $arComment["USER_ID"], "id" => $arComment["USER_ID"])));
         } else {
             $arCreatedBy = array("FORMATTED" => GetMessage("SONET_SLM_CREATED_BY_ANONYMOUS"));
         }
         $arTmpCommentEvent = array("LOG_DATE" => $arComment["LOG_DATE"], "LOG_DATE_FORMAT" => $arComment["LOG_DATE_FORMAT"], "LOG_DATE_DAY" => ConvertTimeStamp(MakeTimeStamp($arComment["LOG_DATE"]), "SHORT"), "LOG_TIME_FORMAT" => $timeFormated, "MESSAGE" => $arComment["MESSAGE"], "MESSAGE_FORMAT" => $arComment["~MESSAGE"], "CREATED_BY" => $arCreatedBy, "AVATAR_SRC" => CSocNetLogTools::FormatEvent_CreateAvatar($arUser, $arParams, ""), "USER_ID" => $arComment["USER_ID"]);
         $arEventTmp = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
         if ($arEventTmp && array_key_exists("CLASS_FORMAT", $arEventTmp) && array_key_exists("METHOD_FORMAT", $arEventTmp)) {
             $arComment["UF"] = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("SONET_COMMENT", $arComment["ID"], LANGUAGE_ID);
             $arFIELDS_FORMATTED = call_user_func(array($arEventTmp["CLASS_FORMAT"], $arEventTmp["METHOD_FORMAT"]), $arComment, array_merge($arParams, array("MOBILE" => "N", "PATH_TO_USER" => COption::GetOptionString("main", "TOOLTIP_PATH_TO_USER", SITE_DIR . "company/personal/user/#user_id#/", SITE_ID))));
             $arTmpCommentEvent["MESSAGE_FORMAT"] = htmlspecialcharsback($arFIELDS_FORMATTED["EVENT_FORMATTED"]["MESSAGE"]);
             $arFIELDS_FORMATTED = call_user_func(array($arEventTmp["CLASS_FORMAT"], $arEventTmp["METHOD_FORMAT"]), $arComment, array_merge($arParams, array("MOBILE" => "Y", "PATH_TO_USER" => SITE_DIR . "mobile/users/?user_id=#user_id#")));
             $arTmpCommentEvent["MESSAGE_FORMAT_MOBILE"] = htmlspecialcharsback($arFIELDS_FORMATTED["EVENT_FORMATTED"]["MESSAGE"]);
         }
         return $arTmpCommentEvent;
     }
 }
Beispiel #7
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;
 }
 function GetSubSelect($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;
     }
     $bGroupCounters = $type === "group";
     if (!$entity_type || !$entity_id || !$created_by_id) {
         if ($type == "L" && ($arLog = CSocNetLog::GetByID($log_id))) {
             $entity_type = $arLog["ENTITY_TYPE"];
             $entity_id = $arLog["ENTITY_ID"];
             $event_id = $arLog["EVENT_ID"];
             $created_by_id = $arLog["USER_ID"];
         } elseif ($type == "LC" && ($arLogComment = CSocNetLogComments::GetByID($log_id))) {
             $entity_type = $arLogComment["ENTITY_TYPE"];
             $entity_id = $arLogComment["ENTITY_ID"];
             $event_id = $arLogComment["EVENT_ID"];
             $created_by_id = $arLogComment["USER_ID"];
             $log_id = $arLogComment["LOG_ID"];
         }
     }
     if (!in_array($entity_type, $GLOBALS["arSocNetAllowedSubscribeEntityTypes"])) {
         return false;
     }
     if (intval($entity_id) <= 0) {
         return false;
     }
     if (strlen($event_id) <= 0) {
         return false;
     }
     if (!$arOfEntities) {
         if (array_key_exists($entity_type, $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"]) && array_key_exists("HAS_MY", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["HAS_MY"] == "Y" && array_key_exists("CLASS_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && array_key_exists("METHOD_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["CLASS_OF"]) > 0 && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["METHOD_OF"]) > 0 && method_exists($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["METHOD_OF"])) {
             $arOfEntities = call_user_func(array($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["CLASS_OF"], $GLOBALS["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" . $log_id . "' OR LFW.CODE = '**') ";
             $followWhere = "AND (LFW.USER_ID IS NULL OR LFW.TYPE = 'Y')";
         } else {
             $followJoin = " INNER JOIN b_sonet_log_follow LFW ON LFW.USER_ID = U.ID AND (LFW.CODE = 'L" . $log_id . "' OR LFW.CODE = '**') ";
             $followWhere = "AND (LFW.USER_ID IS NOT NULL AND LFW.TYPE = 'Y')";
         }
     }
     if (is_array($arOfEntities) && count($arOfEntities) > 0) {
         $strOfEntities = "U.ID IN (" . implode(",", $arOfEntities) . ")";
     } else {
         $strOfEntities = "";
     }
     $strSQL = "\n\t\tSELECT DISTINCT\n\t\t\tU.ID as ID\n\t\t\t,1\n\t\t\t," . $DB->IsNull("SLS.SITE_ID", "'**'") . " as SITE_ID\n\t\t\t," . ($bGroupCounters ? "SLR0.GROUP_CODE" : "'**'") . " as CODE\n\t\tFROM\n\t\t\tb_user U \n\t\t\tINNER JOIN b_sonet_log_right SLR ON SLR.LOG_ID = " . $log_id . "\n\t\t\t" . ($bGroupCounters ? "INNER JOIN b_sonet_log_right SLR0 ON SLR0.LOG_ID = SLR.LOG_ID " : "") . "\n\t\t\tINNER 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\tWHERE\n\t\t\tU.ACTIVE = 'Y'\n\t\t\t" . (array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["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%\\_%')" : "") . "\n\t\t\tAND (\n\t\t\t\t0=1 \n\t\t\t\tOR (SLR.GROUP_CODE IN ('AU', 'G2'))\n\t\t\t\tOR (UA.ACCESS_CODE = SLR.GROUP_CODE)\n\t\t\t)\n\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", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["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", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["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", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["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", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["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", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) && $GLOBALS["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;
 }
Beispiel #9
0
	public static function OnAddRatingVote($id, $arParams)
	{
		if (CModule::IncludeModule("socialnetwork"))
		{
			$followValue = CSocNetLogFollow::GetExactValueByRating(
				intval($arParams["OWNER_ID"]),
				trim($arParams["ENTITY_TYPE_ID"]),
				intval($arParams["ENTITY_ID"])
			);
			if ($followValue === "N")
				return false;
		}
		if ($arParams['ENTITY_TYPE_ID'] == 'LOG_COMMENT')
		{
			if ($arComment = CSocNetLogComments::GetByID($arParams['ENTITY_ID']))
			{
				if ($arComment['USER_ID'] == $arParams['USER_ID'])
					return false;

				$arEventTmp = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
				if (
					$arEventTmp
					&& array_key_exists("CLASS_FORMAT", $arEventTmp)
					&& array_key_exists("METHOD_FORMAT", $arEventTmp)
				)
				{
					$arFIELDS_FORMATTED = call_user_func(array($arEventTmp["CLASS_FORMAT"], $arEventTmp["METHOD_FORMAT"]), $arComment, array());

					$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"]);
				}

				$arParams["ENTITY_TITLE"] = strip_tags(str_replace(array("<br>","<br/>","<br />", "#BR#"), Array(" "," ", " ", " "), $arComment["MESSAGE"]));

				$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);
			}
		}
		else
		{
			if ($arParams['OWNER_ID'] == $arParams['USER_ID'])
				return false;

			if (!CModule::IncludeModule("search") || BX_SEARCH_VERSION <= 1)
				return false;

			$CSI = new CSearchItem;
			$res = $CSI->GetList(Array(), Array('=ENTITY_TYPE_ID' => $arParams['ENTITY_TYPE_ID'], '=ENTITY_ID' => $arParams['ENTITY_ID']), Array('URL', 'TITLE', 'BODY', 'PARAM1'));
			if ($arItem = $res->GetNext(true, false))
			{
				$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)
				{
					if (CModule::IncludeModule("extranet"))
					{
						$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"]))
							);
						}

						$bExtranetUser = false;
						if ($arSites[$extranet_site_id])
						{
							$bExtranetUser = true;
							$rsUser = CUser::GetByID(intval($arParams['OWNER_ID']));
							if ($arUser = $rsUser->Fetch())
								if (intval($arUser["UF_DEPARTMENT"][0]) > 0)
									$bExtranetUser = false;
						}

						if ($bExtranetUser)
						{
							$link = $arParams['ENTITY_LINK'];
							if (substr($link, 0, strlen($arSites[$extranet_site_id]['DIR'])) == $arSites[$extranet_site_id]['DIR'])
								$link = substr($link, strlen($arSites[$extranet_site_id]['DIR']));

							$SiteServerName = $arSites[$extranet_site_id]['SERVER_NAME'].$arSites[$extranet_site_id]['DIR'].ltrim($link, "/");
						}
						else
						{
							$link = $arParams['ENTITY_LINK'];
							if (substr($link, 0, strlen($arSites[$intranet_site_id]['DIR'])) == $arSites[$intranet_site_id]['DIR'])
								$link = substr($link, strlen($arSites[$intranet_site_id]['DIR']));

							$SiteServerName = $arSites[$intranet_site_id]['SERVER_NAME'].$arSites[$intranet_site_id]['DIR'].ltrim($link, "/");
						}

						$arParams['ENTITY_LINK'] = (CMain::IsHTTPS() ? "https" : "http")."://".$SiteServerName;
					}
					else
					{
						if (defined('SITE_SERVER_NAME') && strlen(SITE_SERVER_NAME) > 0)
							$SiteServerName = SITE_SERVER_NAME;
						else
							$SiteServerName = COption::GetOptionString("main", "server_name", $GLOBALS["SERVER_NAME"]);

						if (strlen($SiteServerName) > 0)
							$arParams['ENTITY_LINK'] = (CMain::IsHTTPS() ? "https" : "http")."://".$SiteServerName.$arParams['ENTITY_LINK'];
					}

					$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);
				}
			}
		}
	}
Beispiel #10
0
	public static function GetSubSelect($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", $params = array())
	{
		global $DB;

		if (intval($log_id) <= 0)
			return false;

		$bGroupCounters = ($type === "group");
		$params = (is_array($params) ? $params : array());
		$params['CODE'] = (!empty($params['CODE']) ? $params['CODE'] : ($bGroupCounters ? "SLR0.GROUP_CODE" : "'**'"));

		if ($type == "L" && ($arLog = CSocNetLog::GetByID($log_id)))
		{
			$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($log_id)))
		{
			$entity_type = $arLogComment["ENTITY_TYPE"];
			$entity_id = $arLogComment["ENTITY_ID"];
			$event_id = $arLogComment["EVENT_ID"];
			$created_by_id = $arLogComment["USER_ID"];
			$log_id = $arLogComment["LOG_ID"]; // recalculate log_id
			$log_user_id = $arLogComment["LOG_USER_ID"];
		}

		if (!in_array($entity_type, $GLOBALS["arSocNetAllowedSubscribeEntityTypes"]))
			return false;

		if (intval($entity_id) <= 0)
			return false;

		if (strlen($event_id) <= 0)
			return false;

		if (!$arOfEntities)
		{
			if (
				array_key_exists($entity_type, $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"])
				&& array_key_exists("HAS_MY", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["HAS_MY"] == "Y"
				&& array_key_exists("CLASS_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& array_key_exists("METHOD_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["CLASS_OF"]) > 0
				&& strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["METHOD_OF"]) > 0
				&& method_exists($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["METHOD_OF"])
			)
				$arOfEntities = call_user_func(array($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["CLASS_OF"], $GLOBALS["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".$log_id."' OR LFW.CODE = '**') ";
				$followWhere = "AND (LFW.USER_ID IS NULL OR LFW.TYPE = 'Y')";
			}
			else
			{
				$followJoin = " 
					INNER JOIN b_sonet_log_follow LFW ON LFW.USER_ID = U.ID AND (LFW.CODE = 'L".$log_id."' OR LFW.CODE = '**') 
					LEFT JOIN b_sonet_log_follow LFW2 ON LFW2.USER_ID = U.ID AND (LFW2.CODE = 'L".$log_id."' AND LFW2.TYPE = 'N')
				";
				$followWhere = "
					AND (LFW.USER_ID IS NOT NULL AND LFW.TYPE = 'Y')
					AND LFW2.USER_ID IS NULL
				";
			}
		}

		if (
			is_array($arOfEntities)
			&& count($arOfEntities) > 0
		)
			$strOfEntities = "U.ID IN (".implode(",", $arOfEntities).")";
		else
			$strOfEntities = "";

		$strSQL = "
		SELECT DISTINCT
			U.ID as ID
			,1 as CNT
			,".$DB->IsNull("SLS.SITE_ID", "'**'")." as SITE_ID
			,".$params['CODE']." as CODE,
			0 as SENT
		FROM
			b_user U 
			INNER JOIN b_sonet_log_right SLR ON SLR.LOG_ID = ".$log_id."
			".($bGroupCounters ? "INNER JOIN b_sonet_log_right SLR0 ON SLR0.LOG_ID = SLR.LOG_ID ": "")."
			INNER JOIN b_user_access UA ON UA.USER_ID = U.ID
			LEFT JOIN b_sonet_log_site SLS ON SLS.LOG_ID = SLR.LOG_ID
			".(strlen($followJoin) > 0 ? $followJoin : "")."
			".(!$bGroupCounters && !IsModuleInstalled("intranet") ? "LEFT JOIN b_sonet_log_smartfilter SLSF ON SLSF.USER_ID = U.ID " : "")."
			
		WHERE
			U.ACTIVE = 'Y'
			".(
				array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]) 
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["USE_CB_FILTER"] == "Y" 
				&& intval($created_by_id) > 0 
					? "AND U.ID <> ".$created_by_id 
					: ""
			)."
			".($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"
							? "
								AND (
									0=1 
									OR (
										(
											SLSF.USER_ID IS NULL 
											OR SLSF.TYPE = 'Y'
										) 
										AND UA.ACCESS_CODE = SLR.GROUP_CODE 
										AND (
											SLR.GROUP_CODE LIKE 'SG%'
											OR SLR.GROUP_CODE = 'U".$log_user_id."' 
											OR SLR.GROUP_CODE = ".$DB->Concat("'U'", ($DB->type == "MSSQL" ? "CAST(U.ID as varchar(17))" : "U.ID"))." 
										)
									)
									OR (
										SLSF.TYPE <> 'Y'
										AND (
											SLR.GROUP_CODE IN ('AU', 'G2') 
											OR UA.ACCESS_CODE = SLR.GROUP_CODE
										)
									)
								)
							"
							: "
								AND (
									0=1 
									OR (
										(
											SLSF.USER_ID IS NULL 
											OR SLSF.TYPE <> 'Y'
										) 
										AND (
											SLR.GROUP_CODE IN ('AU', 'G2') 
											OR UA.ACCESS_CODE = SLR.GROUP_CODE
										)
									)
									OR (
										SLSF.TYPE = 'Y' 
										AND UA.ACCESS_CODE = SLR.GROUP_CODE 
										AND (
											SLR.GROUP_CODE LIKE 'SG%'
											OR SLR.GROUP_CODE = 'U".$log_user_id."'
											OR SLR.GROUP_CODE = ".$DB->Concat("'U'", ($DB->type == "MSSQL" ? "CAST(U.ID as varchar(17))" : "U.ID"))." 
										)
									)
								)
							"
					)
					: "
						AND (
							0=1 
							OR (SLR.GROUP_CODE IN ('AU', 'G2'))
							OR (UA.ACCESS_CODE = SLR.GROUP_CODE)
						)
					"
			)." ".
			(strlen($followWhere) > 0 ? $followWhere : "")."
		";

		if($bGroupCounters)
			return $strSQL;

		if (
			strlen($visibleFilter) > 0 
			|| strlen($transportFilter) > 0
		)
		{
			$strSQL .= "
				AND	
				(
					EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_TYPE = '".$entity_type."'
							AND SLE.ENTITY_CB = 'N'
							AND SLE.ENTITY_ID = ".$entity_id."
							AND SLE.EVENT_ID = '".$event_id."'
							".$transportFilter."
							".$visibleFilter."
					)";

			if (
				array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["USE_CB_FILTER"] == "Y"
				&& intval($created_by_id) > 0
			)
			{
				$strSQL .= "
				OR
				(
					EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_CB = 'Y'
							AND SLE.ENTITY_ID = ".$created_by_id."
							AND SLE.EVENT_ID = '".$event_id."'
							".$transportFilter."
							".$visibleFilter."
					)
				)";
			}

			$strSQL .= "
			OR
			(
				(
					NOT EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_TYPE = '".$entity_type."'
							AND SLE.ENTITY_CB = 'N'
							AND SLE.ENTITY_ID = ".$entity_id."
							AND SLE.EVENT_ID = '".$event_id."'
					)
					OR
					EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_TYPE = '".$entity_type."'
							AND SLE.ENTITY_CB = 'N'
							AND SLE.ENTITY_ID = ".$entity_id."
							AND SLE.EVENT_ID = '".$event_id."'
							AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
					)
				)";

			if (
				array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["USE_CB_FILTER"] == "Y"
				&& intval($created_by_id) > 0
			)
			{
				$strSQL .= "
				AND
				(
					NOT EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_CB = 'Y'
							AND SLE.ENTITY_ID = ".$created_by_id."
							AND SLE.EVENT_ID = '".$event_id."'
					)
					OR
					EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_CB = 'Y'
							AND SLE.ENTITY_ID = ".$created_by_id."
							AND SLE.EVENT_ID = '".$event_id."'
							AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
					)

				)";
			}

			$strSQL .= "
				AND
				(
					EXISTS(
						SELECT ID
						FROM b_sonet_log_events SLE
						WHERE
							SLE.USER_ID = U.ID
							AND SLE.ENTITY_TYPE = '".$entity_type."'
							AND SLE.ENTITY_CB = 'N'
							AND SLE.ENTITY_ID = ".$entity_id."
							AND SLE.EVENT_ID = 'all'
							".$transportFilter."
							".$visibleFilter."
					)";

			if (
				array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["USE_CB_FILTER"] == "Y"
				&& intval($created_by_id) > 0
			)
			{
				$strSQL .= "
					OR
					(
						EXISTS(
							SELECT ID
							FROM b_sonet_log_events SLE
							WHERE
								SLE.USER_ID = U.ID
								AND SLE.ENTITY_CB = 'Y'
								AND SLE.ENTITY_ID = ".$created_by_id."
								AND SLE.EVENT_ID = 'all'
								".$transportFilter."
								".$visibleFilter."
						)
					)";
			}

			$strSQL .= "
					OR
					(
						(
							NOT EXISTS(
								SELECT ID
								FROM b_sonet_log_events SLE
								WHERE
									SLE.USER_ID = U.ID
									AND SLE.ENTITY_TYPE = '".$entity_type."'
									AND SLE.ENTITY_CB = 'N'
									AND SLE.ENTITY_ID = ".$entity_id."
									AND SLE.EVENT_ID = 'all'
							)
							OR
							EXISTS(
								SELECT ID
								FROM b_sonet_log_events SLE
								WHERE
									SLE.USER_ID = U.ID
									AND SLE.ENTITY_TYPE = '".$entity_type."'
									AND SLE.ENTITY_CB = 'N'
									AND SLE.ENTITY_ID = ".$entity_id."
									AND SLE.EVENT_ID = 'all'
									AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
							)
						)
						AND ";

			if (
				array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["USE_CB_FILTER"] == "Y"
				&& intval($created_by_id) > 0
			)
			{
				$strSQL .= "
						(
							NOT EXISTS(
								SELECT ID
								FROM b_sonet_log_events SLE
								WHERE
									SLE.USER_ID = U.ID
									AND SLE.ENTITY_CB = 'Y'
									AND SLE.ENTITY_ID = ".$created_by_id."
									AND SLE.EVENT_ID = 'all'
							)
							OR
							EXISTS(
								SELECT ID
								FROM b_sonet_log_events SLE
								WHERE
									SLE.USER_ID = U.ID
									AND SLE.ENTITY_CB = 'Y'
									AND SLE.ENTITY_ID = ".$created_by_id."
									AND SLE.EVENT_ID = 'all'
									AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
							)
						)
						AND
						(
						";
			}

			if (strlen($strOfEntities) > 0)
			{
					$strSQL .= "
						(
							".$strOfEntities."
							AND
							(
								EXISTS(
									SELECT ID
									FROM b_sonet_log_events SLE
									WHERE
										SLE.USER_ID = U.ID
										AND SLE.ENTITY_TYPE = '".$entity_type."'
										AND SLE.ENTITY_ID = 0
										AND SLE.ENTITY_MY = 'Y'
										AND SLE.EVENT_ID = '".$event_id."'
										".$transportFilter."
										".$visibleFilter."
								)
								OR
								(
									(
										EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'Y'
												AND SLE.EVENT_ID = '".$event_id."'
												AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
										)
										OR
										NOT EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'Y'
												AND SLE.EVENT_ID = '".$event_id."'
										)
									)
									AND
									(
										EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'Y'
												AND SLE.EVENT_ID = 'all'
												".$transportFilter."
												".$visibleFilter."
										)
									)
								)
							)
						)
						OR
					";
			}

			$strSQL .=	"
							(
								EXISTS(
									SELECT ID
									FROM b_sonet_log_events SLE
									WHERE
										SLE.USER_ID = U.ID
										AND SLE.ENTITY_TYPE = '".$entity_type."'
										AND SLE.ENTITY_ID = 0
										AND SLE.ENTITY_MY = 'N'
										AND SLE.EVENT_ID = '".$event_id."'
										".$transportFilter."
										".$visibleFilter."
								)
								OR
								(
									(
										EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'N'
												AND SLE.EVENT_ID = '".$event_id."'
												AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
											)
										OR
										NOT EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'N'
												AND SLE.EVENT_ID = '".$event_id."'
										)
									)
									AND
									(
										EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'N'
												AND SLE.EVENT_ID = 'all'
										".$transportFilter."
										".$visibleFilter."
										)
										OR
										EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'N'
												AND SLE.EVENT_ID = 'all'
												AND ".($visibleFilter ? "SLE.VISIBLE = 'I'" : "SLE.TRANSPORT = 'I'")."
										)
										OR
										NOT EXISTS(
											SELECT ID
											FROM b_sonet_log_events SLE
											WHERE
												SLE.USER_ID = U.ID
												AND SLE.ENTITY_TYPE = '".$entity_type."'
												AND SLE.ENTITY_ID = 0
												AND SLE.ENTITY_MY = 'N'
												AND SLE.EVENT_ID = 'all'
										)
									)
								)
							)";

			if (
				array_key_exists("USE_CB_FILTER", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type])
				&& $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$entity_type]["USE_CB_FILTER"] == "Y"
				&& intval($created_by_id) > 0
			)
				$strSQL .="
						)";

			$strSQL .="
					)
				)
			)

			)";
		}

		return $strSQL;
	}