function OnReindex($NS = array(), $oCallback = NULL, $callback_method = "") { global $DB; $arResultAll = array(); $arParams = array("PERMISSION" => array(), "SITE" => array(), "DEFAULT_URL" => array()); $search_message_count = intVal(COption::GetOptionInt("forum", "search_message_count", 0)); $strNSJoin = ""; $strFilter = ""; if ($NS["MODULE"] == "forum" && intVal($NS["ID"]) > 0 && intVal($NS["CNT"]) > 0) { $strFilter = " AND (FM.ID>" . intVal($NS["ID"]) . ") "; } elseif ($NS["MODULE"] == "forum" && intVal($NS["ID"]) > 0) { // out of date $strFilter = " AND (FM.ID>=" . intVal($NS["ID"]) . ") "; } if ($NS["SITE_ID"] != "") { $strNSJoin .= " INNER JOIN b_forum2site FS ON (FS.FORUM_ID=F.ID) "; $strFilter .= " AND FS.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "' "; } $strSql = "SELECT STRAIGHT_JOIN FT.ID as TID, FM.ID as MID, FM.ID as ID, FT.FORUM_ID, FT.TITLE, " . CForumNew::Concat("-", array("FT.ID", "FT.TITLE_SEO")) . ",\n\t\t\t\tFT.DESCRIPTION, FT.TAGS, FT.HTML as FT_HTML,\n\t\t\t\tFM.PARAM1, FM.PARAM2, FM.POST_MESSAGE, FM.POST_MESSAGE_FILTER, FM.POST_MESSAGE_HTML, FM.AUTHOR_NAME, FM.AUTHOR_ID, FM.NEW_TOPIC,\n\t\t\t\t" . $DB->DateToCharFunction("FM.POST_DATE") . " as POST_DATE, " . $DB->DateToCharFunction("FM.EDIT_DATE") . " as EDIT_DATE, FT.SOCNET_GROUP_ID, FT.OWNER_ID\n\t\t\tFROM b_forum_message FM use index (PRIMARY), b_forum_topic FT, b_forum F\n\t\t\t" . $strNSJoin . "\n\t\t\tWHERE (FM.TOPIC_ID = FT.ID) AND (F.ID = FT.FORUM_ID) AND (F.INDEXATION = 'Y') AND (FM.APPROVED = 'Y')\n\t\t\t" . $strFilter . "\n\t\t\tORDER BY FM.ID"; if ($search_message_count > 0) { $strSql .= " LIMIT 0, " . $search_message_count; } $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($db_res && COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $db_res = new _CMessageDBResult($db_res); } $rownum = 0; while ($res = $db_res->Fetch()) { $rownum++; if (empty($arParams["PERMISSION"][$res["FORUM_ID"]])) { $arGroups = CForumNew::GetAccessPermissions($res["FORUM_ID"]); $arParams["PERMISSION"][$res["FORUM_ID"]] = array(); for ($i = 0; $i < count($arGroups); $i++) { if ($arGroups[$i][1] >= "E") { $arParams["PERMISSION"][$res["FORUM_ID"]][] = $arGroups[$i][0]; if ($arGroups[$i][0] == 2) { break; } } } } if (empty($arParams["SITE"][$res["FORUM_ID"]])) { $arParams["SITE"][$res["FORUM_ID"]] = CForumNew::GetSites($res["FORUM_ID"]); } $arResult = array("ID" => $res["MID"], "LID" => array(), "LAST_MODIFIED" => !empty($res["EDIT_DATE"]) ? $res["EDIT_DATE"] : $res["POST_DATE"], "PARAM1" => $res["FORUM_ID"], "PARAM2" => $res["TID"], "USER_ID" => $res["AUTHOR_ID"], "ENTITY_TYPE_ID" => $res["NEW_TOPIC"] == "Y" ? "FORUM_TOPIC" : "FORUM_POST", "ENTITY_ID" => $res["NEW_TOPIC"] == "Y" ? $res["TID"] : $res["MID"], "PERMISSIONS" => $arParams["PERMISSION"][$res["FORUM_ID"]], "TITLE" => $res["TITLE"] . ($res["NEW_TOPIC"] == "Y" && !empty($res["DESCRIPTION"]) ? ", " . $res["DESCRIPTION"] : ""), "TAGS" => $res["NEW_TOPIC"] == "Y" ? $res["TAGS"] : "", "BODY" => GetMessage("AVTOR_PREF") . " " . $res["AUTHOR_NAME"] . ". " . textParser::killAllTags(COption::GetOptionString("forum", "FILTER", "Y") != "Y" ? $res["POST_MESSAGE"] : $res["POST_MESSAGE_FILTER"]), "URL" => "", "INDEX_TITLE" => $res["NEW_TOPIC"] == "Y"); foreach ($arParams["SITE"][$res["FORUM_ID"]] as $key => $val) { $arResult["LID"][$key] = CForumNew::PreparePath2Message($val, array("FORUM_ID" => $res["FORUM_ID"], "TOPIC_ID" => $res["TID"], "MESSAGE_ID" => $res["MID"], "SOCNET_GROUP_ID" => $res["SOCNET_GROUP_ID"], "OWNER_ID" => $res["OWNER_ID"], "PARAM1" => $res["PARAM1"], "PARAM2" => $res["PARAM2"])); if (empty($arResult["URL"]) && !empty($arResult["LID"][$key])) { $arResult["URL"] = $arResult["LID"][$key]; } } if (empty($arResult["URL"])) { if (empty($arParams["DEFAULT_URL"][$res["FORUM_ID"]])) { $arParams["DEFAULT_URL"][$res["FORUM_ID"]] = "/"; foreach ($arParams["SITE"][$res["FORUM_ID"]] as $key => $val) { $db_lang = CLang::GetByID($key); if ($db_lang && ($ar_lang = $db_lang->Fetch())) { $arParams["DEFAULT_URL"][$res["FORUM_ID"]] = $ar_lang["DIR"]; break; } } $arParams["DEFAULT_URL"][$res["FORUM_ID"]] .= COption::GetOptionString("forum", "REL_FPATH", "") . "forum/read.php?FID=#FID#&TID=#TID#&MID=#MID##message#MID#"; } $arResult["URL"] = CForumNew::PreparePath2Message($arParams["DEFAULT_URL"][$res["FORUM_ID"]], array("FORUM_ID" => $res["FORUM_ID"], "TOPIC_ID" => $res["TID"], "MESSAGE_ID" => $res["MID"], "SOCNET_GROUP_ID" => $res["SOCNET_GROUP_ID"], "OWNER_ID" => $res["OWNER_ID"], "PARAM1" => $res["PARAM1"], "PARAM2" => $res["PARAM2"])); } if ($oCallback) { $resCall = call_user_func(array($oCallback, $callback_method), $arResult); if (!$resCall) { return $arResult["ID"]; } } else { $arResultAll[] = $arResult; } } if ($oCallback && $search_message_count > 0 && $rownum >= $search_message_count - 1) { return $arResult["ID"]; } if ($oCallback) { return false; } return $arResultAll; }
function GetListEx($arOrder = Array("ID"=>"ASC"), $arFilter = Array(), $bCount = false, $iNum = 0, $arAddParams = array()) { global $DB; $arSqlSearch = array(); $arSqlOrder = array(); $arSqlFrom = array(); $arSqlSelect = array(); $arSqlGroup = array(); $strSqlSearch = ""; $strSqlOrder = ""; $strSqlFrom = ""; $strSqlSelect = ""; $strSqlGroup = ""; $UseGroup = false; $arFilter = (is_array($arFilter) ? $arFilter : array()); $arAddParams = (is_array($arAddParams) ? $arAddParams : array()); foreach ($arFilter as $key => $val) { $key_res = CForumNew::GetFilterOperation($key); $key = strtoupper($key_res["FIELD"]); $strNegative = $key_res["NEGATIVE"]; $strOperation = $key_res["OPERATION"]; switch ($key) { case "PARAM1": case "AUTHOR_NAME": case "POST_MESSAGE_CHECK": case "APPROVED": case "NEW_TOPIC": case "POST_MESSAGE": if ($strOperation == "LIKE") $val = "%".$val."%"; if (strlen($val)<=0) $arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(FM.".$key." IS NULL OR LENGTH(FM.".$key.")<=0)"; else $arSqlSearch[] = ($strNegative=="Y"?" FM.".$key." IS NULL OR NOT ":"")."(FM.".$key." ".$strOperation." '".$DB->ForSql($val)."' )"; break; case "APPROVED_AND_MINE": if ($val >= 0) $arSqlSearch[] = "(FM.APPROVED='Y' OR (FM.APPROVED != 'Y' AND FM.AUTHOR_ID=".intval($val)."))"; else $arSqlSearch[] = "(FM.APPROVED='Y')"; break; case "PARAM2": case "ID": case "AUTHOR_ID": case "FORUM_ID": case "TOPIC_ID": case "ATTACH_IMG": if ( ($strOperation == "IN") && (!is_array($val)) && (strpos($val,",")>0) ) $val = explode(",", $val); if (($strOperation!="IN") && (intVal($val) > 0)) $arSqlSearch[] = ($strNegative=="Y"?" FM.".$key." IS NULL OR NOT ":"")."(FM.".$key." ".$strOperation." ".intVal($val)." )"; elseif (($strOperation =="IN") && ((is_array($val) && (array_sum($val) > 0)) || (strlen($val) > 0) )) { if (is_array($val)) { $val_int = array(); foreach ($val as $v) $val_int[] = intVal($v); $val = implode(", ", $val_int); } else { $val = intval($val); } $arSqlSearch[] = ($strNegative=="Y"?" NOT ":"")."(FM.".$key." IN (".$DB->ForSql($val).") )"; } else $arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(FM.".$key." IS NULL OR FM.".$key."<=0)"; break; case "POINTS_TO_AUTHOR_ID": if (intVal($val) > 0) { $arSqlSelect["FR.POINTS"] = "FR.POINTS"; $arSqlSelect["FR.DATE_UPDATE"] = "FR.DATE_UPDATE"; $arSqlFrom["FR"] = "LEFT JOIN b_forum_user_points FR ON ((FM.AUTHOR_ID = FR.TO_USER_ID) AND (FR.FROM_USER_ID=".intVal($val)."))"; } break; case "POST_DATE": if (strlen($val)<=0) $arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(FM.".$key." IS NULL OR LENGTH(FM.".$key.")<=0)"; else $arSqlSearch[] = ($strNegative=="Y"?" FM.".$key." IS NULL OR NOT ":"")."(FM.".$key." ".$strOperation." ".$DB->CharToDateFunction($DB->ForSql($val), "FULL").")"; break; case "USER_ID": // $arSqlSelect["LAST_VISIT"] = $DB->DateToCharFunction("FUT.LAST_VISIT", "FULL"); if(intVal($val) > 0) { $arSqlFrom["FUT"] = " LEFT JOIN b_forum_user_topic FUT ON (FM.TOPIC_ID = FUT.TOPIC_ID AND FUT.USER_ID=".intVal($val).")"; } break; case "NEW_MESSAGE": if (strLen($val) > 0 && intVal($arFilter["USER_ID"]) > 0) { $arSqlFrom["FUT"] = " LEFT JOIN b_forum_user_topic FUT ON (FM.TOPIC_ID = FUT.TOPIC_ID AND FUT.USER_ID=".intVal($arFilter["USER_ID"]).")"; $arSqlSearch[] = " (FUT.LAST_VISIT IS NOT NULL AND FM.POST_DATE > FUT.LAST_VISIT) OR (FUT.LAST_VISIT IS NULL AND FM.POST_DATE ".$strOperation." ".$DB->CharToDateFunction($DB->ForSql($val), "FULL").") "; } break; case "USER_GROUP": if (!empty($val)) { if (!is_array($val)) $val = explode(",", $val); if (!in_array(2, $val)) $val[] = 2; $val = implode(",", $val); $arSqlFrom["FP"] = "LEFT JOIN b_forum_perms FP ON (FP.FORUM_ID=FM.FORUM_ID)"; $arSqlSearch[] = "FP.GROUP_ID IN (".$DB->ForSql($val).") AND ((FP.PERMISSION IN ('E','I','M') AND FM.APPROVED='Y') OR (FP.PERMISSION IN ('Q','U','Y')))"; $UseGroup = true; } break; case "TOPIC_SOCNET_GROUP_ID": $arSqlFrom["FT"] = " LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)"; $arSqlSearch[] = "FT.SOCNET_GROUP_ID = ".IntVal($val); $arSqlSelect[] = "FT.SOCNET_GROUP_ID as TOPIC_SOCNET_GROUP_ID"; break; case "TOPIC_OWNER_ID": $arSqlFrom["FT"] = " LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)"; $arSqlSearch[] = "FT.OWNER_ID = ".IntVal($val); $arSqlSelect[] = "FT.OWNER_ID as TOPIC_OWNER_ID"; break; case "TOPIC": $arSqlFrom["FT"] = " LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)"; $arSqlSelect[] = "FT.TITLE"; $arSqlSelect[] = CForumNew::Concat("-", array("FT.ID", "FT.TITLE_SEO"))." as TITLE_SEO"; $arSqlSelect[] = "FT.DESCRIPTION AS TOPIC_DESCRIPTION"; $arSqlSelect[] = $DB->DateToCharFunction("FT.START_DATE", "FULL")." as START_DATE"; $arSqlSelect[] = "FT.USER_START_NAME"; $arSqlSelect[] = "FT.USER_START_ID"; $arSqlSelect[] = "FT.XML_ID AS TOPIC_XML_ID"; $arSqlSelect[] = "FT.SOCNET_GROUP_ID AS TOPIC_SOCNET_GROUP_ID"; $arSqlSelect[] = "FT.OWNER_ID AS TOPIC_OWNER_ID"; break; case "TOPIC_MESSAGE_ID": if (is_array($val)) { $val_int = array(); foreach ($val as $v) $val_int[] = intval($v); $val = implode(", ", $val_int); } else { $val = intval($val); } if (!empty($val)) { $arSqlFrom["FT"] = " LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)"; $arSqlSearch[] = "FT.ID IN (SELECT DISTINCT TOPIC_ID FROM b_forum_message WHERE ID IN (".$val."))"; } break; case "TOPIC_TITLE": case "TITLE": $arSqlFrom["FT"] = " LEFT JOIN b_forum_topic FT ON (FT.ID = FM.TOPIC_ID)"; $key = "TITLE"; if ($strOperation == "LIKE") $val = "%".$val."%"; if (strlen($val)<=0) $arSqlSearch[] = ($strNegative=="Y"?"NOT":"")."(FT.".$key." IS NULL OR LENGTH(FT.".$key.")<=0)"; else $arSqlSearch[] = ($strNegative=="Y"?" FT.".$key." IS NULL OR NOT ":"")."(FT.".$key." ".$strOperation." '".$DB->ForSql($val)."' )"; break; } } foreach ($arOrder as $by=>$order) { $by = strtoupper($by); $order = strtoupper($order); if ($order!="ASC") $order = "DESC"; if (in_array($by, array("FORUM_ID", "TOPIC_ID", "USE_SMILES", "NEW_TOPIC", "APPROVED", "POST_DATE", "POST_MESSAGE", "ATTACH_IMG", "PARAM1", "PARAM2", "AUTHOR_ID", "AUTHOR_NAME", "AUTHOR_EMAIL", "AUTHOR_IP", "AUTHOR_REAL_IP", "GUEST_ID", "EDITOR_ID", "EDITOR_NAME", "EDITOR_EMAIL", "EDIT_REASON", "EDIT_DATE", "HTML"))): $arSqlOrder[] = "FM.".$by." ".$order; elseif ($by == "SORT" || $by == "NAME"): $arSqlFrom["F"] = " LEFT JOIN b_forum F ON (F.ID = FM.FORUM_ID)"; $arSqlSelect["F.".$by] = "F.".$by; $arSqlOrder[] = "F_M.".$by." ".$order; else: $arSqlOrder[] = "FM.ID ".$order; $by = "ID"; endif; } $arSqlOrder = array_unique($arSqlOrder); DelDuplicateSort($arSqlOrder); if(count($arSqlOrder) > 0) $strSqlOrder = " ORDER BY ".implode(", ", $arSqlOrder); if (count($arSqlSearch) > 0) $strSqlSearch = " AND (".implode(") AND (", $arSqlSearch).") "; if (count($arSqlSelect) > 0) $strSqlSelect = ",\n\t".implode(", ", $arSqlSelect); if (count($arSqlFrom) > 0) $strSqlFrom .= "\n\t".implode("\n\t", $arSqlFrom); if ($UseGroup) { foreach ($arSqlSelect as $key => $val) { if (substr($key, 0, 1) != "!") $arSqlGroup[$key] = $val; } if (!empty($arSqlGroup)): $strSqlGroup = ", ".implode(", ", $arSqlGroup); endif; } if ($bCount || (is_set($arAddParams, "bDescPageNumbering") && intVal($arAddParams["nTopCount"]) <= 0)) { $strSql = "SELECT COUNT(FM.ID) as CNT, MAX(FM.ID) AS LAST_MESSAGE_ID FROM b_forum_message FM ".$strSqlFrom." WHERE 1 = 1 ".$strSqlSearch; if ($bCount === 3) { $strSql .= "GROUP BY FM.TOPIC_ID"; return $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); } // This code exists because of http://bugs.mysql.com/bug.php?id=64002 $iCnt = 0; $iLAST_MESSAGE_ID = 0; if ((array_intersect_key($arFilter, array("TOPIC_ID" => null, "APPROVED" => null)) == $arFilter || array_intersect_key($arFilter, array("TOPIC_ID" => null)) == $arFilter) && $arFilter["TOPIC_ID"] > 0) // high-usage { $strSql .= "GROUP BY FM.TOPIC_ID"; // explane the same as without "GROUP BY" $db_res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($ar_res = $db_res->Fetch()) { $iCnt = intVal($ar_res["CNT"]); $iLAST_MESSAGE_ID = intVal($ar_res["LAST_MESSAGE_ID"]); } } else { $strSql = "SELECT COUNT(FM.ID) as CNT \nFROM b_forum_message FM ".$strSqlFrom."\nWHERE 1 = 1 ".$strSqlSearch; $db_res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($ar_res = $db_res->Fetch()) { $iCnt = intVal($ar_res["CNT"]); } if ($bCount === 4) { $strSql = "SELECT MAX(FM.ID) AS LAST_MESSAGE_ID \nFROM b_forum_message FM ".$strSqlFrom."\nWHERE 1 = 1 ".$strSqlSearch; $db_res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if ($ar_res = $db_res->Fetch()) { $iLAST_MESSAGE_ID = intVal($ar_res["LAST_MESSAGE_ID"]); } } } // / This code exists because of http://bugs.mysql.com/bug.php?id=64002 if ($bCount === 4) return array("CNT" => $iCnt, "LAST_MESSAGE_ID" => $iLAST_MESSAGE_ID); if ($bCount) return $iCnt; } if ($UseGroup) { $strSql = "SELECT F_M.*, FM.FORUM_ID, FM.TOPIC_ID, FM.USE_SMILES, FM.NEW_TOPIC, \n". " FM.APPROVED, FM.SOURCE_ID, \n". " ".$DB->DateToCharFunction("FM.POST_DATE", "FULL")." as POST_DATE, \n". " FM.POST_MESSAGE, FM.POST_MESSAGE_HTML, FM.POST_MESSAGE_FILTER, \n". " FM.ATTACH_IMG, FM.XML_ID, FM.PARAM1, FM.PARAM2, \n". " FM.AUTHOR_ID, FM.AUTHOR_NAME, FM.AUTHOR_EMAIL, \n". " FM.AUTHOR_IP, FM.AUTHOR_REAL_IP, FM.GUEST_ID, \n". " FM.EDITOR_ID, FM.EDITOR_NAME, FM.EDITOR_EMAIL, FM.EDIT_REASON, \n". " ".$DB->DateToCharFunction("FM.EDIT_DATE", "FULL")." as EDIT_DATE, \n". " FM.HTML, FM.MAIL_HEADER, \n". " FU.SHOW_NAME, FU.DESCRIPTION, FU.NUM_POSTS, FU.POINTS as NUM_POINTS, FU.SIGNATURE, FU.AVATAR, \n". " ".$DB->DateToCharFunction("FU.DATE_REG", "SHORT")." as DATE_REG, \n". " U.LOGIN, U.NAME, U.SECOND_NAME, U.LAST_NAME, U.PERSONAL_PHOTO, FU.RANK_ID, U.PERSONAL_WWW, U.PERSONAL_GENDER, \n". " U.EMAIL, U.PERSONAL_ICQ, U.PERSONAL_CITY, U.PERSONAL_COUNTRY". (!empty($arAddParams["sNameTemplate"]) ? ",\n\t".CForumUser::GetFormattedNameFieldsForSelect(array_merge( $arAddParams, array( "sUserTablePrefix" => "U.", "sForumUserTablePrefix" => "FU.", "sFieldName" => "AUTHOR_NAME_FRMT")), false) : "")." \n". "FROM ( \n". " SELECT FM.ID".$strSqlSelect." \n". " FROM b_forum_message FM \n". " LEFT JOIN b_forum_user FU ON FM.AUTHOR_ID = FU.USER_ID \n". " LEFT JOIN b_user U ON FM.AUTHOR_ID = U.ID \n". " ".$strSqlFrom." \n". " WHERE (1=1 ".$strSqlSearch.") \n". " GROUP BY FM.ID".$strSqlGroup." \n". " ) F_M \n". " INNER JOIN b_forum_message FM ON (F_M.ID = FM.ID) \n". " LEFT JOIN b_forum_user FU ON (FM.AUTHOR_ID = FU.USER_ID) \n". " LEFT JOIN b_user U ON (FM.AUTHOR_ID = U.ID) \n". $strSqlOrder; } else { $strSql = "SELECT FM.ID, FM.FORUM_ID, FM.TOPIC_ID, FM.USE_SMILES, FM.NEW_TOPIC, \n". " FM.APPROVED, FM.SOURCE_ID, \n". " ".$DB->DateToCharFunction("FM.POST_DATE", "FULL")." as POST_DATE, \n". " FM.POST_MESSAGE, FM.POST_MESSAGE_HTML, FM.POST_MESSAGE_FILTER, \n". " FM.ATTACH_IMG, FM.XML_ID, FM.PARAM1, FM.PARAM2, \n". " FM.AUTHOR_ID, FM.AUTHOR_NAME, FM.AUTHOR_EMAIL, \n". " FM.AUTHOR_IP, FM.AUTHOR_REAL_IP, FM.GUEST_ID, \n". " FM.EDITOR_ID, FM.EDITOR_NAME, FM.EDITOR_EMAIL, FM.EDIT_REASON, \n". " ".$DB->DateToCharFunction("FM.EDIT_DATE", "FULL")." as EDIT_DATE, \n". " FM.HTML, FM.MAIL_HEADER, \n". " FU.SHOW_NAME, FU.DESCRIPTION, FU.NUM_POSTS, FU.POINTS as NUM_POINTS, FU.SIGNATURE, FU.AVATAR, \n". " ".$DB->DateToCharFunction("FU.DATE_REG", "SHORT")." as DATE_REG, \n". " U.LOGIN, U.NAME, U.SECOND_NAME, U.LAST_NAME, U.PERSONAL_PHOTO, FU.RANK_ID, U.PERSONAL_WWW, U.PERSONAL_GENDER, \n". " U.EMAIL, U.PERSONAL_ICQ, U.PERSONAL_CITY, U.PERSONAL_COUNTRY". (!empty($arAddParams["sNameTemplate"]) ? ",\n\t".CForumUser::GetFormattedNameFieldsForSelect(array_merge( $arAddParams, array( "sUserTablePrefix" => "U.", "sForumUserTablePrefix" => "FU.", "sFieldName" => "AUTHOR_NAME_FRMT")), false)."\n" : "").$strSqlSelect."\n". "FROM b_forum_message FM \n". " LEFT JOIN b_forum_user FU ON (FM.AUTHOR_ID = FU.USER_ID) \n". " LEFT JOIN b_user U ON (FM.AUTHOR_ID = U.ID) \n". " ".$strSqlFrom." \n". "WHERE 1 = 1 ".$strSqlSearch." \n". $strSqlOrder; } $iNum = intVal($iNum); if ($iNum > 0 || intVal($arAddParams["nTopCount"]) > 0): $iNum = ($iNum > 0) ? $iNum : intVal($arAddParams["nTopCount"]); $strSql .= "\nLIMIT 0,".$iNum; endif; if (!$iNum && is_array($arAddParams) && is_set($arAddParams, "bDescPageNumbering") && (intVal($arAddParams["nTopCount"])<=0)) { $db_res = new CDBResult(); $db_res->NavQuery($strSql, $iCnt, $arAddParams); } else { $db_res = $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); } return new _CMessageDBResult($db_res, $arAddParams); }
public static function GetListEx($arOrder = array("ID" => "ASC"), $arFilter = array()) { global $DB; $arSqlSearch = array(); $arSqlFrom = array(); $arSqlGroup = array(); $arSqlSelect = array(); $arSqlOrder = array(); $strSqlSelect = ""; $strSqlSearch = ""; $strSqlFrom = ""; $strSqlGroup = ""; $strSqlOrder = ""; $arSqlSelectConst = array("FS.ID" => "FS.ID", "FS.USER_ID" => "FS.USER_ID", "FS.FORUM_ID" => "FS.FORUM_ID", "FS.TOPIC_ID" => "FS.TOPIC_ID", "TITLE_SEO" => CForumNew::Concat("-", array("FS.TOPIC_ID", "FT.TITLE_SEO")), "FS.LAST_SEND" => "FS.LAST_SEND", "FS.NEW_TOPIC_ONLY" => "FS.NEW_TOPIC_ONLY", "FS.SITE_ID" => "FS.SITE_ID", "START_DATE" => $DB->DateToCharFunction("FS.START_DATE", "FULL"), "U.EMAIL" => "U.EMAIL", "U.LOGIN" => "U.LOGIN", "U.NAME" => "U.NAME", "U.LAST_NAME" => "U.LAST_NAME", "FT.TITLE" => "FT.TITLE", "FORUM_NAME" => "F.NAME"); $arFilter = is_array($arFilter) ? $arFilter : array(); foreach ($arFilter as $key => $val) { $key_res = CForumNew::GetFilterOperation($key); $key = strtoupper($key_res["FIELD"]); $strNegative = $key_res["NEGATIVE"]; $strOperation = $key_res["OPERATION"]; switch ($key) { case "ID": case "USER_ID": case "FORUM_ID": case "TOPIC_ID": case "LAST_SEND": if (intVal($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(FS." . $key . " IS NULL OR FS." . $key . "<=0)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " FS." . $key . " IS NULL OR NOT " : "") . "(FS." . $key . " " . $strOperation . " " . intVal($val) . " )"; } break; case "TOPIC_ID_OR_NULL": $arSqlSearch[] = "(FS.TOPIC_ID = " . intVal($val) . " OR FS.TOPIC_ID = 0 OR FS.TOPIC_ID IS NULL)"; break; case "NEW_TOPIC_ONLY": if (strLen($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(FS." . $key . " IS NULL)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " FS." . $key . " IS NULL OR NOT " : "") . "(FS." . $key . " " . $strOperation . " '" . $DB->ForSql($val) . "' )"; } break; case "START_DATE": if (strLen($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(FS." . $key . " IS NULL)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " FS." . $key . " IS NULL OR NOT " : "") . "(FS." . $key . " " . $strOperation . " " . $DB->CharToDateFunction($DB->ForSql($val), "SHORT") . ")"; } break; case "LAST_SEND_OR_NULL": $arSqlSearch[] = "(FS.LAST_SEND IS NULL OR FS.LAST_SEND = 0 OR FS.LAST_SEND < " . intVal($val) . ")"; break; case "ACTIVE": if (strLen($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(U." . $key . " IS NULL)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " U." . $key . " IS NULL OR NOT " : "") . "(U." . $key . " " . $strOperation . " '" . $DB->ForSql($val) . "' )"; } break; case "FORUM": case "TOPIC": $key = $key == "FORUM" ? "F.NAME" : "FT.TITLE"; $arSqlSearch[] = GetFilterQuery($key, $val); break; case "SOCNET_GROUP_ID": if ($val > 0) { $arSqlSearch[] = "FS.SOCNET_GROUP_ID=" . intval($val); } else { $arSqlSearch[] = "FS.SOCNET_GROUP_ID IS NULL"; } break; case "PERMISSION": if ($arFilter["SOCNET_GROUP_ID"] > 0) { $arSqlSearch[] = "EXISTS(SELECT 'x'\n\t\t\t\t\t\t\tFROM b_sonet_features SF\n\t\t\t\t\t\t\t\tINNER JOIN b_sonet_features2perms SFP ON SFP.FEATURE_ID = SF.ID AND SFP.OPERATION_ID = 'view'\n\t\t\t\t\t\t\tWHERE SF.ENTITY_TYPE = 'G'\n\t\t\t\t\t\t\t\tAND SF.ENTITY_ID = FS.SOCNET_GROUP_ID\n\t\t\t\t\t\t\t\tAND SF.FEATURE = 'forum'\n\t\t\t\t\t\t\t\tAND SFP.ROLE = 'N' OR EXISTS(SELECT 'x' FROM b_sonet_user2group UG WHERE UG.USER_ID = FS.USER_ID AND " . $DB->IsNull("SFP.ROLE", "'K'") . " >= UG.ROLE AND UG.GROUP_ID = FS.SOCNET_GROUP_ID)\n\t\t\t\t\t\t) "; } elseif (strLen($val) > 0) { $arSqlSearch[] = "(\n\t\t\t\t\t\t\t(FP.PERMISSION >= '" . $DB->ForSql($val) . "') OR\n\t\t\t\t\t\t\t(FP1.PERMISSION >= '" . $DB->ForSql($val) . "') OR\n\t\t\t\t\t\t\t((FP.ID IS NULL) AND (UG.GROUP_ID = 1)))"; $arSqlSelect[] = "FU.SUBSC_GROUP_MESSAGE, FU.SUBSC_GET_MY_MESSAGE"; $arSqlFrom[] = "\n\t\t\t\t\t\t\tLEFT JOIN b_forum_user FU ON (U.ID = FU.USER_ID)\n\t\t\t\t\t\t\tLEFT JOIN b_user_group UG ON (U.ID = UG.USER_ID)\n\t\t\t\t\t\t\tLEFT JOIN b_forum_perms FP ON (FP.FORUM_ID = FS.FORUM_ID AND FP.GROUP_ID=UG.GROUP_ID)\n\t\t\t\t\t\t\tLEFT JOIN b_forum_perms FP1 ON (FP1.FORUM_ID = FS.FORUM_ID AND FP1.GROUP_ID=2)"; $arSqlGroup = array_values($arSqlSelectConst); $arSqlGroup[] = "FU.SUBSC_GROUP_MESSAGE, FU.SUBSC_GET_MY_MESSAGE"; } break; } } if (count($arSqlSelect) > 0) { $strSqlSelect .= ", " . implode(", ", $arSqlSelect); } if (count($arSqlSearch) > 0) { $strSqlSearch .= " AND (" . implode(")\n\t\t\tAND\n\t\t\t(", $arSqlSearch) . ") "; } if (count($arSqlFrom) > 0) { $strSqlFrom .= " " . implode(" ", $arSqlFrom) . " "; } if (count($arSqlGroup) > 0) { $strSqlGroup .= " GROUP BY " . implode(", ", $arSqlGroup) . " "; } foreach ($arOrder as $by => $order) { $by = strtoupper($by); $order = strtoupper($order); if ($order != "ASC") { $order = "DESC"; } if ($by == "FORUM_ID") { $arSqlOrder[] = " FS.FORUM_ID " . $order . " "; } elseif ($by == "USER_ID") { $arSqlOrder[] = " FS.USER_ID " . $order . " "; } elseif ($by == "FORUM_NAME") { $arSqlOrder[] = " F.NAME " . $order . " "; } elseif ($by == "TOPIC_ID") { $arSqlOrder[] = " FS.TOPIC_ID " . $order . " "; } elseif ($by == "TITLE") { $arSqlOrder[] = " FT.TITLE " . $order . " "; } elseif ($by == "START_DATE") { $arSqlOrder[] = " FS.START_DATE " . $order . " "; } elseif ($by == "NEW_TOPIC_ONLY") { $arSqlOrder[] = " FS.NEW_TOPIC_ONLY " . $order . " "; } elseif ($by == "LAST_SEND") { $arSqlOrder[] = " FS.LAST_SEND " . $order . " "; } else { $arSqlOrder[] = " FS.ID " . $order . " "; $by = "ID"; } } DelDuplicateSort($arSqlOrder); if (count($arSqlOrder) > 0) { $strSqlOrder = " ORDER BY " . implode(", ", $arSqlOrder); } $strSql = "\n\t\t\tSELECT FS.ID, FS.USER_ID, FS.FORUM_ID, FS.TOPIC_ID, FS.LAST_SEND, FS.NEW_TOPIC_ONLY, FS.SITE_ID,\n\t\t\t\t" . CForumNew::Concat("-", array("FS.TOPIC_ID", "FT.TITLE_SEO")) . " as TITLE_SEO,\n\t\t\t\t" . $DB->DateToCharFunction("FS.START_DATE", "FULL") . " as START_DATE,\n\t\t\t\tU.EMAIL, U.LOGIN, U.NAME, U.LAST_NAME, FT.TITLE, F.NAME AS FORUM_NAME" . $strSqlSelect . "\n\t\t\tFROM b_forum_subscribe FS\n\t\t\t\tINNER JOIN b_user U ON (FS.USER_ID = U.ID)\n\t\t\t\tLEFT JOIN b_forum_topic FT ON (FS.TOPIC_ID = FT.ID)\n\t\t\t\tLEFT JOIN b_forum F ON (FS.FORUM_ID = F.ID)\n\t\t\t\t" . $strSqlFrom . "\n\t\t\tWHERE 1 = 1\n\t\t\t\t" . $strSqlSearch . "\n\t\t\t" . $strSqlGroup . "\n\t\t\t" . $strSqlOrder; $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); return $db_res; }
function GetListEx($arOrder = array("SORT" => "ASC"), $arFilter = array(), $bCount = false, $iNum = 0, $arAddParams = array()) { global $DB, $USER; $arOrder = is_array($arOrder) ? $arOrder : array(); $arFilter = is_array($arFilter) ? $arFilter : array(); $arSqlSearch = array(); $arSqlFrom = array(); $arSqlSelect = array(); $arSqlGroup = array(); $arSqlOrder = array(); $strSqlSearch = ""; $strSqlFrom = ""; $strSqlSelect = ""; $strSqlGroup = ""; $strSqlOrder = ""; $UseGroup = false; $arAddParams = is_array($arAddParams) ? $arAddParams : array($arAddParams); foreach ($arFilter as $key => $val) { $key_res = CForumNew::GetFilterOperation($key); $key = strtoupper($key_res["FIELD"]); $strNegative = $key_res["NEGATIVE"]; $strOperation = $key_res["OPERATION"]; switch ($key) { case "STATE": case "XML_ID": case "APPROVED": if (strlen($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(FT." . $key . " IS NULL OR " . ($DB->type == "MSSQL" ? "LEN" : "LENGTH") . "(FT." . $key . ")<=0)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " FT." . $key . " IS NULL OR NOT " : "") . "(FT." . $key . " " . $strOperation . " '" . $DB->ForSql($val) . "' )"; } break; case "ID": case "FORUM_ID": case "SOCNET_GROUP_ID": case "OWNER_ID": case "USER_START_ID": case "SORT": case "POSTS": case "TOPICS": if ($strOperation != "IN" && intVal($val) > 0) { $arSqlSearch[] = ($strNegative == "Y" ? " FT." . $key . " IS NULL OR NOT " : "") . "(FT." . $key . " " . $strOperation . " " . intVal($val) . " )"; } elseif ($strOperation == "IN" && (is_array($val) && array_sum($val) > 0 || strlen($val) > 0)) { if (!is_array($val)) { $val = explode(',', $val); } $val_int = array(); foreach ($val as $v) { $val_int[] = intVal($v); } $val = implode(", ", $val_int); $arSqlSearch[] = ($strNegative == "Y" ? " NOT " : "") . "(FT." . $key . " IN (" . $DB->ForSql($val) . ") )"; } else { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(FT." . $key . " IS NULL OR FT." . $key . "<=0)"; } break; case "TITLE_ALL": $arSqlSearch[] = GetFilterQuery("FT.TITLE, FT.DESCRIPTION", $val); break; case "TITLE": case "DESCRIPTION": $arSqlSearch[] = GetFilterQuery("FT." . $key, $val); $arSqlSearch[] = GetFilterQuery("FT." . $key, $val); break; case "START_DATE": case "LAST_POST_DATE": case "ABS_LAST_POST_DATE": if (strlen($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(FT." . $key . " IS NULL)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " FT." . $key . " IS NULL OR NOT " : "") . "(FT." . $key . " " . $strOperation . " " . $DB->CharToDateFunction($DB->ForSql($val), "FULL") . ")"; } break; case "USER_ID": $arSqlSelect["LAST_VISIT"] = $DB->DateToCharFunction("FUT.LAST_VISIT", "FULL"); $arSqlFrom["FUT"] = "LEFT JOIN b_forum_user_topic FUT ON (" . (strlen($val) <= 0 ? ($strNegative == "Y" ? "NOT" : "") . "(FUT.USER_ID IS NULL)" : "FUT.USER_ID=" . intVal($val)) . " AND FUT.FORUM_ID = FT.FORUM_ID AND FUT.TOPIC_ID = FT.ID)"; break; case "RENEW_TOPIC": if (strlen($val) > 0 && array_key_exists("FUT", $arSqlFrom)) { $arSqlSearch[] = "((FT.LAST_POST_DATE " . $strOperation . " " . $DB->CharToDateFunction($DB->ForSql($val), "FULL") . ") AND\n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t(LAST_VISIT IS NULL) OR\n\t\t\t\t\t\t\t\t\t\t(LAST_VISIT < " . $DB->CharToDateFunction($DB->ForSql($val), "FULL") . ")\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\tOR\n\t\t\t\t\t\t\t\t((FT.LAST_POST_DATE > FUT.LAST_VISIT) AND \n\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t(LAST_VISIT IS NOT NULL) AND\n\t\t\t\t\t\t\t\t\t\t(LAST_VISIT > " . $DB->CharToDateFunction($DB->ForSql($val), "FULL") . ")\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t)"; } break; case "PERMISSION": if (!is_array($val)) { $val = explode(',', $val); } if (empty($val)) { $val = $GLOBALS["USER"]->GetGroups(); } elseif (is_array($val)) { $val_int = array(); foreach ($val as $v) { $val_int[] = intVal($v); } $val = implode(", ", $val_int); } $arSqlFrom["FPP"] = " INNER JOIN ( \n" . "\tSELECT FPP.FORUM_ID, MAX(FPP.PERMISSION) AS PERMISSION \n" . "\tFROM b_forum_perms FPP \n" . "\tWHERE FPP.GROUP_ID IN (" . $DB->ForSql($val) . ") AND FPP.PERMISSION > 'A' \n" . "\tGROUP BY FPP.FORUM_ID) FPP ON (FPP.FORUM_ID = FT.FORUM_ID) "; $arSqlSelect[] = "FPP.PERMISSION AS PERMISSION"; break; case "RENEW": $val = is_array($val) ? $val : array("USER_ID" => $val); $val["USER_ID"] = intVal($val["USER_ID"]); if ($val["USER_ID"] <= 0) { continue; } $perms = "NOT_CHECK"; $arUserGroups = $GLOBALS["USER"]->GetGroups(); if (is_set($arFilter, "PERMISSION")) { $perms = "NORMAL"; } elseif (is_set($arFilter, "APPROVED") && $arFilter["APPROVED"] == "Y") { $perms = "ONLY_APPROVED"; } $arSqlFrom["FUT"] = "LEFT JOIN b_forum_user_topic FUT ON (FUT.USER_ID=" . intVal($val["USER_ID"]) . " AND FUT.FORUM_ID = FT.FORUM_ID AND FUT.TOPIC_ID = FT.ID)"; $arSqlFrom["FUF"] = "LEFT JOIN b_forum_user_forum FUF ON (FUF.USER_ID=" . $val["USER_ID"] . " AND FUF.FORUM_ID = FT.FORUM_ID)"; $arSqlFrom["FUF_ALL"] = "LEFT JOIN b_forum_user_forum FUF_ALL ON (FUF_ALL.USER_ID=" . $val["USER_ID"] . " AND FUF_ALL.FORUM_ID = 0)"; $arSqlSearch[] = "FT.STATE != 'L'"; $arSqlSearch[] = "\n\t\t\t\t\t(\n\t\t\t\t\t\tFUT.LAST_VISIT IS NULL \n\t\t\t\t\t\tAND \n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t(FUF_ALL.LAST_VISIT IS NULL AND FUF.LAST_VISIT IS NULL)\n\t\t\t\t\t\t\tOR \n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tFUF.LAST_VISIT IS NOT NULL\n\t\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\t\t\t\t(FPP.PERMISSION >= 'Q' AND FUF.LAST_VISIT < FT.ABS_LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\tOR \n\t\t\t\t\t\t\t\t\t(FT.APPROVED = 'Y' AND FUF.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t" : ($perms == "NOT_CHECK" ? "\n\t\t\t\t\t\t\t\t\t(FUF.LAST_VISIT < FT.ABS_LAST_POST_DATE OR FUF.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\t\t(FT.APPROVED = 'Y' AND FUF.LAST_VISIT < FT.LAST_POST_DATE)\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\tOR \n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tFUF.LAST_VISIT IS NULL AND FUF_ALL.LAST_VISIT IS NOT NULL \n\t\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\t\t\t\t(FPP.PERMISSION >= 'Q' AND FUF_ALL.LAST_VISIT < FT.ABS_LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\tOR \n\t\t\t\t\t\t\t\t\t(FT.APPROVED = 'Y' AND FUF_ALL.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t" : ($perms == "NOT_CHECK" ? "\n\t\t\t\t\t\t\t\t\t(FUF_ALL.LAST_VISIT < FT.ABS_LAST_POST_DATE OR FUF_ALL.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\t\t(FT.APPROVED = 'Y' AND FUF_ALL.LAST_VISIT < FT.LAST_POST_DATE)\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)\n\t\t\t\t\tOR\n\t\t\t\t\t(\n\t\t\t\t\t\tFUT.LAST_VISIT IS NOT NULL \n\t\t\t\t\t\tAND \n\t\t\t\t\t\t(\n\t\t\t\t\t" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\t\t\t\t(FPP.PERMISSION >= 'Q' AND FUT.LAST_VISIT < FT.ABS_LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\tOR \n\t\t\t\t\t\t\t\t\t(FT.APPROVED = 'Y' AND FUT.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t" : ($perms == "NOT_CHECK" ? "\n\t\t\t\t\t\t\t\t\t(FUT.LAST_VISIT < FT.ABS_LAST_POST_DATE OR FUT.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\t\t(FT.APPROVED = 'Y' AND FUT.LAST_VISIT < FT.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t")) . "\t)\n\t\t\t\t\t)"; break; case "PERMISSION_STRONG": $arSqlFrom["FP"] = "LEFT JOIN b_forum_perms FP ON (FP.FORUM_ID=FT.FORUM_ID)"; $arSqlSearch[] = "FP.GROUP_ID IN (" . $DB->ForSql($USER->GetGroups()) . ") AND (FP.PERMISSION IN ('Q','U','Y'))"; $UseGroup = true; break; } } if (count($arSqlSearch) > 0) { $strSqlSearch = " AND (" . implode(") AND (", $arSqlSearch) . ")"; } if (count($arSqlSelect) > 0) { $res = array(); foreach ($arSqlSelect as $key => $val) { if (substr($key, 0, 1) == "!") { $key = substr($key, 1); } if ($key != $val) { $res[] = $val . " AS " . $key; } else { $res[] = $val; } } $strSqlSelect = ", " . implode(", ", $res); } if (count($arSqlFrom) > 0) { $strSqlFrom = implode("\n", $arSqlFrom); } if ($UseGroup) { foreach ($arSqlSelect as $key => $val) { if (substr($key, 0, 1) != "!") { $arSqlGroup[$key] = $val; } } if (!empty($arSqlGroup)) { $strSqlGroup = ", " . implode(", ", $arSqlGroup); } } foreach ($arOrder as $by => $order) { $by = strtoupper($by); $order = strtoupper($order); if ($order != "ASC") { $order = "DESC"; } if (in_array($by, array("ID", "FORUM_ID", "TOPIC_ID", "TITLE", "TAGS", "DESCRIPTION", "ICON_ID", "STATE", "APPROVED", "SORT", "VIEWS", "USER_START_ID", "USER_START_NAME", "START_DATE", "POSTS", "LAST_POSTER_ID", "LAST_POSTER_NAME", "LAST_POST_DATE", "LAST_MESSAGE_ID", "POSTS_UNAPPROVED", "ABS_LAST_POSTER_ID", "ABS_LAST_POSTER_NAME", "ABS_LAST_POST_DATE", "ABS_LAST_MESSAGE_ID", "SOCNET_GROUP_ID", "OWNER_ID", "HTML", "XML_ID"))) { $arSqlOrder[] = "FT." . $by . " " . $order; } elseif ($by == "FORUM_NAME") { $arSqlOrder[] = "F.NAME " . $order; } else { $arSqlOrder[] = "FT.SORT " . $order; $by = "SORT"; } } $arSqlOrder = array_unique($arSqlOrder); DelDuplicateSort($arSqlOrder); if (count($arSqlOrder) > 0) { $strSqlOrder = " ORDER BY " . implode(", ", $arSqlOrder); } if ($bCount || is_set($arAddParams, "bDescPageNumbering") && intVal($arAddParams["nTopCount"]) <= 0) { $strSql = "SELECT COUNT(FT.ID) as CNT FROM b_forum_topic FT "; $arCountSqlFrom = $arSqlFrom; if (isset($arSqlFrom['FUT']) && strpos($strSqlSearch, "FUT.") === false) { unset($arCountSqlFrom['FUT']); } $strSqlCountFrom = implode("\n", $arCountSqlFrom); $strSql .= $strSqlCountFrom . " WHERE 1 = 1 " . $strSqlSearch; $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $iCnt = 0; if ($ar_res = $db_res->Fetch()) { $iCnt = intVal($ar_res["CNT"]); } if ($bCount) { return $iCnt; } } $arSQL = array("select" => "", "join" => ""); if (!empty($arAddParams["sNameTemplate"])) { $arSQL = array_merge_recursive(CForumUser::GetFormattedNameFieldsForSelect(array_merge($arAddParams, array("sUserTablePrefix" => "U_START.", "sForumUserTablePrefix" => "FU_START.", "sFieldName" => "USER_START_NAME_FRMT", "sUserIDFieldName" => "FT.USER_START_ID"))), CForumUser::GetFormattedNameFieldsForSelect(array_merge($arAddParams, array("sUserTablePrefix" => "U_LAST.", "sForumUserTablePrefix" => "FU_LAST.", "sFieldName" => "LAST_POSTER_NAME_FRMT", "sUserIDFieldName" => "FT.LAST_POSTER_ID"))), CForumUser::GetFormattedNameFieldsForSelect(array_merge($arAddParams, array("sUserTablePrefix" => "U_ABS_LAST.", "sForumUserTablePrefix" => "FU_ABS_LAST.", "sFieldName" => "ABS_LAST_POSTER_NAME_FRMT", "sUserIDFieldName" => "FT.ABS_LAST_POSTER_ID")))); $arSQL["select"] = ",\n\t" . implode(",\n\t", $arSQL["select"]); $arSQL["join"] = "\n" . implode("\n", $arSQL["join"]); } if ($UseGroup) { $strSql = " SELECT F_T.*, FT.FORUM_ID, FT.TOPIC_ID, FT.TITLE, FT.TAGS, FT.DESCRIPTION, FT.ICON_ID, \n" . "\tFT.STATE, FT.APPROVED, FT.SORT, FT.VIEWS, FT.USER_START_ID, FT.USER_START_NAME, \n" . "\t" . CForumNew::Concat("-", array("FT.ID", "FT.TITLE_SEO")) . " as TITLE_SEO, \n" . "\t" . $DB->DateToCharFunction("FT.START_DATE", "FULL") . " as START_DATE, \n" . "\tFT.POSTS, FT.LAST_POSTER_ID, FT.LAST_POSTER_NAME, \n" . "\t" . $DB->DateToCharFunction("FT.LAST_POST_DATE", "FULL") . " as LAST_POST_DATE, \n" . "\tFT.LAST_POST_DATE AS LAST_POST_DATE_ORIGINAL, FT.LAST_MESSAGE_ID, \n" . "\tFT.POSTS_UNAPPROVED, FT.ABS_LAST_POSTER_ID, FT.ABS_LAST_POSTER_NAME, \n" . "\t" . $DB->DateToCharFunction("FT.ABS_LAST_POST_DATE", "FULL") . " as ABS_LAST_POST_DATE, \n" . "\tFT.ABS_LAST_POST_DATE AS ABS_LAST_POST_DATE_ORIGINAL, FT.ABS_LAST_MESSAGE_ID, \n" . "\tFT.SOCNET_GROUP_ID, FT.OWNER_ID, FT.HTML, FT.XML_ID, \n" . "\tF.NAME as FORUM_NAME, \n" . "\tFS.IMAGE, '' as IMAGE_DESCR " . $arSQL["select"] . " \n" . " FROM \n" . "\t( \n" . "\t\tSELECT FT.ID" . $strSqlSelect . " \n" . "\t\tFROM b_forum_topic FT \n" . "\t\t\tLEFT JOIN b_forum F ON (FT.FORUM_ID = F.ID) \n" . "\t\t\t" . $strSqlFrom . " \n" . "\t\tWHERE 1 = 1 " . $strSqlSearch . " \n" . "\t\tGROUP BY FT.ID" . $strSqlGroup . " \n" . "\t) F_T \n" . " INNER JOIN b_forum_topic FT ON (F_T.ID = FT.ID) \n" . " LEFT JOIN b_forum F ON (FT.FORUM_ID = F.ID) \n" . " LEFT JOIN b_forum_smile FS ON (FT.ICON_ID = FS.ID) " . $arSQL["join"] . " \n" . $strSqlOrder; } else { $strSql = " SELECT FT.ID, FT.FORUM_ID, FT.TOPIC_ID, FT.TITLE, FT.TAGS, FT.DESCRIPTION, FT.ICON_ID, \n" . "\tFT.STATE, FT.APPROVED, FT.SORT, FT.VIEWS, FT.USER_START_ID, FT.USER_START_NAME, \n" . "\t" . CForumNew::Concat("-", array("FT.ID", "FT.TITLE_SEO")) . " as TITLE_SEO, \n" . "\t" . $DB->DateToCharFunction("FT.START_DATE", "FULL") . " as START_DATE, \n" . "\tFT.POSTS, FT.LAST_POSTER_ID, FT.LAST_POSTER_NAME, \n" . "\t" . $DB->DateToCharFunction("FT.LAST_POST_DATE", "FULL") . " as LAST_POST_DATE, \n" . "\tFT.LAST_POST_DATE AS LAST_POST_DATE_ORIGINAL, FT.LAST_MESSAGE_ID, \n" . "\tFT.POSTS_UNAPPROVED, FT.ABS_LAST_POSTER_ID, FT.ABS_LAST_POSTER_NAME, \n" . "\t" . $DB->DateToCharFunction("FT.ABS_LAST_POST_DATE", "FULL") . " as ABS_LAST_POST_DATE, \n" . "\tFT.ABS_LAST_POST_DATE AS ABS_LAST_POST_DATE_ORIGINAL, FT.ABS_LAST_MESSAGE_ID, \n" . "\tFT.SOCNET_GROUP_ID, FT.OWNER_ID, FT.HTML, FT.XML_ID, \n" . "\tF.NAME as FORUM_NAME, \n" . "\tFS.IMAGE, '' as IMAGE_DESCR" . $strSqlSelect . $arSQL["select"] . " \n" . " FROM b_forum_topic FT \n" . "\tLEFT JOIN b_forum F ON (FT.FORUM_ID = F.ID) \n" . "\tLEFT JOIN b_forum_smile FS ON (FT.ICON_ID = FS.ID) \n" . "\t" . $strSqlFrom . $arSQL["join"] . " \n" . " WHERE 1 = 1 " . $strSqlSearch . " \n" . $strSqlOrder; } $iNum = intVal($iNum); if ($iNum > 0 || intVal($arAddParams["nTopCount"]) > 0) { $iNum = $iNum > 0 ? $iNum : intVal($arAddParams["nTopCount"]); $strSql .= "\nLIMIT 0," . $iNum; } if (!$iNum && is_set($arAddParams, "bDescPageNumbering") && intVal($arAddParams["nTopCount"]) <= 0) { $db_res = new CDBResult(); $db_res->NavQuery($strSql, $iCnt, $arAddParams); } else { $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if (is_set($arAddParams, 'NoFilter') && $arAddParams['NoFilter'] == true) { return $db_res; } return new _CTopicDBResult($db_res, $arAddParams); }
function GetListEx($arOrder = array("SORT" => "ASC"), $arFilter = array(), $bCount = false, $iNum = 0, $arAddParams = array()) { global $DB; $arSqlSearch = array(); $orSqlSearch = array(); $arSqlSelect = array(); $arSqlFrom = array(); $arSqlGroup = array(); $arSqlOrder = array(); $strSqlSearch = ""; $strSqlSelect = ""; $strSqlSearchOR = ""; $strSqlFrom = ""; $strSqlGroup = ""; $strSqlOrder = ""; $arFilter = is_array($arFilter) ? $arFilter : array(); foreach ($arFilter as $key => $val) { $key_res = CForumNew::GetFilterOperation($key); $key = strtoupper($key_res["FIELD"]); $strNegative = $key_res["NEGATIVE"]; $strOperation = $key_res["OPERATION"]; switch ($key) { case "LID": case "SITE_ID": if (strLen($val) <= 0) { continue; } $arSqlSelect["PATH2FORUM_MESSAGE"] = "F2S.PATH2FORUM_MESSAGE"; $arSqlGroup["PATH2FORUM_MESSAGE"] = "F2S.PATH2FORUM_MESSAGE"; $arSqlFrom["F2S"] = "\n\t\t\t\t\tINNER JOIN b_forum2site F2S ON (F2S.FORUM_ID=F.ID)"; $arSqlSearch[] = ($strNegative == "Y" ? " NOT " : "") . "(F2S.SITE_ID " . $strOperation . " '" . $DB->ForSql($val) . "')"; break; case "INDEXATION": case "DEDUPLICATION": case "ACTIVE": case "XML_ID": case "ALLOW_MOVE_TOPIC": case "ALLOW_SIGNATURE": if (strLen($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(F." . $key . " IS NULL OR " . ($DB->type == "MSSQL" ? "LEN" : "LENGTH") . "(F." . $key . ") <= 0)"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " F." . $key . " IS NULL OR NOT " : "") . "(F." . $key . " " . $strOperation . " '" . $DB->ForSql($val) . "')"; } break; case "ID": case "FORUM_GROUP_ID": case "TOPICS": case "POSTS": if ($strOperation == "IN") { if (is_array($val)) { $val_int = array(); foreach ($val as $v) { $val_int[] = intVal($v); } $val = implode(", ", $val_int); } $val = trim($val); } if ($strOperation == "IN" && strLen($val) <= 0 || intVal($val) <= 0) { $arSqlSearch[] = ($strNegative == "Y" ? "NOT" : "") . "(F." . $key . " IS NULL OR F." . $key . "<=0)"; } elseif ($strOperation == "IN") { $arSqlSearch[] = ($strNegative == "Y" ? " NOT " : "") . "(F." . $key . " IN (" . $DB->ForSql($val) . "))"; } else { $arSqlSearch[] = ($strNegative == "Y" ? " F." . $key . " IS NULL OR NOT " : "") . "(F." . $key . " " . $strOperation . " " . intVal($val) . " )"; } break; case "TEXT": $arSqlSearch[] = " (" . GetFilterQuery("F.NAME,F.DESCRIPTION", $DB->ForSql($val), "Y") . ") "; break; case "PERMS": if (!is_array($val) || count($val) <= 0) { continue; } $arSqlFrom["FP"] = "\n\t\t\t\t\tINNER JOIN b_forum_perms FP ON (F.ID = FP.FORUM_ID)"; if (strToUpper($val[1]) == "ALLOW_MOVE_TOPIC") { $arSqlSearch[] = "FP.GROUP_ID IN (" . $DB->ForSql($val[0]) . ") AND ((FP.PERMISSION > 'M') OR (F.ALLOW_MOVE_TOPIC = 'Y'))"; } else { $arSqlSearch[] = "FP.GROUP_ID IN (" . $DB->ForSql($val[0]) . ") AND FP.PERMISSION > '" . $DB->ForSql($val[1]) . "' "; } break; case "APPROVED": if (strLen($val) <= 0) { continue; } $arSqlFrom["FMM"] = "\n\t\t\t\t\tLEFT JOIN b_forum_message FMM ON (FMM.FORUM_ID=F.ID AND (FMM.APPROVED " . $strOperation . " '" . $DB->ForSql($val) . "'))"; $arSqlSelect["FMM"] = "count(FMM.ID) MCNT"; break; case "RENEW": $val = intVal($val); if ($val <= 0) { continue; } $perms = "NOT_CHECK"; $arUserGroups = $GLOBALS["USER"]->GetGroups(); if (is_set($arFilter, "PERMS")) { $perms = "NORMAL"; $arUserGroups = $arFilter["PERMS"][0]; } elseif (is_set($arFilter, "APPROVED") && $arFilter["APPROVED"] == "Y") { $perms = "ONLY_APPROVED"; } $arSqlSelect["TCRENEW"] = "MAX(BFF.TCRENEW) AS TCRENEW"; $arSqlFrom["RENEW"] = "\n\t\t\t\t\tLEFT JOIN (\n\t\t\t\t\t\tSELECT BF.ID AS RENEW_FORUM_ID, COUNT(FT_RENEW.ID) TCRENEW\n\t\t\t\t\t\tFROM b_forum BF\n\t\t\t\t\t\t" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tSELECT FPP.FORUM_ID, MAX(FPP.PERMISSION) AS PERMISSION\n\t\t\t\t\t\t\tFROM b_forum_perms FPP\n\t\t\t\t\t\t\tWHERE FPP.GROUP_ID IN (" . $arUserGroups . ")\n\t\t\t\t\t\t\tGROUP BY FPP.FORUM_ID\n\t\t\t\t\t\t) FP ON (FP.FORUM_ID = BF.ID)" : "") . "\n\t\t\t\t\t\tLEFT JOIN b_forum_user_forum FUF ON (FUF.USER_ID=" . $val . " AND FUF.FORUM_ID = BF.ID)\n\t\t\t\t\t\tLEFT JOIN b_forum_user_forum FUF_ALL ON (FUF_ALL.USER_ID=" . $val . " AND FUF_ALL.FORUM_ID = 0)\n\t\t\t\t\t\tLEFT JOIN b_forum_topic FT_RENEW ON (BF.ID = FT_RENEW.FORUM_ID AND FT_RENEW.STATE != 'L' AND (FUF_ALL.LAST_VISIT IS NULL OR FT_RENEW.ABS_LAST_POST_DATE > FUF_ALL.LAST_VISIT))\n\t\t\t\t\t\tLEFT JOIN b_forum_user_topic FUT_RENEW ON (FUT_RENEW.FORUM_ID = BF.ID AND FUT_RENEW.TOPIC_ID = FT_RENEW.ID AND FUT_RENEW.USER_ID=" . $val . ")\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tFUT_RENEW.LAST_VISIT IS NULL\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(FUF_ALL.LAST_VISIT IS NULL AND FUF.LAST_VISIT IS NULL)\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\tFUF.LAST_VISIT IS NOT NULL\n\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\t\t\t\t\t(FP.PERMISSION >= 'Q' AND FUF.LAST_VISIT < FT_RENEW.ABS_LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t(FT_RENEW.APPROVED = 'Y' AND FUF.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t" : ($perms == "NOT_CHECK" ? "\n\t\t\t\t\t\t\t\t\t\t(FUF.LAST_VISIT < FT_RENEW.ABS_LAST_POST_DATE OR FUF.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\t\t\t(FT_RENEW.APPROVED = 'Y' AND FUF.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\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\tOR\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\tFUF.LAST_VISIT IS NULL AND FUF_ALL.LAST_VISIT IS NOT NULL\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" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\t\t\t\t\t(FP.PERMISSION >= 'Q' AND FUF_ALL.LAST_VISIT < FT_RENEW.ABS_LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t(FT_RENEW.APPROVED = 'Y' AND FUF_ALL.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t" : ($perms == "NOT_CHECK" ? "\n\t\t\t\t\t\t\t\t\t\t(FUF_ALL.LAST_VISIT < FT_RENEW.ABS_LAST_POST_DATE OR FUF_ALL.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\t\t\t(FT_RENEW.APPROVED = 'Y' AND FUF_ALL.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\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\t(\n\t\t\t\t\t\t\tFUT_RENEW.LAST_VISIT IS NOT NULL\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t" . ($perms == "NORMAL" ? "\n\t\t\t\t\t\t\t\t\t\t(FP.PERMISSION >= 'Q' AND FUT_RENEW.LAST_VISIT < FT_RENEW.ABS_LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t(FT_RENEW.APPROVED = 'Y' AND FUT_RENEW.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t" : ($perms == "NOT_CHECK" ? "\n\t\t\t\t\t\t\t\t\t\t(FUT_RENEW.LAST_VISIT < FT_RENEW.ABS_LAST_POST_DATE OR FUT_RENEW.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\t\t\t(FT_RENEW.APPROVED = 'Y' AND FUT_RENEW.LAST_VISIT < FT_RENEW.LAST_POST_DATE)\n\t\t\t\t\t\t\t\t\t\t")) . "\n\t\t\t\t\t\t)\n\t\t\t\t\t\tGROUP BY BF.ID" . ($perms == "NORMAL" ? ", FP.PERMISSION" : "") . "\n\t\t\t\t\t) BFF ON (BFF.RENEW_FORUM_ID = F.ID)\n\t\t\t\t\t"; break; } } if (count($arSqlSearch) > 0) { $strSqlSearch = " AND (" . implode(") AND (", $arSqlSearch) . ") "; } if (count($orSqlSearch) > 0) { $strSqlSearchOR = " OR (" . implode(") AND (", $orSqlSearch) . ") "; } if (count($arSqlSelect) > 0) { $strSqlSelect = ", " . implode(", ", $arSqlSelect); } if (count($arSqlFrom) > 0) { $strSqlFrom = " " . implode(" ", $arSqlFrom); } if (count($arSqlGroup) > 0) { $strSqlGroup = "," . implode(",", $arSqlGroup); } foreach ($arOrder as $by => $order) { $by = strtoupper($by); $order = strtoupper($order); if ($order != "ASC") { $order = "DESC" . ($DB->type == "ORACLE" ? " NULLS LAST" : ""); } else { $order = "ASC" . ($DB->type == "ORACLE" ? " NULLS FIRST" : ""); } if ($by == "ID") { $arSqlOrder["F_FORUM.ID"] = " F_FORUM.ID " . $order . " "; } elseif ($by == "NAME") { $arSqlOrder["F.NAME"] = " F.NAME " . $order . " "; } elseif ($by == "ACTIVE") { $arSqlOrder["F.ACTIVE"] = " F.ACTIVE " . $order . " "; } elseif ($by == "MODERATION") { $arSqlOrder["F.MODERATION"] = " F.MODERATION " . $order . " "; } elseif ($by == "FORUM_GROUP_ID") { $arSqlOrder["F.FORUM_GROUP_ID"] = " F.FORUM_GROUP_ID " . $order . " "; } elseif ($by == "FORUM_GROUP_SORT") { $arSqlOrder["FG.SORT"] = " FG.SORT " . $order . " "; } elseif ($by == "FORUM_GROUP_LEFT_MARGIN") { $arSqlOrder["FG.LEFT_MARGIN"] = " FG.LEFT_MARGIN " . $order . " "; } elseif ($by == "TOPICS") { $arSqlOrder["F.TOPICS"] = " F.TOPICS " . $order . " "; } elseif ($by == "POSTS") { $arSqlOrder["F.POSTS"] = " F.POSTS " . $order . " "; } elseif ($by == "POSTS_UNAPPROVED") { $arSqlOrder["F.POSTS_UNAPPROVED"] = " F.POSTS_UNAPPROVED " . $order . " "; } elseif ($by == "LAST_POST_DATE") { $arSqlOrder["F.LAST_POST_DATE"] = " F.LAST_POST_DATE " . $order . " "; } elseif ($by == "ABS_LAST_POST_DATE") { $arSqlOrder["F.ABS_LAST_POST_DATE"] = " F.ABS_LAST_POST_DATE " . $order . " "; } else { $arSqlOrder["F.SORT"] = " F.SORT " . $order . " "; $by = "SORT"; } } if (count($arSqlOrder) > 0) { $strSqlOrder = " ORDER BY " . implode(", ", $arSqlOrder); } if ($bCount || is_set($arAddParams, "bDescPageNumbering") && intVal($arAddParams["nTopCount"]) <= 0) { $arCountSqlFrom = $arSqlFrom; if (isset($arSqlFrom['RENEW']) && strpos($strSqlSearch, "RENEW.") === false) { unset($arCountSqlFrom['RENEW']); } $strSqlCountFrom = implode(" ", $arCountSqlFrom); $strSql = "SELECT COUNT(FORUMCOUNT.ID) as CNT FROM (" . "SELECT F.ID " . " FROM b_forum F " . $strSqlCountFrom . " " . " WHERE (1=1 " . $strSqlSearch . ") " . $strSqlSearchOR . " GROUP BY F.ID" . ") FORUMCOUNT"; $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $iCnt = 0; if ($ar_res = $db_res->Fetch()) { $iCnt = intVal($ar_res["CNT"]); } if ($bCount) { return $iCnt; } } if (!$iNum && is_set($arAddParams, "bDescPageNumbering") && intVal($arAddParams["nTopCount"]) <= 0 && isset($arAddParams['nav_result'])) { if (!$arAddParams['nav_result']) { $strSubSql = "SELECT F_FORUM.* " . "FROM " . "(SELECT F.ID, FG.SORT " . $strSqlSelect . " " . "FROM b_forum F " . $strSqlFrom . " " . "LEFT JOIN b_forum_group FG ON F.FORUM_GROUP_ID = FG.ID " . "WHERE (1=1 " . $strSqlSearch . ") " . $strSqlSearchOR . " " . "GROUP BY F.ID, FG.SORT" . $strSqlGroup . ") F_FORUM " . "INNER JOIN b_forum F ON (F_FORUM.ID = F.ID) " . str_replace("FG.SORT", "F_FORUM.SORT", $strSqlOrder); $db_res = new CDBResult(); $db_res->NavQuery($strSubSql, $iCnt, $arAddParams); return $db_res; } else { $db_res = $arAddParams['nav_result']; } $arForumID = array(); while ($ar_res = $db_res->Fetch()) { $arForumID[] = $ar_res['ID']; } $sForumID = implode(', ', $arForumID); $strSqlSearch = "(" . ($sForumID != "" ? "F.ID IN (" . $sForumID . ") " : "1=1 ") . $strSqlSearch . ")"; } else { $strSqlSearch = "(1=1 " . $strSqlSearch . ")"; } $arSQL = array("select" => "", "join" => ""); if (!empty($arAddParams["sNameTemplate"])) { $arSQL = array_merge_recursive(CForumUser::GetFormattedNameFieldsForSelect(array_merge($arAddParams, array("sUserTablePrefix" => "U_LAST.", "sForumUserTablePrefix" => "FU_LAST.", "sFieldName" => "LAST_POSTER_NAME_FRMT", "sUserIDFieldName" => "F.LAST_POSTER_ID"))), CForumUser::GetFormattedNameFieldsForSelect(array_merge($arAddParams, array("sUserTablePrefix" => "U_ABS_LAST.", "sForumUserTablePrefix" => "FU_ABS_LAST.", "sFieldName" => "ABS_LAST_POSTER_NAME_FRMT", "sUserIDFieldName" => "F.ABS_LAST_POSTER_ID")))); $arSQL["select"] = ",\n\t" . implode(",\n\t", $arSQL["select"]); $arSQL["join"] = "\n" . implode("\n", $arSQL["join"]); } $strSql = "SELECT F_FORUM.*, F.FORUM_GROUP_ID, F.NAME, F.DESCRIPTION, F.SORT, F.ACTIVE,\n\t\t\t\tF.ALLOW_HTML, F.ALLOW_ANCHOR, F.ALLOW_BIU, F.ALLOW_IMG, F.ALLOW_VIDEO,\n\t\t\t\tF.ALLOW_LIST, F.ALLOW_QUOTE, F.ALLOW_CODE, F.ALLOW_FONT, F.ALLOW_SMILES,\n\t\t\t\tF.ALLOW_ALIGN, F.ALLOW_UPLOAD, F.ALLOW_UPLOAD_EXT, F.ALLOW_MOVE_TOPIC,\n\t\t\t\tF.ALLOW_NL2BR, F.ALLOW_TABLE, F.ALLOW_TOPIC_TITLED, F.ALLOW_SIGNATURE,\n\t\t\t\t" . (strpos($strSqlSelect, "PATH2FORUM_MESSAGE") === false ? "'' as PATH2FORUM_MESSAGE," : "") . "\n\t\t\t\tF.ASK_GUEST_EMAIL, F.USE_CAPTCHA, F.MODERATION, F.INDEXATION, F.DEDUPLICATION,\n\t\t\t\tF.ORDER_BY, F.ORDER_DIRECTION,\n\t\t\t\t'' as LID, '' as DIR,\n\t\t\t\tF.TOPICS, F.XML_ID,\n\t\t\t\tF.POSTS, F.LAST_POSTER_ID, F.LAST_POSTER_NAME,\n\t\t\t\t" . $DB->DateToCharFunction("F.LAST_POST_DATE", "FULL") . " as LAST_POST_DATE,\n\t\t\t\tF.LAST_MESSAGE_ID, FM.TOPIC_ID as TID, F.LAST_MESSAGE_ID as MID,\n\t\t\t\tF.POSTS_UNAPPROVED, F.ABS_LAST_POSTER_ID, F.ABS_LAST_POSTER_NAME,\n\t\t\t\t" . $DB->DateToCharFunction("F.ABS_LAST_POST_DATE", "FULL") . " as ABS_LAST_POST_DATE,\n\t\t\t\tF.ABS_LAST_MESSAGE_ID, FM_ABS.TOPIC_ID as ABS_TID,\n\t\t\t\tF.EVENT1, F.EVENT2, F.EVENT3,\n\t\t\t\tFT.TITLE, FT.SOCNET_GROUP_ID, FT.OWNER_ID,\n\t\t\t\t" . CForumNew::Concat("-", array("FT.ID", "FT.TITLE_SEO")) . " AS TITLE_SEO,\n\t\t\t\tFT.HTML AS TOPIC_HTML, FM.PARAM1, FM.PARAM2,\n\t\t\t\tFT_ABS.TITLE as ABS_TITLE, FT_ABS.SOCNET_GROUP_ID as ABS_SOCNET_GROUP_ID, FT_ABS.OWNER_ID as ABS_OWNER_ID,\n\t\t\t\t" . CForumNew::Concat("-", array("FT_ABS.ID", "FT_ABS.TITLE_SEO")) . " AS ABS_TITLE_SEO,\n\t\t\t\tFT_ABS.HTML AS ABS_TOPIC_HTML, FM_ABS.PARAM1 as ABS_PARAM1, FM_ABS.PARAM2 as ABS_PARAM2,\n\t\t\t\tF.HTML" . $arSQL["select"] . "\n\t\t\tFROM\n\t\t\t(\n\t\t\t\tSELECT F.ID " . $strSqlSelect . "\n\t\t\t\tFROM b_forum F\n\t\t\t\t\t" . $strSqlFrom . "\n\t\t\t\tWHERE " . $strSqlSearch . "\n\t\t\t\t\t" . $strSqlSearchOR . "\n\t\t\t\tGROUP BY F.ID" . $strSqlGroup . "\n\t\t\t) F_FORUM\n\t\t\tINNER JOIN b_forum F ON (F_FORUM.ID = F.ID)" . $arSQL["join"] . "\n\t\t\tLEFT JOIN b_forum_group FG ON F.FORUM_GROUP_ID = FG.ID\n\t\t\tLEFT JOIN b_forum_message FM ON F.LAST_MESSAGE_ID = FM.ID\n\t\t\tLEFT JOIN b_forum_topic FT ON FM.TOPIC_ID = FT.ID\n\t\t\tLEFT JOIN b_forum_message FM_ABS ON F.ABS_LAST_MESSAGE_ID = FM_ABS.ID\n\t\t\tLEFT JOIN b_forum_topic FT_ABS ON FM_ABS.TOPIC_ID = FT_ABS.ID\n\t\t\t" . $strSqlOrder; $iNum = intVal($iNum); if ($iNum > 0 || intVal($arAddParams["nTopCount"]) > 0) { $iNum = $iNum > 0 ? $iNum : intVal($arAddParams["nTopCount"]); $strSql .= " LIMIT 0," . $iNum; } $db_res = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if (is_set($arAddParams, 'NoFilter') && $arAddParams['NoFilter'] == true) { return $db_res; } return new _CForumDBResult($db_res, $arAddParams); }
function GetSelectFields($arAddParams = array(), $fields = array()) { global $DB; $arAddParams = is_array($arAddParams) ? $arAddParams : array(); $arAddParams["sPrefix"] = $DB->ForSql(empty($arAddParams["sPrefix"]) ? "FT." : $arAddParams["sPrefix"]); $arAddParams["sTablePrefix"] = $DB->ForSql(empty($arAddParams["sTablePrefix"]) ? "FT." : $arAddParams["sTablePrefix"]); $arAddParams["sReturnResult"] = $arAddParams["sReturnResult"] == "string" ? "string" : "array"; $fields = is_array($fields) ? $fields : array(); $fields = array_merge(array("ID" => "ID", "TITLE" => "TITLE", "TITLE_SEO_REAL" => $arAddParams["sTablePrefix"] . "TITLE_SEO", "TITLE_SEO" => CForumNew::Concat("-", array($arAddParams["sTablePrefix"] . "ID", $arAddParams["sTablePrefix"] . "TITLE_SEO")), "TAGS" => "TAGS", "DESCRIPTION" => "DESCRIPTION", "VIEWS" => "VIEWS", "LAST_POSTER_ID" => "LAST_POSTER_ID", "START_DATE" => $DB->DateToCharFunction($arAddParams["sTablePrefix"] . "START_DATE", "FULL"), "USER_START_NAME" => "USER_START_NAME", "USER_START_ID" => "USER_START_ID", "POSTS" => "POSTS", "LAST_POSTER_NAME" => "LAST_POSTER_NAME", "LAST_POST_DATE" => $DB->DateToCharFunction($arAddParams["sTablePrefix"] . "LAST_POST_DATE", "FULL"), "LAST_MESSAGE_ID" => "LAST_MESSAGE_ID", "APPROVED" => "APPROVED", "STATE" => "STATE", "FORUM_ID" => "FORUM_ID", "TOPIC_ID" => "TOPIC_ID", "ICON" => "ICON", "SORT" => "SORT", "SOCNET_GROUP_ID" => "SOCNET_GROUP_ID", "OWNER_ID" => "OWNER_ID", "XML_ID" => "XML_ID"), $fields); foreach ($fields as $key => $val) { if ($key == $val) { $res[$arAddParams["sPrefix"] . $key] = $arAddParams["sTablePrefix"] . $val; } else { $res[($arAddParams["sPrefix"] == $arAddParams["sTablePrefix"] ? "" : $arAddParams["sPrefix"]) . $key] = $val; } } if ($arAddParams["sReturnResult"] == "string") { $arRes = array(); foreach ($res as $key => $val) { $arRes[] = $val . ($key != $val ? " AS " . $key : ""); } $res = implode(", ", $arRes); } return $res; }