9use \Bitrix\Main\Application;
27 "BANNERS_ALL" =>
array(),
28 "BANNERS_CNT" =>
array(),
29 "CONTRACTS_ALL" =>
array(),
30 "CONTRACTS_CNT" =>
array(),
43define(
"BANNER_UNIFORMITY_DIVERGENCE_COEF", 0.05);
54 return "<br>Module: ".$module_id.
"<br>Class: CAdvContract_all<br>File: ".__FILE__;
60 $arContract = $rsContracts->Fetch();
61 return intval($arContract[
"SORT"])+10;
103 public static function HaveRole($role, $USER_ID=
false)
107 if($USER_ID ===
false && is_object(
$USER))
108 $USER_ID =
$USER->GetID();
109 $USER_ID = intval($USER_ID);
113 if(is_object(
$USER) && $USER_ID ==
$USER->GetID())
114 $arrGroups =
$USER->GetUserGroupArray();
116 $arrGroups = CUser::GetUserGroup($USER_ID);
118 $arRoles =
$APPLICATION->GetUserRoles(
"advertising", $arrGroups);
119 if(in_array($role, $arRoles))
134 public static function IsAdmin($USER_ID=
false)
137 if ($USER_ID===
false && is_object(
$USER))
139 if (
$USER->IsAdmin())
return true;
146 public static function IsDemo($USER_ID=
false)
166 while(
$zr =
$z->Fetch())
169 if (in_array($role, $arRoles))
$arGroups[] = intval(
$zr[
"ID"]);
181 $rsUser = CUser::GetList(
"id",
"desc",
array(
"ACTIVE" =>
"Y",
"GROUPS_ID" =>
$arGroups));
182 while ($arUser = $rsUser->Fetch()) $arrRes[] = $arUser;
196 $rsUser = CUser::GetList(
"id",
"desc",
array(
"ACTIVE" =>
"Y",
"GROUPS_ID" =>
$arGroups));
197 while ($arUser = $rsUser->Fetch())
199 $arrEMail[] = $arUser[
"EMAIL"];
202 return array_unique($arrEMail);
232 return array(
"VIEW",
"ADD",
"EDIT");
236 public static function GetOwnerEmails($CONTRACT_ID, &$OWNER_EMAIL, &$ADD_EMAIL, &$VIEW_EMAIL, &$EDIT_EMAIL)
238 $OWNER_EMAIL =
array();
239 $VIEW_EMAIL =
array();
240 $ADD_EMAIL =
array();
241 $EDIT_EMAIL =
array();
249 $OWNER_EMAIL[] =
$ar[
"USER_EMAIL"];
250 if (
$perm==
"VIEW") $VIEW_EMAIL[] =
$ar[
"USER_EMAIL"];
251 if (
$perm==
"ADD") $ADD_EMAIL[] =
$ar[
"USER_EMAIL"];
252 if (
$perm==
"EDIT") $EDIT_EMAIL[] =
$ar[
"USER_EMAIL"];
256 $OWNER_EMAIL = array_unique($OWNER_EMAIL);
257 $VIEW_EMAIL = array_unique($VIEW_EMAIL);
258 $ADD_EMAIL = array_unique($ADD_EMAIL);
259 $EDIT_EMAIL = array_unique($EDIT_EMAIL);
267 static $CONTRACT_RIGHTS =
array();
268 $USER_ID = ($USER_ID===
false) ? intval(
$USER->GetID()) : intval($USER_ID);
269 if (intval($USER_ID)<=0)
return false;
270 $CONTRACT_ID = intval($CONTRACT_ID);
273 if ($CONTRACT_ID>0 &&
is_set($CONTRACT_RIGHTS[$USER_ID], $CONTRACT_ID))
275 $arrRes = $CONTRACT_RIGHTS[$USER_ID];
283 elseif ($isManager) $arrRes[0] =
array(
"VIEW",
"ADD");
284 else $arrRes[0] =
array();
288 $strSqlSearch =
" and C.ID= $CONTRACT_ID ";
295 LEFT JOIN b_adv_contract_2_user CU ON (CU.CONTRACT_ID=C.ID and CU.USER_ID=$USER_ID)
300 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
301 while (
$ar =
$rs->Fetch()) $arrRes[
$ar[
"ID"]][] =
$ar[
"PERMISSION"];
302 if ($isAdmin || $isManager)
304 foreach ($arrRes as $cid => $arrPerm)
311 $arrPerm = array_unique($arrPerm);
313 $arrRes[$cid] = $arrPerm;
317 foreach ($arrRes as $cid => $arrPerm)
320 $CONTRACT_RIGHTS[$USER_ID][$cid] = $arrPerm;
321 $arrRes[$cid] = $arrPerm;
330 public static function IsOwner($CONTRACT_ID, $USER_ID=
false)
332 $CONTRACT_ID = intval($CONTRACT_ID);
333 if ($CONTRACT_ID<=0)
return false;
335 $arrPERM = $arrPERM[$CONTRACT_ID];
336 if (is_array($arrPERM) &&
count($arrPERM)>0)
return true;
346 $CONTRACT_ID = intval($CONTRACT_ID);
347 if ($CONTRACT_ID<=0)
return false;
357 b_adv_contract_2_user CU,
360 CU.CONTRACT_ID = $CONTRACT_ID
361 and U.ID = CU.USER_ID
364 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
365 while (
$ar =
$rs->Fetch())
367 $arrPerm[
$ar[
"PERMISSION"]][] =
array(
368 "USER_ID" =>
$ar[
"USER_ID"],
369 "USER_LOGIN" =>
$ar[
"LOGIN"],
370 "USER_NAME" =>
$ar[
"NAME"],
371 "USER_LAST_NAME" =>
$ar[
"LAST_NAME"],
372 "USER_EMAIL" =>
$ar[
"EMAIL"]
385 $CONTRACT_ID = $arContract[
"ID"];
388 $OWNER_EMAIL =
array();
389 $ADD_EMAIL =
array();
390 $EDIT_EMAIL =
array();
394 $ADMIN_EMAIL = array_merge($MANAGER_EMAIL, $ADMIN_EMAIL);
395 $ADMIN_EMAIL = array_unique($ADMIN_EMAIL);
398 $EMAIL_TO = $OWNER_EMAIL;
399 if (
count($EMAIL_TO)<=0)
401 $EMAIL_TO = $ADMIN_EMAIL;
403 else $BCC = $ADMIN_EMAIL;
405 $CREATED_BY = $MODIFIED_BY =
"";
406 if (intval($arContract[
"CREATED_BY"])>0)
408 $rsUser = CUser::GetByID($arContract[
"CREATED_BY"]);
409 if ($arUser = $rsUser->Fetch())
411 $CREATED_BY =
"[".$arUser[
"ID"].
"] (".$arUser[
"LOGIN"].
") ".$arUser[
"NAME"].
" ".$arUser[
"LAST_NAME"];
414 if (intval($arContract[
"MODIFIED_BY"])==intval($arContract[
"CREATED_BY"]) && intval($arContract[
"CREATED_BY"])>0)
416 $MODIFIED_BY = $CREATED_BY;
418 elseif (intval($arContract[
"MODIFIED_BY"])>0)
420 $rsUser = CUser::GetByID($arContract[
"MODIFIED_BY"]);
421 if ($arUser = $rsUser->Fetch())
423 $MODIFIED_BY =
"[".$arUser[
"ID"].
"] (".$arUser[
"LOGIN"].
") ".$arUser[
"NAME"].
" ".$arUser[
"LAST_NAME"];
427 $mess =
"\n".$mess.
"\n";
429 if ($arContract[
"DESCRIPTION"] <>
'')
431 $arEventFields =
array(
432 "ID" => $CONTRACT_ID,
434 "EMAIL_TO" => implode(
",", $EMAIL_TO),
435 "ADMIN_EMAIL" => implode(
",", $ADMIN_EMAIL),
436 "ADD_EMAIL" => implode(
",", $ADD_EMAIL),
437 "STAT_EMAIL" => implode(
",", $VIEW_EMAIL),
438 "EDIT_EMAIL" => implode(
",", $EDIT_EMAIL),
439 "OWNER_EMAIL" => implode(
",", $OWNER_EMAIL),
440 "BCC" => implode(
",", $BCC),
441 "INDICATOR" =>
GetMessage(
"AD_".mb_strtoupper($arContract[
"LAMP"].
"_CONTRACT_STATUS")),
442 "ACTIVE" => $arContract[
"ACTIVE"],
443 "NAME" => $arContract[
"NAME"],
445 "MAX_SHOW_COUNT" => $arContract[
"MAX_SHOW_COUNT"],
446 "SHOW_COUNT" => $arContract[
"SHOW_COUNT"],
447 "MAX_CLICK_COUNT" => $arContract[
"MAX_CLICK_COUNT"],
448 "CLICK_COUNT" => $arContract[
"CLICK_COUNT"],
449 "BANNERS" => $arContract[
"BANNER_COUNT"],
450 "DATE_SHOW_FROM" => $arContract[
"DATE_SHOW_FROM"],
451 "DATE_SHOW_TO" => $arContract[
"DATE_SHOW_TO"],
452 "DATE_CREATE" => $arContract[
"DATE_CREATE"],
453 "CREATED_BY" => $CREATED_BY,
454 "DATE_MODIFY" => $arContract[
"DATE_MODIFY"],
455 "MODIFIED_BY" => $MODIFIED_BY
458 CEvent::Send(
"ADV_CONTRACT_INFO", $arrSITE, $arEventFields);
466 while ($arContract = $rsContracts->Fetch())
470 $DB->Update(
"b_adv_contract",
$arFields,
"WHERE ID='".$arContract[
"ID"].
"'",$err_mess.__LINE__);
472 return "CAdvContract::SendInfo();";
483 $find_date_modify_1 =
$arFilter[
"DATE_MODIFY_1"] ??
'';
484 $find_date_modify_2 =
$arFilter[
"DATE_MODIFY_2"] ??
'';
485 if (trim($find_date_modify_1) <>
'' || trim($find_date_modify_2) <>
'')
490 if (!$date1_stm && trim($find_date_modify_1) <>
'')
492 else $date_1_ok =
true;
493 if (!$date2_stm && trim($find_date_modify_2) <>
'')
495 elseif ($date_1_ok && $date2_stm <= $date1_stm && $date2_stm <>
'')
510 $CONTRACT_ID = intval($CONTRACT_ID);
511 if ($CONTRACT_ID<=0)
return false;
518 b_adv_contract_2_weekday
520 CONTRACT_ID = $CONTRACT_ID
522 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
523 while (
$ar =
$rs->Fetch())
525 $arrRes[
$ar[
"C_WEEKDAY"]][] =
$ar[
"C_HOUR"];
536 $CONTRACT_ID = intval($CONTRACT_ID);
547 b_adv_contract_2_type CT
548 INNER JOIN b_adv_type T ON (T.SID = CT.TYPE_SID or CT.TYPE_SID='ALL')
549 WHERE CT.CONTRACT_ID=".$CONTRACT_ID.
"
554 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
557 $arrRes[
$ar[
"SID"]] =
$ar[
"NAME"];
558 if(
$ar[
"TYPE_SID"] ==
'ALL')
559 $arrRes[
"ALL"] =
true;
569 $CONTRACT_ID = intval($CONTRACT_ID);
570 if ($CONTRACT_ID<=0)
return false;
576 b_adv_contract_2_site CS
578 CS.CONTRACT_ID = $CONTRACT_ID
581 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
582 while (
$ar =
$rs->Fetch()) $arrRes[] =
$ar[
"SITE_ID"];
591 $CONTRACT_ID = intval($CONTRACT_ID);
592 if ($CONTRACT_ID<=0)
return false;
594 $SHOW_ON_PAGE = ($SHOW==
"NOT_SHOW") ?
"'N'" :
"'Y'";
599 b_adv_contract_2_page
601 CONTRACT_ID = $CONTRACT_ID
602 and SHOW_ON_PAGE = $SHOW_ON_PAGE
604 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
605 while (
$ar =
$rs->Fetch()) $arrRes[] =
$ar[
"PAGE"];
610 public static function GetByID($CONTRACT_ID, $CHECK_RIGHTS=
"Y")
612 $CONTRACT_ID = intval($CONTRACT_ID);
613 if ($CONTRACT_ID<=0)
return false;
615 "ID" => $CONTRACT_ID,
616 "ID_EXACT_MATCH" =>
"Y"
628 if ($CHECK_RIGHTS==
"Y")
631 $arrPERM = $arrPERM[$CONTRACT_ID];
633 if ($CHECK_RIGHTS!=
"Y" || (is_array($arrPERM) && in_array(
"EDIT", $arrPERM)))
638 $str.=
GetMessage(
"AD_ERROR_WRONG_DATE_SHOW_FROM_CONTRACT").
"<br>";
643 $str .=
GetMessage(
"AD_ERROR_WRONG_DATE_SHOW_TO_CONTRACT").
"<br>";
649 $str .=
GetMessage(
"AD_ERROR_NOT_ENOUGH_PERMISSIONS_CONTRACT").
"<br>";
651 $str .=
GetMessage(
"AD_ERROR_NOT_ENOUGH_PERMISSIONS_FOR_NEW_CONTRACT").
"<br>";
668 if ($CHECK_RIGHTS==
"Y")
670 $USER_ID = intval(
$USER->GetID());
675 if (is_object(
$USER)) $USER_ID = intval(
$USER->GetID());
else $USER_ID = 0;
679 $check_activity =
"N";
680 $arFields_i =
array();
684 if (in_array(
"SHOW_COUNT", $arrKeys))
686 $check_activity =
"Y";
687 $arFields_i[
"SHOW_COUNT"] = intval(
$arFields[
"SHOW_COUNT"]);
690 if (in_array(
"VISITOR_COUNT", $arrKeys))
692 $check_activity =
"Y";
693 $arFields_i[
"VISITOR_COUNT"] = intval(
$arFields[
"VISITOR_COUNT"]);
696 if (in_array(
"CLICK_COUNT", $arrKeys))
698 $check_activity =
"Y";
699 $arFields_i[
"CLICK_COUNT"] = intval(
$arFields[
"CLICK_COUNT"]);
702 if (in_array(
"ACTIVE", $arrKeys) && (
$arFields[
"ACTIVE"]==
"Y" ||
$arFields[
"ACTIVE"]==
"N"))
704 $check_activity =
"Y";
705 $arFields_i[
"ACTIVE"] =
"'".$arFields[
"ACTIVE"].
"'";
708 if (in_array(
"WEIGHT", $arrKeys))
709 $arFields_i[
"WEIGHT"] = intval(
$arFields[
"WEIGHT"]);
711 if (in_array(
"ADMIN_COMMENTS", $arrKeys))
712 $arFields_i[
"ADMIN_COMMENTS"] =
"'".$DB->ForSql(
$arFields[
"ADMIN_COMMENTS"],2000).
"'";
714 if (in_array(
"KEYWORDS", $arrKeys))
715 $arFields_i[
"KEYWORDS"] =
"'".$DB->ForSql(
$arFields[
"KEYWORDS"], 2000).
"'";;
717 if (in_array(
"MAX_SHOW_COUNT", $arrKeys))
719 $check_activity =
"Y";
721 $arFields_i[
"MAX_SHOW_COUNT"] = intval(
$arFields[
"MAX_SHOW_COUNT"]);
723 $arFields_i[
"MAX_SHOW_COUNT"] =
"null";
726 if (in_array(
"MAX_VISITOR_COUNT", $arrKeys))
728 $check_activity =
"Y";
729 if (
$arFields[
"MAX_VISITOR_COUNT"] <>
'')
730 $arFields_i[
"MAX_VISITOR_COUNT"] = intval(
$arFields[
"MAX_VISITOR_COUNT"]);
732 $arFields_i[
"MAX_VISITOR_COUNT"] =
"null";
735 if (in_array(
"MAX_CLICK_COUNT", $arrKeys))
737 $check_activity =
"Y";
739 $arFields_i[
"MAX_CLICK_COUNT"] = intval(
$arFields[
"MAX_CLICK_COUNT"]);
741 $arFields_i[
"MAX_CLICK_COUNT"] =
"null";
744 if (in_array(
"DATE_SHOW_FROM", $arrKeys))
746 $check_activity =
"Y";
749 $arFields_i[
"DATE_SHOW_FROM"] =
$DB->CharToDateFunction(
$arFields[
"DATE_SHOW_FROM"]);
751 else $arFields_i[
"DATE_SHOW_FROM"] =
"null";
754 if (in_array(
"DATE_SHOW_TO", $arrKeys))
756 $check_activity =
"Y";
764 $arFields_i[
"DATE_SHOW_TO"] =
$DB->CharToDateFunction(
$arFields[
"DATE_SHOW_TO"].
$time);
768 $arFields_i[
"DATE_SHOW_TO"] =
"null";
772 if (in_array(
"DEFAULT_STATUS_SID", $arrKeys))
775 $arrV = array_values($arrStatus[
"reference_id"]);
776 if (in_array(
$arFields[
"DEFAULT_STATUS_SID"], $arrV))
778 $arFields_i[
"DEFAULT_STATUS_SID"] =
"'".$DB->ForSql(
$arFields[
"DEFAULT_STATUS_SID"],255).
"'";
782 if (in_array(
"SORT", $arrKeys))
783 $arFields_i[
"SORT"] = intval(
$arFields[
"SORT"]);
785 if (in_array(
"NAME", $arrKeys))
786 $arFields_i[
"NAME"] =
"'".$DB->ForSql(
$arFields[
"NAME"],255).
"'";
787 if (in_array(
"DESCRIPTION", $arrKeys))
788 $arFields_i[
"DESCRIPTION"] =
"'".$DB->ForSql(
$arFields[
"DESCRIPTION"],2000).
"'";
792 $arFields_i[
"EMAIL_COUNT"] = 0;
795 if (intval($CONTRACT_ID)>0)
798 $arContract = $rsContract->Fetch();
799 $str_PREV_LAMP = $arContract[
"LAMP"];
802 $arFields_i[
"DATE_MODIFY"] =
$DB->CharToDateFunction(
$arFields[
"DATE_MODIFY"]);
804 $arFields_i[
"DATE_MODIFY"] =
$DB->GetNowFunction();
806 if (in_array(
"MODIFIED_BY", $arrKeys))
807 $arFields_i[
"MODIFIED_BY"] = intval(
$arFields[
"MODIFIED_BY"]);
809 $arFields_i[
"MODIFIED_BY"] = $USER_ID;
811 $DB->Update(
"b_adv_contract",$arFields_i,
"WHERE ID='".intval($CONTRACT_ID).
"'",$err_mess.__LINE__);
815 $check_activity =
"Y";
818 $arFields_i[
"DATE_CREATE"] =
$DB->CharToDateFunction(
$arFields[
"DATE_CREATE"]);
820 $arFields_i[
"DATE_CREATE"] =
$DB->GetNowFunction();
822 if (in_array(
"CREATED_BY", $arrKeys))
823 $arFields_i[
"CREATED_BY"] = intval(
$arFields[
"CREATED_BY"]);
825 $arFields_i[
"CREATED_BY"] = $USER_ID;
828 $arFields_i[
"DATE_MODIFY"] =
$DB->CharToDateFunction(
$arFields[
"DATE_MODIFY"]);
830 $arFields_i[
"DATE_MODIFY"] =
$DB->GetNowFunction();
832 if (in_array(
"MODIFIED_BY", $arrKeys))
833 $arFields_i[
"MODIFIED_BY"] = intval(
$arFields[
"MODIFIED_BY"]);
835 $arFields_i[
"MODIFIED_BY"] = $USER_ID;
837 $CONTRACT_ID =
$DB->Insert(
"b_adv_contract",$arFields_i, $err_mess.__LINE__);
840 $CONTRACT_ID = intval($CONTRACT_ID);
846 if (in_array(
"arrSITE", $arrKeys))
851 $arrSite = array_unique(
$arFields[
"arrSITE"]);
852 foreach($arrSite as $sid)
854 if (trim($sid) <>
'')
856 $strSql =
"INSERT INTO b_adv_contract_2_site(CONTRACT_ID, SITE_ID) VALUES ($CONTRACT_ID, '".$DB->ForSql($sid, 2).
"')";
857 $DB->Query($strSql,
false, $err_mess.__LINE__);
863 if (in_array(
"arrSHOW_PAGE", $arrKeys))
868 $arrPage = array_unique(
$arFields[
"arrSHOW_PAGE"]);
869 foreach($arrPage as
$page)
875 "CONTRACT_ID" => $CONTRACT_ID,
876 "PAGE" =>
"'".
$DB->ForSql(
$page, 255).
"'",
877 "SHOW_ON_PAGE" =>
"'Y'"
879 $DB->Insert(
"b_adv_contract_2_page",$arFields_i, $err_mess.__LINE__);
885 if (in_array(
"arrNOT_SHOW_PAGE", $arrKeys))
888 if (is_array(
$arFields[
"arrNOT_SHOW_PAGE"]))
890 $arrPage = array_unique(
$arFields[
"arrNOT_SHOW_PAGE"]);
891 foreach($arrPage as
$page)
897 "CONTRACT_ID" => $CONTRACT_ID,
898 "PAGE" =>
"'".
$DB->ForSql(
$page, 255).
"'",
899 "SHOW_ON_PAGE" =>
"'N'"
901 $DB->Insert(
"b_adv_contract_2_page",$arFields_i, $err_mess.__LINE__);
907 if (in_array(
"arrTYPE", $arrKeys))
912 $arrType = array_unique(
$arFields[
"arrTYPE"]);
913 foreach($arrType as
$type)
915 if (trim(
$type) <>
'')
917 $strSql =
"INSERT INTO b_adv_contract_2_type(CONTRACT_ID, TYPE_SID) VALUES ($CONTRACT_ID, '".$DB->ForSql(
$type, 255).
"')";
918 $DB->Query($strSql,
false, $err_mess.__LINE__);
924 if (in_array(
"arrWEEKDAY", $arrKeys))
929 $arrWeekday = array_keys(
$arFields[
"arrWEEKDAY"]);
930 $arrWeekday = array_unique($arrWeekday);
931 if (is_array($arrWeekday) &&
count($arrWeekday)>0)
933 foreach ($arrWeekday as $weekday)
937 $arrHour =
$arFields[
"arrWEEKDAY"][$weekday];
944 $arrHour = array_unique($arrHour);
945 foreach($arrHour as $hour)
947 if ($hour>=0 && $hour<=23)
949 $strSql =
"INSERT INTO b_adv_contract_2_weekday (CONTRACT_ID, C_WEEKDAY, C_HOUR) VALUES (".$CONTRACT_ID.
", '".
$DB->ForSql($weekday, 10).
"', ".$hour.
")";
950 $DB->Query($strSql,
false, $err_mess.__LINE__);
960 if (in_array(
"arrUSER_VIEW", $arrKeys))
965 $arrUser = array_unique(
$arFields[
"arrUSER_VIEW"]);
966 foreach($arrUser as $user_id)
968 if (intval($user_id)>0)
971 "CONTRACT_ID" => $CONTRACT_ID,
972 "USER_ID" => intval($user_id),
973 "PERMISSION" =>
"'VIEW'"
975 $DB->Insert(
"b_adv_contract_2_user",$arFields_i, $err_mess.__LINE__);
981 if (in_array(
"arrUSER_ADD", $arrKeys))
986 $arrUser = array_unique(
$arFields[
"arrUSER_ADD"]);
987 foreach($arrUser as $user_id)
989 if (intval($user_id)>0)
992 "CONTRACT_ID" => $CONTRACT_ID,
993 "USER_ID" => intval($user_id),
994 "PERMISSION" =>
"'ADD'"
996 $DB->Insert(
"b_adv_contract_2_user",$arFields_i, $err_mess.__LINE__);
1004 if (in_array(
"arrUSER_EDIT", $arrKeys))
1007 if (is_array(
$arFields[
"arrUSER_EDIT"]))
1009 $arrUser = array_unique(
$arFields[
"arrUSER_EDIT"]);
1010 foreach($arrUser as $user_id)
1012 if (intval($user_id)>0)
1014 $arFields_i =
array(
1015 "CONTRACT_ID" => $CONTRACT_ID,
1016 "USER_ID" => intval($user_id),
1017 "PERMISSION" =>
"'EDIT'"
1019 $DB->Insert(
"b_adv_contract_2_user",$arFields_i, $err_mess.__LINE__);
1026 if ($check_activity==
"Y")
1028 CTimeZone::Disable();
1030 CTimeZone::Enable();
1032 $arContract = $rsContract->Fetch();
1033 $str_CURRENT_LAMP = $arContract[
"LAMP"];
1034 if ($str_PREV_LAMP!=$str_CURRENT_LAMP)
1036 $mess = ($str_CURRENT_LAMP==
"red") ?
"< ".
GetMessage(
"AD_CONTRACT_NOT_ACTIVE").
" >" :
"< ".GetMessage(
"AD_CONTRACT_ACTIVE").
" >";
1039 if ($str_CURRENT_LAMP==
"red")
1042 $DB->Update(
"b_adv_contract",
$arFields,
"WHERE ID='".$CONTRACT_ID.
"'",$err_mess.__LINE__);
1048 return $CONTRACT_ID;
1052 public static function Delete($CONTRACT_ID, $CHECK_RIGHTS=
"Y")
1056 $CONTRACT_ID = intval($CONTRACT_ID);
1057 if ($CONTRACT_ID<=1)
1062 $strSql =
"SELECT ID FROM b_adv_banner WHERE CONTRACT_ID = $CONTRACT_ID";
1063 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1072 $strSql =
"DELETE FROM b_adv_contract WHERE ID = $CONTRACT_ID";
1073 $DB->Query($strSql,
false, $err_mess.__LINE__);
1088 $CONTRACT_ID = intval($CONTRACT_ID);
1089 if ($CONTRACT_ID<=0)
1091 $strSql =
"DELETE FROM b_adv_contract_2_page WHERE CONTRACT_ID = $CONTRACT_ID ".$where;
1092 $DB->Query($strSql,
false, $err_mess.__LINE__);
1101 $CONTRACT_ID = intval($CONTRACT_ID);
1102 if ($CONTRACT_ID<=0)
1104 $strSql =
"DELETE FROM b_adv_contract_2_site WHERE CONTRACT_ID = $CONTRACT_ID";
1105 $DB->Query($strSql,
false, $err_mess.__LINE__);
1114 $CONTRACT_ID = intval($CONTRACT_ID);
1115 if ($CONTRACT_ID<=0)
1117 $strSql =
"DELETE FROM b_adv_contract_2_type WHERE CONTRACT_ID = $CONTRACT_ID";
1118 $DB->Query($strSql,
false, $err_mess.__LINE__);
1127 $CONTRACT_ID = intval($CONTRACT_ID);
1128 if ($CONTRACT_ID<=0)
1130 $strSql =
"DELETE FROM b_adv_contract_2_user WHERE CONTRACT_ID = $CONTRACT_ID ".$where;
1131 $DB->Query($strSql,
false, $err_mess.__LINE__);
1140 $CONTRACT_ID = intval($CONTRACT_ID);
1141 if ($CONTRACT_ID<=0)
1143 $strSql =
"DELETE FROM b_adv_contract_2_weekday WHERE CONTRACT_ID = $CONTRACT_ID";
1144 $DB->Query($strSql,
false, $err_mess.__LINE__);
1153 $arSqlSearch = Array();
1169 if( ((
string)
$val ==
'') || (
"$val"==
"NOT_REF") )
continue;
1175 $arSqlSearch[] =
"D.DATE_STAT>=".$DB->CharToDateFunction(
$val,
"SHORT");
1178 $arSqlSearch[] =
"D.DATE_STAT<=".$DB->CharToDateFunction(
$val.
" 23:59:59",
"FULL");
1188 $arSqlSearch[] = $where->_NumberIN(
"C.ID",
$arFilter[
'CONTRACT_ID']);
1195 if ($by ==
"s_date")
1197 $strSqlOrder =
" ORDER BY D.DATE_STAT ";
1199 elseif ($by ==
"s_visitors")
1201 $strSqlOrder =
" ORDER BY VISITOR_COUNT ";
1203 elseif ($by ==
"s_clicks")
1205 $strSqlOrder =
" ORDER BY CLICK_COUNT ";
1209 $strSqlOrder =
" ORDER BY CTR";
1213 $strSqlOrder =
" ORDER BY SHOW_COUNT ";
1217 $strSqlOrder =
" ORDER BY C.ID";
1221 $strSqlOrder =
" ORDER BY DATE_STAT";
1227 $strSqlOrder .=
" desc ";
1231 if ($by !=
"s_date")
1233 $strSqlOrder .=
', DATE_STAT ASC';
1240 ".$DB->DateToCharFunction(
"D.DATE_STAT",
"SHORT").
" DATE_STAT,
1241 SUM(D.SHOW_COUNT) SHOW_COUNT,
1242 SUM(D.CLICK_COUNT) CLICK_COUNT,
1243 SUM(D.VISITOR_COUNT) VISITOR_COUNT,
1246 b_adv_banner_2_day D
1247 INNER JOIN b_adv_banner B ON (D.BANNER_ID = B.ID)
1248 INNER JOIN b_adv_contract C ON (B.CONTRACT_ID = C.ID)
1259 ".$DB->DateToCharFunction(
"D.DATE_STAT",
"SHORT").
" DATE_STAT,
1260 SUM(D.SHOW_COUNT) SHOW_COUNT,
1261 SUM(D.CLICK_COUNT) CLICK_COUNT,
1262 SUM(D.VISITOR_COUNT) VISITOR_COUNT,
1264 C.NAME CONTRACT_NAME,
1267 b_adv_banner_2_day D
1268 INNER JOIN b_adv_banner B ON (D.BANNER_ID = B.ID)
1269 INNER JOIN b_adv_contract C ON (B.CONTRACT_ID = C.ID)
1272 GROUP by DATE_STAT, C.ID, C.NAME
1277 return $DB->Query($strSql,
false, $err_mess.__LINE__);
1290 return "<br>Module: ".$module_id.
"<br>Class: CAdvBanner_all<br>File: ".__FILE__;
1310 public static function GetByID($BANNER_ID, $CHECK_RIGHTS=
"Y")
1312 $BANNER_ID = intval($BANNER_ID);
1317 "ID_EXACT_MATCH" =>
"Y"
1324 public static function Copy($BANNER_ID, $CHECK_RIGHTS=
"Y")
1328 if ($arBanner = $rsBanner->Fetch())
1331 "CONTRACT_ID" => $arBanner[
"CONTRACT_ID"],
1332 "TYPE_SID" => $arBanner[
"TYPE_SID"],
1333 "STATUS_SID" => $arBanner[
"STATUS_SID"],
1334 "STATUS_COMMENTS" => $arBanner[
"STATUS_COMMENTS"],
1335 "NAME" => $arBanner[
"NAME"],
1336 "GROUP_SID" => $arBanner[
"GROUP_SID"],
1337 "ACTIVE" => $arBanner[
"ACTIVE"],
1338 "WEIGHT" => $arBanner[
"WEIGHT"],
1339 "MAX_VISITOR_COUNT" => $arBanner[
"MAX_VISITOR_COUNT"],
1340 "RESET_VISITOR_COUNT" =>
"Y",
1341 "SHOWS_FOR_VISITOR" => $arBanner[
"SHOWS_FOR_VISITOR"],
1342 "MAX_SHOW_COUNT" => $arBanner[
"MAX_SHOW_COUNT"],
1343 "RESET_SHOW_COUNT" =>
"Y",
1344 "MAX_CLICK_COUNT" => $arBanner[
"MAX_CLICK_COUNT"],
1345 "RESET_CLICK_COUNT" => $arBanner[
"RESET_CLICK_COUNT"],
1346 "DATE_SHOW_FROM" => $arBanner[
"DATE_SHOW_FROM"],
1347 "DATE_SHOW_TO" => $arBanner[
"DATE_SHOW_TO"],
1348 "IMAGE_ALT" => $arBanner[
"IMAGE_ALT"],
1349 "URL" => $arBanner[
"URL"],
1350 "URL_TARGET" => $arBanner[
"URL_TARGET"],
1351 "NO_URL_IN_FLASH" => $arBanner[
"NO_URL_IN_FLASH"],
1352 "CODE" => $arBanner[
"CODE"],
1353 "CODE_TYPE" => $arBanner[
"CODE_TYPE"],
1354 "FOR_NEW_GUEST" => $arBanner[
"FOR_NEW_GUEST"],
1355 "COMMENTS" => $arBanner[
"COMMENTS"],
1356 "SHOW_USER_GROUP" => $arBanner[
"SHOW_USER_GROUP"],
1359 "STAT_TYPE" => $arBanner[
"STAT_TYPE"],
1365 "KEYWORDS" => $arBanner[
"KEYWORDS"],
1366 "SEND_EMAIL" =>
"Y",
1367 "AD_TYPE" => $arBanner[
"AD_TYPE"],
1368 "FLASH_TRANSPARENT" => $arBanner[
"FLASH_TRANSPARENT"],
1369 "arrFlashIMAGE_ID" => $arBanner[
"arrFlashIMAGE_ID"],
1370 "FLASH_JS" => $arBanner[
"FLASH_JS"],
1371 "FLASH_VER" => $arBanner[
"FLASH_VER"],
1372 "TEMPLATE" => $arBanner[
"TEMPLATE"]
1374 if (intval($arBanner[
"IMAGE_ID"])>0)
1376 $arrIMAGE = CFile::MakeFileArray($arBanner[
"IMAGE_ID"]);
1377 $arrIMAGE[
"MODULE_ID"] =
"advertising";
1381 $arBanner[
"TEMPLATE_FILES"] = unserialize(
1382 htmlspecialchars_decode($arBanner[
"TEMPLATE_FILES"]),
1383 [
'allowed_classes' =>
false]
1386 $arBanner[
"TEMPLATE_FILES"] =
array();
1387 $arrTEMPLATE_FILES =
array();
1388 foreach ($arBanner[
"TEMPLATE_FILES"] as $k1 => $v1)
1390 foreach ($v1 as $k2 => $v2)
1392 $arrTEMPLATE_FILES[$k1][$k2] = CFile::MakeFileArray($v2);
1396 $arFields[
"TEMPLATE_FILES"] = $arrTEMPLATE_FILES;
1404 public static function Delete($BANNER_ID, $CHECK_RIGHTS=
"Y")
1408 $BANNER_ID = intval($BANNER_ID);
1412 $strSql =
"SELECT CONTRACT_ID, IMAGE_ID, TYPE_SID FROM b_adv_banner WHERE ID = '$BANNER_ID'";
1413 $rsBanner =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1414 if ($arBanner = $rsBanner->Fetch())
1417 if ($CHECK_RIGHTS==
"Y")
1420 $arrPERM = $arrPERM[$arBanner[
"CONTRACT_ID"]];
1421 if (in_array(
"ADD", $arrPERM))
1431 if (defined(
'BX_COMP_MANAGED_CACHE'))
1433 $taggedCache = Application::getInstance()->getTaggedCache();
1434 $taggedCache->clearByTag(
'advertising_banner_type_'.$arBanner[
'TYPE_SID']);
1437 CFile::Delete($arBanner[
"IMAGE_ID"]);
1445 $strSql =
"DELETE FROM b_adv_banner_2_day WHERE BANNER_ID = $BANNER_ID";
1446 $DB->Query($strSql,
false, $err_mess.__LINE__);
1448 $strSql =
"DELETE FROM b_adv_banner WHERE ID = $BANNER_ID";
1449 $DB->Query($strSql,
false, $err_mess.__LINE__);
1465 $BANNER_ID = intval($BANNER_ID);
1468 $strSql =
"DELETE FROM b_adv_banner_2_weekday WHERE BANNER_ID = $BANNER_ID";
1469 $DB->Query($strSql,
false, $err_mess.__LINE__);
1478 $BANNER_ID = intval($BANNER_ID);
1481 $strSql =
"DELETE FROM b_adv_banner_2_site WHERE BANNER_ID = $BANNER_ID";
1482 $DB->Query($strSql,
false, $err_mess.__LINE__);
1491 $BANNER_ID = intval($BANNER_ID);
1494 $strSql =
"DELETE FROM b_adv_banner_2_country WHERE BANNER_ID = $BANNER_ID";
1495 $DB->Query($strSql,
false, $err_mess.__LINE__);
1504 $BANNER_ID = intval($BANNER_ID);
1507 $strSql =
"DELETE FROM b_adv_banner_2_stat_adv WHERE BANNER_ID = $BANNER_ID";
1508 $DB->Query($strSql,
false, $err_mess.__LINE__);
1517 $BANNER_ID = intval($BANNER_ID);
1520 $strSql =
"DELETE FROM b_adv_banner_2_page WHERE BANNER_ID = $BANNER_ID ".$where;
1521 $DB->Query($strSql,
false, $err_mess.__LINE__);
1529 $BANNER_ID = intval($BANNER_ID);
1532 $strSql =
"DELETE FROM b_adv_banner_2_group WHERE BANNER_ID = $BANNER_ID";
1533 $DB->Query($strSql,
false, $err_mess.__LINE__);
1549 $arr =
array(
"reference_id" => $ref_id,
"reference" => $ref);
1558 $BANNER_ID = intval($BANNER_ID);
1562 $SHOW_ON_PAGE = ($SHOW==
"NOT_SHOW") ?
"'N'" :
"'Y'";
1569 BANNER_ID = $BANNER_ID
1570 and SHOW_ON_PAGE = $SHOW_ON_PAGE
1572 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1573 while (
$ar =
$rs->Fetch())
1574 $arrRes[] =
$ar[
"PAGE"];
1583 $BANNER_ID = intval($BANNER_ID);
1592 b_adv_banner_2_group
1594 BANNER_ID = $BANNER_ID
1596 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1597 while (
$ar =
$rs->Fetch())
1598 $arrRes[] =
$ar[
"GROUP_ID"];
1607 $BANNER_ID = intval($BANNER_ID);
1617 BANNER_ID = $BANNER_ID
1619 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1620 while (
$ar =
$rs->Fetch())
1621 $arrRes[] =
$ar[
"SITE_ID"];
1630 $BANNER_ID = intval($BANNER_ID);
1634 if(!is_array($WHAT))
1636 if($WHAT ===
"CITY")
1637 $arSelect =
array(
"COUNTRY_ID",
"REGION",
"CITY_ID");
1638 elseif($WHAT ===
"REGION")
1639 $arSelect =
array(
"COUNTRY_ID",
"REGION");
1641 $arSelect =
array(
"COUNTRY_ID");
1645 $arSelect =
array();
1646 foreach($WHAT as $FIELD)
1648 if($FIELD ===
"CITY_ID")
1649 $arSelect[$FIELD] = $FIELD;
1650 elseif($FIELD ===
"REGION")
1651 $arSelect[$FIELD] = $FIELD;
1652 elseif($FIELD ===
"COUNTRY_ID")
1653 $arSelect[$FIELD] = $FIELD;
1655 if(
count($arSelect) <= 0)
1656 $arSelect =
array(
"COUNTRY_ID");
1661 ".implode(
", ", $arSelect).
"
1663 b_adv_banner_2_country
1665 BANNER_ID = $BANNER_ID
1667 ".implode(
", ", $arSelect).
"
1669 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1670 while(
$ar =
$rs->Fetch())
1672 if($WHAT ===
"COUNTRY")
1673 $arrRes[] =
$ar[
"COUNTRY_ID"];
1685 $BANNER_ID = intval($BANNER_ID);
1694 b_adv_banner_2_weekday
1696 BANNER_ID = $BANNER_ID
1698 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1699 while (
$ar =
$rs->Fetch())
1700 $arrRes[
$ar[
"C_WEEKDAY"]][] =
$ar[
"C_HOUR"];
1709 $BANNER_ID = intval($BANNER_ID);
1717 b_adv_banner_2_stat_adv
1719 BANNER_ID = $BANNER_ID
1721 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
1722 while (
$ar =
$rs->Fetch())
1723 $arrRes[] =
$ar[
"STAT_ADV_ID"];
1731 $maxLongString = 65534;
1733 if ($CHECK_RIGHTS==
"Y")
1745 if (!in_array(
"CONTRACT_ID", $arrKeys) && $BANNER_ID>0)
1748 $arBanner = $rsBanner->Fetch();
1749 $CONTRACT_ID = intval($arBanner[
"CONTRACT_ID"]);
1753 $CONTRACT_ID = intval(
$arFields[
"CONTRACT_ID"]);
1756 if (in_array(
"TEMPLATE", $arrKeys))
1758 if (mb_strlen(
$arFields[
'TEMPLATE']) > $maxLongString)
1767 if ($isAdmin || $isManager)
1774 $arrPERM = $arrPERM[$CONTRACT_ID];
1775 if (in_array(
"ADD", $arrPERM))
1784 $str.=
GetMessage(
"AD_ERROR_WRONG_DATE_SHOW_FROM_BANNER").
"<br>";
1792 if (in_array(
"arrIMAGE_ID", $arrKeys))
1795 $arIMAGE[
"MODULE_ID"] =
"advertising";
1796 $strRes = CFile::CheckImageFile($arIMAGE, 0, 0, 0,
array(
"FLASH",
"IMAGE"));
1798 $str .= $strRes.
"<br>";
1801 if (in_array(
"arrFlashIMAGE_ID", $arrKeys))
1803 $arIMAGE =
$arFields[
"arrFlashIMAGE_ID"];
1804 $arIMAGE[
"MODULE_ID"] =
"advertising";
1805 $strRes = CFile::CheckImageFile($arIMAGE, 0, 0, 0,
array(
"IMAGE"));
1807 $str .= $strRes.
"<br>";
1810 if (in_array(
"TEMPLATE_FILES", $arrKeys) && is_array(
$arFields[
"TEMPLATE_FILES"]))
1812 foreach (
$arFields[
"TEMPLATE_FILES"] as $unit)
1814 if (is_array($unit))
1816 foreach ($unit as $file)
1818 $file[
"MODULE_ID"] =
"advertising";
1821 $str .= $strRes.
"<br>";
1829 if (
$arFields[
"DATE_SHOW_FROM"] ==
'' or
1836 if (intval(
$arFields[
"MAX_SHOW_COUNT"])<=0)
1837 $str .=
GetMessage(
"AD_ERROR_MAX_SHOW_COUNT_HAVETOBE_SET").
"<br>";
1843 $str .=
GetMessage(
"AD_ERROR_NOT_ENOUGH_PERMISSIONS_BANNER").
"<br>";
1845 $str .=
GetMessage(
"AD_ERROR_NOT_ENOUGH_PERMISSIONS_CONTRACT").
"<br>";
1860 public static function CheckFile($arFile, $iMaxSize=0, $iMaxWidth=0, $iMaxHeight=0, $access_typies=
array(), $bForceMD5=
false, $bSkipExt=
false)
1862 if ($arFile[
"name"] ==
"")
1867 if (preg_match(
"#^php://filter#i", $arFile[
"tmp_name"]))
1869 return GetMessage(
"FILE_BAD_FILE_TYPE").
".<br>";
1875 case "jpg":
case "jpeg":
case "gif":
case "bmp":
case "png": $file_type =
"IMAGE";
break;
1876 case "swf": $file_type =
"FLASH";
break;
1877 case "mp4":
case "webm":
case "ogg": $file_type =
"VIDEO";
break;
1878 default: $file_type =
"UNKNOWN";
1882 $flashEnabled =
false;
1883 if(!in_array($file_type, $access_typies))
1885 $file_type =
"IMAGE";
1888 if ($file_type ==
"FLASH")
1890 $flashEnabled =
true;
1891 static $flashMime =
array(
"application/x-shockwave-flash",
"application/vnd.adobe.flash.movie");
1892 $res = CFile::CheckFile($arFile, $iMaxSize, $flashMime, CFile::GetFlashExtensions(), $bForceMD5, $bSkipExt);
1894 else if ($file_type ==
"VIDEO")
1896 $res = CFile::CheckFile($arFile, $iMaxSize,
"video/",
"mp4,webm,ogg", $bForceMD5, $bSkipExt);
1900 $res = CFile::CheckFile($arFile, $iMaxSize,
"image/", CFile::GetImageExtensions(), $bForceMD5, $bSkipExt);
1908 if ($file_type ==
'IMAGE' || $file_type ==
"FLASH")
1910 $imgArray = CFile::GetImageSize($arFile[
"tmp_name"],
true, $flashEnabled);
1911 if(is_array($imgArray))
1913 $intWIDTH = $imgArray[0];
1914 $intHEIGHT = $imgArray[1];
1918 return GetMessage(
"FILE_BAD_FILE_TYPE").
".<br>";
1921 if($iMaxWidth > 0 && ($intWIDTH > $iMaxWidth || $intWIDTH == 0) || $iMaxHeight > 0 && ($intHEIGHT > $iMaxHeight || $intHEIGHT == 0))
1923 return GetMessage(
"FILE_BAD_MAX_RESOLUTION").
" (".$iMaxWidth.
" * ".$iMaxHeight.
" ".
GetMessage(
"main_include_dots").
").<br>";
1979 $result = CFile::MakeFileArray($file_id);
1995 if (preg_match(
"/^https?:\\/\\//", $file_path))
2002 $normPath =
$io->CombinePath(
"/", $file_path);
2003 $absPath =
$io->CombinePath(
$_SERVER[
"DOCUMENT_ROOT"], $normPath);
2004 if (
$io->ValidatePathString($absPath) &&
$io->FileExists($absPath))
2025 if (is_uploaded_file($file_array[
"tmp_name"]))
2032 $file_array[
"tmp_name"] <>
''
2033 && mb_strpos($file_array[
"tmp_name"], CTempFile::GetAbsoluteRoot()) === 0
2037 $absPath =
$io->CombinePath(
"/", $file_array[
"tmp_name"]);
2039 if (mb_strpos($absPath, $tmpPath) === 0 || (($absPath = ltrim($absPath,
"/")) && mb_strpos($absPath, $tmpPath) === 0))
2042 $result[
"tmp_name"] = $absPath;
2048 elseif ($file_array[
"tmp_name"] <>
'')
2051 $normPath =
$io->CombinePath(
"/", $file_array[
"tmp_name"]);
2052 $absPath =
$io->CombinePath(CTempFile::GetAbsoluteRoot(), $normPath);
2054 if (mb_strpos($absPath, $tmpPath) === 0 &&
$io->FileExists($absPath) ||
2055 ($absPath =
$io->CombinePath(
$_SERVER[
"DOCUMENT_ROOT"], $normPath)) && mb_strpos($absPath, $tmpPath) === 0)
2058 $result[
"tmp_name"] = $absPath;
2073 if ($file_array == $emptyFile)
2089 $BANNER_ID = intval($BANNER_ID);
2092 if ($CHECK_RIGHTS==
"Y")
2094 $USER_ID = intval(
$USER->GetID());
2097 $CHECK_CONTRACT_RIGHTS =
"Y";
2099 $CHECK_CONTRACT_RIGHTS =
"N";
2104 $isAdmin = $isManager =
true;
2105 $CHECK_CONTRACT_RIGHTS =
"N";
2108 if ($BANNER_ID <= 0)
2111 $events =
GetModuleEvents(
"advertising",
"OnBeforeBannerUpdate",
true);
2113 foreach ($events as $arEvent)
2118 $strError .= $err->GetString().
"<br />";
2126 $arFields_i =
array();
2129 $arBanner =
array();
2133 $arBanner = $rsBanner->Fetch();
2134 if (!in_array(
"CONTRACT_ID", $arrKeys))
2135 $CONTRACT_ID = intval($arBanner[
"CONTRACT_ID"]);
2137 $CONTRACT_ID = intval(
$arFields[
"CONTRACT_ID"]);
2141 $CONTRACT_ID = intval(
$arFields[
"CONTRACT_ID"]);
2144 $modify_status =
"N";
2148 if ($BANNER_ID<=0 && (!$isAdmin || !$isManager || in_array(
"STATUS_SID", $arrKeys)))
2149 $modify_status =
"Y";
2152 $arContract = $rsContract->Fetch();
2154 if (($isAdmin || $isManager) && in_array(
"RESET_VISITOR_COUNT", $arrKeys) &&
$arFields[
"RESET_VISITOR_COUNT"])
2156 $arFields_i[
"VISITOR_COUNT"] = 0;
2158 if (intval($arBanner[
"VISITOR_COUNT"])>0)
2161 $value = intval($arContract[
"VISITOR_COUNT"]) - intval($arBanner[
"VISITOR_COUNT"]);
2162 $value = ($value<0) ? 0 : $value;
2167 if (($isAdmin || $isManager) && in_array(
"RESET_SHOW_COUNT", $arrKeys) &&
$arFields[
"RESET_SHOW_COUNT"])
2169 $arFields_i[
"SHOW_COUNT"] = 0;
2171 if (intval($arBanner[
"SHOW_COUNT"])>0)
2174 $value = intval($arContract[
"SHOW_COUNT"]) - intval($arBanner[
"SHOW_COUNT"]);
2175 $value = ($value<0) ? 0 : $value;
2180 if (($isAdmin || $isManager) && in_array(
"FIX_SHOW", $arrKeys) && (
$arFields[
"FIX_SHOW"]==
"Y" ||
$arFields[
"FIX_SHOW"]==
"N"))
2181 $arFields_i[
"FIX_SHOW"] =
"'".$arFields[
"FIX_SHOW"].
"'";
2183 if (($isAdmin || $isManager) && in_array(
"FLYUNIFORM", $arrKeys) && (
$arFields[
"FLYUNIFORM"]==
"Y" ||
$arFields[
"FLYUNIFORM"]==
"N"))
2184 $arFields_i[
"FLYUNIFORM"] =
"'".$arFields[
"FLYUNIFORM"].
"'";
2186 if (($isAdmin || $isManager) && in_array(
"RESET_CLICK_COUNT", $arrKeys) &&
$arFields[
"RESET_CLICK_COUNT"])
2188 $arFields_i[
"CLICK_COUNT"] = 0;
2190 if (intval($arBanner[
"CLICK_COUNT"])>0)
2193 $value = intval($arContract[
"CLICK_COUNT"]) - intval($arBanner[
"CLICK_COUNT"]);
2194 $value = ($value<0) ? 0 : $value;
2199 if (($isAdmin || $isManager) && in_array(
"KEYWORDS", $arrKeys))
2200 $arFields_i[
"KEYWORDS"] =
"'".$DB->ForSql(
$arFields[
"KEYWORDS"], 2000).
"'";;
2202 if (in_array(
"CONTRACT_ID", $arrKeys) && intval(
$arFields[
"CONTRACT_ID"])>0)
2203 $arFields_i[
"CONTRACT_ID"] = intval(
$arFields[
"CONTRACT_ID"]);
2205 if (in_array(
"TYPE_SID", $arrKeys) &&
$arFields[
"TYPE_SID"] <>
'')
2207 $arFields_i[
"TYPE_SID"] =
"'".$DB->ForSql(
$arFields[
"TYPE_SID"],255).
"'";
2208 if (
"'".
$DB->ForSql($arBanner[
"TYPE_SID"],255).
"'"!=$arFields_i[
"TYPE_SID"])
2209 $modify_status =
"Y";
2212 if (in_array(
"NAME", $arrKeys))
2213 $arFields_i[
"NAME"] =
"'".$DB->ForSql(
$arFields[
"NAME"],255).
"'";
2215 if (in_array(
"GROUP_SID", $arrKeys))
2216 $arFields_i[
"GROUP_SID"] =
"'".$DB->ForSql(
$arFields[
"GROUP_SID"],255).
"'";
2218 if (in_array(
"ACTIVE", $arrKeys) && (
$arFields[
"ACTIVE"]==
"Y" ||
$arFields[
"ACTIVE"]==
"N"))
2219 $arFields_i[
"ACTIVE"] =
"'".$arFields[
"ACTIVE"].
"'";
2221 if (in_array(
"WEIGHT", $arrKeys))
2222 $arFields_i[
"WEIGHT"] = intval(
$arFields[
"WEIGHT"]);
2224 if (in_array(
"MAX_VISITOR_COUNT", $arrKeys))
2226 if (
$arFields[
"MAX_VISITOR_COUNT"] <>
'')
2227 $arFields_i[
"MAX_VISITOR_COUNT"] = intval(
$arFields[
"MAX_VISITOR_COUNT"]);
2229 $arFields_i[
"MAX_VISITOR_COUNT"] =
"null";
2232 if (in_array(
"SHOWS_FOR_VISITOR", $arrKeys))
2234 if (
$arFields[
"SHOWS_FOR_VISITOR"] <>
'')
2235 $arFields_i[
"SHOWS_FOR_VISITOR"] = intval(
$arFields[
"SHOWS_FOR_VISITOR"]);
2237 $arFields_i[
"SHOWS_FOR_VISITOR"] =
"null";
2240 if (in_array(
"MAX_SHOW_COUNT", $arrKeys))
2243 $arFields_i[
"MAX_SHOW_COUNT"] = intval(
$arFields[
"MAX_SHOW_COUNT"]);
2245 $arFields_i[
"MAX_SHOW_COUNT"] =
"null";
2248 if (in_array(
"MAX_CLICK_COUNT", $arrKeys))
2251 $arFields_i[
"MAX_CLICK_COUNT"] = intval(
$arFields[
"MAX_CLICK_COUNT"]);
2253 $arFields_i[
"MAX_CLICK_COUNT"] =
"null";
2256 if (in_array(
"DATE_SHOW_FROM", $arrKeys))
2259 $arFields_i[
"DATE_SHOW_FROM"] =
$DB->CharToDateFunction(
$arFields[
"DATE_SHOW_FROM"]);
2261 $arFields_i[
"DATE_SHOW_FROM"] =
"null";
2264 if (in_array(
"DATE_SHOW_TO", $arrKeys))
2271 $time =
" 23:59:59";
2273 $arFields_i[
"DATE_SHOW_TO"] =
$DB->CharToDateFunction(
$arFields[
"DATE_SHOW_TO"].
$time);
2277 $arFields_i[
"DATE_SHOW_TO"] =
"null";
2281 if (in_array(
"DATE_SHOW_FIRST", $arrKeys))
2282 $arFields_i[
"DATE_SHOW_FIRST"] =
"null";
2284 if (in_array(
"arrIMAGE_ID", $arrKeys) && is_array(
$arFields[
"arrIMAGE_ID"]))
2287 $arIMAGE[
"MODULE_ID"] =
"advertising";
2290 $z =
$DB->Query(
"SELECT IMAGE_ID FROM b_adv_banner WHERE ID='$BANNER_ID'",
false, $err_mess.__LINE__);
2292 $arIMAGE[
"old_file"] =
$zr[
"IMAGE_ID"];
2294 if ($arIMAGE[
"name"] <>
'' || $arIMAGE[
"del"] <>
'')
2296 $subdir = COption::GetOptionString(
"advertising",
"UPLOAD_SUBDIR");
2297 $fid = CFile::SaveFile($arIMAGE, $subdir);
2300 $arFields_i[
"IMAGE_ID"] = intval($fid);
2304 $arFields_i[
"IMAGE_ID"] =
"null";
2306 if (intval($arBanner[
"IMAGE_ID"])!=intval($arFields_i[
"IMAGE_ID"]))
2308 $modify_status =
"Y";
2313 if (in_array(
"TEMPLATE_FILES", $arrKeys) && is_array(
$arFields[
"TEMPLATE_FILES"]))
2317 $z =
$DB->Query(
"SELECT TEMPLATE_FILES FROM b_adv_banner WHERE ID='$BANNER_ID'",
false, $err_mess.__LINE__);
2320 $zr = unserialize(
$zr[
'TEMPLATE_FILES'], [
'allowed_classes' =>
false]);
2324 $subdir = COption::GetOptionString(
"advertising",
"UPLOAD_SUBDIR");
2325 $arTemplateFiles =
array();
2327 foreach (
$arFields[
"TEMPLATE_FILES"] as $tfk => $tfv)
2331 foreach($tfv as
$k => $arFile)
2333 $arFile[
"MODULE_ID"] =
"advertising";
2334 if(isset(
$zr[$arFile[
'lastKey']][
$k]))
2335 $arFile[
"old_file"] =
$zr[$arFile[
'lastKey']][
$k];
2337 if ($arFile[
"name"] <>
'' || $arFile[
"description"] <>
'' || isset($arFile[
"del"]) && $arFile[
"del"] <>
'')
2339 $fid = CFile::SaveFile($arFile, $subdir);
2341 if ($fid ===
false && $arFile[
"description"] <>
'' && $arFile[
"old_file"] <>
'')
2343 $arTemplateFiles[$cnt][
$k] = intval($arFile[
"old_file"]);
2349 $arTemplateFiles[$cnt][
$k] = intval($fid);
2353 $arTemplateFiles[$cnt][
$k] =
"null";
2355 if (intval(
$zr[$arFile[
'lastKey']][
$k]) != intval($arTemplateFiles[$cnt][
$k]))
2357 $modify_status =
"Y";
2362 $arTemplateFiles[$cnt][
$k] =
$zr[$arFile[
'lastKey']][
$k];
2368 $arFields_i[
"TEMPLATE_FILES"] =
"'".$DB->ForSql(serialize($arTemplateFiles),2000).
"'";
2371 if (in_array(
"IMAGE_ALT", $arrKeys))
2373 $arFields_i[
"IMAGE_ALT"] =
"'".$DB->ForSql(
$arFields[
"IMAGE_ALT"],255).
"'";
2374 if (
"'".
$DB->ForSql($arBanner[
"IMAGE_ALT"],255).
"'"!=$arFields_i[
"IMAGE_ALT"])
2376 $modify_status =
"Y";
2380 if (in_array(
"URL", $arrKeys))
2382 $arFields_i[
"URL"] =
"'".$DB->ForSql(
$arFields[
"URL"]).
"'";
2383 if (
"'".
$DB->ForSql($arBanner[
"URL"],2000).
"'" != $arFields_i[
"URL"])
2385 $modify_status =
"Y";
2389 if (in_array(
"URL_TARGET", $arrKeys))
2391 $arFields_i[
"URL_TARGET"] =
"'".$DB->ForSql(
$arFields[
"URL_TARGET"], 255).
"'";
2392 if (
"'".
$DB->ForSql($arBanner[
"URL_TARGET"], 255).
"'" != $arFields_i[
"URL_TARGET"])
2394 $modify_status =
"Y";
2398 if (in_array(
"NO_URL_IN_FLASH", $arrKeys) && (
$arFields[
"NO_URL_IN_FLASH"]==
"Y" ||
$arFields[
"NO_URL_IN_FLASH"]==
"N"))
2400 $arFields_i[
"NO_URL_IN_FLASH"] =
"'".$arFields[
"NO_URL_IN_FLASH"].
"'";
2401 if ($arBanner[
"NO_URL_IN_FLASH"]!=$arFields_i[
"NO_URL_IN_FLASH"])
2403 $modify_status =
"Y";
2407 if (in_array(
"CODE", $arrKeys))
2409 $arFields_i[
"CODE"] =
$arFields[
"CODE"];
2410 if ($arBanner[
"CODE"] != $arFields_i[
"CODE"])
2412 $modify_status =
"Y";
2416 if (in_array(
"FLASH_JS", $arrKeys) && (
$arFields[
"FLASH_JS"]==
"Y" ||
$arFields[
"FLASH_JS"]==
"N"))
2418 $arFields_i[
"FLASH_JS"] =
"'".$arFields[
"FLASH_JS"].
"'";
2419 if (
"'" . $arBanner[
"FLASH_JS"] .
"'" != $arFields_i[
"FLASH_JS"])
2421 $modify_status =
"Y";
2425 if (in_array(
"FLASH_VER", $arrKeys))
2427 $arFields_i[
"FLASH_VER"] =
"'".$DB->ForSQL(
$arFields[
"FLASH_VER"], 20).
"'";
2428 if (
"'".
$DB->ForSQL($arBanner[
"FLASH_VER"], 20).
"'" != $arFields_i[
"FLASH_VER"])
2430 $modify_status =
"Y";
2434 if (in_array(
"arrFlashIMAGE_ID", $arrKeys) && is_array(
$arFields[
"arrFlashIMAGE_ID"]))
2436 $arrFlashIMAGE =
$arFields[
"arrFlashIMAGE_ID"];
2437 $arrFlashIMAGE[
"MODULE_ID"] =
"advertising";
2440 $z =
$DB->Query(
"SELECT FLASH_IMAGE FROM b_adv_banner WHERE ID='$BANNER_ID'",
false, $err_mess.__LINE__);
2441 if(
$zr =
$z->Fetch())
2443 $arrFlashIMAGE[
"old_file"] =
$zr[
"FLASH_IMAGE"];
2446 if ($arrFlashIMAGE[
"name"] <>
'' || $arrFlashIMAGE[
"del"] <>
'')
2448 $subdir = COption::GetOptionString(
"advertising",
"UPLOAD_SUBDIR");
2449 $fid = CFile::SaveFile($arrFlashIMAGE, $subdir);
2450 if (intval($fid)>0) $arFields_i[
"FLASH_IMAGE"] = intval($fid);
2451 else $arFields_i[
"FLASH_IMAGE"] =
"null";
2452 if (intval($arBanner[
"FLASH_IMAGE"])!=intval($arFields_i[
"FLASH_IMAGE"]))
2454 $modify_status =
"Y";
2459 if (in_array(
"AD_TYPE", $arrKeys))
2461 $arFields_i[
"AD_TYPE"] =
"'".$DB->ForSql(
$arFields[
"AD_TYPE"],20).
"'";
2462 if (
"'".
$DB->ForSql($arBanner[
"AD_TYPE"], 20).
"'"!=$arFields_i[
"AD_TYPE"])
2464 $modify_status =
"Y";
2468 if (in_array(
"TEMPLATE", $arrKeys))
2473 if (in_array(
"FLASH_TRANSPARENT", $arrKeys))
2475 $arFields_i[
"FLASH_TRANSPARENT"] =
"'".$DB->ForSql(
$arFields[
"FLASH_TRANSPARENT"],11).
"'";
2476 if (
"'".
$DB->ForSql($arBanner[
"FLASH_TRANSPARENT"],11).
"'"!=$arFields_i[
"FLASH_TRANSPARENT"])
2478 $modify_status =
"Y";
2482 if (in_array(
"CODE_TYPE", $arrKeys))
2484 $arFields_i[
"CODE_TYPE"] = (
$arFields[
"CODE_TYPE"]==
"text") ?
"'text'" :
"'html'";
2485 $value = ($arBanner[
"CODE_TYPE"]==
"text") ?
"'text'" :
"'html'";
2486 if ($value!=$arFields_i[
"CODE_TYPE"])
2488 $modify_status =
"Y";
2492 if (in_array(
"FOR_NEW_GUEST", $arrKeys))
2496 $arFields_i[
"FOR_NEW_GUEST"] =
"'".$arFields[
"FOR_NEW_GUEST"].
"'";
2500 $arFields_i[
"FOR_NEW_GUEST"] =
"null";
2504 if (in_array(
"COMMENTS", $arrKeys))
2505 $arFields_i[
"COMMENTS"] =
"'".$DB->ForSql(
$arFields[
"COMMENTS"],2000).
"'";
2507 if (($isAdmin || $isManager) && in_array(
"STATUS_COMMENTS", $arrKeys))
2509 $arFields_i[
"STATUS_COMMENTS"] =
"'".$DB->ForSql(
$arFields[
"STATUS_COMMENTS"],2000).
"'";
2512 $email_notify =
"N";
2514 if ($modify_status==
"Y" || (in_array(
"STATUS_SID", $arrKeys) && ($isAdmin || $isManager)))
2516 $new_status = ($isAdmin || $isManager) ?
$arFields[
"STATUS_SID"] : $arContract[
"DEFAULT_STATUS_SID"];
2517 $arFields_i[
"STATUS_SID"] =
"'".$DB->ForSql($new_status,255).
"'";
2520 if (
"'".
$DB->ForSql($arBanner[
"STATUS_SID"],255).
"'"!=$arFields_i[
"STATUS_SID"])
2522 $email_notify =
"Y";
2526 if (in_array(
"arrSITE", $arrKeys))
2528 $arFields_i[
"FIRST_SITE_ID"] =
"''";
2531 $arrSITE = array_unique(
$arFields[
"arrSITE"]);
2534 $arFields_i[
"FIRST_SITE_ID"] =
"'".$DB->ForSql(
$site_id,2).
"'";
2538 if (in_array(
"SHOW_USER_GROUP", $arrKeys))
2540 if(
$arFields[
"SHOW_USER_GROUP"] ==
"Y" && (in_array(
"arrUSERGROUP", $arrKeys) &&
count(
$arFields[
"arrUSERGROUP"])>0))
2541 $SHOW_USER_GROUP =
"Y";
2543 $SHOW_USER_GROUP =
"N";
2544 $arFields_i[
"SHOW_USER_GROUP"] =
"'".$DB->ForSql($SHOW_USER_GROUP,1).
"'";
2547 if (in_array(
"STAT_TYPE", $arrKeys))
2550 $arFields_i[
"STAT_TYPE"] =
"'CITY'";
2552 $arFields_i[
"STAT_TYPE"] =
"'REGION'";
2554 $arFields_i[
"STAT_TYPE"] =
"'COUNTRY'";
2557 if (intval($BANNER_ID)>0)
2560 $arFields_i[
"DATE_MODIFY"] =
$DB->CharToDateFunction(
$arFields[
"DATE_MODIFY"]);
2562 $arFields_i[
"DATE_MODIFY"] =
$DB->GetNowFunction();
2564 if (in_array(
"MODIFIED_BY", $arrKeys))
2565 $arFields_i[
"MODIFIED_BY"] = intval(
$arFields[
"MODIFIED_BY"]);
2567 $arFields_i[
"MODIFIED_BY"] = $USER_ID;
2574 $arFields_i[
"DATE_CREATE"] =
$DB->CharToDateFunction(
$arFields[
"DATE_CREATE"]);
2576 $arFields_i[
"DATE_CREATE"] =
$DB->GetNowFunction();
2578 if (in_array(
"CREATED_BY", $arrKeys)) $arFields_i[
"CREATED_BY"] = intval(
$arFields[
"CREATED_BY"]);
2579 else $arFields_i[
"CREATED_BY"] = $USER_ID;
2582 $arFields_i[
"DATE_MODIFY"] =
$DB->CharToDateFunction(
$arFields[
"DATE_MODIFY"]);
2584 $arFields_i[
"DATE_MODIFY"] =
$DB->GetNowFunction();
2586 if (in_array(
"MODIFIED_BY", $arrKeys))
2587 $arFields_i[
"MODIFIED_BY"] = intval(
$arFields[
"MODIFIED_BY"]);
2589 $arFields_i[
"MODIFIED_BY"] = $USER_ID;
2594 if (defined(
'BX_COMP_MANAGED_CACHE'))
2596 $taggedCache = Application::getInstance()->getTaggedCache();
2597 $taggedCache->clearByTag(
'advertising_banner_type_'.
$arFields[
'TYPE_SID']);
2600 $BANNER_ID = intval($BANNER_ID);
2604 if (in_array(
"arrSITE", $arrKeys))
2609 $arrSITE = array_unique(
$arFields[
"arrSITE"]);
2611 foreach($arrSITE as $sid)
2613 if (trim($sid) <>
'')
2615 $strSql =
"INSERT INTO b_adv_banner_2_site (BANNER_ID, SITE_ID) VALUES ($BANNER_ID, '".$DB->ForSql($sid, 2).
"')";
2616 $DB->Query($strSql,
false, $err_mess.__LINE__);
2622 if (in_array(
"arrSHOW_PAGE", $arrKeys))
2625 if (is_array(
$arFields[
"arrSHOW_PAGE"]))
2627 $arrPage = array_unique(
$arFields[
"arrSHOW_PAGE"]);
2628 foreach($arrPage as
$page)
2633 $arFields_i =
array(
2634 "BANNER_ID" => $BANNER_ID,
2635 "PAGE" =>
"'".
$DB->ForSql(
$page, 255).
"'",
2636 "SHOW_ON_PAGE" =>
"'Y'"
2638 $DB->Insert(
"b_adv_banner_2_page",$arFields_i, $err_mess.__LINE__);
2644 if (in_array(
"arrNOT_SHOW_PAGE", $arrKeys))
2647 if (is_array(
$arFields[
"arrNOT_SHOW_PAGE"]))
2649 $arrPage = array_unique(
$arFields[
"arrNOT_SHOW_PAGE"]);
2650 foreach($arrPage as
$page)
2655 $arFields_i =
array(
2656 "BANNER_ID" => $BANNER_ID,
2657 "PAGE" =>
"'".
$DB->ForSql(
$page, 255).
"'",
2658 "SHOW_ON_PAGE" =>
"'N'"
2660 $DB->Insert(
"b_adv_banner_2_page",$arFields_i, $err_mess.__LINE__);
2666 if (in_array(
"arrCOUNTRY", $arrKeys))
2672 $arrCOUNTRY =
array();
2673 foreach(
$arFields[
"arrCOUNTRY"] as $COUNTRY)
2675 if(is_array($COUNTRY))
2677 $COUNTRY[
"COUNTRY_ID"] = trim($COUNTRY[
"COUNTRY_ID"]);
2678 if($COUNTRY[
"COUNTRY_ID"] ==
'')
2680 $key = $COUNTRY[
"COUNTRY_ID"].
"|".$COUNTRY[
"REGION"].
"|".$COUNTRY[
"CITY_ID"];
2681 $strInsert =
"'".$DB->ForSQL($COUNTRY[
"COUNTRY_ID"], 2).
"', ".($COUNTRY[
"REGION"] ==
''?
"null":
"'".$DB->ForSQL($COUNTRY[
"REGION"], 200).
"'").
", ".(intval($COUNTRY[
"CITY_ID"]) <= 0?
"null": intval($COUNTRY[
"CITY_ID"])).
"";
2685 $COUNTRY = trim($COUNTRY);
2688 $key = $COUNTRY.
"||";
2689 $strInsert =
"'".$DB->ForSQL($COUNTRY, 2).
"', null, null";
2691 $arrCOUNTRY[
$key] = $strInsert;
2693 foreach($arrCOUNTRY as $strInsert)
2695 $strSql =
"INSERT INTO b_adv_banner_2_country (BANNER_ID, COUNTRY_ID, REGION, CITY_ID) VALUES ($BANNER_ID, ".$strInsert.
")";
2696 $DB->Query($strSql,
false, $err_mess.__LINE__);
2700 $DB->Query(
"UPDATE b_adv_banner SET STAT_COUNT = ".$iCounter.
" WHERE ID = ".$BANNER_ID);
2703 if (in_array(
"arrSTAT_ADV", $arrKeys))
2708 $arrSTAT_ADV = array_unique(
$arFields[
"arrSTAT_ADV"]);
2709 foreach($arrSTAT_ADV as $aid)
2713 $strSql =
"INSERT INTO b_adv_banner_2_stat_adv (BANNER_ID, STAT_ADV_ID) VALUES ($BANNER_ID, '".intval($aid).
"')";
2714 $DB->Query($strSql,
false, $err_mess.__LINE__);
2720 if (in_array(
"arrWEEKDAY", $arrKeys))
2725 $arrWeekday = array_keys(
$arFields[
"arrWEEKDAY"]);
2726 $arrWeekday = array_unique($arrWeekday);
2727 if (is_array($arrWeekday) &&
count($arrWeekday)>0)
2729 foreach ($arrWeekday as $weekday)
2733 $arrHour =
$arFields[
"arrWEEKDAY"][$weekday];
2740 $arrHour = array_unique($arrHour);
2741 foreach($arrHour as $hour)
2743 if ($hour>=0 && $hour<=23)
2745 $strSql =
"INSERT INTO b_adv_banner_2_weekday (BANNER_ID, C_WEEKDAY, C_HOUR) VALUES ($BANNER_ID, '".$DB->ForSql($weekday, 10).
"', $hour)";
2746 $DB->Query($strSql,
false, $err_mess.__LINE__);
2755 if (in_array(
"arrUSERGROUP", $arrKeys))
2758 if (is_array(
$arFields[
"arrUSERGROUP"]))
2760 $arrGROUPS = array_unique(
$arFields[
"arrUSERGROUP"]);
2761 foreach($arrGROUPS as
$uid)
2765 $strSql =
"INSERT INTO b_adv_banner_2_group (BANNER_ID, GROUP_ID) VALUES ($BANNER_ID, ".intval(
$uid).
")";
2766 $DB->Query($strSql,
false, $err_mess.__LINE__);
2773 $SEND_EMAIL =
$arFields[
"SEND_EMAIL"] ==
"N" ?
"N" :
"Y";
2774 if ($email_notify ==
"Y" && (!$isAdmin || !$isManager || $SEND_EMAIL ==
"Y"))
2777 CTimeZone::Disable();
2779 CTimeZone::Enable();
2781 if ($arBanner=$rsBanner->Fetch())
2784 $OWNER_EMAIL =
array();
2785 $ADD_EMAIL =
array();
2786 $STAT_EMAIL =
array();
2787 $EDIT_EMAIL =
array();
2791 $ADMIN_EMAIL = array_merge($MANAGER_EMAIL, $ADMIN_EMAIL);
2792 $ADMIN_EMAIL = array_unique($ADMIN_EMAIL);
2795 $CREATED_BY = $MODIFIED_BY = 0;
2796 if (intval($arBanner[
"CREATED_BY"])>0)
2798 $rsUser = CUser::GetByID($arBanner[
"CREATED_BY"]);
2799 if ($arUser = $rsUser->Fetch())
2801 $CREATED_BY =
"[".$arUser[
"ID"].
"] (".$arUser[
"LOGIN"].
") ".$arUser[
"NAME"].
" ".$arUser[
"LAST_NAME"];
2804 if (intval($arBanner[
"MODIFIED_BY"])==intval($arBanner[
"CREATED_BY"]) && intval($arBanner[
"CREATED_BY"])>0)
2806 $MODIFIED_BY = $CREATED_BY;
2808 elseif (intval($arBanner[
"MODIFIED_BY"])>0)
2810 $rsUser = CUser::GetByID($arBanner[
"MODIFIED_BY"]);
2811 if ($arUser = $rsUser->Fetch())
2813 $MODIFIED_BY =
"[".$arUser[
"ID"].
"] (".$arUser[
"LOGIN"].
") ".$arUser[
"NAME"].
" ".$arUser[
"LAST_NAME"];
2817 $arImage = CFile::GetFileArray($arBanner[
"IMAGE_ID"]);
2823 $arImage = CFile::GetFileArray($arBanner[
"FLASH_IMAGE"]);
2827 $FLASHIMAGE_LINK =
"";
2829 $EMAIL_TO = $OWNER_EMAIL;
2830 if (
count($EMAIL_TO)<=0)
2832 $EMAIL_TO = $ADMIN_EMAIL;
2834 else $BCC = $ADMIN_EMAIL;
2836 $arEventFields =
array(
2837 "ID" => $arBanner[
"ID"],
2838 "EMAIL_TO" => implode(
",", $EMAIL_TO),
2839 "ADMIN_EMAIL" => implode(
",", $ADMIN_EMAIL),
2840 "ADD_EMAIL" => implode(
",", $ADD_EMAIL),
2841 "STAT_EMAIL" => implode(
",", $STAT_EMAIL),
2842 "EDIT_EMAIL" => implode(
",", $EDIT_EMAIL),
2843 "OWNER_EMAIL" => implode(
",", $OWNER_EMAIL),
2844 "BCC" => implode(
",", $BCC),
2845 "CONTRACT_ID" => $CONTRACT_ID,
2846 "CONTRACT_NAME" => $arContract[
"NAME"],
2847 "TYPE_SID" => $arBanner[
"TYPE_SID"],
2848 "TYPE_NAME" => $arBanner[
"TYPE_NAME"],
2849 "STATUS" => ( ( $arBanner[
"STATUS_SID"] <>
'' ) ?
GetMessage(
"AD_STATUS_" . $arBanner[
"STATUS_SID"] ) :
"" ),
2850 "STATUS_COMMENTS" => $arBanner[
"STATUS_COMMENTS"],
2851 "NAME" => $arBanner[
"NAME"],
2852 "GROUP_SID" => $arBanner[
"GROUP_SID"],
2853 "INDICATOR" =>
GetMessage(
"AD_".mb_strtoupper($arBanner[
"LAMP"]).
"_BANNER_STATUS"),
2854 "ACTIVE" => $arBanner[
"ACTIVE"],
2855 "MAX_SHOW_COUNT" => $arBanner[
"MAX_SHOW_COUNT"],
2856 "SHOW_COUNT" => $arBanner[
"SHOW_COUNT"],
2857 "MAX_CLICK_COUNT" => $arBanner[
"MAX_CLICK_COUNT"],
2858 "CLICK_COUNT" => $arBanner[
"CLICK_COUNT"],
2859 "DATE_LAST_SHOW" => $arBanner[
"DATE_LAST_SHOW"],
2860 "DATE_LAST_CLICK" => $arBanner[
"DATE_LAST_CLICK"],
2861 "DATE_SHOW_FROM" => $arBanner[
"DATE_SHOW_FROM"],
2862 "DATE_SHOW_TO" => $arBanner[
"DATE_SHOW_TO"],
2863 "IMAGE_LINK" => $IMAGE_LINK,
2864 "IMAGE_ALT" => $arBanner[
"IMAGE_ALT"],
2865 "URL" => $arBanner[
"URL"],
2866 "URL_TARGET" => $arBanner[
"URL_TARGET"],
2867 "NO_URL_IN_FLASH" => $arBanner[
"NO_URL_IN_FLASH"],
2868 "CODE" => $arBanner[
"CODE"],
2869 "CODE_TYPE" => $arBanner[
"CODE_TYPE"],
2870 "COMMENTS" => $arBanner[
"COMMENTS"],
2871 "DATE_CREATE" => $arBanner[
"DATE_CREATE"],
2872 "CREATED_BY" => $CREATED_BY,
2873 "DATE_MODIFY" => $arBanner[
"DATE_MODIFY"],
2874 "MODIFIED_BY" => $MODIFIED_BY,
2875 "AD_TYPE" => $arBanner[
"AD_TYPE"],
2876 "TEMPLATE" => unserialize($arBanner[
"TEMPLATE"], [
'allowed_classes' =>
false]),
2877 "FLASH_TRANSPARENT" => $arBanner[
"FLASH_TRANSPARENT"],
2878 "FLASH_IMAGE_LINK" => $FLASHIMAGE_LINK,
2879 "FLASH_JS" => $arBanner[
"FLASH_JS"],
2880 "FLASH_VER" => $arBanner[
"FLASH_VER"],
2883 CEvent::Send(
"ADV_BANNER_STATUS_CHANGE", $arrSITE, $arEventFields);
2892 public static function SetKeywords($keywords, $TYPE_SID=
"", $LOGIC=
"DESIRED")
2895 if ($LOGIC ==
'')
return;
2896 if ($TYPE_SID ==
'') $TYPE_SID =
"";
2897 $arrKeywords =
array();
2898 if (is_array($keywords) &&
count($keywords)>0)
2900 foreach($keywords as $word)
2902 if (is_array($word))
2904 $exact_match = $word[
"EXACT_MATCH"]==
"Y" ?
"Y" :
"N";
2905 $value = $word[
"KEYWORD"];
2912 $arrKeywords[$exact_match][] = trim($value);
2917 $arrWords = explode(
",",$keywords);
2918 if (is_array($arrWords) &&
count($arrWords)>0)
2920 foreach($arrWords as $word)
2922 if (trim($word) <>
'')
2923 $arrKeywords[
"N"][] = trim($word);
2929 foreach (
$arr as $exact_match)
2931 $arrWords = is_array($arrKeywords[$exact_match]) ? array_unique($arrKeywords[$exact_match]) :
array();
2932 if (
count($arrWords)>0)
2935 if (is_array($arrTemp) &&
count($arrTemp)>0)
2937 $arrTemp = array_merge($arrWords, $arrTemp);
2938 $arrTemp = array_unique($arrTemp);
2946 public static function GetKeywords($TYPE_SID=
"", $LOGIC=
"", $EXACT_MATCH=
"")
2959 $keywords =
$APPLICATION->GetProperty(
"adv_desired_target_keywords");
2960 if($keywords ===
false)
2962 $arrWords = explode(
",", $keywords);
2964 $arrKeywords =
array();
2965 foreach($arrWords as $word)
2967 $word = trim($word);
2969 $arrKeywords[] = $word;
2972 if(
count($arrKeywords) > 0)
2973 $arrReturn[$TYPE_SID][
"DESIRED"][
"N"] = $arrKeywords;
2980 if($EXACT_MATCH <>
'')
2981 return $arrReturn[$TYPE_SID][$LOGIC][$EXACT_MATCH];
2983 return $arrReturn[$TYPE_SID][$LOGIC];
2987 return $arrReturn[$TYPE_SID];
2999 if ($TYPE_SID <>
'')
3033 if (
$a[
"val"] < $b[
"val"])
3047 static $arrWeightSum =
false;
3049 $TYPE_SID = trim($TYPE_SID);
3050 if ($TYPE_SID ==
'')
3055 $DONT_USE_CONTRACT = COption::GetOptionString(
"advertising",
"DONT_USE_CONTRACT",
"N");
3057 if ($arrWeightSum ===
false)
3060 $arrWeightSum =
array();
3062 $arrCookie_counter =
array();
3068 $arrCookie_counter[$banner_id] =
$arr[
"COUNTER"];
3080 $banner_id = intval(
$ar[1]);
3082 $arrCookie_counter[$banner_id] =
$counter;
3087 $arrWeightSum_RequiredKeywords =
array();
3088 $arrWeightSum_DesiredKeywords =
array();
3089 $arrWeightSum_EmptyKeywords =
array();
3090 $arrWeightSum_all =
array();
3091 $arKeywordsSet =
array();
3093 $arrRequiredKeywordsBanners =
array();
3094 $arrDesiredKeywordsBanners =
array();
3095 $arrEmptyKeywordsBanners =
array();
3098 $arrDesiredPageKeywords_all = is_array($arrPAGE_KEYWORDS[
""][
"DESIRED"]) ? $arrPAGE_KEYWORDS[
""][
"DESIRED"] :
array();
3099 $arrRequiredPageKeywords_all = is_array($arrPAGE_KEYWORDS[
""][
"REQUIRED"]) ? $arrPAGE_KEYWORDS[
""][
"REQUIRED"] :
array();
3105 if (isset(
$ar[
"FLYUNIFORM"]) and
$ar[
"FLYUNIFORM"] ==
"Y")
3112 $arKeywordsSet[
$ar[
"TYPE_SID"]] =
"N";
3114 if ((intval(
$ar[
"SHOWS_FOR_VISITOR"])>0 && intval($arrCookie_counter[
$ar[
"BANNER_ID"]])<intval(
$ar[
"SHOWS_FOR_VISITOR"])) || intval(
$ar[
"SHOWS_FOR_VISITOR"])<=0)
3116 $arr = $arrPAGE_KEYWORDS[
$ar[
"TYPE_SID"]][
"DESIRED"];
3119 $arr = $arrPAGE_KEYWORDS[
$ar[
"TYPE_SID"]][
"REQUIRED"];
3122 if (
count($arrRequiredPageKeywords)>0 ||
3123 count($arrRequiredPageKeywords_all)>0 ||
3124 count($arrDesiredPageKeywords)>0 ||
3125 count($arrDesiredPageKeywords_all)>0
3128 $arKeywordsSet[
$ar[
"TYPE_SID"]] =
"Y";
3131 $arrBannerKeywords = preg_split(
'/[\n\r]+/',
$ar[
"BANNER_KEYWORDS"]);
3132 if (is_array($arrBannerKeywords))
3137 if ($DONT_USE_CONTRACT <>
"Y" &&
$ar[
"CONTRACT_KEYWORDS"] <>
'')
3139 $arrContractKeywords = preg_split(
'/[\n\r]+/',
$ar[
"CONTRACT_KEYWORDS"]);
3140 if (is_array($arrContractKeywords))
3142 TrimArr($arrContractKeywords);
3144 $arrBannerKeywords = array_unique(array_merge($arrBannerKeywords, $arrContractKeywords));
3147 if ($DONT_USE_CONTRACT ==
"Y" || !array_key_exists(
"CONTRACT_ID",
$ar))
3148 $ar[
"CONTRACT_ID"] = 0;
3150 if (
count($arrBannerKeywords)>0)
3152 $found_required =
true;
3153 if (
count($arrRequiredPageKeywords)>0 ||
count($arrRequiredPageKeywords_all)>0)
3156 foreach(
$arr as $exact_match)
3158 $arr1 = is_array($arrRequiredPageKeywords[$exact_match]) ? $arrRequiredPageKeywords[$exact_match] :
array();
3159 $arr2 = is_array($arrRequiredPageKeywords_all[$exact_match]) ? $arrRequiredPageKeywords_all[$exact_match] :
array();
3160 $arrRequiredKeywords = array_unique(array_merge($arr1, $arr2));
3161 if (
count($arrRequiredKeywords)>0)
3163 reset($arrRequiredKeywords);
3164 foreach($arrRequiredKeywords as $page_word)
3166 $page_word = mb_strtoupper($page_word);
3167 reset($arrBannerKeywords);
3169 foreach($arrBannerKeywords as $banner_word)
3171 $banner_word = mb_strtoupper($banner_word);
3173 if ($exact_match==
"Y")
3175 if ($banner_word==$page_word)
3181 elseif ($exact_match==
"N")
3183 if (mb_strpos($page_word, $banner_word) !==
false || mb_strpos($banner_word, $page_word) !==
false)
3192 $found_required =
false;
3199 if ($found_required)
3202 $arrRequiredKeywordsBanners[] =
$ar[
"BANNER_ID"];
3207 if ($found_required && (
count($arrDesiredPageKeywords)>0 ||
count($arrDesiredPageKeywords_all)>0))
3209 $found_desired =
false;
3211 foreach(
$arr as $exact_match)
3213 $arr1 = is_array($arrDesiredPageKeywords) ? $arrDesiredPageKeywords[$exact_match] :
array();
3214 $arr2 = is_array($arrDesiredPageKeywords_all) ? $arrDesiredPageKeywords_all[$exact_match] :
array();
3215 if (!is_array($arr1)) $arr1 =
array();
3216 if (!is_array($arr2)) $arr2 =
array();
3217 $arrDesiredKeywords = array_unique(array_merge($arr1, $arr2));
3218 if (is_array($arrDesiredKeywords) &&
count($arrDesiredKeywords)>0)
3220 reset($arrDesiredKeywords);
3221 foreach($arrDesiredKeywords as $page_word)
3223 $page_word = mb_strtoupper($page_word);
3224 reset($arrBannerKeywords);
3225 foreach($arrBannerKeywords as $banner_word)
3227 $banner_word = mb_strtoupper($banner_word);
3229 if ($exact_match==
"Y")
3231 if ($banner_word==$page_word)
3233 $found_desired =
true;
3237 elseif ($exact_match==
"N")
3239 if (mb_strpos($page_word, $banner_word) !==
false || mb_strpos($banner_word, $page_word) !==
false)
3241 $found_desired =
true;
3253 $arrDesiredKeywordsBanners[] =
$ar[
"BANNER_ID"];
3260 $arrEmptyKeywordsBanners[] =
$ar[
"BANNER_ID"];
3263 if (in_array(
$ar[
"BANNER_ID"], $arrRequiredKeywordsBanners))
3265 $arrWeightSum_RequiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3266 $arrWeightSum_RequiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3268 if (in_array(
$ar[
"BANNER_ID"], $arrDesiredKeywordsBanners))
3270 $arrWeightSum_DesiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3271 $arrWeightSum_DesiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3273 if (in_array(
$ar[
"BANNER_ID"], $arrEmptyKeywordsBanners))
3275 $arrWeightSum_EmptyKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3276 $arrWeightSum_EmptyKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3278 $arrWeightSum_all[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3279 $arrWeightSum_all[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3283 $arrAllTypies = array_keys($arrWeightSum_all);
3284 if (
count($arrAllTypies)>0)
3286 foreach($arrAllTypies as $tsid)
3289 if ($arKeywordsSet[$tsid]==
"Y")
3292 if (is_array($arrWeightSum_DesiredKeywords[$tsid]) &&
count($arrWeightSum_DesiredKeywords[$tsid])>0)
3294 $arrWeightSum[$tsid] = $arrWeightSum_DesiredKeywords[$tsid];
3297 elseif (is_array($arrWeightSum_RequiredKeywords[$tsid]) &&
count($arrWeightSum_RequiredKeywords[$tsid])>0)
3299 $arrWeightSum[$tsid] = $arrWeightSum_RequiredKeywords[$tsid];
3302 elseif ($arKeywordsSet[$tsid]==
"Y" && is_array($arrWeightSum_EmptyKeywords[$tsid]))
3304 $arrWeightSum[$tsid] = $arrWeightSum_EmptyKeywords[$tsid];
3309 $arrWeightSum[$tsid] = $arrWeightSum_all[$tsid];
3315 $arrWSum = $arrWeightSum[$TYPE_SID];
3318 if (is_array($arrWSum) &&
count($arrWSum)>0)
3322 if ($DONT_USE_CONTRACT ==
"N" || !array_key_exists(
"0", $arrWSum))
3327 foreach ($arrWSum as $cid =>
$arr)
3329 $CONTRACT_ID = $cid;
3330 $intSum += intval(
$arr[
"WEIGHT"]);
3335 $rndWeight = $intSum * (mt_rand()/mt_getrandmax());
3337 foreach ($arrWSum as $cid =>
$arr)
3339 if($rndWeight>=$intStep && $rndWeight<=$intStep+
$arr[
"WEIGHT"])
3341 $CONTRACT_ID = $cid;
3344 $intStep +=
$arr[
"WEIGHT"];
3346 $CONTRACT_ID = intval($CONTRACT_ID)<=0 ? 1 : intval($CONTRACT_ID);
3349 $arrWeightBanners = $arrWSum[$CONTRACT_ID][
"BANNERS"];
3352 if (is_array($arrWeightBanners) &&
count($arrWeightBanners)>0)
3358 foreach ($arrWeightBanners as $bid => $weight)
3362 $intSum += intval($weight);
3363 $strBanners .=
",".intval($bid);
3371 ".$DB->DateToCharFunction(
"B.DATE_SHOW_FIRST",
"FULL").
" DATE_SHOW_FIRST,
3372 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_FROM",
"FULL").
" DATE_SHOW_FROM,
3373 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_TO",
"FULL").
" DATE_SHOW_TO,
3374 C.MAX_VISITOR_COUNT CONTRACT_MAX_VISITOR_COUNT
3379 B.CONTRACT_ID = $CONTRACT_ID
3380 and B.TYPE_SID = '".
$DB->ForSql($TYPE_SID,255).
"'
3381 and B.ID in (".$strBanners.
")
3382 and C.ID = B.CONTRACT_ID
3392 ".$DB->DateToCharFunction(
"B.DATE_SHOW_FIRST",
"FULL").
" DATE_SHOW_FIRST,
3393 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_FROM",
"FULL").
" DATE_SHOW_FROM,
3394 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_TO",
"FULL").
" DATE_SHOW_TO
3398 B.TYPE_SID = '".
$DB->ForSql($TYPE_SID,255).
"'
3399 AND B.ID in (".$strBanners.
")
3411 $rsBanners =
$DB->Query($strSql,
false, $err_mess.__LINE__);
3412 while($arBanner = $rsBanners->Fetch())
3414 if (isset($arBanner[
"FLYUNIFORM"]) and $arBanner[
"FLYUNIFORM"] ==
"Y")
3418 if ($unitest < $infVal or !$infUniform)
3421 $infUniform = $arBanner;
3426 $intSum += intval($arBanner[
"WEIGHT"]);
3427 array_push($stubs, $arBanner);
3432 if ($infUniform ==
null or
3436 $infUniform =
array();
3437 if (
count($stubs) > 0)
3440 $rndWeight = $intSum * (mt_rand()/mt_getrandmax());
3443 $infUniform = current($stubs);
3444 if($rndWeight<$intStep or $rndWeight>$intStep+$infUniform[
"WEIGHT"])
3446 $intStep += $infUniform[
"WEIGHT"];
3447 while ($infUniform = next($stubs))
3449 if($rndWeight>=$intStep && $rndWeight<=$intStep+$infUniform[
"WEIGHT"])
3451 $intStep += $infUniform[
"WEIGHT"];
3457 $arBanner = $infUniform;
3459 $BANNER_ID = intval($arBanner[
"ID"]);
3462 unset($arrWeightSum[$TYPE_SID][$CONTRACT_ID][
"BANNERS"][$arBanner[
"ID"]]);
3463 if(
count($arrWeightSum[$TYPE_SID][$CONTRACT_ID][
"BANNERS"])<=0)
3464 unset($arrWeightSum[$TYPE_SID][$CONTRACT_ID]);
3479 static $arrWeightSum =
false;
3481 $TYPE_SID = trim($TYPE_SID);
3482 if ($TYPE_SID ==
'')
3487 $DONT_USE_CONTRACT = COption::GetOptionString(
"advertising",
"DONT_USE_CONTRACT",
"N");
3489 if ($arrWeightSum ===
false)
3492 $arrWeightSum =
array();
3494 $arrCookie_counter =
array();
3500 $arrCookie_counter[$banner_id] =
$arr[
"COUNTER"];
3514 $banner_id = intval(
$ar[1]);
3516 $arrCookie_counter[$banner_id] =
$counter;
3522 $arrWeightSum_RequiredKeywords =
array();
3523 $arrWeightSum_DesiredKeywords =
array();
3524 $arrWeightSum_EmptyKeywords =
array();
3525 $arrWeightSum_all =
array();
3526 $arKeywordsSet =
array();
3528 $arrRequiredKeywordsBanners =
array();
3529 $arrDesiredKeywordsBanners =
array();
3530 $arrEmptyKeywordsBanners =
array();
3533 $arrDesiredPageKeywords_all = $arrPAGE_KEYWORDS[
""][
"DESIRED"] ?? [];
3534 $arrRequiredPageKeywords_all = $arrPAGE_KEYWORDS[
""][
"REQUIRED"] ?? [];
3540 if (isset(
$ar[
"FLYUNIFORM"]) and
$ar[
"FLYUNIFORM"] ==
"Y")
3547 $arKeywordsSet[
$ar[
"TYPE_SID"]] =
"N";
3549 if ((intval(
$ar[
"SHOWS_FOR_VISITOR"])>0 && intval($arrCookie_counter[
$ar[
"BANNER_ID"]])<intval(
$ar[
"SHOWS_FOR_VISITOR"])) || intval(
$ar[
"SHOWS_FOR_VISITOR"])<=0)
3551 $arrDesiredPageKeywords = $arrPAGE_KEYWORDS[
$ar[
"TYPE_SID"]][
"DESIRED"] ?? [];
3552 $arrRequiredPageKeywords = $arrPAGE_KEYWORDS[
$ar[
"TYPE_SID"]][
"REQUIRED"] ?? [];
3554 if (
count($arrRequiredPageKeywords)>0 ||
3555 count($arrRequiredPageKeywords_all)>0 ||
3556 count($arrDesiredPageKeywords)>0 ||
3557 count($arrDesiredPageKeywords_all)>0
3560 $arKeywordsSet[
$ar[
"TYPE_SID"]] =
"Y";
3563 $arrBannerKeywords = preg_split(
'/[\n\r]+/',
$ar[
"BANNER_KEYWORDS"]);
3564 if (is_array($arrBannerKeywords))
3569 if ($DONT_USE_CONTRACT <>
"Y" &&
$ar[
"CONTRACT_KEYWORDS"] <>
'')
3571 $arrContractKeywords = preg_split(
'/[\n\r]+/',
$ar[
"CONTRACT_KEYWORDS"]);
3572 if (is_array($arrContractKeywords))
3574 TrimArr($arrContractKeywords);
3576 $arrBannerKeywords = array_unique(array_merge($arrBannerKeywords, $arrContractKeywords));
3579 if ($DONT_USE_CONTRACT ==
"Y" || !array_key_exists(
"CONTRACT_ID",
$ar))
3580 $ar[
"CONTRACT_ID"] = 0;
3582 if (
count($arrBannerKeywords)>0)
3584 $found_required =
true;
3585 if (
count($arrRequiredPageKeywords)>0 ||
count($arrRequiredPageKeywords_all)>0)
3588 foreach(
$arr as $exact_match)
3590 $arr1 = is_array($arrRequiredPageKeywords[$exact_match]) ? $arrRequiredPageKeywords[$exact_match] :
array();
3591 $arr2 = is_array($arrRequiredPageKeywords_all[$exact_match]) ? $arrRequiredPageKeywords_all[$exact_match] :
array();
3592 $arrRequiredKeywords = array_unique(array_merge($arr1, $arr2));
3593 if (
count($arrRequiredKeywords)>0)
3595 reset($arrRequiredKeywords);
3596 foreach($arrRequiredKeywords as $page_word)
3598 $page_word = mb_strtoupper($page_word);
3599 reset($arrBannerKeywords);
3601 foreach($arrBannerKeywords as $banner_word)
3603 $banner_word = mb_strtoupper($banner_word);
3605 if ($exact_match==
"Y")
3607 if ($banner_word==$page_word)
3613 elseif ($exact_match==
"N")
3615 if (mb_strpos($page_word, $banner_word) !==
false || mb_strpos($banner_word, $page_word) !==
false)
3624 $found_required =
false;
3631 if ($found_required)
3634 $arrRequiredKeywordsBanners[] =
$ar[
"BANNER_ID"];
3639 if ($found_required && (
count($arrDesiredPageKeywords)>0 ||
count($arrDesiredPageKeywords_all)>0))
3641 $found_desired =
false;
3643 foreach(
$arr as $exact_match)
3645 $arr1 = is_array($arrDesiredPageKeywords) ? $arrDesiredPageKeywords[$exact_match] :
array();
3646 $arr2 = is_array($arrDesiredPageKeywords_all) ? $arrDesiredPageKeywords_all[$exact_match] :
array();
3647 if (!is_array($arr1)) $arr1 =
array();
3648 if (!is_array($arr2)) $arr2 =
array();
3649 $arrDesiredKeywords = array_unique(array_merge($arr1, $arr2));
3650 if (is_array($arrDesiredKeywords) &&
count($arrDesiredKeywords)>0)
3652 reset($arrDesiredKeywords);
3653 foreach($arrDesiredKeywords as $page_word)
3655 $page_word = mb_strtoupper($page_word);
3656 reset($arrBannerKeywords);
3657 foreach($arrBannerKeywords as $banner_word)
3659 $banner_word = mb_strtoupper($banner_word);
3661 if ($exact_match==
"Y")
3663 if ($banner_word==$page_word)
3665 $found_desired =
true;
3669 elseif ($exact_match==
"N")
3671 if (mb_strpos($page_word, $banner_word) !==
false || mb_strpos($banner_word, $page_word) !==
false)
3673 $found_desired =
true;
3685 $arrDesiredKeywordsBanners[] =
$ar[
"BANNER_ID"];
3692 $arrEmptyKeywordsBanners[] =
$ar[
"BANNER_ID"];
3695 if (in_array(
$ar[
"BANNER_ID"], $arrRequiredKeywordsBanners))
3697 $arrWeightSum_RequiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3698 $arrWeightSum_RequiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3700 if (in_array(
$ar[
"BANNER_ID"], $arrDesiredKeywordsBanners))
3702 $arrWeightSum_DesiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3703 $arrWeightSum_DesiredKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3705 if (in_array(
$ar[
"BANNER_ID"], $arrEmptyKeywordsBanners))
3707 $arrWeightSum_EmptyKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3708 $arrWeightSum_EmptyKeywords[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3710 $arrWeightSum_all[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"WEIGHT"] = intval(
$ar[
"CONTRACT_WEIGHT"]);
3711 $arrWeightSum_all[
$ar[
"TYPE_SID"]][
$ar[
"CONTRACT_ID"]][
"BANNERS"][
$ar[
"BANNER_ID"]] = intval(
$ar[
"BANNER_WEIGHT"]);
3715 $arrAllTypies = array_keys($arrWeightSum_all);
3716 if (
count($arrAllTypies)>0)
3718 foreach($arrAllTypies as $tsid)
3721 if ($arKeywordsSet[$tsid]==
"Y")
3724 if (isset($arrWeightSum_DesiredKeywords[$tsid]) && is_array($arrWeightSum_DesiredKeywords[$tsid]) && !empty($arrWeightSum_DesiredKeywords[$tsid]))
3726 $arrWeightSum[$tsid] = $arrWeightSum_DesiredKeywords[$tsid];
3729 elseif (isset($arrWeightSum_RequiredKeywords[$tsid]) && is_array($arrWeightSum_RequiredKeywords[$tsid]) && !empty($arrWeightSum_RequiredKeywords[$tsid]))
3731 $arrWeightSum[$tsid] = $arrWeightSum_RequiredKeywords[$tsid];
3734 elseif ($arKeywordsSet[$tsid]==
"Y" && is_array($arrWeightSum_EmptyKeywords[$tsid]))
3736 $arrWeightSum[$tsid] = $arrWeightSum_EmptyKeywords[$tsid];
3741 $arrWeightSum[$tsid] = $arrWeightSum_all[$tsid];
3747 $arrWSum = $arrWeightSum[$TYPE_SID];
3750 if (is_array($arrWSum) &&
count($arrWSum)>0)
3754 if ($DONT_USE_CONTRACT ==
"N" || !array_key_exists(
"0", $arrWSum))
3759 foreach ($arrWSum as $cid =>
$arr)
3761 $CONTRACT_ID = $cid;
3762 $intSum += intval(
$arr[
"WEIGHT"]);
3767 $rndWeight = $intSum * (mt_rand()/mt_getrandmax());
3769 foreach ($arrWSum as $cid =>
$arr)
3771 if($rndWeight>=$intStep && $rndWeight<=$intStep+
$arr[
"WEIGHT"])
3773 $CONTRACT_ID = $cid;
3776 $intStep +=
$arr[
"WEIGHT"];
3778 $CONTRACT_ID = intval($CONTRACT_ID)<=0 ? 1 : intval($CONTRACT_ID);
3781 $arrWeightBanners = $arrWSum[$CONTRACT_ID][
"BANNERS"];
3784 if (is_array($arrWeightBanners) &&
count($arrWeightBanners)>0)
3790 foreach ($arrWeightBanners as $bid => $weight)
3794 $intSum += intval($weight);
3795 $strBanners .=
",".intval($bid);
3803 ".$DB->DateToCharFunction(
"B.DATE_SHOW_FIRST",
"FULL").
" DATE_SHOW_FIRST,
3804 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_FROM",
"FULL").
" DATE_SHOW_FROM,
3805 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_TO",
"FULL").
" DATE_SHOW_TO,
3806 C.MAX_VISITOR_COUNT CONTRACT_MAX_VISITOR_COUNT
3811 B.CONTRACT_ID = $CONTRACT_ID
3812 and B.TYPE_SID = '".
$DB->ForSql($TYPE_SID,255).
"'
3813 and B.ID in (".$strBanners.
")
3814 and C.ID = B.CONTRACT_ID
3824 ".$DB->DateToCharFunction(
"B.DATE_SHOW_FIRST",
"FULL").
" DATE_SHOW_FIRST,
3825 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_FROM",
"FULL").
" DATE_SHOW_FROM,
3826 ".
$DB->DateToCharFunction(
"B.DATE_SHOW_TO",
"FULL").
" DATE_SHOW_TO
3830 B.TYPE_SID = '".
$DB->ForSql($TYPE_SID,255).
"'
3831 AND B.ID in (".$strBanners.
")
3842 $rsBanners =
$DB->Query($strSql,
false, $err_mess.__LINE__);
3843 while($arBanner = $rsBanners->Fetch())
3845 if (isset($arBanner[
"FLYUNIFORM"]) and $arBanner[
"FLYUNIFORM"] ==
"Y")
3849 $inf[$arBanner[
'ID']] = $arBanner;
3853 $intSum += intval($arBanner[
"WEIGHT"]);
3854 $stubs[$arBanner[
'ID']] = $arBanner;
3859 uasort($inf,
array(
'CAdvBanner_all',
'arr_comp_uniform'));
3862 $infStubs =
array();
3863 while (
count($stubs))
3866 $rndWeight = $intSum * (mt_rand()/mt_getrandmax());
3869 $infCurr = current($stubs);
3870 if($rndWeight < $intStep or $rndWeight > $intStep + $infCurr[
"WEIGHT"])
3872 $intStep += $infCurr[
"WEIGHT"];
3873 while (next($stubs))
3875 $infCurr = current($stubs);
3876 if($rndWeight>=$intStep && $rndWeight<=$intStep+$infCurr[
"WEIGHT"])
3878 $intStep += $infCurr[
"WEIGHT"];
3881 $infStubs[$infCurr[
'ID']] = $infCurr;
3882 unset($stubs[$infCurr[
'ID']]);
3885 $arBanners = array_slice(array_merge($inf, $infStubs), 0, intval($quantity));
3887 foreach ($arBanners as $arB)
3889 $BANNER_ID = intval($arB[
"ID"]);
3892 unset($arrWeightSum[$TYPE_SID][$CONTRACT_ID][
"BANNERS"][$arB[
"ID"]]);
3893 if(
count($arrWeightSum[$TYPE_SID][$CONTRACT_ID][
"BANNERS"]) <= 0)
3894 unset($arrWeightSum[$TYPE_SID][$CONTRACT_ID]);
3910 if ($rot and $tim) $arProgress = $rot/$tim;
3917 $fs =
array(
"to" => 0,
"first" => 0,
"from" => 0);
3918 if (isset($arBanner[
"DATE_SHOW_TO"])) $fs[
"to"] = $arBanner[
"DATE_SHOW_TO"];
3919 if (isset($arBanner[
"DATE_SHOW_FIRST"])) $fs[
"first"] = $arBanner[
"DATE_SHOW_FIRST"];
3920 if (isset($arBanner[
"DATE_SHOW_FROM"])) $fs[
"from"] = $arBanner[
"DATE_SHOW_FROM"];
3921 if ($fs[
"to"] and mb_strstr(trim($fs[
"to"]),
" ") ==
false) $fs[
"to"].=
" 23:59:59";
3922 if ($fs[
"first"] and mb_strstr(trim($fs[
"first"]),
" ") ==
false) $fs[
"first"].=
" 00:00:00";
3923 if ($fs[
"from"] and mb_strstr(trim($fs[
"from"]),
" ") ==
false) $fs[
"from"].=
" 00:00:00";
3932 if (!$dt[
"to"])
return 0;
3936 $dtformat =
"DD.MM.YYYY HH:MI:SS";
3942 if ($stmpfirst>0 and $stmpfirst>=$stmpfrom and $stmpto>$stmpfirst)
3944 $stmpfrom = $stmpfirst;
3947 if ($stmpfrom >= $stmpto)
return 0;
3948 $rStmp = $stmpto - $stmpfrom;
3958 $dtformat =
"DD.MM.YYYY HH:MI:SS";
3964 if ($stmpfirst>0 and $stmpfirst>=$stmpfrom and $stmpto>$stmpfirst)
3966 $stmpfrom = $stmpfirst;
3969 $stmpnow -= $stmpfrom;
3971 if ($stmpnow <= 0 or !$diff)
return 0;
3973 return $stmpnow/$diff;
3978 if (!isset($arBanner[
"MAX_SHOW_COUNT"]) or !isset($arBanner[
"SHOW_COUNT"]) or
3979 intval($arBanner[
"MAX_SHOW_COUNT"])==0)
return 0;
3980 return intval($arBanner[
"SHOW_COUNT"])/intval($arBanner[
"MAX_SHOW_COUNT"]);
3990 static $search =
array(
"#RANDOM1#",
"#RANDOM2#",
"#RANDOM3#",
"#RANDOM4#",
"#RANDOM5#",
"#BANNER_NAME#",
"#BANNER_ID#",
"#CONTRACT_ID#",
"#TYPE_SID#");
3991 if (trim(
$text) <>
'')
3993 $text = str_replace($search,
array(
$nRandom1,
$nRandom2,
$nRandom3,
$nRandom4,
$nRandom5, $arBanner[
"NAME"], $arBanner[
"ID"], $arBanner[
"CONTRACT_ID"], $arBanner[
"TYPE_SID"]),
$text);
3994 if (mb_strpos(
$text,
"#EVENT_GID#") !==
false)
3996 if (CModule::IncludeModule(
"statistic"))
4016 public static function GetHTML($arBanner, $bNoIndex=
false)
4021 if(intval($arBanner[
"IMAGE_ID"]) > 0 && $arBanner[
"AD_TYPE"] <>
"html" && $arBanner[
"AD_TYPE"] <>
"template")
4023 $arImage = CFile::GetFileArray($arBanner[
"IMAGE_ID"]);
4027 $path = $arImage[
"SRC"];
4033 $alt = $a_title = $a_target =
"";
4034 if (trim($arBanner[
"URL"]) <>
'')
4039 $arParams[] =
"flash_link=".urlencode($param);
4040 if (trim($arBanner[
"URL_TARGET"]) <>
'')
4042 $arParams[] =
"flash_target=".urlencode($arBanner[
"URL_TARGET"]);
4043 $a_target =
' target="'.htmlspecialcharsbx($arBanner[
"URL_TARGET"]).
'" ';
4046 if (trim($arBanner[
"IMAGE_ALT"]) <>
'')
4049 $arParams[] =
"flash_alt=".urlencode($alt);
4050 $a_title =
" title=\"".htmlspecialcharsbx($alt).
"\" ";
4054 $param =
"?".implode(
"&",
$arParams);
4056 if ($arBanner[
"FLASH_TRANSPARENT"] ==
'')
4057 $arBanner[
"FLASH_TRANSPARENT"] =
'transparent';
4059 if ($arBanner[
"FLASH_JS"] !=
'Y')
4061 $strReturn =
'<div style="width: '.$arImage[
"WIDTH"].
'px; height: '.$arImage[
"HEIGHT"].
'px; padding:0; margin:0">';
4062 if(trim($arBanner[
"URL"]) <>
'' && $arBanner[
"NO_URL_IN_FLASH"] ==
"Y")
4064 $strReturn .= ($bNoIndex?
'<noindex>':
'').
'<div style="position:absolute; z-index:100;"><a href="'.
$url.
'"'.$a_target.$a_title.($bNoIndex?
' rel="nofollow"':
'').
'><img src="/bitrix/images/1.gif" width="'.$arImage[
"WIDTH"].
'" height="'.$arImage[
"HEIGHT"].
'" style="border:0;" alt="'.
htmlspecialcharsEx($alt).
'" /></a></div>'.($bNoIndex?
'</noindex>':
'');
4068 classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000"
4069 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
4070 id="banner_'.$arBanner[
"ID"].
'"
4071 WIDTH="'.$arImage[
"WIDTH"].
'"
4072 HEIGHT="'.$arImage[
"HEIGHT"].
'">
4073 <PARAM NAME="movie" VALUE="'.
$path.$param.
'" />
4074 <PARAM NAME="quality" VALUE="high" />
4075 <PARAM NAME="bgcolor" VALUE="#FFFFFF" />
4076 <PARAM NAME="wmode" VALUE="'.$arBanner[
"FLASH_TRANSPARENT"].
'" />
4078 src="'.
$path.$param.
'"
4081 wmode="'.$arBanner[
"FLASH_TRANSPARENT"].
'"
4082 WIDTH="'.$arImage[
"WIDTH"].
'"
4083 HEIGHT="'.$arImage[
"HEIGHT"].
'"
4085 TYPE="application/x-shockwave-flash"
4086 PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
4094 static $bScript =
null;
4095 if($bScript ===
null)
4098 $strReturn .=
'<script src="'.CUtil::GetAdditionalFileURL(
'/bitrix/js/advertising/flash.js').
'"></script>';
4102 $arAltImage = CFile::GetFileArray($arBanner[
"FLASH_IMAGE"]);
4105 $altImgPath = $arAltImage[
"SRC"];
4108 $test_id =
'id'.RandString(10);
4109 $strReturn .=
'<div id="'.$test_id.
'" style="width: '.$arImage[
"WIDTH"].
'px; height: '.$arImage[
"HEIGHT"].
'px; padding:0; margin:0;">';
4111 if(trim($arBanner[
"URL"]) <>
'')
4113 if($arBanner[
"NO_URL_IN_FLASH"] ==
"Y")
4114 $strReturn .= ($bNoIndex?
'<noindex>':
'').
'<div style="position:absolute; z-index:100;"><a href="'.
$url.
'"'.$a_target.$a_title.($bNoIndex?
' rel="nofollow"':
'').
'><img src="/bitrix/images/1.gif" width="'.$arImage[
"WIDTH"].
'" height="'.$arImage[
"HEIGHT"].
'" style="border:0;" alt="'.
htmlspecialcharsEx($alt).
'" /></a></div>'.($bNoIndex?
'</noindex>':
'');
4118 $strReturn .=
'</div>';
4119 $strReturn .=
'<script>bx_adv_includeFlash("'.$test_id.
'", "'.
4120 CUtil::JSEscape(
$path.$param).
'", "'.
4121 $arImage[
"WIDTH"].
'", "'.$arImage[
"HEIGHT"].
'", "'.
4122 $arBanner[
"FLASH_TRANSPARENT"].
'", "'.
4123 CUtil::JSEscape($altImgPath).
'", '.
4124 (intval($arBanner[
"FLASH_VER"]) <= 0?
'null':intval($arBanner[
"FLASH_VER"])).
', "'.
4125 CUtil::JSEscape($altHref).
'", "'.
4133 $strImage =
"<img alt=\"".htmlspecialcharsEx($alt).
"\" title=\"".
htmlspecialcharsEx($alt).
"\" src=\"".
$path.
"\" width=\"".$arImage[
"WIDTH"].
"\" height=\"".$arImage[
"HEIGHT"].
"\" style=\"border:0;\" />";
4134 if (trim($arBanner[
"URL"]) <>
'')
4136 $url = $arBanner[
"URL"];
4139 $target = (trim($arBanner[
"URL_TARGET"]) <>
'') ?
" target=\"".$arBanner[
"URL_TARGET"].
"\" " :
"";
4140 $strReturn = ($bNoIndex?
'<noindex>':
'').
"<a href=\"".
$url.
"\"".$target.($bNoIndex?
' rel="nofollow"':
'').
">".$strImage.
"</a>".($bNoIndex?
'</noindex>':
'');
4144 $strReturn .= $strImage;
4151 if($arBanner[
"CODE"] <>
'')
4153 $code = $arBanner[
"CODE"];
4154 if ($arBanner[
"CODE_TYPE"] ==
"text")
4182 $DB->Update(
"b_adv_banner", Array(
"DATE_SHOW_FIRST" => $value ),
"WHERE ID='" .
$key .
"'", $err_mess . __LINE__ );
4190 "SHOW_COUNT" =>
"SHOW_COUNT + 1",
4191 "DATE_LAST_SHOW" =>
$DB->GetNowFunction(),
4194 $arFields[
"VISITOR_COUNT"] =
"VISITOR_COUNT + 1";
4198 $group_all .= ($group_all <>
''?
',':
'').intval($b);
4200 $DB->Update(
"b_adv_banner",
$arFields,
"WHERE ID IN(".$group_all.
")",$err_mess.__LINE__);
4204 $arFields = Array(
"VISITOR_COUNT" =>
"VISITOR_COUNT + 1");
4207 $group_inc .= ($group_inc <>
""?
",":
"").intval($BANNERS_CNT);
4208 $DB->Update(
"b_adv_banner",
$arFields,
"WHERE ID IN(".$group_inc.
")",$err_mess.__LINE__);
4212 $strSql =
"SELECT BANNER_ID FROM b_adv_banner_2_day WHERE BANNER_ID IN (".$group_all.
") and DATE_STAT = ".
$DB->GetNowDate();
4213 $res =
$DB->Query($strSql,
false, $err_mess.__LINE__);
4214 $arExist = $arInsert = Array();
4216 $arExist[] =
$ar[
"BANNER_ID"];
4220 foreach ($arInsert as $BANNER_ID)
4222 $strSql =
"INSERT INTO b_adv_banner_2_day (DATE_STAT, BANNER_ID, SHOW_COUNT, VISITOR_COUNT) VALUES (".$DB->GetNowDate().
", $BANNER_ID,1,1)";
4223 $DB->Query($strSql,
true, $err_mess.__LINE__);
4226 if (!empty($arExist))
4229 if (!empty($arExistInc))
4232 foreach($arExistInc as $b)
4233 $sExistInc .= ($sExistInc <>
''?
',':
'').intval($b);
4235 $arFields = Array(
"SHOW_COUNT" =>
"SHOW_COUNT + 1",
"VISITOR_COUNT" =>
"VISITOR_COUNT + 1");
4236 $DB->Update(
"b_adv_banner_2_day",
$arFields,
"WHERE BANNER_ID IN(".$sExistInc.
") and DATE_STAT = ".
$DB->GetNowDate(),$err_mess.__LINE__);
4239 $arExistInc = array_diff($arExist, $arExistInc);
4241 if (!empty($arExistInc))
4244 foreach($arExistInc as $b)
4245 $sExistInc .= ($sExistInc <>
''?
',':
'').intval($b);
4247 $arFields = Array(
"SHOW_COUNT" =>
"SHOW_COUNT + 1");
4248 $DB->Update(
"b_adv_banner_2_day",
$arFields,
"WHERE BANNER_ID IN(".$sExistInc.
") and DATE_STAT = ".
$DB->GetNowDate(),$err_mess.__LINE__);
4253 $DONT_USE_CONTRACT = COption::GetOptionString(
"advertising",
"DONT_USE_CONTRACT",
"N");
4254 if ($DONT_USE_CONTRACT ==
"N" &&
4264 $arUpdate = Array();
4265 foreach($arCount as $CONTRACT_ID => $value)
4266 $arUpdate[$value][] = $CONTRACT_ID;
4268 foreach ($arUpdate as
$count => $arContact)
4271 if ($arContact == (array_intersect($arContact,
$CACHE_ADVERTISING[
"CONTRACTS_CNT"])))
4273 $arFields[
"VISITOR_COUNT"] =
"VISITOR_COUNT + 1";
4277 foreach($arContact as $c)
4278 $sContact .= ($sContact <>
''?
',':
'').intval($c);
4280 $DB->Update(
"b_adv_contract",
$arFields,
"WHERE ID IN(".$sContact.
")",$err_mess.__LINE__);
4287 $sContrCnt .= ($sContrCnt <>
''?
',':
'').intval($c);
4289 $arFields = Array(
"VISITOR_COUNT" =>
"VISITOR_COUNT + 1");
4290 $DB->Update(
"b_adv_banner",
$arFields,
"WHERE ID IN(".$sContrCnt.
")",$err_mess.__LINE__);
4298 foreach($arrCookie as
$key =>
$arr)
4300 $cookie_value .= intval(
$arr[
"CONTRACT_ID"]).
"_".
$key.
"_".intval(
$arr[
"COUNTER"]).
"_".trim(
$arr[
"EXPIRATION_DATE"]).
",";
4303 $max_length = 4*1024;
4305 while (mb_strlen($cookie_value) > $max_length && $j<200)
4308 $arrCookie_temp = $arrCookie;
4309 $arrCookie =
array();
4311 foreach($arrCookie_temp as
$key => $arrValue)
4315 $arrCookie[
$key] = $arrValue;
4318 foreach($arrCookie as
$key =>
$arr)
4320 $cookie_value .= intval(
$arr[
"CONTRACT_ID"]).
"_".
$key.
"_".intval(
$arr[
"COUNTER"]).
"_".trim(
$arr[
"EXPIRATION_DATE"]).
",";
4322 $cookie_value = trim($cookie_value,
",");
4324 $secure = (COption::GetOptionString(
"main",
"use_secure_password_cookies",
"N") ==
"Y" && CMain::IsHTTPS());
4337 if (intval($_SESSION[
"SESS_SEARCHER_ID"])<=0 && $arBanner[
"FIX_SHOW"] ==
"Y" && COption::GetOptionString(
'advertising',
'DONT_FIX_BANNER_SHOWS') <>
"Y")
4339 $BANNER_ID = intval($arBanner[
"ID"]);
4340 $CONTRACT_ID = intval($arBanner[
"CONTRACT_ID"]);
4346 if ($arBanner[
"DATE_SHOW_FIRST"] ==
'')
4352 isset($_SESSION[
"SESS_VIEWED_BANNERS"])
4353 && is_array($_SESSION[
"SESS_VIEWED_BANNERS"])
4354 && in_array($BANNER_ID, $_SESSION[
"SESS_VIEWED_BANNERS"])
4357 $inc_banner_counter=
"N";
4361 isset($_SESSION[
"SESS_VIEWED_CONTRACTS"])
4362 && is_array($_SESSION[
"SESS_VIEWED_CONTRACTS"])
4363 && in_array($CONTRACT_ID, $_SESSION[
"SESS_VIEWED_CONTRACTS"])
4366 $inc_contract_counter=
"N";
4371 if ($inc_banner_counter==
"Y")
4374 $_SESSION[
"SESS_VIEWED_BANNERS"][] = $BANNER_ID;
4381 if ($inc_contract_counter==
"Y")
4384 $_SESSION[
"SESS_VIEWED_CONTRACTS"][] = $CONTRACT_ID;
4395 "BANNERS_ALL" =>
array(),
4396 "BANNERS_CNT" =>
array(),
4397 "CONTRACTS_ALL" =>
array(),
4398 "CONTRACTS_CNT" =>
array(),
4406 public static function SetCookie($arBanner, &$inc_banner_counter, &$inc_contract_counter)
4409 if (intval($arBanner[
"ID"])>0)
4411 $inc_contract_counter =
"N";
4412 $inc_banner_counter =
"N";
4414 $days = COption::GetOptionString(
"advertising",
"COOKIE_DAYS");
4416 $arrCookie =
array();
4417 $arrContracts =
array();
4426 foreach ($arrCookie as
$arr)
4428 $arrContracts[] =
$arr[
"CONTRACT_ID"];
4431 if (in_array($arBanner[
"ID"],array_keys($arrCookie)))
4433 $arrCookie[$arBanner[
"ID"]][
"COUNTER"] = $arrCookie[$arBanner[
"ID"]][
"COUNTER"]+1;
4434 $arrCookie[$arBanner[
"ID"]][
"EXPIRATION_DATE"] = date(
"dmY",time()+(intval($days)*86400));
4448 $contract_id = intval(
$ar[0]);
4449 $arrContracts[] = $contract_id;
4450 $banner_id = intval(
$ar[1]);
4452 if ($arBanner[
"ID"]==$banner_id)
4455 $arrCookie[$arBanner[
"ID"]] =
array(
4456 "CONTRACT_ID" => $arBanner[
"CONTRACT_ID"],
4458 "EXPIRATION_DATE" => date(
"dmY",time()+(intval($days)*86400))
4463 $strDate = trim(
$ar[3]);
4464 $month = intval(mb_substr($strDate, 2, 2));
4465 $day = intval(mb_substr($strDate, 0, 2));
4466 $year = intval(mb_substr($strDate, 4, 4));
4469 if ($month && $day &&
$year)
4471 $stmp = mktime(0, 0, 0, $month, $day,
$year);
4479 $arrCookie[$banner_id] =
array(
4480 "CONTRACT_ID" => $contract_id,
4482 "EXPIRATION_DATE" => ($stmp ? date(
"dmY", $stmp) : $strDate)
4491 if (!in_array($arBanner[
"CONTRACT_ID"], $arrContracts))
4492 $inc_contract_counter =
"Y";
4495 if (!in_array($arBanner[
"ID"], array_keys($arrCookie)))
4498 $inc_banner_counter=
"Y";
4501 $arrCookie[$arBanner[
"ID"]] =
array(
4502 "CONTRACT_ID" => $arBanner[
"CONTRACT_ID"],
4504 "EXPIRATION_DATE" => date(
"dmY",time()+(intval($days)*86400))
4512 public static function Show($TYPE_SID, $HTML_BEFORE=
"", $HTML_AFTER=
"")
4517 if(\
Bitrix\Main\Application::getInstance()->getKernelSession()[
"SESS_SHOW_INCLUDE_TIME_EXEC"]==
"Y" &&
$USER->IsAdmin())
4525 if($strReturn <>
'')
4530 $strReturn =
$APPLICATION->IncludeString($strReturn, $arIcons);
4532 $strReturn = $HTML_BEFORE.$strReturn.$HTML_AFTER;
4535 $strReturn .= $debug->Output();
4541 echo $debug->Output();
4549 static $arContractTypes =
false;
4550 static $arContracts =
false;
4556 if (is_array($arIcons) &&
count($arIcons) > 0)
4558 if (!empty($arBanner) && isset($arBanner[
"ID"]))
4563 'URL' =>
"/bitrix/admin/adv_banner_edit.php?bxpublic=Y&from_module=advertising&lang=".LANGUAGE_ID.
"&ID=".$arBanner[
"ID"].
"&CONTRACT_ID=".$arBanner[
"CONTRACT_ID"],
4571 "TEXT" => $arBanner[
"NAME"]
4574 if (!is_array($arIcons[0][
'MENU']))
4576 $arIcons[0][
'MENU'] =
array(
4578 "URL" => $arIcons[0][
'URL'],
4579 "TEXT" => $arIcons[0][
'MESS']
4582 unset($arIcons[0][
'URL']);
4583 unset($arIcons[0][
'MESS']);
4586 array_push($arIcons[0][
'MENU'], $curIcon);
4592 if (!empty($arBanner) && isset($arBanner[
"ID"]))
4597 'URL' =>
"/bitrix/admin/adv_banner_edit.php?bxpublic=Y&from_module=advertising&lang=".LANGUAGE_ID.
"&ID=".$arBanner[
"ID"].
"&CONTRACT_ID=".$arBanner[
"CONTRACT_ID"],
4605 "ICON" =>
"bx-context-toolbar-edit-icon",
4606 "TITLE" =>
GetMessage(
"AD_PUBLIC_ICON_EDIT_BANNER"),
4607 "MESS" => $arBanner[
"NAME"]
4610 $TYPE_SID = $arBanner[
"TYPE_SID"];
4612 if ($TYPE_SID <>
'')
4614 $arSubMenu =
array();
4616 if($arContracts ===
false)
4618 $arContracts =
array();
4619 $arContractTypes =
array();
4621 while($arContract = $contracts->Fetch())
4623 $arContracts[] = $arContract;
4628 foreach($arContracts as $arContract)
4630 if (array_key_exists(
"ALL", $arContractTypes[$arContract[
"ID"]]) || array_key_exists($TYPE_SID, $arContractTypes[$arContract[
"ID"]]))
4632 $arSubMenu[] =
array(
4635 'URL' =>
"/bitrix/admin/adv_banner_edit.php?bxpublic=Y&from_module=advertising&lang=".LANGUAGE_ID.
"&TYPE_SID=".$TYPE_SID.
"&CONTRACT_ID=".$arContract[
"ID"],
4643 "TEXT" => $arContract[
"NAME"]
4649 "ICON" =>
"bx-context-toolbar-create-icon",
4650 "TITLE" =>
GetMessage(
"AD_PUBLIC_ICON_ADD_BANNER")
4653 $nSubMenu =
count($arSubMenu);
4656 $arIcon[
"URL"] = $arSubMenu[0][
"URL"];
4657 $arIcons[] = $arIcon;
4661 $arIcon[
"MENU"] = $arSubMenu;
4662 $arIcons[] = $arIcon;
4667 "URL" =>
"/bitrix/admin/adv_banner_list.php?lang=".LANGUAGE_ID.
"&find_contract_id[]=".$arBanner[
"CONTRACT_ID"].
"&find_type_sid[]=".$arBanner[
"TYPE_SID"].
"&set_filter=Y",
4668 "SRC" =>
"/bitrix/themes/.default/icons/advertising/comp_view.gif",
4669 "TITLE" =>
GetMessage(
"AD_PUBLIC_ICON_BANNER_LIST"),
4670 "IN_PARAMS_MENU" =>
true
4686 if (trim($find_date_1) <>
'' || trim($find_date_2) <>
'')
4691 if (!$date1_stm && trim($find_date_1) <>
'')
4693 else $date_1_ok =
true;
4694 if (!$date2_stm && trim($find_date_2) <>
'')
4696 elseif ($date_1_ok && $date2_stm <= $date1_stm && $date2_stm <>
'')
4700 if (
$str <> '')
return false;
else return true;
4708 $arSqlSearch = Array();
4724 if( ((
string)
$val ==
'') || (
"$val"==
"NOT_REF") )
continue;
4730 $arSqlSearch[] =
"D.DATE_STAT>=".$DB->CharToDateFunction(
$val,
"SHORT");
4733 $arSqlSearch[] =
"D.DATE_STAT<=".$DB->CharToDateFunction(
$val.
" 23:59:59",
"FULL");
4742 $contract_total =
$arFilter[
"CONTRACT_SUMMA"]==
"Y" ?
"Y" :
"N";
4743 $banner_total =
$arFilter[
"BANNER_SUMMA"]==
"Y" ?
"Y" :
"N";
4744 $group_total =
$arFilter[
"GROUP_SUMMA"]==
"Y" ?
"Y" :
"N";
4746 if (in_array(
"ctr",$arShow))
4749 $arShow[] =
"click";
4751 $arShow = array_unique($arShow);
4753 $arrLegend =
array();
4757 $rsD =
$DB->Query($strSql,
false, $err_mess.__LINE__);
4758 while ($arD = $rsD->Fetch())
4760 $arrDays[$arD[
"DATE_STAT"]][
"DATE"] = $arD[
"DATE_STAT"];
4761 $arrDays[$arD[
"DATE_STAT"]][
"D"] = $arD[
"DAY"];
4762 $arrDays[$arD[
"DATE_STAT"]][
"M"] = $arD[
"MONTH"];
4763 $arrDays[$arD[
"DATE_STAT"]][
"Y"] = $arD[
"YEAR"];
4765 foreach($arShow as $ctype)
4767 if ($ctype==
"CTR")
continue;
4768 $ctype_u = mb_strtoupper($ctype);
4769 if (intval($arD[$ctype_u.
"_COUNT"])>0)
4771 if (in_array($arD[
"CONTRACT_ID"], $arContract))
4773 if ($contract_total==
"N")
4775 $arrLegend[
"3_CONTRACT_".$arD[
"CONTRACT_ID"]][
"TYPE"] =
"CONTRACT";
4776 $arrLegend[
"3_CONTRACT_".$arD[
"CONTRACT_ID"]][
"ID"] = $arD[
"CONTRACT_ID"];
4777 $arrLegend[
"3_CONTRACT_".$arD[
"CONTRACT_ID"]][
"NAME"] = $arD[
"CONTRACT_NAME"];
4778 $arrLegend[
"3_CONTRACT_".$arD[
"CONTRACT_ID"]][
"COUNTER_TYPE"] =
"DETAIL";
4779 $arrLegend[
"3_CONTRACT_".$arD[
"CONTRACT_ID"]][$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4780 $arrDays[$arD[
"DATE_STAT"]][
"CONTRACT"][
"DETAIL_".$ctype_u][$arD[
"CONTRACT_ID"]] += $arD[$ctype_u.
"_COUNT"];
4782 elseif ($contract_total==
"Y")
4784 $arrLegend[
"3_CONTRACT"][
"TYPE"] =
"CONTRACT";
4785 $arrLegend[
"3_CONTRACT"][
"COUNTER_TYPE"] =
"TOTAL";
4786 $arrLegend[
"3_CONTRACT"][$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4787 $arrDays[$arD[
"DATE_STAT"]][
"CONTRACT"][
"TOTAL_".$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4790 if (in_array($arD[
"BANNER_ID"], $arBanner))
4792 if ($banner_total==
"N")
4794 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"TYPE"] =
"BANNER";
4795 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"ID"] = $arD[
"BANNER_ID"];
4796 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"TYPE_SID"] = $arD[
"BANNER_TYPE_SID"];
4797 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"GROUP"] = $arD[
"GROUP_SID"];
4798 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"NAME"] = $arD[
"BANNER_NAME"];
4799 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"CONTRACT_ID"] = $arD[
"CONTRACT_ID"];
4800 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][
"COUNTER_TYPE"] =
"DETAIL";
4801 $arrLegend[
"1_BANNER_".$arD[
"BANNER_ID"]][$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4802 $arrDays[$arD[
"DATE_STAT"]][
"BANNER"][
"DETAIL_".$ctype_u][$arD[
"BANNER_ID"]] += $arD[$ctype_u.
"_COUNT"];
4804 elseif ($banner_total==
"Y")
4806 $arrLegend[
"1_BANNER"][
"TYPE"] =
"BANNER";
4807 $arrLegend[
"1_BANNER"][
"COUNTER_TYPE"] =
"TOTAL";
4808 $arrLegend[
"1_BANNER"][$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4809 $arrDays[$arD[
"DATE_STAT"]][
"BANNER"][
"TOTAL_".$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4812 if (in_array($arD[
"GROUP_SID"], $arGroup))
4814 if ($group_total==
"N")
4816 $arrLegend[
"2_GROUP_".$arD[
"GROUP_SID"]][
"TYPE"] =
"GROUP";
4817 $arrLegend[
"2_GROUP_".$arD[
"GROUP_SID"]][
"ID"] = $arD[
"GROUP_SID"];
4818 $arrLegend[
"2_GROUP_".$arD[
"GROUP_SID"]][
"COUNTER_TYPE"] =
"DETAIL";
4819 $arrLegend[
"2_GROUP_".$arD[
"GROUP_SID"]][$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4820 $arrDays[$arD[
"DATE_STAT"]][
"GROUP"][
"DETAIL_".$ctype_u][$arD[
"GROUP_SID"]] += $arD[$ctype_u.
"_COUNT"];
4822 elseif ($group_total==
"Y")
4824 $arrLegend[
"2_GROUP"][
"TYPE"] =
"GROUP";
4825 $arrLegend[
"2_GROUP"][
"COUNTER_TYPE"] =
"TOTAL";
4826 $arrLegend[
"2_GROUP"][$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4827 $arrDays[$arD[
"DATE_STAT"]][
"GROUP"][
"TOTAL_".$ctype_u] += $arD[$ctype_u.
"_COUNT"];
4834 if (in_array(
"ctr", $arShow))
4837 foreach ($arrDays as $keyD => $arD)
4839 foreach ($arrLegend as $arrS)
4841 if ($arrS[
"COUNTER_TYPE"]==
"DETAIL")
4843 $show_value = intval($arD[$arrS[
"TYPE"]][$arrS[
"COUNTER_TYPE"].
"_SHOW"][$arrS[
"ID"]]);
4844 $click_value = intval($arD[$arrS[
"TYPE"]][$arrS[
"COUNTER_TYPE"].
"_CLICK"][$arrS[
"ID"]]);
4845 if ($show_value<=0) $ctr_value=0;
4846 else $ctr_value = round(($click_value*100)/$show_value, 2);
4847 $arD[$arrS[
"TYPE"]][
"DETAIL_CTR"][$arrS[
"ID"]] = $ctr_value;
4848 $arrDays[$keyD] = $arD;
4852 $show_value = intval($arD[$arrS[
"TYPE"]][$arrS[
"COUNTER_TYPE"].
"_SHOW"]);
4853 $click_value = intval($arD[$arrS[
"TYPE"]][$arrS[
"COUNTER_TYPE"].
"_CLICK"]);
4854 if ($show_value<=0) $ctr_value=0;
4855 else $ctr_value = round(($click_value*100)/$show_value, 2);
4856 $arD[$arrS[
"TYPE"]][
"TOTAL_CTR"] = $ctr_value;
4857 $arrDays[$keyD] = $arD;
4865 if (in_array(
"ctr", $arShow)) $s++;
4866 if (
$arFilter[
"WHAT_SHOW"]!=
array(
"ctr") && in_array(
"show", $arShow)) $s++;
4867 if (
$arFilter[
"WHAT_SHOW"]!=
array(
"ctr") && in_array(
"click", $arShow)) $s++;
4868 if (
$arFilter[
"WHAT_SHOW"]!=
array(
"ctr") && in_array(
"visitor", $arShow)) $s++;
4869 $total =
sizeof($arrLegend)*$s;
4871 foreach ($arrLegend as
$key =>
$arr)
4873 if (in_array(
"ctr", $arShow))
4876 $arr[
"COLOR_CTR"] = $color;
4877 if (
$arr[
"SHOW"]<=0) $ctr = 0;
4878 else $ctr = round((
$arr[
"CLICK"]*100)/
$arr[
"SHOW"], 2);
4883 if (in_array(
"show", $arShow))
4886 $arr[
"COLOR_SHOW"] = $color;
4888 if (in_array(
"click", $arShow))
4891 $arr[
"COLOR_CLICK"] = $color;
4893 if (in_array(
"visitor", $arShow))
4896 $arr[
"COLOR_VISITOR"] = $color;
4899 $arr[
"COLOR"] = $color;
4914 $arSqlSearch = Array();
4930 if( ((
string)
$val ==
'') || (
"$val"==
"NOT_REF") )
continue;
4936 $arSqlSearch[] =
"D.DATE_STAT>=".$DB->CharToDateFunction(
$val,
"SHORT");
4939 $arSqlSearch[] =
"D.DATE_STAT<=".$DB->CharToDateFunction(
$val.
" 23:59:59",
"FULL");
4949 $arSqlSearch[] = $where->_NumberIN(
"D.BANNER_ID",
$arFilter[
'BANNER_ID']);
4955 if ($by ==
"s_date")
4957 $strSqlOrder =
" ORDER BY D.DATE_STAT ";
4959 elseif ($by ==
"s_visitors")
4961 $strSqlOrder =
" ORDER BY VISITOR_COUNT ";
4963 elseif ($by ==
"s_clicks")
4965 $strSqlOrder =
" ORDER BY CLICK_COUNT ";
4969 $strSqlOrder =
" ORDER BY CTR";
4973 $strSqlOrder =
" ORDER BY SHOW_COUNT ";
4977 $strSqlOrder =
" ORDER BY D.BANNER_ID";
4981 $strSqlOrder =
" ORDER BY DATE_STAT";
4987 $strSqlOrder .=
" desc ";
4991 if ($by !=
"s_date")
4993 $strSqlOrder .=
', DATE_STAT ASC';
5000 ".$DB->DateToCharFunction(
"D.DATE_STAT",
"SHORT").
" DATE_STAT,
5001 SUM(D.SHOW_COUNT) SHOW_COUNT,
5002 SUM(D.CLICK_COUNT) CLICK_COUNT,
5003 SUM(D.VISITOR_COUNT) VISITOR_COUNT,
5006 b_adv_banner_2_day D
5007 INNER JOIN b_adv_banner B ON (D.BANNER_ID = B.ID)
5008 INNER JOIN b_adv_contract C ON (B.CONTRACT_ID = C.ID)
5019 ".$DB->DateToCharFunction(
"D.DATE_STAT",
"SHORT").
" DATE_STAT,
5020 SUM(D.SHOW_COUNT) SHOW_COUNT,
5021 SUM(D.CLICK_COUNT) CLICK_COUNT,
5022 SUM(D.VISITOR_COUNT) VISITOR_COUNT,
5027 b_adv_banner_2_day D
5028 INNER JOIN b_adv_banner B ON (D.BANNER_ID = B.ID)
5029 INNER JOIN b_adv_contract C ON (B.CONTRACT_ID = C.ID)
5032 GROUP by D.DATE_STAT, D.BANNER_ID, B.NAME
5037 return $DB->Query($strSql,
false, $err_mess.__LINE__);
5050 return "<br>Module: ".$module_id.
"<br>Class: CAdvType_all<br>File: ".__FILE__;
5057 $find_date_modify_1 =
$arFilter[
"DATE_MODIFY_1"];
5058 $find_date_modify_2 =
$arFilter[
"DATE_MODIFY_2"];
5059 if (trim($find_date_modify_1) <>
'' || trim($find_date_modify_2) <>
'')
5064 if (!$date1_stm && trim($find_date_modify_1) <>
'')
5066 else $date_1_ok =
true;
5067 if (!$date2_stm && trim($find_date_modify_2) <>
'')
5069 elseif ($date_1_ok && $date2_stm <= $date1_stm && $date2_stm <>
'')
5073 if (
$str <> '')
return false;
else return true;
5081 $strSql =
"SELECT max(SORT) MAX_SORT FROM b_adv_type";
5082 $z =
$DB->Query($strSql,
false, $err_mess.__LINE__);
5084 return intval(
$zr[
"MAX_SORT"])+100;
5092 if ($CHECK_RIGHTS==
"Y")
5103 if (in_array(
"SID", $arrKeys))
5105 if(trim($SID) ==
'')
5111 if (preg_match(
"/[^A-Za-z_0-9]/", $SID))
5119 $arFilter =
array(
"SID" => $SID.
" & ~".$OLD_SID,
"SID_EXACT_MATCH" =>
"Y");
5125 $rows = intval(
$rs->SelectedRowsCount());
5128 if (
$rows>=1 || $SID ==
"ALL" || $OLD_SID ==
"ALL")
5130 $str .= str_replace(
"#SID#", ($OLD_SID ==
"ALL" ? $OLD_SID : $SID),
GetMessage(
"AD_ERROR_SID_EXISTS"));
5139 if ($OLD_SID <>
'')
$str .=
GetMessage(
"AD_ERROR_NOT_ENOUGH_PERMISSIONS_TYPE").
"<br>";
5140 else $str .=
GetMessage(
"AD_ERROR_NOT_ENOUGH_PERMISSIONS_FOR_CREATE_TYPE").
"<br>";
5144 if (
$str <> '')
return false;
else return true;
5153 $OLD_SID = trim($OLD_SID);
5156 $arFields_i =
array();
5158 if (in_array(
"SID", $arrKeys))
5159 $arFields_i[
"SID"] =
"'".$DB->ForSql(
$arFields[
"SID"], 255).
"'";
5160 if (in_array(
"ACTIVE", $arrKeys) && (
$arFields[
"ACTIVE"]==
"Y" ||
$arFields[
"ACTIVE"]==
"N"))
5161 $arFields_i[
"ACTIVE"] =
"'".$arFields[
"ACTIVE"].
"'";
5162 if (in_array(
"SORT", $arrKeys))
5163 $arFields_i[
"SORT"] =
"'".intval(
$arFields[
"SORT"]).
"'";
5164 if (in_array(
"NAME", $arrKeys))
5165 $arFields_i[
"NAME"] =
"'".$DB->ForSql(
$arFields[
"NAME"], 255).
"'";
5166 if (in_array(
"DESCRIPTION", $arrKeys))
5167 $arFields_i[
"DESCRIPTION"] =
"'".$DB->ForSql(
$arFields[
"DESCRIPTION"], 2000).
"'";
5168 if (
count($arFields_i)>0)
5173 $arFields_i[
"DATE_MODIFY"] =
$DB->CharToDateFunction(
$arFields[
"DATE_MODIFY"]);
5175 $arFields_i[
"DATE_MODIFY"] =
$DB->GetNowFunction();
5177 if (in_array(
"MODIFIED_BY", $arrKeys))
5178 $arFields_i[
"MODIFIED_BY"] = intval(
$arFields[
"MODIFIED_BY"]);
5180 $arFields_i[
"MODIFIED_BY"] =
$USER->GetID();
5183 foreach ($arFields_i as $field => $value)
5185 if ($value ==
'')
$str .=
"$field = '', ";
else $str .=
"$field = $value, ";
5188 $strSql =
"UPDATE b_adv_type SET ".$str.
" WHERE SID='".
$DB->ForSql($OLD_SID, 255).
"'";
5189 $DB->Query($strSql,
false, $err_mess.__LINE__);
5191 if (in_array(
"SID", $arrKeys))
5199 $DB->Update(
"b_adv_banner",$arF,
"WHERE TYPE_SID='".
$DB->ForSql($OLD_SID, 255).
"'",$err_mess.__LINE__);
5203 $DB->Update(
"b_adv_contract_2_type",$arF,
"WHERE TYPE_SID='".
$DB->ForSql($OLD_SID, 255).
"'",$err_mess.__LINE__);
5206 else $SID = $OLD_SID;
5208 elseif ($arFields_i[
"SID"] <>
'')
5211 $arFields_i[
"DATE_CREATE"] =
$DB->CharToDateFunction(
$arFields[
"DATE_CREATE"]);
5213 $arFields_i[
"DATE_CREATE"] =
$DB->GetNowFunction();
5215 if (in_array(
"CREATED_BY", $arrKeys))
5216 $arFields_i[
"CREATED_BY"] = intval(
$arFields[
"CREATED_BY"]);
5218 $arFields_i[
"CREATED_BY"] =
$USER->GetID();
5221 $arFields_i[
"DATE_MODIFY"] =
$DB->CharToDateFunction(
$arFields[
"DATE_MODIFY"]);
5223 $arFields_i[
"DATE_MODIFY"] =
$DB->GetNowFunction();
5225 if (in_array(
"MODIFIED_BY", $arrKeys))
5226 $arFields_i[
"MODIFIED_BY"] = intval(
$arFields[
"MODIFIED_BY"]);
5228 $arFields_i[
"MODIFIED_BY"] =
$USER->GetID();
5231 foreach ($arFields_i as $field => $value)
5233 $str1 .= $field.
", ";
5234 if ($value ==
'') $str2 .=
"'', ";
else $str2 .=
"$value, ";
5236 $str1 = trim($str1,
", ");
5237 $str2 = trim($str2,
", ");
5238 $strSql =
"INSERT INTO b_adv_type (".$str1.
") VALUES (".$str2.
")";
5239 $DB->Query($strSql,
false, $err_mess.__LINE__);
5255 if (trim($TYPE_SID) ==
'')
return false;
5258 "SID_EXACT_MATCH" =>
"Y"
5265 public static function Delete($TYPE_SID, $CHECK_RIGHTS=
"Y")
5269 if ($TYPE_SID ==
'')
return false;
5270 if ($CHECK_RIGHTS==
"Y")
5280 $strSql =
"SELECT ID FROM b_adv_banner WHERE TYPE_SID = '".$DB->ForSql($TYPE_SID,255).
"'";
5281 $rs =
$DB->Query($strSql,
false, $err_mess.__LINE__);
5286 $strSql =
"DELETE FROM b_adv_type WHERE SID = '".$DB->ForSql($TYPE_SID,255).
"'";
5287 $DB->Query($strSql,
false, $err_mess.__LINE__);
5301 if ($TYPE_SID ==
'')
5306 $strSql =
"DELETE FROM b_adv_contract_2_type WHERE TYPE_SID = '".$DB->ForSql($TYPE_SID,255).
"'";
5307 $DB->Query($strSql,
false, $err_mess.__LINE__);
5316 $arSqlSearch = Array();
5317 if ($CHECK_RIGHTS==
"Y")
5329 $isAdvertiser =
true;
5331 if ($isAdmin || $isDemo || $isManager || $isAdvertiser)
5349 if( ((
string)
$val ==
'') || (
$val ===
"NOT_REF") )
5352 $match_value_set = (in_array(
$key.
"_EXACT_MATCH", $filter_keys)) ?
true :
false;
5357 $match = (
$arFilter[
$key.
"_EXACT_MATCH"]==
"N" && $match_value_set) ?
"Y" :
"N";
5360 case "DATE_MODIFY_1":
5361 $arSqlSearch[] =
"T.DATE_MODIFY>=".$DB->CharToDateFunction(
$val,
"SHORT");
5363 case "DATE_MODIFY_2":
5364 $arSqlSearch[] =
"T.DATE_MODIFY<=".$DB->CharToDateFunction(
$val.
" 23:59:59",
"FULL");
5367 $arSqlSearch[] = (
$val==
"Y") ?
"T.ACTIVE='Y'" :
"T.ACTIVE='N'";
5371 $match = (
$arFilter[
$key.
"_EXACT_MATCH"]==
"Y" && $match_value_set) ?
"N" :
"Y";
5378 if ($by ==
"s_sid") $strSqlOrder =
" ORDER BY T.SID ";
5379 elseif ($by ==
"s_date_modify") $strSqlOrder =
" ORDER BY T.DATE_MODIFY ";
5380 elseif ($by ==
"s_modified_by") $strSqlOrder =
" ORDER BY T.MODIFIED_BY ";
5381 elseif ($by ==
"s_date_create") $strSqlOrder =
" ORDER BY T.DATE_CREATE ";
5382 elseif ($by ==
"s_created_by") $strSqlOrder =
" ORDER BY T.CREATED_BY ";
5383 elseif ($by ==
"s_active") $strSqlOrder =
" ORDER BY T.ACTIVE ";
5384 elseif ($by ==
"s_name") $strSqlOrder =
" ORDER BY T.NAME ";
5385 elseif ($by ==
"s_banners") $strSqlOrder =
" ORDER BY BANNER_COUNT ";
5386 elseif ($by ==
"s_description") $strSqlOrder =
" ORDER BY T.DESCRIPTION ";
5389 $strSqlOrder =
" ORDER BY T.SORT ";
5394 $strSqlOrder .=
" desc ";
5398 $strSqlOrder .=
" asc ";
5404 if (!$isAdmin && !$isDemo && !$isManager)
5406 $strContracts =
"0";
5408 foreach ($arPermissions as $contract_id => $arContractPerms)
5410 if (is_array($arContractPerms) && !empty($arContractPerms))
5411 $strContracts .=
",".$contract_id;
5422 ".$DB->DateToCharFunction(
"T.DATE_CREATE").
" DATE_CREATE,
5423 ".
$DB->DateToCharFunction(
"T.DATE_MODIFY").
" DATE_MODIFY,
5426 count(distinct B.ID) BANNER_COUNT
5429 LEFT JOIN b_adv_banner B ON (B.TYPE_SID=T.SID".($strContracts ==
"" ?
"" :
" AND B.CONTRACT_ID IN (".$strContracts.
")").
")
5432 ($strContracts ==
"" ?
"" :
5433 "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.
")) "
5437 T.SID, T.ACTIVE, T.SORT, T.NAME, T.DESCRIPTION, T.DATE_CREATE, T.DATE_MODIFY, T.CREATED_BY, T.MODIFIED_BY
5441 $res =
$DB->Query($strSql,
false, $err_mess.__LINE__);
static normalizeArrayValuesByInt(&$map, $sorted=true)
static FixShow($arBanner)
static GetStatList($by, $order, $arFilter)
static DeleteGroupLink($BANNER_ID)
static Copy($BANNER_ID, $CHECK_RIGHTS="Y")
static GetPageArray($BANNER_ID, $SHOW="SHOW")
static GetRedirectURL($url, $arBanner)
static CalculateTimeDiff($arBanner)
static GetSiteArray($BANNER_ID)
static GetByID($BANNER_ID, $CHECK_RIGHTS="Y")
static Show($TYPE_SID, $HTML_BEFORE="", $HTML_AFTER="")
static makeFileArray($data, $del=false, $description=null, $options=array())
static GetKeywords($TYPE_SID="", $LOGIC="", $EXACT_MATCH="")
static arr_comp_uniform($a, $b)
static PrepareHTML($text, $arBanner)
static DeleteCountryLink($BANNER_ID)
static ReplaceURL($text, $arBanner)
static GetHTML($arBanner, $bNoIndex=false)
static GetDesiredKeywords($TYPE_SID="", $EXACT_MATCH="")
static SetCookie($arBanner, &$inc_banner_counter, &$inc_contract_counter)
static SetKeywords($keywords, $TYPE_SID="", $LOGIC="DESIRED")
static SetDesiredKeywords($keywords, $TYPE_SID="")
static DeletePageLink($BANNER_ID, $where="")
static SetRequiredKeywords($keywords, $TYPE_SID="")
static CheckFields($arFields, $BANNER_ID, $CHECK_RIGHTS="Y")
static DeleteSiteLink($BANNER_ID)
static CheckFile($arFile, $iMaxSize=0, $iMaxWidth=0, $iMaxHeight=0, $access_typies=array(), $bForceMD5=false, $bSkipExt=false)
static BeforeRestartBuffer()
static GetDynamicList($arFilter, &$arrLegend, &$is_filtered)
static GetRandomArray($TYPE_SID, $quantity=1)
static GetEditIcons($arBanner, $TYPE_SID="", $arIcons=array())
static GetStatAdvArray($BANNER_ID)
static GetRequiredKeywords($TYPE_SID="", $EXACT_MATCH="")
static CheckDynamicFilter($arFilter)
static __innerExtractBitrixDates($arBanner)
static ResetKeywords($TYPE_SID="", $LOGIC="", $EXACT_MATCH="")
static GetRandom($TYPE_SID)
static GetGroupArray($BANNER_ID)
static DeleteStatAdvLink($BANNER_ID)
static Delete($BANNER_ID, $CHECK_RIGHTS="Y")
static GetUniformityCoef($arBanner)
static SetCurUri($uri=false)
static DeleteWeekdayLink($BANNER_ID)
static Set($arFields, $BANNER_ID, $CHECK_RIGHTS="Y")
static GetCountryArray($BANNER_ID, $WHAT="COUNTRY")
static GetWeekdayArray($BANNER_ID)
static CalculateTimeProgress($arBanner)
static CalculateRotationProgress($arBanner)
static GetDynamicList_SQL($strSqlSearch)
static addBindField($field, $bannerField, &$modifyStatus)
static GetList($by='s_id', $order='desc', $arFilter=[], $is_filtered=null, $CHECK_RIGHTS="Y")
static Update($arFields, $BANNER_ID)
static GetPageWeights_RS()
static GetStatList($by, $order, $arFilter)
static Delete($CONTRACT_ID, $CHECK_RIGHTS="Y")
static GetEmailArrayByRole($role)
static GetTypeArray($CONTRACT_ID)
static GetGroupsByRole($role)
static GetAdvertisersArray()
static HaveRole($role, $USER_ID=false)
static GetUserPermissions($CONTRACT_ID=0, $USER_ID=false)
static DeleteWeekdayLink($CONTRACT_ID)
static GetMaxPermissionsArray()
static GetManagerEmails()
static DeletePageLink($CONTRACT_ID, $where="")
static DeleteTypeLink($CONTRACT_ID)
static IsAdmin($USER_ID=false)
static SendEMail($arContract, $mess="")
static DeleteSiteLink($CONTRACT_ID)
static GetOwnerEmails($CONTRACT_ID, &$OWNER_EMAIL, &$ADD_EMAIL, &$VIEW_EMAIL, &$EDIT_EMAIL)
static GetAdvertiserRoleID()
static GetContractPermissions($CONTRACT_ID)
static Set($arFields, $CONTRACT_ID, $CHECK_RIGHTS="Y")
static GetByID($CONTRACT_ID, $CHECK_RIGHTS="Y")
static GetManagerRoleID()
static GetPageArray($CONTRACT_ID, $SHOW="SHOW")
static DeleteUserLink($CONTRACT_ID, $where="")
static IsDemo($USER_ID=false)
static CheckFields($arFields, $CONTRACT_ID, $CHECK_RIGHTS="Y")
static GetSiteArray($CONTRACT_ID)
static IsAdvertiser($USER_ID=false)
static CheckFilter($arFilter)
static GetWeekdayArray($CONTRACT_ID)
static IsOwner($CONTRACT_ID, $USER_ID=false)
static IsManager($USER_ID=false)
static GetList($by="s_sort", $order="desc", $arFilter=[], $is_filtered=null, $CHECK_RIGHTS="Y")
static Delete($TYPE_SID, $CHECK_RIGHTS="Y")
static GetByID($TYPE_SID)
static DeleteContractLink($TYPE_SID)
static GetList($by="s_sort", $order="asc", $arFilter=[], $is_filtered=null, $CHECK_RIGHTS="Y")
static Set($arFields, $OLD_SID, $CHECK_RIGHTS="Y")
static CheckFields($arFields, $OLD_SID, $CHECK_RIGHTS)
static CheckFilter($arFilter)
static ClickAdv($BANNER_ID)
static GetList($by='c_sort', $order='asc', $arFilter=[], $SHOW_USERS_AMOUNT="N")
static GetGID($site_id=false)
static MakeFileArray($path, $mimetype=false, $skipInternal=false, $external_id="")
static URN2URI($urn, $server_name='')
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
global $arrADV_VIEWED_BANNERS
global $CACHE_ADVERTISING
const BANNER_UNIFORMITY_DIVERGENCE_COEF
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
$_SERVER["DOCUMENT_ROOT"]
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
GetNextRGB($base_color, $total)
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
if(!is_array($deviceNotifyCodes)) $access
CheckSerializedData($str, $max_depth=200)
ConvertDateTime($datetime, $to_format=false, $from_site=false, $bSearchInSitesOnly=false)
ExecuteModuleEventEx($arEvent, $arParams=[])
TrimArr(&$arr, $trim_value=false)
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
TxtToHTML( $str, $bMakeUrls=true, $iMaxStringLen=0, $QUOTE_ENABLED="N", $NOT_CONVERT_AMPERSAND="Y", $CODE_ENABLED="N", $BIU_ENABLED="N", $quote_table_class="quotetable", $quote_head_class="tdquotehead", $quote_body_class="tdquote", $code_table_class="codetable", $code_head_class="tdcodehead", $code_body_class="tdcodebody", $code_textarea_class="codetextarea", $link_class="txttohtmllink", $arUrlEvent=[], $link_target="_self")
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
GetMessage($name, $aReplace=null)
CheckDateTime($datetime, $format=false)
MkDateTime($strDT, $format="d.m.Y H:i:s")
MakeTimeStamp($datetime, $format=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($_SERVER $cookie_name['REQUEST_METHOD']=="POST" && $STAT_RIGHT=="W" && $RestoreDefaults<> '' &&check_bitrix_sessid())