Exemplo n.º 1
0
 public static function SendEvent($ID, $mailTemplate = "SONET_NEW_EVENT", $bTransport = false)
 {
     $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
     $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"], $arSocNetAllowedSubscribeEntityTypesDesc) && array_key_exists("HAS_MY", $arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]) && $arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["HAS_MY"] == "Y" && array_key_exists("CLASS_OF", $arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]) && array_key_exists("METHOD_OF", $arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]) && strlen($arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["CLASS_OF"]) > 0 && strlen($arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["METHOD_OF"]) > 0 && method_exists($arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["CLASS_OF"], $arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["METHOD_OF"])) {
         $arOfEntities = call_user_func(array($arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["CLASS_OF"], $arSocNetAllowedSubscribeEntityTypesDesc[$arLogComment["ENTITY_TYPE"]]["METHOD_OF"]), $arLogComment["ENTITY_ID"]);
     }
     if ($bTransport) {
         $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":
                     $link = array_key_exists("URL_TO_SEND", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0 ? GetMessage("SONET_GLC_SEND_EVENT_LINK") . $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] : "";
                     $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"];
                     $arFields["URL"] = array_key_exists("URL_TO_SEND", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0 ? $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] : $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:
             }
         }
     }
     if (!$bHasAccessAll || strtolower($GLOBALS["DB"]->type) != "mysql") {
         CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect2($arLogComment["ID"], array("TYPE" => "LC", "FOR_ALL_ACCESS" => $bHasAccessAll)));
     } else {
         $tag = time();
         CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect2($arLogComment["ID"], array("TYPE" => "LC", "FOR_ALL_ACCESS_ONLY" => true, "TAG_SET" => $tag)), false, array("TAG_SET" => $tag));
         CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect2($arLogComment["ID"], array("TYPE" => "LC", "FOR_ALL_ACCESS_ONLY" => false)), true, array("TAG_CHECK" => $tag));
     }
     return true;
 }
