function GetList(&$by, &$order, $arFilter = array(), &$is_filtered, $CHECK_RIGHTS = "Y") { $err_mess = CAdvBanner::err_mess() . "<br>Function: GetList<br>Line: "; global $DB, $USER, $APPLICATION; if ($CHECK_RIGHTS == "Y") { $USER_ID = intval($USER->GetID()); $isAdmin = CAdvContract::IsAdmin(); $isDemo = CAdvContract::IsDemo(); $isManager = CAdvContract::IsManager(); $isAdvertiser = CAdvContract::IsAdvertiser(); } else { if (is_object($USER)) { $USER_ID = intval($USER->GetID()); } else { $USER_ID = 0; } $isAdmin = true; $isDemo = true; $isManager = true; $isAdvertiser = true; } $arSqlSearch = array(); $strSqlSearch = ""; $DONT_USE_CONTRACT = COption::GetOptionString("advertising", "DONT_USE_CONTRACT", "N"); if ($DONT_USE_CONTRACT == "Y") { $lamp = "\n\t\t\t\tif ((\n\t\t\t\t\t(B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_FROM is null or length(B.DATE_SHOW_FROM)<=0) and\n\t\t\t\t\t(B.DATE_SHOW_TO>=now() or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0) and\n\t\t\t\t\t(ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0) or ifnull(B.MAX_SHOW_COUNT,0)=0) and\n\t\t\t\t\t(ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0) or ifnull(B.MAX_CLICK_COUNT,0)=0) and\n\t\t\t\t\t(ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0) or ifnull(B.MAX_VISITOR_COUNT,0)=0) and\n\t\t\t\t\t(B.ACTIVE='Y') and\n\t\t\t\t\t(B.STATUS_SID='PUBLISHED') and\n\t\t\t\t\t(T.ACTIVE='Y')\n\t\t\t\t\t),\n\t\t\t\t\t'green',\n\t\t\t\t\t'red')\n\t\t\t\t"; } else { $lamp = "\n\t\t\t\tif ((\n\t\t\t\t\t(B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_FROM is null or length(B.DATE_SHOW_FROM)<=0) and\n\t\t\t\t\t(B.DATE_SHOW_TO>=now() or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0) and\n\t\t\t\t\t(ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0) or ifnull(B.MAX_SHOW_COUNT,0)=0) and\n\t\t\t\t\t(ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0) or ifnull(B.MAX_CLICK_COUNT,0)=0) and\n\t\t\t\t\t(ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0) or ifnull(B.MAX_VISITOR_COUNT,0)=0) and\n\t\t\t\t\t(B.ACTIVE='Y') and\n\t\t\t\t\t(B.STATUS_SID='PUBLISHED') and\n\t\t\t\t\t(T.ACTIVE='Y') and\n\t\t\t\t\t(C.DATE_SHOW_FROM<=now() or C.DATE_SHOW_FROM is null or length(C.DATE_SHOW_FROM)<=0) and\n\t\t\t\t\t(C.DATE_SHOW_TO>=now() or C.DATE_SHOW_TO is null or length(C.DATE_SHOW_TO)<=0) and\n\t\t\t\t\t(ifnull(C.MAX_SHOW_COUNT,0)>ifnull(C.SHOW_COUNT,0) or ifnull(C.MAX_SHOW_COUNT,0)=0) and\n\t\t\t\t\t(ifnull(C.MAX_CLICK_COUNT,0)>ifnull(C.CLICK_COUNT,0) or ifnull(C.MAX_CLICK_COUNT,0)=0) and\n\t\t\t\t\t(ifnull(C.MAX_VISITOR_COUNT,0)>ifnull(C.VISITOR_COUNT,0) or ifnull(C.MAX_VISITOR_COUNT,0)=0) and\n\t\t\t\t\t(C.ACTIVE='Y')\n\t\t\t\t\t),\n\t\t\t\t\t'green',\n\t\t\t\t\t'red')\n\t\t\t\t"; } if (CAdvBanner::CheckFilter($arFilter)) { if (is_array($arFilter)) { $filter_keys = array_keys($arFilter); for ($i = 0; $i < count($filter_keys); $i++) { $key = $filter_keys[$i]; $val = $arFilter[$filter_keys[$i]]; if (is_array($val) && count($val) <= 0) { continue; } if ($val == '' || $val == "NOT_REF") { continue; } $match_value_set = in_array($key . "_EXACT_MATCH", $filter_keys) ? true : false; $key = strtoupper($key); switch ($key) { case "ID": $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N"; $arSqlSearch[] = GetFilterQuery("B.ID", $val, $match); break; case "LAMP": $arSqlSearch[] = " " . $lamp . " = '" . $DB->ForSQL($val) . "'"; break; case "SITE": if (is_array($val)) { $val = implode(" | ", $val); } $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N"; $arSqlSearch[] = GetFilterQuery("BS.SITE_ID", $val, $match); $left_join = "LEFT JOIN b_adv_banner_2_site BS ON (B.ID = BS.BANNER_ID)"; break; case "DATE_MODIFY_1": $arSqlSearch[] = "B.DATE_MODIFY>=" . $DB->CharToDateFunction($val, "SHORT"); break; case "DATE_MODIFY_2": $arSqlSearch[] = "B.DATE_MODIFY<" . $DB->CharToDateFunction($val, "SHORT") . " + INTERVAL 1 DAY"; break; case "DATE_CREATE_1": $arSqlSearch[] = "B.DATE_CREATE>=" . $DB->CharToDateFunction($val, "SHORT"); break; case "DATE_CREATE_2": $arSqlSearch[] = "B.DATE_CREATE<" . $DB->CharToDateFunction($val, "SHORT") . " + INTERVAL 1 DAY"; break; case "DATE_SHOW_FROM_1": $arSqlSearch[] = "B.DATE_SHOW_FROM>=" . $DB->CharToDateFunction($val, "SHORT"); break; case "DATE_SHOW_FROM_2": $arSqlSearch[] = "B.DATE_SHOW_FROM<" . $DB->CharToDateFunction($val, "SHORT") . " + INTERVAL 1 DAY"; break; case "DATE_SHOW_TO_1": $arSqlSearch[] = "B.DATE_SHOW_TO>=" . $DB->CharToDateFunction($val, "SHORT"); break; case "DATE_SHOW_TO_2": $arSqlSearch[] = "B.DATE_SHOW_TO<" . $DB->CharToDateFunction($val, "SHORT") . " + INTERVAL 1 DAY"; break; case "ACTIVE": case "FIX_SHOW": $arSqlSearch[] = $val == "Y" ? "B." . $key . "='Y'" : "B." . $key . "='N'"; break; case "WEIGHT_1": $arSqlSearch[] = "ifnull(B.WEIGHT,0)>='" . intval($val) . "'"; break; case "WEIGHT_2": $arSqlSearch[] = "ifnull(B.WEIGHT,0)<='" . intval($val) . "'"; break; case "MAX_VISITOR_COUNT_1": $arSqlSearch[] = "ifnull(B.MAX_VISITOR_COUNT,0)>='" . intval($val) . "'"; break; case "MAX_VISITOR_COUNT_2": $arSqlSearch[] = "ifnull(B.MAX_VISITOR_COUNT,0)<='" . intval($val) . "'"; break; case "VISITOR_COUNT_1": $arSqlSearch[] = "ifnull(B.VISITOR_COUNT,0)>='" . intval($val) . "'"; break; case "VISITOR_COUNT_2": $arSqlSearch[] = "ifnull(B.VISITOR_COUNT,0)<='" . intval($val) . "'"; break; case "MAX_SHOW_COUNT_1": $arSqlSearch[] = "ifnull(B.MAX_SHOW_COUNT,0)>='" . intval($val) . "'"; break; case "MAX_SHOW_COUNT_2": $arSqlSearch[] = "ifnull(B.MAX_SHOW_COUNT,0)<='" . intval($val) . "'"; break; case "SHOW_COUNT_1": $arSqlSearch[] = "ifnull(B.SHOW_COUNT,0)>='" . intval($val) . "'"; break; case "SHOW_COUNT_2": $arSqlSearch[] = "ifnull(B.SHOW_COUNT,0)<='" . intval($val) . "'"; break; case "MAX_CLICK_COUNT_1": $arSqlSearch[] = "ifnull(B.MAX_CLICK_COUNT,0)>='" . intval($val) . "'"; break; case "MAX_CLICK_COUNT_2": $arSqlSearch[] = "ifnull(B.MAX_CLICK_COUNT,0)<='" . intval($val) . "'"; break; case "CLICK_COUNT_1": $arSqlSearch[] = "ifnull(B.CLICK_COUNT,0)>='" . intval($val) . "'"; break; case "CLICK_COUNT_2": $arSqlSearch[] = "ifnull(B.CLICK_COUNT,0)<='" . intval($val) . "'"; break; case "CTR_1": $arSqlSearch[] = "if(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))>='" . DoubleVal(str_replace(',', '.', $val)) . "'"; break; case "CTR_2": $arSqlSearch[] = "if(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))<='" . DoubleVal(str_replace(',', '.', $val)) . "'"; break; case "GROUP": $match = $arFilter[$key . "_EXACT_MATCH"] == "Y" && $match_value_set ? "N" : "Y"; $arSqlSearch[] = GetFilterQuery("B.GROUP_SID", $val, $match); break; case "STATUS": case "STATUS_SID": if (is_array($val)) { $val = implode(" | ", $val); } $arSqlSearch[] = GetFilterQuery("B.STATUS_SID", $val, "N"); break; case "CONTRACT_ID": if (is_array($val)) { $val = implode(" | ", $val); } $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N"; $arSqlSearch[] = GetFilterQuery("B.CONTRACT_ID", $val, $match); break; case "CONTRACT": if (is_array($val)) { $val = implode(" | ", $val); } $match = $arFilter[$key . "_EXACT_MATCH"] == "Y" && $match_value_set ? "N" : "Y"; $arSqlSearch[] = GetFilterQuery("B.CONTRACT_ID, C.NAME, C.DESCRIPTION", $val, $match); break; case "TYPE_SID": if (is_array($val)) { $val = implode(" | ", $val); } $match = $arFilter[$key . "_EXACT_MATCH"] == "N" && $match_value_set ? "Y" : "N"; $arSqlSearch[] = GetFilterQuery("B.TYPE_SID", $val, $match); break; case "TYPE": if (is_array($val)) { $val = implode(" | ", $val); } $match = $arFilter[$key . "_EXACT_MATCH"] == "Y" && $match_value_set ? "N" : "Y"; $arSqlSearch[] = GetFilterQuery("B.TYPE_SID, T.NAME, T.DESCRIPTION", $val, $match); break; case "SHOW_USER_GROUP": if ($val == "Y") { $arSqlSearch[] = "B.SHOW_USER_GROUP='Y'"; } else { $arSqlSearch[] = "B.SHOW_USER_GROUP <> 'Y'"; } break; case "NAME": case "CODE": case "COMMENTS": $match = $arFilter[$key . "_EXACT_MATCH"] == "Y" && $match_value_set ? "N" : "Y"; $arSqlSearch[] = GetFilterQuery("B." . $key, $val, $match); break; // совместимость со старой версией // совместимость со старой версией case "LANG": case "FIRST_SITE_ID": $arSqlSearch[] = GetFilterQuery("B.FIRST_SITE_ID", $val, "N"); break; } } } } if ($by == "s_id") { $strSqlOrder = " ORDER BY B.ID "; } elseif ($by == "s_lamp") { $strSqlOrder = " ORDER BY LAMP "; } elseif ($by == "s_name") { $strSqlOrder = " ORDER BY B.NAME "; } elseif ($by == "s_type_sid") { $strSqlOrder = " ORDER BY B.TYPE_SID "; } elseif ($by == "s_contract_id") { $strSqlOrder = " ORDER BY B.CONTRACT_ID "; } elseif ($by == "s_group_sid") { $strSqlOrder = " ORDER BY B.GROUP_SID "; } elseif ($by == "s_visitor_count") { $strSqlOrder = " ORDER BY B.VISITOR_COUNT "; } elseif ($by == "s_max_visitor_count") { $strSqlOrder = " ORDER BY ifnull(B.MAX_VISITOR_COUNT,0) "; } elseif ($by == "s_show_count") { $strSqlOrder = " ORDER BY B.SHOW_COUNT "; } elseif ($by == "s_max_show_count") { $strSqlOrder = " ORDER BY ifnull(B.MAX_SHOW_COUNT,0) "; } elseif ($by == "s_date_last_show") { $strSqlOrder = " ORDER BY B.DATE_LAST_SHOW "; } elseif ($by == "s_click_count") { $strSqlOrder = " ORDER BY B.CLICK_COUNT "; } elseif ($by == "s_max_click_count") { $strSqlOrder = " ORDER BY ifnull(B.MAX_CLICK_COUNT,0) "; } elseif ($by == "s_date_last_click") { $strSqlOrder = " ORDER BY B.DATE_LAST_CLICK "; } elseif ($by == "s_active") { $strSqlOrder = " ORDER BY B.ACTIVE "; } elseif ($by == "s_weight") { $strSqlOrder = " ORDER BY B.WEIGHT "; } elseif ($by == "s_status_sid") { $strSqlOrder = " ORDER BY B.STATUS_SID "; } elseif ($by == "s_date_show_from") { $strSqlOrder = " ORDER BY B.DATE_SHOW_FROM "; } elseif ($by == "s_date_show_to") { $strSqlOrder = " ORDER BY B.DATE_SHOW_TO "; } elseif ($by == "s_dropdown") { $strSqlOrder = " ORDER BY B.CONTRACT_ID desc, B.ID "; } elseif ($by == "s_ctr") { $strSqlOrder = " ORDER BY CTR "; } elseif ($by == "s_date_create") { $strSqlOrder = " ORDER BY B.DATE_CREATE "; } elseif ($by == "s_date_modify") { $strSqlOrder = " ORDER BY B.DATE_MODIFY "; } else { $strSqlOrder = " ORDER BY B.ID "; $by = "s_id"; } if ($order != "asc") { $strSqlOrder .= " desc "; $order = "desc"; } $strSqlSearch = GetFilterSqlSearch($arSqlSearch); if ($isAdmin || $isDemo || $isManager) { $strSql = "\n\t\t\t\tSELECT DISTINCT\n\t\t\t\t\t{$lamp}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLAMP,\n\t\t\t\t\tB.*,\n\t\t\t\t\tB.FIRST_SITE_ID,\n\t\t\t\t\tB.FIRST_SITE_ID\t\t\t\t\t\t\t\t\t\t\t\t\t\tLID,\n\t\t\t\t\tif(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))\t\tCTR,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_LAST_SHOW") . "\t\t\t\t\t\tDATE_LAST_SHOW,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_LAST_CLICK") . "\t\t\t\t\tDATE_LAST_CLICK,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_SHOW_FROM", "SHORT") . "\t\t\tDATE_SHOW_FROM,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_SHOW_TO", "SHORT") . "\t\t\t\tDATE_SHOW_TO,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_SHOW_FIRST", "FULL") . "\t\t\tDATE_SHOW_FIRST,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_CREATE") . "\t\t\t\t\t\tDATE_CREATE,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_MODIFY") . "\t\t\t\t\t\tDATE_MODIFY,\n\t\t\t\t\tC.NAME\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tCONTRACT_NAME,\n\t\t\t\t\tT.NAME\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tTYPE_NAME\n\t\t\t\tFROM\n\t\t\t\t\tb_adv_banner B\n\t\t\t\tINNER JOIN b_adv_type T ON (T.SID = B.TYPE_SID)\n\t\t\t\tINNER JOIN b_adv_contract C ON (C.ID = B.CONTRACT_ID)\n\t\t\t\t{$left_join}\n\t\t\t\tWHERE\n\t\t\t\t{$strSqlSearch}\n\t\t\t\t{$strSqlOrder}\n\t\t\t\t"; } else { $strSql = "\n\t\t\t\tSELECT DISTINCT\n\t\t\t\t\t{$lamp}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLAMP,\n\t\t\t\t\tB.*,\n\t\t\t\t\tB.FIRST_SITE_ID,\n\t\t\t\t\tB.FIRST_SITE_ID\t\t\t\t\t\t\t\t\t\t\t\t\t\tLID,\n\t\t\t\t\tif(B.SHOW_COUNT<=0,0,round((B.CLICK_COUNT*100)/B.SHOW_COUNT,2))\t\tCTR,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_LAST_SHOW") . "\t\t\t\t\t\tDATE_LAST_SHOW,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_LAST_CLICK") . "\t\t\t\t\tDATE_LAST_CLICK,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_SHOW_FROM", "SHORT") . "\t\t\tDATE_SHOW_FROM,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_SHOW_TO", "SHORT") . "\t\t\t\tDATE_SHOW_TO,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_SHOW_FIRST", "FULL") . "\t\t\tDATE_SHOW_FIRST,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_CREATE") . "\t\t\t\t\t\tDATE_CREATE,\n\t\t\t\t\t" . $DB->DateToCharFunction("B.DATE_MODIFY") . "\t\t\t\t\t\tDATE_MODIFY,\n\t\t\t\t\tC.NAME\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tCONTRACT_NAME,\n\t\t\t\t\tT.NAME\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tTYPE_NAME\n\t\t\t\tFROM\n\t\t\t\t\tb_adv_banner B\n\t\t\t\tINNER JOIN b_adv_type T ON (T.SID = B.TYPE_SID)\n\t\t\t\tINNER JOIN b_adv_contract C ON (C.ID = B.CONTRACT_ID)\n\t\t\t\tINNER JOIN b_adv_contract_2_user CU ON (CU.CONTRACT_ID=C.ID and CU.USER_ID={$USER_ID})\n\t\t\t\t{$left_join}\n\t\t\t\tWHERE\n\t\t\t\t{$strSqlSearch}\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; }