Example #1
0
 function Set($arFields, $BANNER_ID, $CHECK_RIGHTS = "Y")
 {
     $err_mess = CAdvBanner_all::err_mess() . "<br>Function: Set<br>Line: ";
     global $DB, $USER;
     $BANNER_ID = intval($BANNER_ID);
     if (CAdvBanner::CheckFields($arFields, $BANNER_ID, $CHECK_RIGHTS)) {
         if ($CHECK_RIGHTS == "Y") {
             $USER_ID = intval($USER->GetID());
             $isAdmin = CAdvContract::IsAdmin();
             $isManager = CAdvContract::IsManager();
             $CHECK_CONTRACT_RIGHTS = "Y";
             if ($isManager) {
                 $CHECK_CONTRACT_RIGHTS = "N";
             }
         } else {
             $USER_ID = 0;
             $isAdmin = $isManager = true;
             $CHECK_CONTRACT_RIGHTS = "N";
         }
         $arFields_i = array();
         $arrKeys = array_keys($arFields);
         $arBanner = array();
         if ($BANNER_ID > 0) {
             $rsBanner = CAdvBanner::GetByID($BANNER_ID, $CHECK_RIGHTS);
             $arBanner = $rsBanner->Fetch();
             if (!in_array("CONTRACT_ID", $arrKeys)) {
                 $CONTRACT_ID = intval($arBanner["CONTRACT_ID"]);
             } else {
                 $CONTRACT_ID = intval($arFields["CONTRACT_ID"]);
             }
         } else {
             $CONTRACT_ID = intval($arFields["CONTRACT_ID"]);
         }
         $modify_status = "N";
         if ($CONTRACT_ID > 0) {
             if ($BANNER_ID <= 0 && (!$isAdmin || !$isManager || in_array("STATUS_SID", $arrKeys))) {
                 $modify_status = "Y";
             }
             $rsContract = CAdvContract::GetByID($CONTRACT_ID, $CHECK_CONTRACT_RIGHTS);
             $arContract = $rsContract->Fetch();
             if (($isAdmin || $isManager) && in_array("RESET_VISITOR_COUNT", $arrKeys) && $arFields["RESET_VISITOR_COUNT"]) {
                 $arFields_i["VISITOR_COUNT"] = 0;
                 // если баннер уже показывался то
                 if (intval($arBanner["VISITOR_COUNT"]) > 0) {
                     // уменьшим счетчик у контракта
                     $value = intval($arContract["VISITOR_COUNT"]) - intval($arBanner["VISITOR_COUNT"]);
                     $value = $value < 0 ? 0 : $value;
                     CAdvContract::Set(array("VISITOR_COUNT" => $value), $arContract["ID"], $CHECK_CONTRACT_RIGHTS);
                 }
             }
             if (($isAdmin || $isManager) && in_array("RESET_SHOW_COUNT", $arrKeys) && $arFields["RESET_SHOW_COUNT"]) {
                 $arFields_i["SHOW_COUNT"] = 0;
                 // если баннер уже показывался то
                 if (intval($arBanner["SHOW_COUNT"]) > 0) {
                     // уменьшим счетчик у контракта
                     $value = intval($arContract["SHOW_COUNT"]) - intval($arBanner["SHOW_COUNT"]);
                     $value = $value < 0 ? 0 : $value;
                     CAdvContract::Set(array("SHOW_COUNT" => $value), $arContract["ID"], $CHECK_CONTRACT_RIGHTS);
                 }
             }
             if (($isAdmin || $isManager) && in_array("FIX_CLICK", $arrKeys) && ($arFields["FIX_CLICK"] == "Y" || $arFields["FIX_CLICK"] == "N")) {
                 $arFields_i["FIX_CLICK"] = "'" . $arFields["FIX_CLICK"] . "'";
             }
             if (($isAdmin || $isManager) && in_array("FIX_SHOW", $arrKeys) && ($arFields["FIX_SHOW"] == "Y" || $arFields["FIX_SHOW"] == "N")) {
                 $arFields_i["FIX_SHOW"] = "'" . $arFields["FIX_SHOW"] . "'";
             }
             if (($isAdmin || $isManager) && in_array("FLYUNIFORM", $arrKeys) && ($arFields["FLYUNIFORM"] == "Y" || $arFields["FLYUNIFORM"] == "N")) {
                 $arFields_i["FLYUNIFORM"] = "'" . $arFields["FLYUNIFORM"] . "'";
             }
             if (($isAdmin || $isManager) && in_array("RESET_CLICK_COUNT", $arrKeys) && $arFields["RESET_CLICK_COUNT"]) {
                 $arFields_i["CLICK_COUNT"] = 0;
                 // если на баннер уже кликали то
                 if (intval($arBanner["CLICK_COUNT"]) > 0) {
                     // уменьшим счетчик у контракта
                     $value = intval($arContract["CLICK_COUNT"]) - intval($arBanner["CLICK_COUNT"]);
                     $value = $value < 0 ? 0 : $value;
                     CAdvContract::Set(array("CLICK_COUNT" => $value), $arContract["ID"], $CHECK_CONTRACT_RIGHTS);
                 }
             }
             if (($isAdmin || $isManager) && in_array("KEYWORDS", $arrKeys)) {
                 $arFields_i["KEYWORDS"] = "'" . $DB->ForSql($arFields["KEYWORDS"], 2000) . "'";
             }
             if (in_array("CONTRACT_ID", $arrKeys) && intval($arFields["CONTRACT_ID"]) > 0) {
                 $arFields_i["CONTRACT_ID"] = intval($arFields["CONTRACT_ID"]);
             }
             if (in_array("TYPE_SID", $arrKeys) && strlen($arFields["TYPE_SID"]) > 0) {
                 $arFields_i["TYPE_SID"] = "'" . $DB->ForSql($arFields["TYPE_SID"], 255) . "'";
                 if ("'" . $DB->ForSql($arBanner["TYPE_SID"], 255) . "'" != $arFields_i["TYPE_SID"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("NAME", $arrKeys)) {
                 $arFields_i["NAME"] = "'" . $DB->ForSql($arFields["NAME"], 255) . "'";
             }
             if (in_array("GROUP_SID", $arrKeys)) {
                 $arFields_i["GROUP_SID"] = "'" . $DB->ForSql($arFields["GROUP_SID"], 255) . "'";
             }
             if (in_array("ACTIVE", $arrKeys) && ($arFields["ACTIVE"] == "Y" || $arFields["ACTIVE"] == "N")) {
                 $arFields_i["ACTIVE"] = "'" . $arFields["ACTIVE"] . "'";
             }
             if (in_array("WEIGHT", $arrKeys)) {
                 $arFields_i["WEIGHT"] = intval($arFields["WEIGHT"]);
             }
             if (in_array("MAX_VISITOR_COUNT", $arrKeys)) {
                 if (strlen($arFields["MAX_VISITOR_COUNT"]) > 0) {
                     $arFields_i["MAX_VISITOR_COUNT"] = intval($arFields["MAX_VISITOR_COUNT"]);
                 } else {
                     $arFields_i["MAX_VISITOR_COUNT"] = "null";
                 }
             }
             if (in_array("SHOWS_FOR_VISITOR", $arrKeys)) {
                 if (strlen($arFields["SHOWS_FOR_VISITOR"]) > 0) {
                     $arFields_i["SHOWS_FOR_VISITOR"] = intval($arFields["SHOWS_FOR_VISITOR"]);
                 } else {
                     $arFields_i["SHOWS_FOR_VISITOR"] = "null";
                 }
             }
             if (in_array("MAX_SHOW_COUNT", $arrKeys)) {
                 if (strlen($arFields["MAX_SHOW_COUNT"]) > 0) {
                     $arFields_i["MAX_SHOW_COUNT"] = intval($arFields["MAX_SHOW_COUNT"]);
                 } else {
                     $arFields_i["MAX_SHOW_COUNT"] = "null";
                 }
             }
             if (in_array("MAX_CLICK_COUNT", $arrKeys)) {
                 if (strlen($arFields["MAX_CLICK_COUNT"]) > 0) {
                     $arFields_i["MAX_CLICK_COUNT"] = intval($arFields["MAX_CLICK_COUNT"]);
                 } else {
                     $arFields_i["MAX_CLICK_COUNT"] = "null";
                 }
             }
             if (in_array("DATE_SHOW_FROM", $arrKeys)) {
                 if (strlen($arFields["DATE_SHOW_FROM"]) > 0) {
                     $arFields_i["DATE_SHOW_FROM"] = $DB->CharToDateFunction($arFields["DATE_SHOW_FROM"]);
                 } else {
                     $arFields_i["DATE_SHOW_FROM"] = "null";
                 }
             }
             if (in_array("DATE_SHOW_TO", $arrKeys)) {
                 if (strlen($arFields["DATE_SHOW_TO"]) > 0) {
                     $time = "";
                     if (defined("FORMAT_DATE") && strlen($arFields["DATE_SHOW_TO"]) <= strlen(FORMAT_DATE)) {
                         $time = " 23:59:59";
                     }
                     $arFields_i["DATE_SHOW_TO"] = $DB->CharToDateFunction($arFields["DATE_SHOW_TO"] . $time);
                 } else {
                     $arFields_i["DATE_SHOW_TO"] = "null";
                 }
             }
             if (in_array("DATE_SHOW_FIRST", $arrKeys)) {
                 $arFields_i["DATE_SHOW_FIRST"] = "null";
             }
             if (in_array("arrIMAGE_ID", $arrKeys) && is_array($arFields["arrIMAGE_ID"])) {
                 $arIMAGE = $arFields["arrIMAGE_ID"];
                 $arIMAGE["MODULE_ID"] = "advertising";
                 if ($BANNER_ID > 0) {
                     $z = $DB->Query("SELECT IMAGE_ID FROM b_adv_banner WHERE ID='{$BANNER_ID}'", false, $err_mess . __LINE__);
                     $zr = $z->Fetch();
                     $arIMAGE["old_file"] = $zr["IMAGE_ID"];
                 }
                 if (strlen($arIMAGE["name"]) > 0 || strlen($arIMAGE["del"]) > 0) {
                     $subdir = COption::GetOptionString("advertising", "UPLOAD_SUBDIR");
                     $fid = CFile::SaveFile($arIMAGE, $subdir);
                     if (intval($fid) > 0) {
                         $arFields_i["IMAGE_ID"] = intval($fid);
                     } else {
                         $arFields_i["IMAGE_ID"] = "null";
                     }
                     if (intval($arBanner["IMAGE_ID"]) != intval($arFields_i["IMAGE_ID"])) {
                         $modify_status = "Y";
                     }
                 }
             }
             if (in_array("IMAGE_ALT", $arrKeys)) {
                 $arFields_i["IMAGE_ALT"] = "'" . $DB->ForSql($arFields["IMAGE_ALT"], 255) . "'";
                 if ("'" . $DB->ForSql($arBanner["IMAGE_ALT"], 255) . "'" != $arFields_i["IMAGE_ALT"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("URL", $arrKeys)) {
                 $arFields_i["URL"] = "'" . $DB->ForSql($arFields["URL"], 2000) . "'";
                 if ("'" . $DB->ForSql($arBanner["URL"], 2000) . "'" != $arFields_i["URL"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("URL_TARGET", $arrKeys)) {
                 $arFields_i["URL_TARGET"] = "'" . $DB->ForSql($arFields["URL_TARGET"], 255) . "'";
                 if ("'" . $DB->ForSql($arBanner["URL_TARGET"], 255) . "'" != $arFields_i["URL_TARGET"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("NO_URL_IN_FLASH", $arrKeys) && ($arFields["NO_URL_IN_FLASH"] == "Y" || $arFields["NO_URL_IN_FLASH"] == "N")) {
                 $arFields_i["NO_URL_IN_FLASH"] = "'" . $arFields["NO_URL_IN_FLASH"] . "'";
                 if ($arBanner["NO_URL_IN_FLASH"] != $arFields_i["NO_URL_IN_FLASH"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("CODE", $arrKeys)) {
                 $arFields_i["CODE"] = $arFields["CODE"];
                 if ($arBanner["CODE"] != $arFields_i["CODE"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("FLASH_JS", $arrKeys) && ($arFields["FLASH_JS"] == "Y" || $arFields["FLASH_JS"] == "N")) {
                 $arFields_i["FLASH_JS"] = "'" . $arFields["FLASH_JS"] . "'";
                 if ("'" . $arBanner["FLASH_JS"] . "'" != $arFields_i["FLASH_JS"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("FLASH_VER", $arrKeys)) {
                 $arFields_i["FLASH_VER"] = "'" . $DB->ForSQL($arFields["FLASH_VER"], 20) . "'";
                 if ("'" . $DB->ForSQL($arBanner["FLASH_VER"], 20) . "'" != $arFields_i["FLASH_VER"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("arrFlashIMAGE_ID", $arrKeys) && is_array($arFields["arrFlashIMAGE_ID"])) {
                 $arrFlashIMAGE = $arFields["arrFlashIMAGE_ID"];
                 $arrFlashIMAGE["MODULE_ID"] = "advertising";
                 if ($BANNER_ID > 0) {
                     $z = $DB->Query("SELECT FLASH_IMAGE FROM b_adv_banner WHERE ID='{$BANNER_ID}'", false, $err_mess . __LINE__);
                     if ($zr = $z->Fetch()) {
                         $arrFlashIMAGE["old_file"] = $zr["FLASH_IMAGE"];
                     }
                 }
                 if (strlen($arrFlashIMAGE["name"]) > 0 || strlen($arrFlashIMAGE["del"]) > 0) {
                     $subdir = COption::GetOptionString("advertising", "UPLOAD_SUBDIR");
                     $fid = CFile::SaveFile($arrFlashIMAGE, $subdir);
                     if (intval($fid) > 0) {
                         $arFields_i["FLASH_IMAGE"] = intval($fid);
                     } else {
                         $arFields_i["FLASH_IMAGE"] = "null";
                     }
                     if (intval($arBanner["FLASH_IMAGE"]) != intval($arFields_i["FLASH_IMAGE"])) {
                         $modify_status = "Y";
                     }
                 }
             }
             if (in_array("AD_TYPE", $arrKeys)) {
                 $arFields_i["AD_TYPE"] = "'" . $DB->ForSql($arFields["AD_TYPE"], 20) . "'";
                 if ("'" . $DB->ForSql($arBanner["AD_TYPE"], 20) . "'" != $arFields_i["AD_TYPE"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("FLASH_TRANSPARENT", $arrKeys)) {
                 $arFields_i["FLASH_TRANSPARENT"] = "'" . $DB->ForSql($arFields["FLASH_TRANSPARENT"], 11) . "'";
                 if ("'" . $DB->ForSql($arBanner["FLASH_TRANSPARENT"], 11) . "'" != $arFields_i["FLASH_TRANSPARENT"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("CODE_TYPE", $arrKeys)) {
                 $arFields_i["CODE_TYPE"] = $arFields["CODE_TYPE"] == "text" ? "'text'" : "'html'";
                 $value = $arBanner["CODE_TYPE"] == "text" ? "'text'" : "'html'";
                 if ($value != $arFields_i["CODE_TYPE"]) {
                     $modify_status = "Y";
                 }
             }
             if (in_array("STAT_EVENT_1", $arrKeys)) {
                 $arFields_i["STAT_EVENT_1"] = "'" . $DB->ForSql($arFields["STAT_EVENT_1"], 255) . "'";
             }
             if (in_array("STAT_EVENT_2", $arrKeys)) {
                 $arFields_i["STAT_EVENT_2"] = "'" . $DB->ForSql($arFields["STAT_EVENT_2"], 255) . "'";
             }
             if (in_array("STAT_EVENT_3", $arrKeys)) {
                 $arFields_i["STAT_EVENT_3"] = "'" . $DB->ForSql($arFields["STAT_EVENT_3"], 255) . "'";
             }
             if (in_array("FOR_NEW_GUEST", $arrKeys)) {
                 if ($arFields["FOR_NEW_GUEST"] == "Y" || $arFields["FOR_NEW_GUEST"] == "N") {
                     $arFields_i["FOR_NEW_GUEST"] = "'" . $arFields["FOR_NEW_GUEST"] . "'";
                 } elseif ($arFields["FOR_NEW_GUEST"] == "NOT_REF" || $arFields["FOR_NEW_GUEST"] == "ALL" || strlen($arFields["FOR_NEW_GUEST"]) <= 0) {
                     $arFields_i["FOR_NEW_GUEST"] = "null";
                 }
             }
             if (in_array("COMMENTS", $arrKeys)) {
                 $arFields_i["COMMENTS"] = "'" . $DB->ForSql($arFields["COMMENTS"], 2000) . "'";
             }
             if (($isAdmin || $isManager) && in_array("STATUS_COMMENTS", $arrKeys)) {
                 $arFields_i["STATUS_COMMENTS"] = "'" . $DB->ForSql($arFields["STATUS_COMMENTS"], 2000) . "'";
             }
             $email_notify = "N";
             if ($modify_status == "Y" || in_array("STATUS_SID", $arrKeys) && ($isAdmin || $isManager)) {
                 $new_status = $isAdmin || $isManager ? $arFields["STATUS_SID"] : $arContract["DEFAULT_STATUS_SID"];
                 $arFields_i["STATUS_SID"] = "'" . $DB->ForSql($new_status, 255) . "'";
                 // если статус изменился то
                 if ("'" . $DB->ForSql($arBanner["STATUS_SID"], 255) . "'" != $arFields_i["STATUS_SID"]) {
                     $email_notify = "Y";
                 }
             }
             if (in_array("arrSITE", $arrKeys)) {
                 $arFields_i["FIRST_SITE_ID"] = "''";
                 if (is_array($arFields["arrSITE"])) {
                     $arrSITE = array_unique($arFields["arrSITE"]);
                     reset($arrSITE);
                     list(, $site_id) = each($arrSITE);
                     $arFields_i["FIRST_SITE_ID"] = "'" . $DB->ForSql($site_id, 2) . "'";
                 }
             }
             if (in_array("SHOW_USER_GROUP", $arrKeys)) {
                 if ($arFields["SHOW_USER_GROUP"] == "Y" && (in_array("arrUSERGROUP", $arrKeys) && count($arFields["arrUSERGROUP"]) > 0)) {
                     $SHOW_USER_GROUP = "Y";
                 } else {
                     $SHOW_USER_GROUP = "N";
                 }
                 $arFields_i["SHOW_USER_GROUP"] = "'" . $DB->ForSql($SHOW_USER_GROUP, 1) . "'";
             }
             if (in_array("STAT_TYPE", $arrKeys)) {
                 if ($arFields["STAT_TYPE"] === "CITY") {
                     $arFields_i["STAT_TYPE"] = "'CITY'";
                 } elseif ($arFields["STAT_TYPE"] === "REGION") {
                     $arFields_i["STAT_TYPE"] = "'REGION'";
                 } else {
                     $arFields_i["STAT_TYPE"] = "'COUNTRY'";
                 }
             }
             if (intval($BANNER_ID) > 0) {
                 if (in_array("DATE_MODIFY", $arrKeys) && CheckDateTime($arFields["DATE_MODIFY"])) {
                     $arFields_i["DATE_MODIFY"] = $DB->CharToDateFunction($arFields["DATE_MODIFY"]);
                 } else {
                     $arFields_i["DATE_MODIFY"] = $DB->GetNowFunction();
                 }
                 if (in_array("MODIFIED_BY", $arrKeys)) {
                     $arFields_i["MODIFIED_BY"] = intval($arFields["MODIFIED_BY"]);
                 } else {
                     $arFields_i["MODIFIED_BY"] = $USER_ID;
                 }
                 CAdvBanner::Update($arFields_i, $BANNER_ID);
             } else {
                 if (in_array("DATE_CREATE", $arrKeys) && CheckDateTime($arFields["DATE_CREATE"])) {
                     $arFields_i["DATE_CREATE"] = $DB->CharToDateFunction($arFields["DATE_CREATE"]);
                 } else {
                     $arFields_i["DATE_CREATE"] = $DB->GetNowFunction();
                 }
                 if (in_array("CREATED_BY", $arrKeys)) {
                     $arFields_i["CREATED_BY"] = intval($arFields["CREATED_BY"]);
                 } else {
                     $arFields_i["CREATED_BY"] = $USER_ID;
                 }
                 if (in_array("DATE_MODIFY", $arrKeys) && CheckDateTime($arFields["DATE_MODIFY"])) {
                     $arFields_i["DATE_MODIFY"] = $DB->CharToDateFunction($arFields["DATE_MODIFY"]);
                 } else {
                     $arFields_i["DATE_MODIFY"] = $DB->GetNowFunction();
                 }
                 if (in_array("MODIFIED_BY", $arrKeys)) {
                     $arFields_i["MODIFIED_BY"] = intval($arFields["MODIFIED_BY"]);
                 } else {
                     $arFields_i["MODIFIED_BY"] = $USER_ID;
                 }
                 $BANNER_ID = CAdvBanner::Add($arFields_i);
             }
             $BANNER_ID = intval($BANNER_ID);
             if ($BANNER_ID > 0) {
                 if (in_array("arrSITE", $arrKeys)) {
                     CAdvBanner::DeleteSiteLink($BANNER_ID);
                     if (is_array($arFields["arrSITE"])) {
                         $arrSITE = array_unique($arFields["arrSITE"]);
                         reset($arrSITE);
                         foreach ($arrSITE as $sid) {
                             if (strlen(trim($sid)) > 0) {
                                 $strSql = "INSERT INTO b_adv_banner_2_site (BANNER_ID, SITE_ID) VALUES ({$BANNER_ID}, '" . $DB->ForSql($sid, 2) . "')";
                                 $DB->Query($strSql, false, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrSHOW_PAGE", $arrKeys)) {
                     CAdvBanner::DeletePageLink($BANNER_ID, " and SHOW_ON_PAGE='Y'");
                     if (is_array($arFields["arrSHOW_PAGE"])) {
                         $arrPage = array_unique($arFields["arrSHOW_PAGE"]);
                         foreach ($arrPage as $page) {
                             $page = trim($page);
                             if (strlen($page) > 0) {
                                 $arFields_i = array("BANNER_ID" => $BANNER_ID, "PAGE" => "'" . $DB->ForSql($page, 255) . "'", "SHOW_ON_PAGE" => "'Y'");
                                 $DB->Insert("b_adv_banner_2_page", $arFields_i, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrNOT_SHOW_PAGE", $arrKeys)) {
                     CAdvBanner::DeletePageLink($BANNER_ID, " and SHOW_ON_PAGE='N'");
                     if (is_array($arFields["arrNOT_SHOW_PAGE"])) {
                         $arrPage = array_unique($arFields["arrNOT_SHOW_PAGE"]);
                         foreach ($arrPage as $page) {
                             $page = trim($page);
                             if (strlen($page) > 0) {
                                 $arFields_i = array("BANNER_ID" => $BANNER_ID, "PAGE" => "'" . $DB->ForSql($page, 255) . "'", "SHOW_ON_PAGE" => "'N'");
                                 $DB->Insert("b_adv_banner_2_page", $arFields_i, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrCOUNTRY", $arrKeys)) {
                     $iCounter = 0;
                     CAdvBanner::DeleteCountryLink($BANNER_ID);
                     if (is_array($arFields["arrCOUNTRY"])) {
                         $arrCOUNTRY = array();
                         foreach ($arFields["arrCOUNTRY"] as $COUNTRY) {
                             if (is_array($COUNTRY)) {
                                 $COUNTRY["COUNTRY_ID"] = trim($COUNTRY["COUNTRY_ID"]);
                                 if (strlen($COUNTRY["COUNTRY_ID"]) <= 0) {
                                     continue;
                                 }
                                 $key = $COUNTRY["COUNTRY_ID"] . "|" . $COUNTRY["REGION"] . "|" . $COUNTRY["CITY_ID"];
                                 $strInsert = "'" . $DB->ForSQL($COUNTRY["COUNTRY_ID"], 2) . "', " . (strlen($COUNTRY["REGION"]) <= 0 ? "null" : "'" . $DB->ForSQL($COUNTRY["REGION"], 200) . "'") . ", " . (intval($COUNTRY["CITY_ID"]) <= 0 ? "null" : intval($COUNTRY["CITY_ID"])) . "";
                             } else {
                                 $COUNTRY = trim($COUNTRY);
                                 if (strlen($COUNTRY) <= 0) {
                                     continue;
                                 }
                                 $key = $COUNTRY . "||";
                                 $strInsert = "'" . $DB->ForSQL($COUNTRY, 2) . "', null, null";
                             }
                             $arrCOUNTRY[$key] = $strInsert;
                         }
                         foreach ($arrCOUNTRY as $strInsert) {
                             $strSql = "INSERT INTO b_adv_banner_2_country (BANNER_ID, COUNTRY_ID, REGION, CITY_ID) VALUES ({$BANNER_ID}, " . $strInsert . ")";
                             $DB->Query($strSql, false, $err_mess . __LINE__);
                             $iCounter++;
                         }
                     }
                     $DB->Query("UPDATE b_adv_banner SET STAT_COUNT = " . $iCounter . " WHERE ID = " . $BANNER_ID);
                 }
                 if (in_array("arrSTAT_ADV", $arrKeys)) {
                     CAdvBanner::DeleteStatAdvLink($BANNER_ID);
                     if (is_array($arFields["arrSTAT_ADV"])) {
                         $arrSTAT_ADV = array_unique($arFields["arrSTAT_ADV"]);
                         foreach ($arrSTAT_ADV as $aid) {
                             if (intval($aid) > 0) {
                                 $strSql = "INSERT INTO b_adv_banner_2_stat_adv (BANNER_ID, STAT_ADV_ID) VALUES ({$BANNER_ID}, '" . intval($aid) . "')";
                                 $DB->Query($strSql, false, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrWEEKDAY", $arrKeys)) {
                     CAdvBanner::DeleteWeekdayLink($BANNER_ID);
                     if (is_array($arFields["arrWEEKDAY"])) {
                         $arrWeekday = array_keys($arFields["arrWEEKDAY"]);
                         $arrWeekday = array_unique($arrWeekday);
                         if (is_array($arrWeekday) && count($arrWeekday) > 0) {
                             foreach ($arrWeekday as $weekday) {
                                 if (is_array($arFields["arrWEEKDAY"][$weekday]) && count($arFields["arrWEEKDAY"][$weekday]) > 0) {
                                     $arrHour = $arFields["arrWEEKDAY"][$weekday];
                                     array_walk($arrHour, create_function("&\$item", "\$item=intval(\$item);"));
                                     $arrHour = array_unique($arrHour);
                                     foreach ($arrHour as $hour) {
                                         if ($hour >= 0 && $hour <= 23) {
                                             $strSql = "INSERT INTO b_adv_banner_2_weekday (BANNER_ID, C_WEEKDAY, C_HOUR) VALUES ({$BANNER_ID}, '" . $DB->ForSql($weekday, 10) . "', {$hour})";
                                             $DB->Query($strSql, false, $err_mess . __LINE__);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if (in_array("arrUSERGROUP", $arrKeys)) {
                     CAdvBanner::DeleteGroupLink($BANNER_ID);
                     if (is_array($arFields["arrUSERGROUP"])) {
                         $arrGROUPS = array_unique($arFields["arrUSERGROUP"]);
                         foreach ($arrGROUPS as $uid) {
                             if (intval($uid) > 0) {
                                 $strSql = "INSERT INTO b_adv_banner_2_group (BANNER_ID, GROUP_ID) VALUES ({$BANNER_ID}, " . IntVal($uid) . ")";
                                 $DB->Query($strSql, false, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 // если необходимо оповестить
                 $SEND_EMAIL = $arFields["SEND_EMAIL"] == "N" ? "N" : "Y";
                 if ($email_notify == "Y" && (!$isAdmin || !$isManager || $SEND_EMAIL == "Y")) {
                     // получаем данные по баннеру
                     CTimeZone::Disable();
                     $rsBanner = CAdvBanner::GetByID($BANNER_ID, $CHECK_RIGHTS);
                     CTimeZone::Enable();
                     if ($arBanner = $rsBanner->Fetch()) {
                         $BCC = array();
                         $OWNER_EMAIL = array();
                         $ADD_EMAIL = array();
                         $STAT_EMAIL = array();
                         $EDIT_EMAIL = array();
                         $MANAGER_EMAIL = CAdvContract::GetManagerEmails();
                         $ADMIN_EMAIL = CAdvContract::GetAdminEmails();
                         $ADMIN_EMAIL = array_merge($MANAGER_EMAIL, $ADMIN_EMAIL);
                         $ADMIN_EMAIL = array_unique($ADMIN_EMAIL);
                         CAdvContract::GetOwnerEmails($CONTRACT_ID, $OWNER_EMAIL, $ADD_EMAIL, $STAT_EMAIL, $EDIT_EMAIL);
                         $CREATED_BY = $MODIFIED_BY = 0;
                         if (intval($arBanner["CREATED_BY"]) > 0) {
                             $rsUser = CUser::GetByID($arBanner["CREATED_BY"]);
                             if ($arUser = $rsUser->Fetch()) {
                                 $CREATED_BY = "[" . $arUser["ID"] . "] (" . $arUser["LOGIN"] . ") " . $arUser["NAME"] . " " . $arUser["LAST_NAME"];
                             }
                         }
                         if (intval($arBanner["MODIFIED_BY"]) == intval($arBanner["CREATED_BY"]) && intval($arBanner["CREATED_BY"]) > 0) {
                             $MODIFIED_BY = $CREATED_BY;
                         } elseif (intval($arBanner["MODIFIED_BY"]) > 0) {
                             $rsUser = CUser::GetByID($arBanner["MODIFIED_BY"]);
                             if ($arUser = $rsUser->Fetch()) {
                                 $MODIFIED_BY = "[" . $arUser["ID"] . "] (" . $arUser["LOGIN"] . ") " . $arUser["NAME"] . " " . $arUser["LAST_NAME"];
                             }
                         }
                         $arImage = CFile::GetFileArray($arBanner["IMAGE_ID"]);
                         if ($arImage) {
                             $IMAGE_LINK = CHTTP::URN2URI($arImage["SRC"]);
                         } else {
                             $IMAGE_LINK = "";
                         }
                         $arImage = CFile::GetFileArray($arBanner["FLASH_IMAGE"]);
                         if ($arImage) {
                             $FLASHIMAGE_LINK = CHTTP::URN2URI($arImage["SRC"]);
                         } else {
                             $FLASHIMAGE_LINK = "";
                         }
                         $EMAIL_TO = $OWNER_EMAIL;
                         if (count($EMAIL_TO) <= 0) {
                             $EMAIL_TO = $ADMIN_EMAIL;
                         } else {
                             $BCC = $ADMIN_EMAIL;
                         }
                         $arEventFields = array("ID" => $arBanner["ID"], "EMAIL_TO" => implode(",", $EMAIL_TO), "ADMIN_EMAIL" => implode(",", $ADMIN_EMAIL), "ADD_EMAIL" => implode(",", $ADD_EMAIL), "STAT_EMAIL" => implode(",", $STAT_EMAIL), "EDIT_EMAIL" => implode(",", $EDIT_EMAIL), "OWNER_EMAIL" => implode(",", $OWNER_EMAIL), "BCC" => implode(",", $BCC), "CONTRACT_ID" => $CONTRACT_ID, "CONTRACT_NAME" => $arContract["NAME"], "TYPE_SID" => $arBanner["TYPE_SID"], "TYPE_NAME" => $arBanner["TYPE_NAME"], "STATUS" => strlen($arBanner["STATUS_SID"]) > 0 ? GetMessage("AD_STATUS_" . $arBanner["STATUS_SID"]) : "", "STATUS_COMMENTS" => $arBanner["STATUS_COMMENTS"], "NAME" => $arBanner["NAME"], "GROUP_SID" => $arBanner["GROUP_SID"], "INDICATOR" => GetMessage("AD_" . strtoupper($arBanner["LAMP"]) . "_BANNER_STATUS"), "ACTIVE" => $arBanner["ACTIVE"], "MAX_SHOW_COUNT" => $arBanner["MAX_SHOW_COUNT"], "SHOW_COUNT" => $arBanner["SHOW_COUNT"], "MAX_CLICK_COUNT" => $arBanner["MAX_CLICK_COUNT"], "CLICK_COUNT" => $arBanner["CLICK_COUNT"], "DATE_LAST_SHOW" => $arBanner["DATE_LAST_SHOW"], "DATE_LAST_CLICK" => $arBanner["DATE_LAST_CLICK"], "DATE_SHOW_FROM" => $arBanner["DATE_SHOW_FROM"], "DATE_SHOW_TO" => $arBanner["DATE_SHOW_TO"], "IMAGE_LINK" => $IMAGE_LINK, "IMAGE_ALT" => $arBanner["IMAGE_ALT"], "URL" => $arBanner["URL"], "URL_TARGET" => $arBanner["URL_TARGET"], "NO_URL_IN_FLASH" => $arBanner["NO_URL_IN_FLASH"], "CODE" => $arBanner["CODE"], "CODE_TYPE" => $arBanner["CODE_TYPE"], "COMMENTS" => $arBanner["COMMENTS"], "DATE_CREATE" => $arBanner["DATE_CREATE"], "CREATED_BY" => $CREATED_BY, "DATE_MODIFY" => $arBanner["DATE_MODIFY"], "MODIFIED_BY" => $MODIFIED_BY, "AD_TYPE" => $arBanner["AD_TYPE"], "FLASH_TRANSPARENT" => $arBanner["FLASH_TRANSPARENT"], "FLASH_IMAGE_LINK" => $FLASHIMAGE_LINK, "FLASH_JS" => $arBanner["FLASH_JS"], "FLASH_VER" => $arBanner["FLASH_VER"]);
                         $arrSITE = CAdvBanner::GetSiteArray($arBanner["ID"]);
                         CEvent::Send("ADV_BANNER_STATUS_CHANGE", $arrSITE, $arEventFields);
                     }
                 }
             }
         }
     }
     return $BANNER_ID;
 }
}
// обработка действий групповых и одиночных
if ($arID = $lAdmin->GroupAction()) {
    if ($_REQUEST['action_target'] == 'selected') {
        $arID = array();
        $rsData = CAdvBanner::GetList($by, $order, $arFilter);
        while ($arRes = $rsData->Fetch()) {
            $arID[] = $arRes['ID'];
        }
    }
    foreach ($arID as $ID) {
        if (IntVal($ID) <= 0) {
            continue;
        }
        $ID = IntVal($ID);
        $ifrsBanner = CAdvBanner::GetByID($ID);
        if ($ifarBanner = $ifrsBanner->Fetch()) {
            $ifCONTRACT_ID = $ifarBanner["CONTRACT_ID"];
        }
        if (is_array($arrPERM[$ifCONTRACT_ID]) && in_array("ADD", $arrPERM[$ifCONTRACT_ID])) {
            switch ($_REQUEST['action']) {
                case "delete":
                    @set_time_limit(0);
                    $DB->StartTransaction();
                    if (!CAdvBanner::Delete($ID)) {
                        $DB->Rollback();
                        $lAdmin->AddGroupError(GetMessage("DELETE_ERROR"), $ID);
                    }
                    $DB->Commit();
                    break;
                case "activate":
Example #3
0
 protected function loadPreview()
 {
     global $APPLICATION;
     if ($banner = CAdvBanner::GetByID($this->arParams["BANNER_ID"])->Fetch()) {
         if ($banner["AD_TYPE"] == 'template') {
             $this->templateProps = unserialize($banner["TEMPLATE"]);
             $this->templateFiles = unserialize($banner["TEMPLATE_FILES"]);
             foreach ($this->templateProps['PROPS'] as $k => $v) {
                 ob_start();
                 $APPLICATION->IncludeComponent('bitrix:advertising.banner.view', $this->templateProps['NAME'], array('PROPS' => $v, 'FILES' => $this->templateFiles[$k], 'EXT_MODE' => $this->templateProps['MODE'], 'INDEX' => $this->bannerIndex, 'PREVIEW' => $this->arParams['PREVIEW'], 'CASUAL_PROPERTIES' => array('TYPE' => $banner['AD_TYPE'])), null, array('HIDE_ICONS' => 'Y'));
                 $strReturn = CAdvBanner::PrepareHTML(ob_get_contents(), $banner);
                 ob_end_clean();
                 $this->arResult["BANNERS"][] = $strReturn;
                 $this->bannerIndex++;
             }
             $this->arResult["BANNERS_PROPERTIES"][] = $banner;
         }
         $this->arResult['SIZE'] = $this->getBannerSize();
     } else {
         $this->arResult = array();
     }
 }