Exemplo n.º 2
0
 function GetList($arOrder = array("ID" => "DESC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array(), $arParams = array())
 {
     global $DB, $arSocNetAllowedEntityTypes, $USER, $USER_FIELD_MANAGER;
     $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
     $obUserFieldsSql = new CUserTypeSQL();
     $obUserFieldsSql->SetEntity("SONET_LOG", "L.ID");
     $obUserFieldsSql->SetSelect($arSelectFields);
     $obUserFieldsSql->SetFilter($arFilter);
     $obUserFieldsSql->SetOrder($arOrder);
     if (count($arSelectFields) <= 0) {
         $arSelectFields = array("ID", "TMP_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "EVENT_ID", "LOG_DATE", "LOG_UPDATE", "TITLE_TEMPLATE", "TITLE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "CALLBACK_FUNC", "EXTERNAL_ID", "SITE_ID", "PARAMS", "COMMENTS_COUNT", "ENABLE_COMMENTS", "SOURCE_ID", "GROUP_NAME", "GROUP_OWNER_ID", "GROUP_INITIATE_PERMS", "GROUP_VISIBLE", "GROUP_OPENED", "GROUP_IMAGE_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "USER_PERSONAL_PHOTO", "USER_PERSONAL_GENDER", "CREATED_BY_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LOGIN", "CREATED_BY_PERSONAL_PHOTO", "CREATED_BY_PERSONAL_GENDER", "RATING_TYPE_ID", "RATING_ENTITY_ID", "RATING_TOTAL_VALUE", "RATING_TOTAL_VOTES", "RATING_TOTAL_POSITIVE_VOTES", "RATING_TOTAL_NEGATIVE_VOTES", "RATING_USER_VOTE_VALUE", "SOURCE_TYPE");
         if (!isset($arParams["USE_FAVORITES"]) || $arParams["USE_FAVORITES"] != "N") {
             $arSelectFields[] = "FAVORITES_USER_ID";
         }
     }
     static $arFields1 = array("ID" => array("FIELD" => "L.ID", "TYPE" => "int"), "TMP_ID" => array("FIELD" => "L.TMP_ID", "TYPE" => "int"), "SOURCE_ID" => array("FIELD" => "L.SOURCE_ID", "TYPE" => "int"), "ENTITY_TYPE" => array("FIELD" => "L.ENTITY_TYPE", "TYPE" => "string"), "ENTITY_ID" => array("FIELD" => "L.ENTITY_ID", "TYPE" => "int"), "USER_ID" => array("FIELD" => "L.USER_ID", "TYPE" => "int"), "EVENT_ID" => array("FIELD" => "L.EVENT_ID", "TYPE" => "string"), "LOG_DATE" => array("FIELD" => "L.LOG_DATE", "TYPE" => "datetime"), "LOG_DATE_TS" => array("FIELD" => "UNIX_TIMESTAMP(L.LOG_DATE)", "TYPE" => "int"), "LOG_UPDATE" => array("FIELD" => "L.LOG_UPDATE", "TYPE" => "datetime"), "TITLE_TEMPLATE" => array("FIELD" => "L.TITLE_TEMPLATE", "TYPE" => "string"), "TITLE" => array("FIELD" => "L.TITLE", "TYPE" => "string"), "MESSAGE" => array("FIELD" => "L.MESSAGE", "TYPE" => "string"), "TEXT_MESSAGE" => array("FIELD" => "L.TEXT_MESSAGE", "TYPE" => "string"), "URL" => array("FIELD" => "L.URL", "TYPE" => "string"), "MODULE_ID" => array("FIELD" => "L.MODULE_ID", "TYPE" => "string"), "CALLBACK_FUNC" => array("FIELD" => "L.CALLBACK_FUNC", "TYPE" => "string"), "EXTERNAL_ID" => array("FIELD" => "L.EXTERNAL_ID", "TYPE" => "string"), "PARAMS" => array("FIELD" => "L.PARAMS", "TYPE" => "string"), "COMMENTS_COUNT" => array("FIELD" => "L.COMMENTS_COUNT", "TYPE" => "int"), "ENABLE_COMMENTS" => array("FIELD" => "L.ENABLE_COMMENTS", "TYPE" => "string"), "SOURCE_TYPE" => array("FIELD" => "L.SOURCE_TYPE", "TYPE" => "string"), "GROUP_NAME" => array("FIELD" => "G.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (L.ENTITY_TYPE = 'G' AND L.ENTITY_ID = G.ID)"), "GROUP_OWNER_ID" => array("FIELD" => "G.OWNER_ID", "TYPE" => "int", "FROM" => "LEFT JOIN b_sonet_group G ON (L.ENTITY_TYPE = 'G' AND L.ENTITY_ID = G.ID)"), "GROUP_INITIATE_PERMS" => array("FIELD" => "G.INITIATE_PERMS", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (L.ENTITY_TYPE = 'G' AND L.ENTITY_ID = G.ID)"), "GROUP_VISIBLE" => array("FIELD" => "G.VISIBLE", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (L.ENTITY_TYPE = 'G' AND L.ENTITY_ID = G.ID)"), "GROUP_OPENED" => array("FIELD" => "G.OPENED", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (L.ENTITY_TYPE = 'G' AND L.ENTITY_ID = G.ID)"), "GROUP_IMAGE_ID" => array("FIELD" => "G.IMAGE_ID", "TYPE" => "int", "FROM" => "LEFT JOIN b_sonet_group G ON (L.ENTITY_TYPE = 'G' AND L.ENTITY_ID = G.ID)"), "USER_NAME" => array("FIELD" => "U.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (L.ENTITY_TYPE = 'U' AND L.ENTITY_ID = U.ID)"), "USER_LAST_NAME" => array("FIELD" => "U.LAST_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (L.ENTITY_TYPE = 'U' AND L.ENTITY_ID = U.ID)"), "USER_SECOND_NAME" => array("FIELD" => "U.SECOND_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (L.ENTITY_TYPE = 'U' AND L.ENTITY_ID = U.ID)"), "USER_LOGIN" => array("FIELD" => "U.LOGIN", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (L.ENTITY_TYPE = 'U' AND L.ENTITY_ID = U.ID)"), "USER_PERSONAL_PHOTO" => array("FIELD" => "U.PERSONAL_PHOTO", "TYPE" => "int", "FROM" => "LEFT JOIN b_user U ON (L.ENTITY_TYPE = 'U' AND L.ENTITY_ID = U.ID)"), "USER_PERSONAL_GENDER" => array("FIELD" => "U.PERSONAL_GENDER", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (L.ENTITY_TYPE = 'U' AND L.ENTITY_ID = U.ID)"), "CREATED_BY_NAME" => array("FIELD" => "U1.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON L.USER_ID = U1.ID"), "CREATED_BY_LAST_NAME" => array("FIELD" => "U1.LAST_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON L.USER_ID = U1.ID"), "CREATED_BY_SECOND_NAME" => array("FIELD" => "U1.SECOND_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON L.USER_ID = U1.ID"), "CREATED_BY_LOGIN" => array("FIELD" => "U1.LOGIN", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON L.USER_ID = U1.ID"), "CREATED_BY_PERSONAL_PHOTO" => array("FIELD" => "U1.PERSONAL_PHOTO", "TYPE" => "int", "FROM" => "LEFT JOIN b_user U1 ON L.USER_ID = U1.ID"), "CREATED_BY_PERSONAL_GENDER" => array("FIELD" => "U1.PERSONAL_GENDER", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON L.USER_ID = U1.ID"), "USER_ID|COMMENT_USER_ID" => array("FIELD" => "L.USER_ID|LC.USER_ID", "WHERE" => array("CSocNetLog", "GetSimpleOrQuery"), "FROM" => "LEFT JOIN b_sonet_log_comment LC ON LC.LOG_ID = L.ID"));
     $arFields = array("RATING_TYPE_ID" => array("FIELD" => "L.RATING_TYPE_ID", "TYPE" => "string"), "RATING_ENTITY_ID" => array("FIELD" => "L.RATING_ENTITY_ID", "TYPE" => "int"), "RATING_TOTAL_VALUE" => array("FIELD" => $DB->IsNull('RG.TOTAL_VALUE', '0'), "TYPE" => "double", "FROM" => "LEFT JOIN b_rating_voting RG ON L.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND L.RATING_ENTITY_ID = RG.ENTITY_ID"), "RATING_TOTAL_VOTES" => array("FIELD" => $DB->IsNull('RG.TOTAL_VOTES', '0'), "TYPE" => "double", "FROM" => "LEFT JOIN b_rating_voting RG ON L.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND L.RATING_ENTITY_ID = RG.ENTITY_ID"), "RATING_TOTAL_POSITIVE_VOTES" => array("FIELD" => $DB->IsNull('RG.TOTAL_POSITIVE_VOTES', '0'), "TYPE" => "int", "FROM" => "LEFT JOIN b_rating_voting RG ON L.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND L.RATING_ENTITY_ID = RG.ENTITY_ID"), "RATING_TOTAL_NEGATIVE_VOTES" => array("FIELD" => $DB->IsNull('RG.TOTAL_NEGATIVE_VOTES', '0'), "TYPE" => "int", "FROM" => "LEFT JOIN b_rating_voting RG ON L.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND L.RATING_ENTITY_ID = RG.ENTITY_ID"));
     if (isset($USER) && is_object($USER)) {
         $arFields["RATING_USER_VOTE_VALUE"] = array("FIELD" => $DB->IsNull('RV.VALUE', '0'), "TYPE" => "double", "FROM" => "LEFT JOIN b_rating_vote RV ON L.RATING_TYPE_ID = RV.ENTITY_TYPE_ID AND L.RATING_ENTITY_ID = RV.ENTITY_ID AND RV.USER_ID = " . intval($USER->GetID()));
         if (!isset($arParams["USE_FAVORITES"]) || $arParams["USE_FAVORITES"] != "N") {
             $join_type = "LEFT";
             $field_value = $DB->IsNull("SLF.USER_ID", "0");
             foreach ($arFilter as $key => $value) {
                 if (strpos($key, "FAVORITES_USER_ID") !== false) {
                     $join_type = "INNER";
                     $field_value = "SLF.USER_ID";
                     break;
                 }
             }
             $arFields["FAVORITES_USER_ID"] = array("FIELD" => $field_value, "TYPE" => "double", "FROM" => $join_type . " JOIN b_sonet_log_favorites SLF ON L.ID = SLF.LOG_ID AND SLF.USER_ID = " . intval($USER->GetID()));
         }
     }
     if (isset($USER) && is_object($USER) && $USER->IsAuthorized() && $arParams["USE_FOLLOW"] == "Y") {
         $default_follow = CSocNetLogFollow::GetDefaultValue($USER->GetID());
         $default_field = $default_follow == "Y" ? "LOG_UPDATE" : "LOG_DATE";
         $arFields["DATE_FOLLOW"] = array("FIELD" => "CASE\n\t\t\t\t\tWHEN LFW.USER_ID IS NULL\n\t\t\t\t\t\tTHEN L." . $default_field . "\n\t\t\t\t\tWHEN LFW.FOLLOW_DATE IS NOT NULL\n\t\t\t\t\t\tTHEN LFW.FOLLOW_DATE\n\t\t\t\t\tWHEN LFW.TYPE = 'Y'\n\t\t\t\t\t\tTHEN L.LOG_UPDATE\n\t\t\t\t\tELSE L.LOG_DATE\n\t\t\t\tEND", "TYPE" => "datetime", "FROM" => "LEFT JOIN b_sonet_log_follow LFW ON LFW.USER_ID = " . $USER->GetID() . " AND LFW.REF_ID = L.ID AND LFW.CODE = " . $DB->Concat("'L'", "L.ID"));
         $arFields["FOLLOW"] = array("FIELD" => "CASE\n\t\t\t\t\tWHEN LFW.USER_ID IS NULL\n\t\t\t\t\t\tTHEN '" . $default_follow . "'\n\t\t\t\t\tELSE LFW.TYPE\n\t\t\t\tEND", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_log_follow LFW ON LFW.USER_ID = " . $USER->GetID() . " AND LFW.REF_ID = L.ID AND LFW.CODE = " . $DB->Concat("'L'", "L.ID"));
         if (!in_array("FOLLOW", $arSelectFields)) {
             $arSelectFields[] = "FOLLOW";
         }
     }
     if (array_key_exists("SITE_ID", $arFilter)) {
         $arFields["SITE_ID"] = array("FIELD" => "SLS.SITE_ID", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_log_site SLS ON L.ID = SLS.LOG_ID");
         if (is_array($arFilter["SITE_ID"])) {
             $site_cnt = 0;
             foreach ($arFilter["SITE_ID"] as $site_id_tmp) {
                 if ($site_id_tmp) {
                     $site_cnt++;
                 }
             }
             $strDistinct = $site_cnt > 1 ? " DISTINCT " : " ";
         } else {
             $strDistinct = " ";
         }
         foreach ($arSelectFields as $i => $strFieldTmp) {
             if ($strFieldTmp == "SITE_ID") {
                 unset($arSelectFields[$i]);
             }
         }
         foreach ($arOrder as $by => $order) {
             if (!in_array($by, $arSelectFields)) {
                 $arSelectFields[] = $by;
             }
         }
     } else {
         $arFields["SITE_ID"] = array("FIELD" => "L.SITE_ID", "TYPE" => "string");
         $strDistinct = " ";
     }
     if (array_key_exists("USER_ID", $arFilter) && !array_key_exists("ENTITY_TYPE", $arFilter)) {
         $arCBFilterEntityType = array();
         foreach ($arSocNetAllowedSubscribeEntityTypesDesc as $entity_type_tmp => $arEntityTypeTmp) {
             if (array_key_exists("USE_CB_FILTER", $arEntityTypeTmp) && $arEntityTypeTmp["USE_CB_FILTER"] == "Y") {
                 $arCBFilterEntityType[] = $entity_type_tmp;
             }
         }
         if (is_array($arCBFilterEntityType) && count($arCBFilterEntityType) > 0) {
             $arFilter["ENTITY_TYPE"] = $arCBFilterEntityType;
         }
     }
     if (array_key_exists("LOG_RIGHTS", $arFilter)) {
         $Rights = array();
         if (is_array($arFilter["LOG_RIGHTS"])) {
             foreach ($arFilter["LOG_RIGHTS"] as $str) {
                 if (trim($str)) {
                     $Rights[] = trim($str);
                 }
             }
         } elseif (trim($arFilter["LOG_RIGHTS"])) {
             $Rights = trim($arFilter["LOG_RIGHTS"]);
         }
         unset($arFilter["LOG_RIGHTS"]);
         if (is_array($Rights) && !empty($Rights) || !is_array($Rights)) {
             $arFilter["LOG_RIGHTS"] = $Rights;
             $arFields["LOG_RIGHTS"] = array("FIELD" => "SLR0.GROUP_CODE", "TYPE" => "string", "FROM" => "INNER JOIN b_sonet_log_right SLR0 ON L.ID = SLR0.LOG_ID");
         }
         if (is_array($Rights) && count($Rights) > 1) {
             $strDistinct = " DISTINCT ";
         }
     }
     if (array_key_exists("USER_ID|COMMENT_USER_ID", $arFilter)) {
         $strDistinct = " DISTINCT ";
     }
     if ($arParams["IS_CRM"] == "Y") {
         $events = GetModuleEvents("socialnetwork", "OnFillSocNetLogFields");
         while ($arEvent = $events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array(&$arFields));
         }
     }
     $arFields = array_merge($arFields1, $arFields);
     $arSqls = CSocNetGroup::PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields, $obUserFieldsSql);
     $listEvents = GetModuleEvents("socialnetwork", "OnBuildSocNetLogSql");
     while ($arEvent = $listEvents->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(&$arFields, &$arOrder, &$arFilter, &$arGroupBy, &$arSelectFields, &$arSqls));
     }
     $r = $obUserFieldsSql->GetFilter();
     if (strlen($r) > 0) {
         $strSqlUFFilter = " (" . $r . ") ";
     }
     $arSqls["RIGHTS"] = "";
     $arSqls["CRM_RIGHTS"] = "";
     if (!empty($arParams) && (array_key_exists("CHECK_RIGHTS", $arParams) && $arParams["CHECK_RIGHTS"] == "Y" || array_key_exists("CHECK_CRM_RIGHTS", $arParams) && $arParams["CHECK_CRM_RIGHTS"] == "Y") && !array_key_exists("USER_ID", $arParams) && is_object($USER)) {
         $arParams["USER_ID"] = $USER->GetID();
     }
     if (!empty($arParams) && array_key_exists("USER_ID", $arParams) && $arParams["CHECK_CRM_RIGHTS"] != "Y") {
         $arParams["CHECK_RIGHTS"] = "Y";
     }
     if (!empty($arParams) && ($arParams["USE_SUBSCRIBE"] == "Y" || $arParams["USE_FOLLOW"] == "Y")) {
         if (!array_key_exists("SUBSCRIBE_USER_ID", $arParams)) {
             if (array_key_exists("USER_ID", $arParams) && intval($arParams["USER_ID"]) > 0) {
                 $arParams["SUBSCRIBE_USER_ID"] = $arParams["USER_ID"];
             } elseif (is_object($USER)) {
                 $arParams["SUBSCRIBE_USER_ID"] = $USER->GetID();
             }
         }
         if ($arParams["USE_SUBSCRIBE"] == "Y" && !array_key_exists("MY_ENTITIES", $arParams)) {
             foreach ($arSocNetAllowedSubscribeEntityTypesDesc as $entity_type_tmp => $arEntityTypeTmp) {
                 if (array_key_exists("HAS_MY", $arEntityTypeTmp) && $arEntityTypeTmp["HAS_MY"] == "Y" && array_key_exists("CLASS_MY", $arEntityTypeTmp) && array_key_exists("METHOD_MY", $arEntityTypeTmp) && strlen($arEntityTypeTmp["CLASS_MY"]) > 0 && strlen($arEntityTypeTmp["METHOD_MY"]) > 0 && method_exists($arEntityTypeTmp["CLASS_MY"], $arEntityTypeTmp["METHOD_MY"])) {
                     $arMyEntities[$entity_type_tmp] = call_user_func(array($arEntityTypeTmp["CLASS_MY"], $arEntityTypeTmp["METHOD_MY"]));
                 }
             }
             $arParams["MY_ENTITIES"] = $arMyEntities;
         }
     }
     if (!empty($arParams) && array_key_exists("CHECK_RIGHTS", $arParams) && $arParams["CHECK_RIGHTS"] == "Y" && array_key_exists("USER_ID", $arParams)) {
         $acc = new CAccess();
         $acc->UpdateCodes();
         $arSqls["RIGHTS"] = "EXISTS ( SELECT SLR.ID FROM b_sonet_log_right SLR\n\t\t\t\tLEFT JOIN b_user_access UA ON (UA.ACCESS_CODE = SLR.GROUP_CODE AND UA.USER_ID = " . (is_object($USER) ? intval($USER->GetID()) : 0) . ")\n\t\t\t\tWHERE L.ID = SLR.LOG_ID " . (is_object($USER) && $USER->IsAuthorized() && $arParams["MY_GROUPS_ONLY"] == "Y" ? " AND (\n\t\t\t\t\t\t\t\t(SLR.GROUP_CODE LIKE 'SG%' AND (UA.ACCESS_CODE = SLR.GROUP_CODE AND UA.USER_ID = " . intval($USER->GetID()) . ")) \n\t\t\t\t\t\t\t\tOR SLR.GROUP_CODE = 'U" . intval($USER->GetID()) . "'\n\t\t\t\t\t\t\t)" : " AND (\n\t\t\t\t\t\t\t\t0=1 " . (is_object($USER) && CSocNetUser::IsCurrentUserModuleAdmin() ? " OR SLR.GROUP_CODE = 'SA'" : "") . (is_object($USER) && $USER->IsAuthorized() ? " OR (SLR.GROUP_CODE = 'AU')" : "") . " OR (SLR.GROUP_CODE = 'G2')" . (is_object($USER) && $USER->IsAuthorized() ? " OR (UA.ACCESS_CODE = SLR.GROUP_CODE AND UA.USER_ID = " . intval($USER->GetID()) . ")" : "") . "\n\t\t\t\t\t\t\t)") . ")";
     }
     if (!empty($arParams) && array_key_exists("CHECK_CRM_RIGHTS", $arParams) && $arParams["CHECK_CRM_RIGHTS"] == "Y" && array_key_exists("USER_ID", $arParams)) {
         $permParams = array('ALIAS_PREFIX' => 'L', 'PERM_TYPE' => 'READ', 'FILTER_PARAMS' => isset($arParams['CUSTOM_FILTER_PARAMS']) ? $arParams['CUSTOM_FILTER_PARAMS'] : array(), 'OPTIONS' => array('ENTITY_TYPE_COLUMN' => 'ENTITY_TYPE', 'IDENTITY_COLUMN' => 'ENTITY_ID'));
         $altPerms = array();
         $events = GetModuleEvents("socialnetwork", "OnBuildSocNetLogPerms");
         while ($arEvent = $events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array(&$altPerms, $permParams));
         }
         if (!empty($altPerms)) {
             foreach ($altPerms as $permSql) {
                 if ($permSql === false) {
                     //Access denied
                     $dbRes = new CDBResult();
                     $dbRes->InitFromArray(array());
                     return $dbRes;
                 }
                 if (is_string($permSql) && $permSql !== '') {
                     if ($arSqls['CRM_RIGHTS'] !== '') {
                         $arSqls['CRM_RIGHTS'] .= ' AND ';
                     }
                     $arSqls['CRM_RIGHTS'] = $permSql;
                 }
             }
         }
     }
     if ($arParams["USE_SUBSCRIBE"] == "Y" && intval($arParams["SUBSCRIBE_USER_ID"]) > 0) {
         $arSqls["SUBSCRIBE"] = CSocNetLogEvents::GetSQL($arParams["SUBSCRIBE_USER_ID"], is_array($arParams["MY_ENTITIES"]) ? $arParams["MY_ENTITIES"] : array(), $arParams["TRANSPORT"], $arParams["VISIBLE"]);
         $arParams["MIN_ID_JOIN"] = true;
     }
     $arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", $strDistinct, $arSqls["SELECT"]);
     $strMinIDJoin = "";
     if (is_array($arGroupBy) && count($arGroupBy) == 0) {
         $strSql = "SELECT " . $arSqls["SELECT"] . " " . $obUserFieldsSql->GetSelect() . " " . "FROM b_sonet_log L " . $strMinIDJoin . "\t" . $arSqls["FROM"] . " " . $obUserFieldsSql->GetJoin("L.ID") . " ";
         $bWhereStarted = false;
         if (strlen($arSqls["WHERE"]) > 0) {
             $strSql .= "WHERE " . $arSqls["WHERE"] . " ";
             $bWhereStarted = true;
         }
         if (strlen($strSqlUFFilter) > 0) {
             $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . $strSqlUFFilter . " ";
             $bWhereStarted = true;
         }
         if (strlen($arSqls["RIGHTS"]) > 0) {
             $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . $arSqls["RIGHTS"] . " ";
             $bWhereStarted = true;
         }
         if (strlen($arSqls["CRM_RIGHTS"]) > 0) {
             $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . $arSqls["CRM_RIGHTS"] . " ";
             $bWhereStarted = true;
         }
         if (strlen($arSqls["SUBSCRIBE"]) > 0) {
             $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . "(" . $arSqls["SUBSCRIBE"] . ") ";
             $bWhereStarted = true;
         }
         if (strlen($arSqls["GROUPBY"]) > 0) {
             $strSql .= "GROUP BY " . $arSqls["GROUPBY"] . " ";
         }
         //echo "!1!=".htmlspecialcharsbx($strSql)."<br>";
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($arRes = $dbRes->Fetch()) {
             return $arRes["CNT"];
         } else {
             return False;
         }
     }
     $strSql = "SELECT " . $arSqls["SELECT"] . " " . $obUserFieldsSql->GetSelect() . " " . "FROM b_sonet_log L " . $strMinIDJoin . "\t" . $arSqls["FROM"] . " " . $obUserFieldsSql->GetJoin("L.ID") . " ";
     $bWhereStarted = false;
     if (strlen($arSqls["WHERE"]) > 0) {
         $strSql .= "WHERE " . $arSqls["WHERE"] . " ";
         $bWhereStarted = true;
     }
     if (strlen($strSqlUFFilter) > 0) {
         $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . $strSqlUFFilter . " ";
         $bWhereStarted = true;
     }
     if (strlen($arSqls["RIGHTS"]) > 0) {
         $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . $arSqls["RIGHTS"] . " ";
         $bWhereStarted = true;
     }
     if (strlen($arSqls["CRM_RIGHTS"]) > 0) {
         $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . $arSqls["CRM_RIGHTS"] . " ";
         $bWhereStarted = true;
     }
     if (strlen($arSqls["SUBSCRIBE"]) > 0) {
         $strSql .= ($bWhereStarted ? " AND " : " WHERE ") . "(" . $arSqls["SUBSCRIBE"] . ") ";
         $bWhereStarted = true;
     }
     if (strlen($arSqls["GROUPBY"]) > 0) {
         $strSql .= "GROUP BY " . $arSqls["GROUPBY"] . " ";
     }
     if (strlen($arSqls["ORDERBY"]) > 0) {
         $strSql .= "ORDER BY " . $arSqls["ORDERBY"] . " ";
     }
     if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) <= 0) {
         if (isset($arNavStartParams["nRecordCount"]) && intval($arNavStartParams["nRecordCount"]) > 0) {
             $cnt = intval($arNavStartParams["nRecordCount"]);
         } else {
             $strSql_tmp = "SELECT COUNT('x') as CNT " . $obUserFieldsSql->GetSelect() . " " . "FROM b_sonet_log L " . $strMinIDJoin . "\t" . $arSqls["FROM"] . " " . $obUserFieldsSql->GetJoin("L.ID") . " ";
             $bWhereStarted = false;
             if (strlen($arSqls["WHERE"]) > 0) {
                 $strSql_tmp .= "WHERE " . $arSqls["WHERE"] . " ";
                 $bWhereStarted = true;
             }
             if (strlen($strSqlUFFilter) > 0) {
                 $strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ") . $strSqlUFFilter . " ";
                 $bWhereStarted = true;
             }
             if (strlen($arSqls["RIGHTS"]) > 0) {
                 $strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ") . $arSqls["RIGHTS"] . " ";
                 $bWhereStarted = true;
             }
             if (strlen($arSqls["CRM_RIGHTS"]) > 0) {
                 $strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ") . $arSqls["CRM_RIGHTS"] . " ";
                 $bWhereStarted = true;
             }
             if (strlen($arSqls["SUBSCRIBE"]) > 0) {
                 $strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ") . "(" . $arSqls["SUBSCRIBE"] . ") ";
                 $bWhereStarted = true;
             }
             if (strlen($arSqls["GROUPBY"]) > 0) {
                 $strSql_tmp .= "GROUP BY " . $arSqls["GROUPBY"] . " ";
             }
             //echo "!2.1!=".htmlspecialcharsbx($strSql_tmp)."<br>";
             $dbRes = $DB->Query($strSql_tmp, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             $cnt = 0;
             if (strlen($arSqls["GROUPBY"]) <= 0) {
                 if ($arRes = $dbRes->Fetch()) {
                     $cnt = $arRes["CNT"];
                 }
             } else {
                 // рнкэйн дкъ MYSQL!!! дкъ ORACLE дпсцни йнд
                 $cnt = $dbRes->SelectedRowsCount();
             }
             // for empty 2nd page show
             if ($arNavStartParams["bSkipPageReset"] && $arNavStartParams["nPageSize"] >= $cnt) {
                 $cnt = $arNavStartParams["nPageSize"] + $cnt;
             }
         }
         $dbRes = new CDBResult();
         //echo "!2.2!=".htmlspecialcharsbx($strSql)."<br>";
         $dbRes->SetUserFields($USER_FIELD_MANAGER->GetUserFields("SONET_LOG"));
         $dbRes->NavQuery($strSql, $cnt, $arNavStartParams);
     } else {
         if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) > 0) {
             $strSql .= "LIMIT " . intval($arNavStartParams["nTopCount"]);
         }
         //echo "!3!=".htmlspecialcharsbx($strSql)."<br>";
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $dbRes->SetUserFields($USER_FIELD_MANAGER->GetUserFields("SONET_LOG"));
     }
     return $dbRes;
 }
