function GetList(&$by, &$order, $arFilter = array(), &$is_filtered, $CHECK_RIGHTS = "Y") { $err_mess = CAdvType_all::err_mess() . "<br>Function: GetList<br>Line: "; global $DB; $arSqlSearch = array(); if ($CHECK_RIGHTS == "Y") { $isAdmin = CAdvContract::IsAdmin(); $isDemo = CAdvContract::IsDemo(); $isManager = CAdvContract::IsManager(); $isAdvertiser = CAdvContract::IsAdvertiser(); } else { $isAdmin = true; $isDemo = true; $isManager = true; $isAdvertiser = true; } if ($isAdmin || $isDemo || $isManager || $isAdvertiser) { if (CAdvType::CheckFilter($arFilter)) { if (is_array($arFilter)) { $filter_keys = array_keys($arFilter); for ($i = 0, $n = count($filter_keys); $i < $n; $i++) { $key = $filter_keys[$i]; $val = $arFilter[$filter_keys[$i]]; if (is_array($val)) { if (count($val) <= 0) { continue; } } else { if (strlen($val) <= 0 || $val === "NOT_REF") { continue; } } $match_value_set = in_array($key . "_EXACT_MATCH", $filter_keys) ? true : false; $key = strtoupper($key); switch ($key) { case "SID": $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N"; $arSqlSearch[] = GetFilterQuery("T.SID", $val, $match); break; case "DATE_MODIFY_1": $arSqlSearch[] = "T.DATE_MODIFY>=" . $DB->CharToDateFunction($val, "SHORT"); break; case "DATE_MODIFY_2": $arSqlSearch[] = "T.DATE_MODIFY<=" . $DB->CharToDateFunction($val . " 23:59:59", "FULL"); break; case "ACTIVE": $arSqlSearch[] = $val == "Y" ? "T.ACTIVE='Y'" : "T.ACTIVE='N'"; break; case "NAME": case "DESCRIPTION": $match = $arFilter[$key . "_EXACT_MATCH"] == "Y" && $match_value_set ? "N" : "Y"; $arSqlSearch[] = GetFilterQuery("T." . $key, $val, $match); break; } } } } if ($by == "s_sid") { $strSqlOrder = " ORDER BY T.SID "; } elseif ($by == "s_date_modify") { $strSqlOrder = " ORDER BY T.DATE_MODIFY "; } elseif ($by == "s_modified_by") { $strSqlOrder = " ORDER BY T.MODIFIED_BY "; } elseif ($by == "s_date_create") { $strSqlOrder = " ORDER BY T.DATE_CREATE "; } elseif ($by == "s_created_by") { $strSqlOrder = " ORDER BY T.CREATED_BY "; } elseif ($by == "s_active") { $strSqlOrder = " ORDER BY T.ACTIVE "; } elseif ($by == "s_name") { $strSqlOrder = " ORDER BY T.NAME "; } elseif ($by == "s_banners") { $strSqlOrder = " ORDER BY BANNER_COUNT "; } elseif ($by == "s_description") { $strSqlOrder = " ORDER BY T.DESCRIPTION "; } else { $strSqlOrder = " ORDER BY T.SORT "; $by = "s_sort"; } if ($order != "desc") { $strSqlOrder .= " asc "; $order = "asc"; } else { $strSqlOrder .= " desc "; $order = "desc"; } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); $strContracts = ""; if (!$isAdmin && !$isDemo && !$isManager) { $strContracts = "0"; $arPermissions = CAdvContract::GetUserPermissions(); foreach ($arPermissions as $contract_id => $arContractPerms) { if (is_array($arContractPerms) && !empty($arContractPerms)) { $strContracts .= "," . $contract_id; } } } $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tT.SID,\n\t\t\t\t\tT.ACTIVE,\n\t\t\t\t\tT.SORT,\n\t\t\t\t\tT.NAME,\n\t\t\t\t\tT.DESCRIPTION,\n\t\t\t\t\t" . $DB->DateToCharFunction("T.DATE_CREATE") . "\tDATE_CREATE,\n\t\t\t\t\t" . $DB->DateToCharFunction("T.DATE_MODIFY") . "\tDATE_MODIFY,\n\t\t\t\t\tT.CREATED_BY,\n\t\t\t\t\tT.MODIFIED_BY,\n\t\t\t\t\tcount(distinct B.ID)\t\t\t\t\t\t\tBANNER_COUNT\n\t\t\t\tFROM\n\t\t\t\t\tb_adv_type T\n\t\t\t\t\tLEFT JOIN b_adv_banner B ON (B.TYPE_SID=T.SID" . ($strContracts == "" ? "" : " AND B.CONTRACT_ID IN (" . $strContracts . ")") . ")\n\t\t\t\tWHERE\n\t\t\t\t{$strSqlSearch} " . ($strContracts == "" ? "" : "and exists(select 'x' from b_adv_contract_2_type CT where (CT.TYPE_SID=T.SID OR CT.TYPE_SID='ALL') AND CT.CONTRACT_ID IN (" . $strContracts . ")) ") . " and T.SID<>'ALL'\n\t\t\t\tGROUP BY\n\t\t\t\t\tT.SID, T.ACTIVE, T.SORT, T.NAME, T.DESCRIPTION,\tT.DATE_CREATE, T.DATE_MODIFY, T.CREATED_BY, T.MODIFIED_BY\n\t\t\t\t{$strSqlOrder}\n\t\t\t\t"; $res = $DB->Query($strSql, false, $err_mess . __LINE__); $is_filtered = IsFiltered($strSqlSearch); return $res; } return null; }