static function GetPageWeights_RS()
{
$err_mess = (CAdvBanner::err_mess())."
Function: GetPageWeights_RS
Line: ";
global $APPLICATION, $DB, $USER;
$stat_adv_id = intval($_SESSION["SESS_LAST_ADV_ID"]);
$stat_country_id = trim($_SESSION["SESS_COUNTRY_ID"]);
$stat_city_id = intval($_SESSION["SESS_CITY_ID"]);
if($stat_city_id > 0 && CModule::IncludeModule('statistic'))
{
$rsCity = CCity::GetList(array(), array("=CITY_ID" => $stat_city_id));
if($arCity = $rsCity->Fetch())
$stat_region = $arCity["REGION_NAME"];
}
$new_guest = ($_SESSION["SESS_GUEST_NEW"]=="N") ? "N" : "Y";
$url = CAdvBanner::GetCurUri();
$arrTime = getdate();
$weekday = mb_strtoupper($arrTime["weekday"]);
$hour = intval($arrTime["hours"]);
$strUserGroups = $USER->GetUserGroupString();
$DONT_USE_CONTRACT = COption::GetOptionString("advertising", "DONT_USE_CONTRACT", "N");
if ($DONT_USE_CONTRACT == "N")
{
$strSql = "
SELECT DISTINCT
B.TYPE_SID,
B.ID BANNER_ID,
B.WEIGHT BANNER_WEIGHT,
B.SHOWS_FOR_VISITOR,
B.FIX_SHOW,
B.KEYWORDS BANNER_KEYWORDS,
".$DB->DateToCharFunction("B.DATE_SHOW_FIRST")." DATE_SHOW_FIRST,
".$DB->DateToCharFunction("B.DATE_SHOW_FROM")." DATE_SHOW_FROM,
".$DB->DateToCharFunction("B.DATE_SHOW_TO")." DATE_SHOW_TO,
B.FLYUNIFORM FLYUNIFORM,
B.MAX_SHOW_COUNT MAX_SHOW_COUNT,
B.SHOW_COUNT SHOW_COUNT,
C.ID CONTRACT_ID,
C.WEIGHT CONTRACT_WEIGHT,
C.KEYWORDS CONTRACT_KEYWORDS
FROM
b_adv_type T
INNER JOIN b_adv_banner B ON (
B.ACTIVE='Y'
and B.TYPE_SID = T.SID
and B.STATUS_SID = 'PUBLISHED'
and (B.FOR_NEW_GUEST is null or B.FOR_NEW_GUEST='$new_guest')
and (ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0) or ifnull(B.MAX_SHOW_COUNT,0)=0)
and (ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0) or ifnull(B.MAX_CLICK_COUNT,0)=0)
and (ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0) or ifnull(B.MAX_VISITOR_COUNT,0)=0)
and (B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_FROM is null or length(B.DATE_SHOW_FROM)<=0)
and (B.DATE_SHOW_TO>=now() or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0))
INNER JOIN b_adv_banner_2_site BS ON (
BS.BANNER_ID = B.ID
and BS.SITE_ID = '".SITE_ID."')
INNER JOIN b_adv_contract C ON (
C.ID = B.CONTRACT_ID
and C.ACTIVE='Y'
and (ifnull(C.MAX_SHOW_COUNT,0)>ifnull(C.SHOW_COUNT,0) or ifnull(C.MAX_SHOW_COUNT,0)=0)
and (ifnull(C.MAX_CLICK_COUNT,0)>ifnull(C.CLICK_COUNT,0) or ifnull(C.MAX_CLICK_COUNT,0)=0)
and (ifnull(C.MAX_VISITOR_COUNT,0)>ifnull(C.VISITOR_COUNT,0) or ifnull(C.MAX_VISITOR_COUNT,0)=0)
and (C.DATE_SHOW_FROM<=now() or C.DATE_SHOW_FROM is null or length(C.DATE_SHOW_FROM)<=0)
and (C.DATE_SHOW_TO>=now() or C.DATE_SHOW_TO is null or length(C.DATE_SHOW_TO)<=0))
INNER JOIN b_adv_contract_2_site CS ON (
CS.CONTRACT_ID = B.CONTRACT_ID
and CS.SITE_ID = '".SITE_ID."')
INNER JOIN b_adv_contract_2_type CT ON (
CT.CONTRACT_ID = C.ID
and (CT.TYPE_SID = 'ALL' or CT.TYPE_SID = T.SID))
INNER JOIN b_adv_banner_2_weekday BW ON (
BW.BANNER_ID = B.ID
and BW.C_WEEKDAY='".$DB->ForSql($weekday,10)."'
and BW.C_HOUR = '$hour')
INNER JOIN b_adv_contract_2_weekday CW ON (
CW.CONTRACT_ID = C.ID
and CW.C_WEEKDAY='".$DB->ForSql($weekday,10)."'
and CW.C_HOUR = '$hour')
LEFT JOIN b_adv_banner_2_group UG1 ON (
(UG1.BANNER_ID = B.ID
and UG1.GROUP_ID in (".$strUserGroups.") and UG1.GROUP_ID<>2)
)
LEFT JOIN b_adv_banner_2_page BP1 ON (
BP1.BANNER_ID = B.ID
and BP1.SHOW_ON_PAGE='Y')
LEFT JOIN b_adv_banner_2_page BP2 ON (
BP2.BANNER_ID = B.ID
and BP2.SHOW_ON_PAGE='N'
and '".$DB->ForSQL($url)."' like concat(BP2.PAGE, '%'))
LEFT JOIN b_adv_contract_2_page CP1 ON (
CP1.CONTRACT_ID = C.ID
and CP1.SHOW_ON_PAGE='Y')
LEFT JOIN b_adv_contract_2_page CP2 ON (
CP2.CONTRACT_ID = C.ID
and CP2.SHOW_ON_PAGE='N'
and '".$DB->ForSQL($url)."' like concat(CP2.PAGE, '%'))
LEFT JOIN b_adv_banner_2_stat_adv BA ON BA.BANNER_ID = B.ID
LEFT JOIN b_adv_banner_2_country BC ON BC.BANNER_ID = B.ID AND (
(
(B.STAT_TYPE is null OR length(B.STAT_TYPE)=0 OR B.STAT_TYPE='COUNTRY')
AND BC.COUNTRY_ID='".$DB->ForSql($stat_country_id,2)."'
) OR (
B.STAT_TYPE='REGION'
AND BC.COUNTRY_ID='".$DB->ForSql($stat_country_id,2)."'
AND BC.REGION='".$DB->ForSql($stat_region)."'
) OR (
B.STAT_TYPE='CITY'
AND BC.CITY_ID='".intval($stat_city_id)."'
)
)
WHERE
T.ACTIVE = 'Y'
and (
B.STAT_COUNT is null
or B.STAT_COUNT = 0
or BC.BANNER_ID is not null
)
and BP2.ID is null
and CP2.ID is null
and (BP1.ID is null or '".$DB->ForSQL($url)."' like concat(BP1.PAGE, '%'))
and (CP1.ID is null or '".$DB->ForSQL($url)."' like concat(CP1.PAGE, '%'))
and (BA.STAT_ADV_ID is null or BA.STAT_ADV_ID='".$stat_adv_id."')
and (BC.COUNTRY_ID is null or BC.COUNTRY_ID='".$DB->ForSql($stat_country_id,2)."')
and
(
(B.SHOW_USER_GROUP = 'Y' and UG1.GROUP_ID is not null)
or
(B.SHOW_USER_GROUP <> 'Y' and UG1.GROUP_ID is null)
)
ORDER BY B.TYPE_SID desc, C.ID desc
";
}
else
{
$strSql = "
SELECT DISTINCT
B.TYPE_SID,
B.ID BANNER_ID,
B.WEIGHT BANNER_WEIGHT,
B.SHOWS_FOR_VISITOR,
B.FIX_SHOW,
B.KEYWORDS BANNER_KEYWORDS
FROM
b_adv_type T
INNER JOIN b_adv_banner B ON (
B.ACTIVE='Y'
and B.TYPE_SID = T.SID
and B.STATUS_SID = 'PUBLISHED'
and (B.FOR_NEW_GUEST is null or B.FOR_NEW_GUEST='$new_guest')
and (ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0) or ifnull(B.MAX_SHOW_COUNT,0)=0)
and (ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0) or ifnull(B.MAX_CLICK_COUNT,0)=0)
and (ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0) or ifnull(B.MAX_VISITOR_COUNT,0)=0)
and (B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_FROM is null or length(B.DATE_SHOW_FROM)<=0)
and (B.DATE_SHOW_TO>=now() or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0))
INNER JOIN b_adv_banner_2_site BS ON (
BS.BANNER_ID = B.ID
and BS.SITE_ID = '".SITE_ID."')
INNER JOIN b_adv_banner_2_weekday BW ON (
BW.BANNER_ID = B.ID
and BW.C_WEEKDAY='".$DB->ForSql($weekday,10)."'
and BW.C_HOUR = '$hour')
LEFT JOIN b_adv_banner_2_group UG1 ON (
(UG1.BANNER_ID = B.ID
and UG1.GROUP_ID in (".$strUserGroups.") and UG1.GROUP_ID<>2)
)
LEFT JOIN b_adv_banner_2_page BP1 ON (
BP1.BANNER_ID = B.ID
and BP1.SHOW_ON_PAGE='Y')
LEFT JOIN b_adv_banner_2_page BP2 ON (
BP2.BANNER_ID = B.ID
and BP2.SHOW_ON_PAGE='N'
and '".$DB->ForSQL($url)."' like concat(BP2.PAGE, '%'))
LEFT JOIN b_adv_banner_2_stat_adv BA ON BA.BANNER_ID = B.ID
LEFT JOIN b_adv_banner_2_country BC ON BC.BANNER_ID = B.ID AND (
(
(B.STAT_TYPE is null OR length(B.STAT_TYPE)=0 OR B.STAT_TYPE='COUNTRY')
AND BC.COUNTRY_ID='".$DB->ForSql($stat_country_id,2)."'
) OR (
B.STAT_TYPE='REGION'
AND BC.COUNTRY_ID='".$DB->ForSql($stat_country_id,2)."'
AND BC.REGION='".$DB->ForSql($stat_region)."'
) OR (
B.STAT_TYPE='CITY'
AND BC.CITY_ID='".intval($stat_city_id)."'
)
)
WHERE
T.ACTIVE = 'Y'
and (
B.STAT_COUNT is null
or B.STAT_COUNT = 0
or BC.BANNER_ID is not null
)
and BP2.ID is null
and (BP1.ID is null or '".$DB->ForSQL($url)."' like concat(BP1.PAGE, '%'))
and (BA.STAT_ADV_ID is null or BA.STAT_ADV_ID='".$stat_adv_id."')
and (BC.COUNTRY_ID is null or BC.COUNTRY_ID='".$DB->ForSql($stat_country_id,2)."')
and
(
(B.SHOW_USER_GROUP = 'Y' and UG1.GROUP_ID is not null)
or
(B.SHOW_USER_GROUP <> 'Y' and UG1.GROUP_ID is null)
)
ORDER BY B.TYPE_SID desc";
}
$rs = $DB->Query($strSql, false, $err_mess.__LINE__);
return $rs;
}