Exemplo n.º 3
0
	function GetList($arOrder = Array("ID" => "DESC"), $arFilter = Array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array(), $arParams = array())
	{
		global $DB, $arSocNetAllowedEntityTypes, $USER, $USER_FIELD_MANAGER;

		$arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();

		$obUserFieldsSql = new CUserTypeSQL;
		$obUserFieldsSql->SetEntity("SONET_COMMENT", "LC.ID");
		$obUserFieldsSql->SetSelect($arSelectFields);
		$obUserFieldsSql->SetFilter($arFilter);
		$obUserFieldsSql->SetOrder($arOrder);

		if (count($arSelectFields) <= 0)
			$arSelectFields = array(
				"ID", "LOG_ID", "SOURCE_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID",
				"GROUP_NAME", "GROUP_OWNER_ID", "GROUP_VISIBLE", "GROUP_OPENED", "GROUP_IMAGE_ID",
				"USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "USER_PERSONAL_PHOTO", "USER_PERSONAL_GENDER",
				"CREATED_BY_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LOGIN", "CREATED_BY_PERSONAL_PHOTO", "CREATED_BY_PERSONAL_GENDER",
				"LOG_SITE_ID", "LOG_SOURCE_ID", "LOG_USER_ID",
				"RATING_TYPE_ID", "RATING_ENTITY_ID", "RATING_TOTAL_VALUE", "RATING_TOTAL_VOTES", "RATING_TOTAL_POSITIVE_VOTES", "RATING_TOTAL_NEGATIVE_VOTES", "RATING_USER_VOTE_VALUE"
			);

		static $arFields1 = array(
			"ID" => Array("FIELD" => "LC.ID", "TYPE" => "int"),
			"LOG_ID" => Array("FIELD" => "LC.LOG_ID", "TYPE" => "int"),
			"SOURCE_ID" => Array("FIELD" => "LC.SOURCE_ID", "TYPE" => "int"),
			"ENTITY_TYPE" => Array("FIELD" => "LC.ENTITY_TYPE", "TYPE" => "string"),
			"ENTITY_ID" => Array("FIELD" => "LC.ENTITY_ID", "TYPE" => "int"),
			"USER_ID" => Array("FIELD" => "LC.USER_ID", "TYPE" => "int"),
			"EVENT_ID" => Array("FIELD" => "LC.EVENT_ID", "TYPE" => "string"),
			"LOG_DATE" => Array("FIELD" => "LC.LOG_DATE", "TYPE" => "datetime"),
			"LOG_DATE_TS" => Array("FIELD" => "UNIX_TIMESTAMP(LC.LOG_DATE)", "TYPE" => "int"),
			"TITLE" => Array("FIELD" => "LC.TITLE", "TYPE" => "string"),
			"MESSAGE" => Array("FIELD" => "LC.MESSAGE", "TYPE" => "string"),
			"TEXT_MESSAGE" => Array("FIELD" => "LC.TEXT_MESSAGE", "TYPE" => "string"),
			"URL" => Array("FIELD" => "LC.URL", "TYPE" => "string"),
			"MODULE_ID" => Array("FIELD" => "LC.MODULE_ID", "TYPE" => "string"),
			"LOG_SOURCE_ID" => Array("FIELD" => "L.SOURCE_ID", "TYPE" => "int", "FROM" => "LEFT JOIN b_sonet_log L ON (LC.LOG_ID = L.ID)"),
			"LOG_USER_ID" => Array("FIELD" => "L.USER_ID", "TYPE" => "int", "FROM" => "LEFT JOIN b_sonet_log L ON (LC.LOG_ID = L.ID)"),
			"LOG_TITLE" => Array("FIELD" => "L1.TITLE", "TYPE" => "string", "FROM" => "INNER JOIN b_sonet_log L1 ON (LC.LOG_ID = L1.ID)"),
			"LOG_URL" => Array("FIELD" => "L1.URL", "TYPE" => "string", "FROM" => "INNER JOIN b_sonet_log L1 ON (LC.LOG_ID = L1.ID)"),
			"LOG_PARAMS" => Array("FIELD" => "L1.PARAMS", "TYPE" => "string", "FROM" => "INNER JOIN b_sonet_log L1 ON (LC.LOG_ID = L1.ID)"),
			"GROUP_NAME" => Array("FIELD" => "G.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (LC.ENTITY_TYPE = 'G' AND LC.ENTITY_ID = G.ID)"),
			"GROUP_OWNER_ID" => Array("FIELD" => "G.OWNER_ID", "TYPE" => "int", "FROM" => "LEFT JOIN b_sonet_group G ON (LC.ENTITY_TYPE = 'G' AND LC.ENTITY_ID = G.ID)"),
			"GROUP_VISIBLE" => Array("FIELD" => "G.VISIBLE", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (LC.ENTITY_TYPE = 'G' AND LC.ENTITY_ID = G.ID)"),
			"GROUP_OPENED" => Array("FIELD" => "G.OPENED", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_group G ON (LC.ENTITY_TYPE = 'G' AND LC.ENTITY_ID = G.ID)"),
			"GROUP_IMAGE_ID" => Array("FIELD" => "G.IMAGE_ID", "TYPE" => "int", "FROM" => "LEFT JOIN b_sonet_group G ON (LC.ENTITY_TYPE = 'G' AND LC.ENTITY_ID = G.ID)"),
			"USER_NAME" => Array("FIELD" => "U.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (LC.ENTITY_TYPE = 'U' AND LC.ENTITY_ID = U.ID)"),
			"USER_LAST_NAME" => Array("FIELD" => "U.LAST_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (LC.ENTITY_TYPE = 'U' AND LC.ENTITY_ID = U.ID)"),
			"USER_SECOND_NAME" => Array("FIELD" => "U.SECOND_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (LC.ENTITY_TYPE = 'U' AND LC.ENTITY_ID = U.ID)"),
			"USER_LOGIN" => Array("FIELD" => "U.LOGIN", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (LC.ENTITY_TYPE = 'U' AND LC.ENTITY_ID = U.ID)"),
			"USER_PERSONAL_PHOTO" => Array("FIELD" => "U.PERSONAL_PHOTO", "TYPE" => "int", "FROM" => "LEFT JOIN b_user U ON (LC.ENTITY_TYPE = 'U' AND LC.ENTITY_ID = U.ID)"),
			"USER_PERSONAL_GENDER" => Array("FIELD" => "U.PERSONAL_GENDER", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U ON (LC.ENTITY_TYPE = 'U' AND LC.ENTITY_ID = U.ID)"),
			"CREATED_BY_NAME" => Array("FIELD" => "U1.NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON LC.USER_ID = U1.ID"),
			"CREATED_BY_LAST_NAME" => Array("FIELD" => "U1.LAST_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON LC.USER_ID = U1.ID"),
			"CREATED_BY_SECOND_NAME" => Array("FIELD" => "U1.SECOND_NAME", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON LC.USER_ID = U1.ID"),
			"CREATED_BY_LOGIN" => Array("FIELD" => "U1.LOGIN", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON LC.USER_ID = U1.ID"),
			"CREATED_BY_PERSONAL_PHOTO" => Array("FIELD" => "U1.PERSONAL_PHOTO", "TYPE" => "int", "FROM" => "LEFT JOIN b_user U1 ON LC.USER_ID = U1.ID"),
			"CREATED_BY_PERSONAL_GENDER" => Array("FIELD" => "U1.PERSONAL_GENDER", "TYPE" => "string", "FROM" => "LEFT JOIN b_user U1 ON LC.USER_ID = U1.ID"),
		);

		if (array_key_exists("LOG_SITE_ID", $arFilter))
		{
			$arFields["LOG_SITE_ID"] = Array("FIELD" => "SLS.SITE_ID", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_log_site SLS ON LC.LOG_ID = SLS.LOG_ID");
			$strDistinct = " DISTINCT ";
			foreach ($arSelectFields as $i => $strFieldTmp)
				if ($strFieldTmp == "LOG_SITE_ID")
					unset($arSelectFields[$i]);

			foreach ($arOrder as $by => $order)
				if (!in_array($by, $arSelectFields))
					$arSelectFields[] = $by;
		}
		else
		{
			$arFields["LOG_SITE_ID"] = Array("FIELD" => "L.SITE_ID", "TYPE" => "string", "FROM" => "LEFT JOIN b_sonet_log L ON (LC.LOG_ID = L.ID)");
			$strDistinct = " ";
		}

		$arFields["RATING_TYPE_ID"] = Array("FIELD" => "LC.RATING_TYPE_ID", "TYPE" => "string");
		$arFields["RATING_ENTITY_ID"] = Array("FIELD" => "LC.RATING_ENTITY_ID", "TYPE" => "int");
		$arFields["RATING_TOTAL_VALUE"] = Array("FIELD" => $DB->IsNull('RG.TOTAL_VALUE', '0'), "TYPE" => "double", "FROM" => "LEFT JOIN b_rating_voting RG ON LC.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND LC.RATING_ENTITY_ID = RG.ENTITY_ID");
		$arFields["RATING_TOTAL_VOTES"] = Array("FIELD" => $DB->IsNull('RG.TOTAL_VOTES', '0'), "TYPE" => "double", "FROM" => "LEFT JOIN b_rating_voting RG ON LC.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND LC.RATING_ENTITY_ID = RG.ENTITY_ID");
		$arFields["RATING_TOTAL_POSITIVE_VOTES"] = Array("FIELD" => $DB->IsNull('RG.TOTAL_POSITIVE_VOTES', '0'), "TYPE" => "int", "FROM" => "LEFT JOIN b_rating_voting RG ON LC.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND LC.RATING_ENTITY_ID = RG.ENTITY_ID");
		$arFields["RATING_TOTAL_NEGATIVE_VOTES"] = Array("FIELD" => $DB->IsNull('RG.TOTAL_NEGATIVE_VOTES', '0'), "TYPE" => "int", "FROM" => "LEFT JOIN b_rating_voting RG ON LC.RATING_TYPE_ID = RG.ENTITY_TYPE_ID AND LC.RATING_ENTITY_ID = RG.ENTITY_ID");
		if (isset($USER) && is_object($USER))
			$arFields["RATING_USER_VOTE_VALUE"] = Array("FIELD" => $DB->IsNull('RV.VALUE', '0'), "TYPE" => "double", "FROM" => "LEFT JOIN b_rating_vote RV ON LC.RATING_TYPE_ID = RV.ENTITY_TYPE_ID AND LC.RATING_ENTITY_ID = RV.ENTITY_ID AND RV.USER_ID = ".intval($USER->GetId()));

		if (array_key_exists("LOG_RIGHTS", $arFilter))
		{
			$Rights = array();
			if(is_array($arFilter["LOG_RIGHTS"]))
			{
				foreach($arFilter["LOG_RIGHTS"] as $str)
					if(trim($str))
						$Rights[] = trim($str);
			}
			elseif(trim($arFilter["LOG_RIGHTS"]))
				$Rights = trim($arFilter["LOG_RIGHTS"]);

			unset($arFilter["LOG_RIGHTS"]);
			if((is_array($Rights) && !empty($Rights)) || !is_array($Rights))
			{
				$arFilter["LOG_RIGHTS"] = $Rights;
				$arFields["LOG_RIGHTS"] = Array("FIELD" => "SLR0.GROUP_CODE", "TYPE" => "string", "FROM" => "INNER JOIN b_sonet_log_right SLR0 ON LC.LOG_ID = SLR0.LOG_ID");
			}

			if(is_array($Rights) && count($Rights) > 1)
				$strDistinct = " DISTINCT ";
		}

		$arFields = array_merge($arFields1, $arFields);

		$arSqls = CSocNetGroup::PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields, $obUserFieldsSql);

		$r = $obUserFieldsSql->GetFilter();
		if(strlen($r)>0)
			$strSqlUFFilter = " (".$r.") ";

		$arSqls["RIGHTS"] = "";
		$arSqls["CRM_RIGHTS"] = "";

		if (
			!empty($arParams)
			&& array_key_exists("CHECK_RIGHTS", $arParams)
			&& $arParams["CHECK_RIGHTS"] == "Y"
			&& !array_key_exists("USER_ID", $arParams)
			&& is_object($GLOBALS["USER"])
		)
			$arParams["USER_ID"] = $GLOBALS["USER"]->GetID();

		if (
			!empty($arParams)
			&& array_key_exists("USER_ID", $arParams)
		)
			$arParams["CHECK_RIGHTS"] = "Y";

		if (
			!empty($arParams)
			&& array_key_exists("USE_SUBSCRIBE", $arParams)
			&& $arParams["USE_SUBSCRIBE"] == "Y"
		)
		{
			if (!array_key_exists("SUBSCRIBE_USER_ID", $arParams))
			{
				if (
					array_key_exists("USER_ID", $arParams)
					&& intval($arParams["USER_ID"]) > 0
				)
					$arParams["SUBSCRIBE_USER_ID"] = $arParams["USER_ID"];
				else
					$arParams["SUBSCRIBE_USER_ID"] = $GLOBALS["USER"]->GetID();
			}

			if (!array_key_exists("MY_ENTITIES", $arParams))
			{
				foreach($arSocNetAllowedSubscribeEntityTypesDesc as $entity_type_tmp => $arEntityTypeTmp)
					if (
						array_key_exists("HAS_MY", $arEntityTypeTmp)
						&& $arEntityTypeTmp["HAS_MY"] == "Y"
						&& array_key_exists("CLASS_MY", $arEntityTypeTmp)
						&& array_key_exists("METHOD_MY", $arEntityTypeTmp)
						&& strlen($arEntityTypeTmp["CLASS_MY"]) > 0
						&& strlen($arEntityTypeTmp["METHOD_MY"]) > 0
						&& method_exists($arEntityTypeTmp["CLASS_MY"], $arEntityTypeTmp["METHOD_MY"])
					)
						$arMyEntities[$entity_type_tmp] = call_user_func(array($arEntityTypeTmp["CLASS_MY"], $arEntityTypeTmp["METHOD_MY"]));

				$arParams["MY_ENTITIES"] = $arMyEntities;
			}
		}

		if (
			!empty($arParams)
			&& array_key_exists("CHECK_RIGHTS", $arParams)
			&& $arParams["CHECK_RIGHTS"] == "Y"
			&& array_key_exists("USER_ID", $arParams)
		)
		{
			$acc = new CAccess;
			$acc->UpdateCodes();

			$arSqls["RIGHTS"] = "EXISTS ( SELECT SLR.ID FROM b_sonet_log_right SLR
				LEFT JOIN b_user_access UA ON (UA.ACCESS_CODE = SLR.GROUP_CODE AND UA.USER_ID = ".(is_object($USER)? intval($USER->GetID()): 0).")
				WHERE LC.LOG_ID = SLR.LOG_ID AND (0=1 ".
				(is_object($USER) && CSocNetUser::IsCurrentUserModuleAdmin() ? " OR SLR.GROUP_CODE = 'SA'" : "").
				(is_object($USER) && $USER->IsAuthorized() ? " OR (SLR.GROUP_CODE = 'AU')" : "").
				" OR (SLR.GROUP_CODE = 'G2')".
				(is_object($USER) && $USER->IsAuthorized() ? " OR (UA.ACCESS_CODE = SLR.GROUP_CODE AND UA.USER_ID = ".$USER->GetID().")" : "")."))";
		}

		if (
			!empty($arParams)
			&& array_key_exists("CHECK_CRM_RIGHTS", $arParams)
			&& $arParams["CHECK_CRM_RIGHTS"] == "Y"
			&& array_key_exists("USER_ID", $arParams)
		)
		{
			$arSqls["CRM_RIGHTS"] = "";
		}

		if (
			$arParams["USE_SUBSCRIBE"] == "Y"
			&& intval($arParams["SUBSCRIBE_USER_ID"]) > 0
		)
		{
			$arSqls["SUBSCRIBE"] = CSocNetLogEvents::GetSQL(
				$arParams["SUBSCRIBE_USER_ID"],
				(is_array($arParams["MY_ENTITIES"]) ? $arParams["MY_ENTITIES"] : array()),
				$arParams["TRANSPORT"],
				$arParams["VISIBLE"],
				"LC"
			);
		}

		$arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", $strDistinct, $arSqls["SELECT"]);

		if (is_array($arGroupBy) && count($arGroupBy)==0)
		{
			$strSql =
				"SELECT ".$arSqls["SELECT"]." ".
				$obUserFieldsSql->GetSelect()." ".
				"FROM b_sonet_log_comment LC ".
				"	".$arSqls["FROM"]." ".
				$obUserFieldsSql->GetJoin("LC.ID")." ";

			$bWhereStarted = false;

			if (strlen($arSqls["WHERE"]) > 0)
			{
				$strSql .= "WHERE ".$arSqls["WHERE"]." ".(strlen($arSqls["SUBSCRIBE"]) > 0 ? "AND (".$arSqls["SUBSCRIBE"].") " : "");
				$bWhereStarted = true;
			}
			elseif (strlen($arSqls["SUBSCRIBE"]) > 0)
			{
				$strSql .= "WHERE (".$arSqls["SUBSCRIBE"].") ";
				$bWhereStarted = true;
			}

			if (strlen($strSqlUFFilter) > 0)
			{
				$strSql .= ($bWhereStarted ? " AND " : " WHERE ").$strSqlUFFilter." ";
				$bWhereStarted = true;
			}

			if (strlen($arSqls["RIGHTS"]) > 0)
			{
				$strSql .= ($bWhereStarted ? " AND " : " WHERE ").$arSqls["RIGHTS"]." ";
				$bWhereStarted = true;
			}

			if (strlen($arSqls["CRM_RIGHTS"]) > 0)
			{
				$strSql .= ($bWhereStarted ? " AND " : " WHERE ").$arSqls["CRM_RIGHTS"]." ";
				$bWhereStarted = true;
			}

			if (strlen($arSqls["GROUPBY"]) > 0)
				$strSql .= "GROUP BY ".$arSqls["GROUPBY"]." ";

			//echo "!1!=".htmlspecialcharsbx($strSql)."<br>";

			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			if ($arRes = $dbRes->Fetch())
				return $arRes["CNT"];
			else
				return false;
		}

		$strSql =
			"SELECT ".$arSqls["SELECT"]." ".
			$obUserFieldsSql->GetSelect()." ".
			"FROM b_sonet_log_comment LC ".
			"	".$arSqls["FROM"]." ".
			$obUserFieldsSql->GetJoin("LC.ID")." ";

		$bWhereStarted = false;

		if (strlen($arSqls["WHERE"]) > 0)
		{
			$strSql .= "WHERE ".$arSqls["WHERE"]." ".(strlen($arSqls["SUBSCRIBE"]) > 0 ? "AND (".$arSqls["SUBSCRIBE"].") " : "");
			$bWhereStarted = true;
		}
		elseif (strlen($arSqls["SUBSCRIBE"]) > 0)
		{
			$strSql .= "WHERE (".$arSqls["SUBSCRIBE"].") ";
			$bWhereStarted = true;
		}

		if (strlen($strSqlUFFilter) > 0)
		{
			$strSql .= ($bWhereStarted ? " AND " : " WHERE ").$strSqlUFFilter." ";
			$bWhereStarted = true;
		}

		if (strlen($arSqls["RIGHTS"]) > 0)
		{
			$strSql .= ($bWhereStarted ? " AND " : " WHERE ").$arSqls["RIGHTS"]." ";
			$bWhereStarted = true;
		}

		if (strlen($arSqls["CRM_RIGHTS"]) > 0)
		{
			$strSql .= ($bWhereStarted ? " AND " : " WHERE ").$arSqls["CRM_RIGHTS"]." ";
			$bWhereStarted = true;
		}

		if (strlen($arSqls["GROUPBY"]) > 0)
			$strSql .= "GROUP BY ".$arSqls["GROUPBY"]." ";
		if (strlen($arSqls["ORDERBY"]) > 0)
			$strSql .= "ORDER BY ".$arSqls["ORDERBY"]." ";

		if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) <= 0)
		{
			$strSql_tmp =
				"SELECT COUNT('x') as CNT ".
				$obUserFieldsSql->GetSelect()." ".
				"FROM b_sonet_log_comment LC ".
				"	".$arSqls["FROM"]." ".
				$obUserFieldsSql->GetJoin("LC.ID")." ";

			$bWhereStarted = false;

			if (strlen($arSqls["WHERE"]) > 0)
			{
				$strSql_tmp .= "WHERE ".$arSqls["WHERE"]." ".(strlen($arSqls["SUBSCRIBE"]) > 0 ? "AND (".$arSqls["SUBSCRIBE"].") " : "");
				$bWhereStarted = true;
			}
			elseif (strlen($arSqls["SUBSCRIBE"]) > 0)
			{
				$strSql_tmp .= "WHERE (".$arSqls["SUBSCRIBE"].") ";
				$bWhereStarted = true;
			}

			if (strlen($strSqlUFFilter) > 0)
			{
				$strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ").$strSqlUFFilter." ";
				$bWhereStarted = true;
			}

			if (strlen($arSqls["RIGHTS"]) > 0)
			{
				$strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ").$arSqls["RIGHTS"]." ";
				$bWhereStarted = true;
			}

			if (strlen($arSqls["CRM_RIGHTS"]) > 0)
			{
				$strSql_tmp .= ($bWhereStarted ? " AND " : " WHERE ").$arSqls["CRM_RIGHTS"]." ";
				$bWhereStarted = true;
			}

			if (strlen($arSqls["GROUPBY"]) > 0)
				$strSql_tmp .= "GROUP BY ".$arSqls["GROUPBY"]." ";

			//echo "!2.1!=".htmlspecialcharsbx($strSql_tmp)."<br>";

			$dbRes = $DB->Query($strSql_tmp, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			$cnt = 0;
			if (strlen($arSqls["GROUPBY"]) <= 0)
			{
				if ($arRes = $dbRes->Fetch())
					$cnt = $arRes["CNT"];
			}
			else
			{
				// рнкэйн дкъ MYSQL!!! дкъ ORACLE дпсцни йнд
				$cnt = $dbRes->SelectedRowsCount();
			}

			$dbRes = new CDBResult();

			//echo "!2.2!=".htmlspecialcharsbx($strSql)."<br>";

			$dbRes->SetUserFields($USER_FIELD_MANAGER->GetUserFields("SONET_COMMENT"));
			$dbRes->NavQuery($strSql, $cnt, $arNavStartParams);
		}
		else
		{
			if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) > 0)
				$strSql .= "LIMIT ".intval($arNavStartParams["nTopCount"]);

			//echo "!3!=".htmlspecialcharsbx($strSql)."<br>";
			$dbRes = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
			$dbRes->SetUserFields($USER_FIELD_MANAGER->GetUserFields("SONET_COMMENT"));
		}

		return $dbRes;
	}
Exemplo n.º 4
0
 static function FormatEvent_Wiki($arFields, $arParams, $bMail = false)
 {
     $GLOBALS['APPLICATION']->SetAdditionalCSS('/bitrix/themes/.default/wiki_sonet_log.css');
     $arResult = array('EVENT' => $arFields, 'CREATED_BY' => array(), 'ENTITY' => array(), 'EVENT_FORMATTED' => array(), "CACHED_CSS_PATH" => array("/bitrix/themes/.default/wiki_sonet_log.css"));
     $arResult['CREATED_BY'] = CSocNetLogTools::FormatEvent_GetCreatedBy($arFields, $arParams, $bMail);
     if (!$bMail) {
         $arResult['AVATAR_SRC'] = CSocNetLog::FormatEvent_CreateAvatar($arFields, $arParams);
     }
     if ($arFields['ENTITY_TYPE'] == SONET_SUBSCRIBE_ENTITY_GROUP && intval($arFields['ENTITY_ID']) > 0) {
         if ($bMail) {
             $arResult['ENTITY']['FORMATTED'] = $arFields['GROUP_NAME'];
             $arResult['ENTITY']['TYPE_MAIL'] = GetMessage('WIKI_SOCNET_LOG_ENTITY_G');
         } else {
             $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
             $url = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_GROUP'], array('group_id' => $arFields['ENTITY_ID']));
             $arResult['ENTITY']['FORMATTED']['TYPE_NAME'] = $arSocNetAllowedSubscribeEntityTypesDesc[SONET_SUBSCRIBE_ENTITY_GROUP]['TITLE_ENTITY'];
             $arResult['ENTITY']['FORMATTED']['URL'] = $url;
             $arResult['ENTITY']['FORMATTED']['NAME'] = $arFields['GROUP_NAME'];
         }
     }
     if (!$bMail && array_key_exists('URL', $arFields) && strlen($arFields['URL']) > 0) {
         $wiki_tmp = '<a href="' . $arFields['URL'] . '">' . $arFields['TITLE'] . '</a>';
     } else {
         $wiki_tmp = $arFields['TITLE'];
     }
     if ($arFields['EVENT_ID'] == 'wiki') {
         $title_tmp = $bMail ? GetMessage('WIKI_SOCNET_LOG_TITLE_MAIL') : GetMessage('WIKI_SOCNET_LOG_TITLE');
         $title_tmp_24 = GetMessage("WIKI_SOCNET_LOG_TITLE_24");
     } elseif ($arFields['EVENT_ID'] == 'wiki_del') {
         $title_tmp = $bMail ? GetMessage('WIKI_DEL_SOCNET_LOG_TITLE_MAIL') : GetMessage('WIKI_DEL_SOCNET_LOG_TITLE');
         $title_tmp_24 = GetMessage("WIKI_DEL_SOCNET_LOG_TITLE_24");
     }
     $title = str_replace(array('#TITLE#', '#ENTITY#', '#CREATED_BY#'), array($wiki_tmp, $arResult['ENTITY']['FORMATTED'], $bMail ? $arResult['CREATED_BY']['FORMATTED'] : ''), $title_tmp);
     $arResult['EVENT_FORMATTED'] = array("TITLE" => $title, "TITLE_24" => $title_tmp_24, "TITLE_24_2" => $arFields["TITLE"], "MESSAGE" => $arFields['MESSAGE']);
     $arResult['HAS_COMMENTS'] = 'N';
     if (intval($arFields['SOURCE_ID']) > 0 && array_key_exists('PARAMS', $arFields) && strlen($arFields['PARAMS']) > 0) {
         $arFieldsParams = explode('&', $arFields['PARAMS']);
         if (is_array($arFieldsParams) && count($arFieldsParams) > 0) {
             foreach ($arFieldsParams as $tmp) {
                 list($key, $value) = explode('=', $tmp);
                 if ($key == 'forum_id') {
                     $arResult['HAS_COMMENTS'] = 'Y';
                     break;
                 }
             }
         }
     }
     if ($bMail) {
         $url = CSocNetLogTools::FormatEvent_GetURL($arFields);
         if (strlen($url) > 0) {
             $arResult['EVENT_FORMATTED']['URL'] = $url;
         }
         $parserLog = new logTextParser(false, $arParams["PATH_TO_SMILE"]);
         $arAllow = array("HTML" => "Y", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "N", "MULTIPLE_BR" => "Y", "VIDEO" => "Y", "LOG_VIDEO" => "Y", "TABLE" => "Y");
         $arResult["EVENT_FORMATTED"]["MESSAGE"] = $arFields["TEXT_MESSAGE"] ? $arFields["TEXT_MESSAGE"] : HTMLToTxt($parserLog->convert(htmlspecialcharsback($arResult["EVENT_FORMATTED"]["MESSAGE"]), array(), $arAllow));
     } else {
         $parserLog = new logTextParser(false, $arParams["PATH_TO_SMILE"]);
         //$arAllow = array("HTML" => "Y", "ANCHOR" => "Y", "BIU" => "Y", "IMG" => "Y", "QUOTE" => "Y", "CODE" => "Y", "FONT" => "Y", "LIST" => "Y", "SMILES" => "Y", "NL2BR" => "Y", "MULTIPLE_BR" => "Y", "VIDEO" => "Y", "LOG_VIDEO" => "N");
         //$arResult["EVENT_FORMATTED"]["MESSAGE"] = htmlspecialcharsbx($parserLog->convert(htmlspecialcharsback($arResult["EVENT_FORMATTED"]["MESSAGE"]), array(), $arAllow));
         if ($arParams["MOBILE"] != "Y") {
             $GLOBALS['APPLICATION']->SetAdditionalCSS('/bitrix/components/bitrix/wiki.show/templates/.default/style.css');
             $arResult["CACHED_CSS_PATH"][] = "/bitrix/components/bitrix/wiki.show/templates/.default/style.css";
             if ($arParams["NEW_TEMPLATE"] != "Y") {
                 $arResult["EVENT_FORMATTED"]["SHORT_MESSAGE"] = $parserLog->html_cut($parserLog->convert(htmlspecialcharsback($arResult["EVENT_FORMATTED"]["MESSAGE"]), array(), $arAllow), 1000);
                 $arResult["EVENT_FORMATTED"]["IS_MESSAGE_SHORT"] = CSocNetLogTools::FormatEvent_IsMessageShort($arResult["EVENT_FORMATTED"]["MESSAGE"], $arResult["EVENT_FORMATTED"]["SHORT_MESSAGE"]);
             }
         }
         if ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP) {
             $arResult["EVENT_FORMATTED"]["DESTINATION"] = array(array("STYLE" => "sonetgroups", "TITLE" => $arResult["ENTITY"]["FORMATTED"]["NAME"], "URL" => $arResult["ENTITY"]["FORMATTED"]["URL"], "IS_EXTRANET" => is_array($GLOBALS["arExtranetGroupID"]) && in_array($arFields["ENTITY_ID"], $GLOBALS["arExtranetGroupID"])));
         }
     }
     return $arResult;
 }
Exemplo n.º 5
0
$arParams["PATH_TO_GROUP"] = trim($arParams["PATH_TO_GROUP"]);
if (strlen($arParams["PATH_TO_GROUP"]) <= 0) {
    $arParams["PATH_TO_GROUP"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=group&" . $arParams["GROUP_VAR"] . "=#group_id#");
}
$arParams["PATH_TO_SUBSCRIBE"] = trim($arParams["PATH_TO_SUBSCRIBE"]);
if (strlen($arParams["PATH_TO_SUBSCRIBE"]) <= 0) {
    $arParams["PATH_TO_SUBSCRIBE"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=subscribe");
}
if (strlen($arParams["NAME_TEMPLATE"]) <= 0) {
    $arParams["NAME_TEMPLATE"] = CSite::GetNameFormat();
}
$bUseLogin = $arParams['SHOW_LOGIN'] != "N" ? true : false;
$arResult["FatalError"] = "";
$arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
$arSocNetLogEvents = CSocNetAllowed::GetAllowedLogEvents();
$arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
if (!$GLOBALS["USER"]->IsAuthorized()) {
    $arResult["NEED_AUTH"] = "Y";
} else {
    if ($arParams["ENTITY_ID"] <= 0) {
        $arResult["FatalError"] = GetMessage("SONET_C3_NO_ENTITY_ID") . ".";
    }
    if (StrLen($arResult["FatalError"]) <= 0) {
        // get upper level subscription
        $is_my = false;
        if (array_key_exists($arParams["ENTITY_TYPE"], $arSocNetAllowedSubscribeEntityTypesDesc) && array_key_exists("CLASS_MY_BY_ID", $arSocNetAllowedSubscribeEntityTypesDesc[$arParams["ENTITY_TYPE"]]) && array_key_exists("METHOD_MY_BY_ID", $arSocNetAllowedSubscribeEntityTypesDesc[$arParams["ENTITY_TYPE"]])) {
            $is_my = call_user_func(array($arSocNetAllowedSubscribeEntityTypesDesc[$arParams["ENTITY_TYPE"]]["CLASS_MY_BY_ID"], $arSocNetAllowedSubscribeEntityTypesDesc[$arParams["ENTITY_TYPE"]]["METHOD_MY_BY_ID"]), $arParams["ENTITY_ID"]);
        }
        $arSubscribesTmpAllMy = array();
        $arSubscribesTmpAll = array();
        if ($is_my) {
Exemplo n.º 6
0
 function GetEntity_News($arFields, $bMail)
 {
     $arEntity = array();
     $arEventParams = unserialize(strlen($arFields["~PARAMS"]) > 0 ? $arFields["~PARAMS"] : $arFields["PARAMS"]);
     if (intval($arFields["ENTITY_ID"]) > 0) {
         if (is_array($arEventParams) && count($arEventParams) > 0 && array_key_exists("ENTITY_NAME", $arEventParams) && strlen($arEventParams["ENTITY_NAME"]) > 0) {
             if (!$bMail && array_key_exists("ENTITY_URL", $arEventParams) && strlen($arEventParams["ENTITY_URL"]) > 0) {
                 $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
                 $arEntity["FORMATTED"]["TYPE_NAME"] = $arSocNetAllowedSubscribeEntityTypesDesc[$arFields["ENTITY_TYPE"]]["TITLE_ENTITY"];
                 $arEntity["FORMATTED"]["URL"] = $arEventParams["ENTITY_URL"];
                 $arEntity["FORMATTED"]["NAME"] = $arEventParams["ENTITY_NAME"];
             } elseif (!$bMail) {
                 $arEntity["FORMATTED"]["NAME"] = $arEventParams["ENTITY_NAME"];
             } else {
                 $arEntity["FORMATTED"] = $arEventParams["ENTITY_NAME"];
                 $arEntity["TYPE_MAIL"] = GetMessage("INTR_SOCNET_LOG_ENTITY_MAIL");
             }
         }
     }
     return $arEntity;
 }
Exemplo n.º 7
0
 function SetFeature($entityType, $entityID, $feature, $op = false, $permX = false, $bCheckEmpty = false)
 {
     global $APPLICATION, $DB, $arSocNetAllowedEntityTypes;
     $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
     $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
     $CacheRelatedUsers = array();
     $entityType = trim($entityType);
     if (!in_array($entityType, $arSocNetAllowedEntityTypes)) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_EUV_INCORRECT_ENTITY_TYPE"), "ERROR_INCORRECT_ENTITY_TYPE");
         return false;
     }
     $entityID = IntVal($entityID);
     if ($entityID <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_EUV_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
         return false;
     }
     if (!$bCheckEmpty || !CSocNetEventUserView::IsEntityEmpty($entityType, $entityID)) {
         $event_id = array();
         if (!$op || !$permX) {
             if (array_key_exists($feature, $arSocNetFeaturesSettings) && array_key_exists("subscribe_events", $arSocNetFeaturesSettings[$feature])) {
                 foreach ($arSocNetFeaturesSettings[$feature]["subscribe_events"] as $event_id_tmp => $arEventIDTmp) {
                     if (array_key_exists("NO_SET", $arEventIDTmp) && $arEventIDTmp["NO_SET"]) {
                         continue;
                     }
                     if (!array_key_exists("ENTITIES", $arEventIDTmp) || !array_key_exists($entityType, $arEventIDTmp["ENTITIES"])) {
                         continue;
                     }
                     $event_id[$arEventIDTmp["OPERATION"]][] = $event_id_tmp;
                     if (array_key_exists("COMMENT_EVENT", $arEventIDTmp) && is_array($arEventIDTmp["COMMENT_EVENT"]) && array_key_exists("OPERATION", $arEventIDTmp["COMMENT_EVENT"]) && strlen($arEventIDTmp["COMMENT_EVENT"]["OPERATION"]) > 0) {
                         $event_id[$arEventIDTmp["OPERATION"]][] = $arEventIDTmp["COMMENT_EVENT"]["EVENT_ID"];
                     }
                 }
                 if (is_array($event_id[$arEventIDTmp["OPERATION"]])) {
                     $event_id[$arEventIDTmp["OPERATION"]] = array_unique($event_id[$arEventIDTmp["OPERATION"]]);
                 }
             }
         } else {
             $arOpTmp = array();
             if (array_key_exists($feature, $arSocNetFeaturesSettings) && array_key_exists("subscribe_events", $arSocNetFeaturesSettings[$feature])) {
                 foreach ($arSocNetFeaturesSettings[$feature]["subscribe_events"] as $event_id_tmp => $arEventIDTmp) {
                     if (array_key_exists("NO_SET", $arEventIDTmp) && $arEventIDTmp["NO_SET"]) {
                         continue;
                     }
                     if (!array_key_exists("ENTITIES", $arEventIDTmp) || !array_key_exists($entityType, $arEventIDTmp["ENTITIES"])) {
                         continue;
                     }
                     if (!array_key_exists("OPERATION", $arEventIDTmp) || strlen($arEventIDTmp["OPERATION"]) <= 0) {
                         continue;
                     }
                     $arOpTmp[] = $arEventIDTmp["OPERATION"];
                     if (array_key_exists("COMMENT_EVENT", $arEventIDTmp) && is_array($arEventIDTmp["COMMENT_EVENT"]) && array_key_exists("OPERATION", $arEventIDTmp["COMMENT_EVENT"]) && strlen($arEventIDTmp["COMMENT_EVENT"]["OPERATION"]) > 0) {
                         $arOpTmp[] = $arEventIDTmp["COMMENT_EVENT"]["OPERATION"];
                     }
                 }
             }
             if (is_array($arOpTmp)) {
                 $arOpTmp = array_unique($arOpTmp);
             }
             if (in_array($op, $arOpTmp)) {
                 foreach ($arSocNetFeaturesSettings[$feature]["subscribe_events"] as $event_id_tmp => $arEventIDTmp) {
                     if ($arEventIDTmp["OPERATION"] == $op) {
                         $event_id[$op][] = $event_id_tmp;
                     }
                     if (array_key_exists("COMMENT_EVENT", $arEventIDTmp) && is_array($arEventIDTmp["COMMENT_EVENT"]) && array_key_exists("OPERATION", $arEventIDTmp["COMMENT_EVENT"]) && $arEventIDTmp["COMMENT_EVENT"]["OPERATION"] == $op) {
                         $event_id[$op][] = $arEventIDTmp["COMMENT_EVENT"]["EVENT_ID"];
                     }
                 }
                 if (is_array($event_id[$op])) {
                     $event_id[$op] = array_unique($event_id[$op]);
                 }
             } else {
                 return true;
             }
         }
         if (intval($entityID) > 0 && array_key_exists($entityType, $arSocNetAllowedSubscribeEntityTypesDesc) && array_key_exists("CLASS_DESC_GET", $arSocNetAllowedSubscribeEntityTypesDesc[$entityType]) && array_key_exists("METHOD_DESC_GET", $arSocNetAllowedSubscribeEntityTypesDesc[$entityType])) {
             $arEntityTmp = call_user_func(array($arSocNetAllowedSubscribeEntityTypesDesc[$entityType]["CLASS_DESC_GET"], $arSocNetAllowedSubscribeEntityTypesDesc[$entityType]["METHOD_DESC_GET"]), $entityID);
         }
         foreach ($event_id as $op => $arEvent) {
             $arRelatedUsers = array();
             if (is_array($arEvent)) {
                 foreach ($arEvent as $event) {
                     if (!CSocNetEventUserView::Delete($entityType, $entityID, $feature, $event)) {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SONET_EUV_ERROR_DELETE"), "ERROR_DELETE");
                         return false;
                     }
                     if (!$feature || !$permX) {
                         $perm = CSocNetFeaturesPerms::GetOperationPerm($entityType, $entityID, $feature, $op);
                     } else {
                         $perm = $permX;
                     }
                     if ($entityType == SONET_SUBSCRIBE_ENTITY_GROUP && $arEntityTmp && $arEntityTmp["VISIBLE"] == "N" && $perm > SONET_ROLES_USER) {
                         $perm = SONET_ROLES_USER;
                     } elseif ($entityType == SONET_SUBSCRIBE_ENTITY_USER) {
                         $perm_profile = CSocNetUserPerms::GetOperationPerms($entityID, "viewprofile");
                         if ($perm < $perm_profile) {
                             $perm = $perm_profile;
                         }
                     }
                     if (array_key_exists($entityType, $CacheRelatedUsers) && array_key_exists($entityID, $CacheRelatedUsers[$entityType]) && array_key_exists($perm, $CacheRelatedUsers[$entityType][$entityID])) {
                         $arRelatedUsers = $CacheRelatedUsers[$entityType][$entityID][$perm];
                     } else {
                         if ($entityType == SONET_SUBSCRIBE_ENTITY_USER) {
                             switch ($perm) {
                                 case SONET_RELATIONS_TYPE_FRIENDS:
                                     $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => $entityID);
                                     $dbFriends = CSocNetUserRelations::GetRelatedUsers($entityID, SONET_RELATIONS_FRIEND);
                                     while ($arFriends = $dbFriends->Fetch()) {
                                         $friendID = $entityID == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
                                         $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => $friendID);
                                     }
                                     break;
                                 case SONET_RELATIONS_TYPE_FRIENDS2:
                                     $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => $entityID);
                                     $dbFriends = CSocNetUserRelations::GetRelatedUsers($entityID, SONET_RELATIONS_FRIEND);
                                     while ($arFriends = $dbFriends->Fetch()) {
                                         $friendID = $entityID == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
                                         $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => $friendID);
                                         $dbFriends2 = CSocNetUserRelations::GetRelatedUsers($friendID, SONET_RELATIONS_FRIEND);
                                         while ($arFriends2 = $dbFriends2->Fetch()) {
                                             $friendID2 = $friendID == $arFriends2["FIRST_USER_ID"] ? $arFriends2["SECOND_USER_ID"] : $arFriends2["FIRST_USER_ID"];
                                             if ($friendID2 != $entityID) {
                                                 $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => $friendID2, "user_im_id" => $friendID);
                                             }
                                         }
                                     }
                                     break;
                                 case SONET_RELATIONS_TYPE_NONE:
                                     $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => $entityID);
                                     break;
                                 case SONET_RELATIONS_TYPE_AUTHORIZED:
                                     $arRelatedUsers[] = array("entity_id" => $entityID, "user_id" => 0);
                                     break;
                                 case SONET_RELATIONS_TYPE_ALL:
                                     $arRelatedUsers = false;
                                     break;
                             }
                             if (!empty($arRelatedUsers)) {
                                 $arRelatedUsers = array_unique($arRelatedUsers);
                             }
                             $CacheRelatedUsers[SONET_ENTITY_USER][$entityID][$perm] = $arRelatedUsers;
                         } elseif ($entityType == SONET_SUBSCRIBE_ENTITY_GROUP) {
                             switch ($perm) {
                                 case SONET_ROLES_USER:
                                     $dbResult = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $entityID, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                                     while ($arResult = $dbResult->Fetch()) {
                                         $arRelatedUsers[] = $arResult["USER_ID"];
                                     }
                                     break;
                                 case SONET_ROLES_MODERATOR:
                                     $dbResult = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $entityID, "<=ROLE" => SONET_ROLES_MODERATOR, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                                     while ($arResult = $dbResult->Fetch()) {
                                         $arRelatedUsers[] = $arResult["USER_ID"];
                                     }
                                     break;
                                 case SONET_ROLES_OWNER:
                                     $dbResult = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $entityID, "<=ROLE" => SONET_ROLES_OWNER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                                     while ($arResult = $dbResult->Fetch()) {
                                         $arRelatedUsers[] = $arResult["USER_ID"];
                                     }
                                     break;
                                 case SONET_ROLES_AUTHORIZED:
                                     $arRelatedUsers[] = 0;
                                     break;
                                 case SONET_ROLES_ALL:
                                     $arRelatedUsers = false;
                                     break;
                             }
                             if ($arRelatedUsers && is_array($arRelatedUsers) && in_array(0, $arRelatedUsers)) {
                                 $arRelatedUsers = array(0);
                             } elseif ($arRelatedUsers && is_array($arRelatedUsers)) {
                                 $arRelatedUsers = array_unique($arRelatedUsers);
                             }
                             $CacheRelatedUsers[SONET_ENTITY_GROUP][$entityID][$perm] = $arRelatedUsers;
                         }
                     }
                     if ($arRelatedUsers && is_array($arRelatedUsers)) {
                         foreach ($arRelatedUsers as $relatedUserID) {
                             if (is_array($relatedUserID)) {
                                 $arFields = array("ENTITY_TYPE" => $entityType, "ENTITY_ID" => $relatedUserID["entity_id"], "EVENT_ID" => $event, "USER_ID" => $relatedUserID["user_id"], "USER_ANONYMOUS" => "N");
                                 if (array_key_exists("user_im_id", $relatedUserID)) {
                                     $arFields["USER_IM_ID"] = $relatedUserID["user_im_id"];
                                 }
                                 if (!CSocNetEventUserView::Add($arFields)) {
                                     $errorMessage = "";
                                     if ($e = $APPLICATION->GetException()) {
                                         $errorMessage = $e->GetString();
                                     }
                                     if (StrLen($errorMessage) <= 0) {
                                         $errorMessage = GetMessage("SONET_EUV_ERROR_SET");
                                     }
                                     $APPLICATION->ThrowException($errorMessage, "ERROR_SET");
                                     return false;
                                 }
                             } else {
                                 $arFields = array("ENTITY_TYPE" => $entityType, "ENTITY_ID" => $entityID, "EVENT_ID" => $event, "USER_ID" => $relatedUserID, "USER_ANONYMOUS" => "N");
                                 if (!CSocNetEventUserView::Add($arFields)) {
                                     $errorMessage = "";
                                     if ($e = $APPLICATION->GetException()) {
                                         $errorMessage = $e->GetString();
                                     }
                                     if (StrLen($errorMessage) <= 0) {
                                         $errorMessage = GetMessage("SONET_EUV_ERROR_SET");
                                     }
                                     $APPLICATION->ThrowException($errorMessage, "ERROR_SET");
                                     return false;
                                 }
                             }
                         }
                     } else {
                         $arFields = array("ENTITY_TYPE" => $entityType, "ENTITY_ID" => $entityID, "EVENT_ID" => $event, "USER_ID" => 0, "USER_ANONYMOUS" => "Y");
                         if (!CSocNetEventUserView::Add($arFields)) {
                             $errorMessage = "";
                             if ($e = $APPLICATION->GetException()) {
                                 $errorMessage = $e->GetString();
                             }
                             if (StrLen($errorMessage) <= 0) {
                                 $errorMessage = GetMessage("SONET_EUV_ERROR_SET");
                             }
                             $APPLICATION->ThrowException($errorMessage, "ERROR_SET");
                             return false;
                         }
                     }
                 }
             }
         }
     } elseif ($entityType == SONET_ENTITY_GROUP) {
         CSocNetEventUserView::SetGroup($entityID, true);
     } elseif ($entityType == SONET_ENTITY_USER) {
         CSocNetEventUserView::SetUser($entityID, false, false, true);
     }
     return true;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
 function FormatEvent_GetEntity($arFields, $arParams, $bMail)
 {
     if ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_USER && intval($arFields["ENTITY_ID"]) > 0) {
         $suffix = is_array($GLOBALS["arExtranetUserID"]) && in_array($arFields["ENTITY_ID"], $GLOBALS["arExtranetUserID"]) ? GetMessage("SONET_LOG_EXTRANET_SUFFIX") : "";
         if ($bMail) {
             if (strlen($arFields["USER_NAME"]) > 0 || strlen($arFields["USER_LAST_NAME"]) > 0) {
                 $arEntity["FORMATTED"] = $arFields["USER_NAME"] . " " . $arFields["USER_LAST_NAME"] . $suffix;
             } else {
                 $arEntity["FORMATTED"] = $arFields["USER_LOGIN"] . $suffix;
             }
             $arEntity["TYPE_MAIL"] = GetMessage("SONET_GL_EVENT_ENTITY_U");
         } else {
             $arFieldsTooltip = array("ID" => $arFields["ENTITY_ID"], "NAME" => $arFields["~USER_NAME"], "LAST_NAME" => $arFields["~USER_LAST_NAME"], "SECOND_NAME" => $arFields["~USER_SECOND_NAME"], "LOGIN" => $arFields["~USER_LOGIN"]);
             $arParams["NAME_TEMPLATE"] .= $suffix;
             $arEntity["TOOLTIP_FIELDS"] = CSocNetLogTools::FormatEvent_FillTooltip($arFieldsTooltip, $arParams);
             $arEntity["FORMATTED"] = "";
         }
     } elseif ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP && intval($arFields["ENTITY_ID"]) > 0) {
         $suffix = is_array($GLOBALS["arExtranetGroupID"]) && in_array($arFields["ENTITY_ID"], $GLOBALS["arExtranetGroupID"]) ? GetMessage("SONET_LOG_EXTRANET_SUFFIX") : "";
         if ($bMail) {
             $arEntity["FORMATTED"] = $arFields["GROUP_NAME"] . $suffix;
             $arEntity["TYPE_MAIL"] = GetMessage("SONET_GL_EVENT_ENTITY_G");
         } else {
             $url = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_GROUP"], array("group_id" => $arFields["ENTITY_ID"]));
             $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
             $arEntity["FORMATTED"]["TYPE_NAME"] = $arSocNetAllowedSubscribeEntityTypesDesc[$arFields["ENTITY_TYPE"]]["TITLE_ENTITY"];
             $arEntity["FORMATTED"]["URL"] = $url;
             $arEntity["FORMATTED"]["NAME"] = $arFields["GROUP_NAME"] . $suffix;
         }
     }
     return $arEntity;
 }
Exemplo n.º 10
0
 function GetSQLForEvent($entity_type, $entity_id, $event_id, $user_id, $transport = false, $visible = true, $arOfEntities = array())
 {
     if (!in_array($entity_type, CSocNetAllowed::GetAllowedEntityTypes())) {
         return false;
     }
     if (intval($entity_id) <= 0) {
         return false;
     }
     $strSQL = "";
     if (is_array($arOfEntities) && count($arOfEntities) > 0) {
         $strOfEntities = "AND LE.USER_ID IN (" . implode(",", $arOfEntities) . ")";
     } else {
         $strOfEntities = "";
     }
     if (is_array($transport) && count($transport) > 0) {
         $strTransport = "AND LE.TRANSPORT IN ('" . implode("', '", $transport) . "')";
     } elseif (!is_array($transport) && strlen($transport) > 0) {
         $strTransport = "AND LE.TRANSPORT = '" . $transport . "'";
     } else {
         $strTransport = "";
     }
     $strSQL .= "AND (\n\t\t\t(\t\n\t\t\t\tLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\tAND LE.ENTITY_ID = " . $entity_id . "\n\t\t\t\tAND LE.ENTITY_CB = 'N'\n\t\t\t\tAND LE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t" . $strTransport . "\n\t\t\t)";
     $arSocNetAllowedSubscribeEntityTypesDesc = CSocNetAllowed::GetAllowedEntityTypesDesc();
     if (array_key_exists("USE_CB_FILTER", $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]) && $arSocNetAllowedSubscribeEntityTypesDesc[$entity_type]["USE_CB_FILTER"] == "Y" && intval($user_id) > 0) {
         $strSQL .= "\n\t\t\t\tOR \n\t\t\t\t(\n\t\t\t\t\tLE.ENTITY_TYPE = '" . SONET_SUBSCRIBE_ENTITY_USER . "'\n\t\t\t\t\tAND LE.ENTITY_ID = " . $user_id . "\n\t\t\t\t\tAND LE.ENTITY_CB = 'Y'\n\t\t\t\t\tAND \n\t\t\t\t\t(\n\t\t\t\t\t\tLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\t\tOR LE.EVENT_ID = 'all'\t\t\t\t\t\t\t\t\n\t\t\t\t\t)\n\t\t\t\t\t" . $strTransport . "\n\t\t\t\t)";
     }
     $strSQL .= "\n\t\t\tOR\n\t\t\t(\n\t\t\t\tLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\tAND LE.ENTITY_ID = " . $entity_id . "\n\t\t\t\tAND LE.ENTITY_CB = 'N'\n\t\t\t\tAND LE.EVENT_ID = 'all'\n\t\t\t\t" . $strTransport . "\n\t\t\t)\n\t\t\tOR \n\t\t\t(\n\t\t\t\tLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\tAND LE.ENTITY_ID = 0\n\t\t\t\tAND LE.ENTITY_MY = 'Y'\n\t\t\t\tAND \n\t\t\t\t(\n\t\t\t\t\tLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\tOR LE.EVENT_ID = 'all'\n\t\t\t\t)\n\t\t\t\t" . $strOfEntities . "\n\t\t\t\t" . $strTransport . "\n\t\t\t)\n\t\t\tOR\n\t\t\t(\n\t\t\t\tLE.ENTITY_TYPE = '" . $entity_type . "'\n\t\t\t\tAND LE.ENTITY_ID = 0\n\t\t\t\tAND LE.ENTITY_MY = 'N'\n\t\t\t\tAND \n\t\t\t\t(\n\t\t\t\t\tLE.EVENT_ID = '" . $event_id . "'\n\t\t\t\t\tOR LE.EVENT_ID = 'all'\n\t\t\t\t)\n\t\t\t\t" . $strTransport . "\n\t\t\t)\n\t\t)";
     return $strSQL;
 }
Exemplo n.º 11
0
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("socialnetwork")) {
    ShowError(GetMessage("SONET_MODULE_NOT_INSTALL"));
    return;
}
$arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
$arSocNetLogEvents = CSocNetAllowed::GetAllowedLogEvents();
$arResult["arSocNetAllowedSubscribeEntityTypesDesc"] = CSocNetAllowed::GetAllowedEntityTypesDesc();
$arResult["arSocNetAllowedSubscribeEntityTypes"] = CSocNetAllowed::GetAllowedEntityTypes();
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/components/bitrix/socialnetwork.subscribe_list/include.php";
$arParams["USER_ID"] = IntVal($GLOBALS["USER"]->GetID());
$arParams["SET_NAV_CHAIN"] = $arParams["SET_NAV_CHAIN"] == "N" ? "N" : "Y";
if (strLen($arParams["USER_VAR"]) <= 0) {
    $arParams["USER_VAR"] = "user_id";
}
if (strLen($arParams["PAGE_VAR"]) <= 0) {
    $arParams["PAGE_VAR"] = "page";
}
if (strLen($arParams["GROUP_VAR"]) <= 0) {
    $arParams["GROUP_VAR"] = "group_id";
}
$arParams["PATH_TO_USER"] = trim($arParams["PATH_TO_USER"]);
if (strlen($arParams["PATH_TO_USER"]) <= 0) {
    $arParams["PATH_TO_USER"] = htmlspecialcharsbx($APPLICATION->GetCurPage() . "?" . $arParams["PAGE_VAR"] . "=user&" . $arParams["USER_VAR"] . "=#user_id#");
}
$arParams["PATH_TO_GROUP"] = trim($arParams["PATH_TO_GROUP"]);
if (strlen($arParams["PATH_TO_GROUP"]) <= 0) {