echo GetMessage("AD_F_LAMP");
?>
:</td>
	<td><?php 
$arr = array("reference" => array(GetMessage("AD_RED"), GetMessage("AD_GREEN")), "reference_id" => array("red", "green"));
echo SelectBoxFromArray("find_lamp", $arr, htmlspecialcharsbx($find_lamp), GetMessage("AD_ALL"));
?>
</td>
</tr>
<tr>
	<td valign="top"><?php 
echo GetMessage("AD_F_STATUS");
?>
:<br><img src="/bitrix/images/advertising/mouse.gif" width="44" height="21" border=0 alt=""></td>
	<td><?php 
$arrStatus = CAdvBanner::GetStatusList();
echo SelectBoxMFromArray("find_status_sid[]", $arrStatus, $find_status_sid, "", false, "3");
?>
</td>
</tr>
<tr>
	<td valign="top"><?php 
echo GetMessage("AD_F_SITE");
?>
:<br><img src="/bitrix/images/advertising/mouse.gif" width="44" height="21" border=0 alt=""></td>
	<td><?php 
$ref = array();
$ref_id = array();
$rs = CSite::GetList($v1 = "sort", $v2 = "asc");
while ($ar = $rs->Fetch()) {
    $ref[] = "[" . $ar["ID"] . "] " . $ar["NAME"];
Exemple #2
0
 function Set($arFields, $CONTRACT_ID, $CHECK_RIGHTS = "Y")
 {
     $err_mess = CAdvContract_all::err_mess() . "<br>Function: Set<br>Line: ";
     global $DB, $USER;
     if (CAdvContract::CheckFields($arFields, $CONTRACT_ID, $CHECK_RIGHTS)) {
         if ($CHECK_RIGHTS == "Y") {
             $USER_ID = intval($USER->GetID());
             $isAdmin = CAdvContract::IsAdmin();
         } else {
             if (is_object($USER)) {
                 $USER_ID = intval($USER->GetID());
             } else {
                 $USER_ID = 0;
             }
             $isAdmin = true;
         }
         $check_activity = "N";
         $arFields_i = array();
         $arrKeys = array_keys($arFields);
         if ($isAdmin) {
             if (in_array("SHOW_COUNT", $arrKeys)) {
                 $check_activity = "Y";
                 $arFields_i["SHOW_COUNT"] = intval($arFields["SHOW_COUNT"]);
             }
             if (in_array("VISITOR_COUNT", $arrKeys)) {
                 $check_activity = "Y";
                 $arFields_i["VISITOR_COUNT"] = intval($arFields["VISITOR_COUNT"]);
             }
             if (in_array("CLICK_COUNT", $arrKeys)) {
                 $check_activity = "Y";
                 $arFields_i["CLICK_COUNT"] = intval($arFields["CLICK_COUNT"]);
             }
             if (in_array("ACTIVE", $arrKeys) && ($arFields["ACTIVE"] == "Y" || $arFields["ACTIVE"] == "N")) {
                 $check_activity = "Y";
                 $arFields_i["ACTIVE"] = "'" . $arFields["ACTIVE"] . "'";
             }
             if (in_array("WEIGHT", $arrKeys)) {
                 $arFields_i["WEIGHT"] = intval($arFields["WEIGHT"]);
             }
             if (in_array("ADMIN_COMMENTS", $arrKeys)) {
                 $arFields_i["ADMIN_COMMENTS"] = "'" . $DB->ForSql($arFields["ADMIN_COMMENTS"], 2000) . "'";
             }
             if (in_array("KEYWORDS", $arrKeys)) {
                 $arFields_i["KEYWORDS"] = "'" . $DB->ForSql($arFields["KEYWORDS"], 2000) . "'";
             }
             if (in_array("MAX_SHOW_COUNT", $arrKeys)) {
                 $check_activity = "Y";
                 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_VISITOR_COUNT", $arrKeys)) {
                 $check_activity = "Y";
                 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("MAX_CLICK_COUNT", $arrKeys)) {
                 $check_activity = "Y";
                 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)) {
                 $check_activity = "Y";
                 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)) {
                 $check_activity = "Y";
                 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("DEFAULT_STATUS_SID", $arrKeys)) {
                 $arrStatus = CAdvBanner::GetStatusList("N");
                 $arrV = array_values($arrStatus["reference_id"]);
                 if (in_array($arFields["DEFAULT_STATUS_SID"], $arrV)) {
                     $arFields_i["DEFAULT_STATUS_SID"] = "'" . $DB->ForSql($arFields["DEFAULT_STATUS_SID"], 255) . "'";
                 }
             }
             if (in_array("SORT", $arrKeys)) {
                 $arFields_i["SORT"] = intval($arFields["SORT"]);
             }
             if (in_array("NAME", $arrKeys)) {
                 $arFields_i["NAME"] = "'" . $DB->ForSql($arFields["NAME"], 255) . "'";
             }
             if (in_array("DESCRIPTION", $arrKeys)) {
                 $arFields_i["DESCRIPTION"] = "'" . $DB->ForSql($arFields["DESCRIPTION"], 2000) . "'";
             }
         }
         $arFields_i["EMAIL_COUNT"] = 0;
         $str_PREV_LAMP = "";
         if (intval($CONTRACT_ID) > 0) {
             $rsContract = CAdvContract::GetByID($CONTRACT_ID);
             $arContract = $rsContract->Fetch();
             $str_PREV_LAMP = $arContract["LAMP"];
             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;
             }
             $DB->Update("b_adv_contract", $arFields_i, "WHERE ID='" . intval($CONTRACT_ID) . "'", $err_mess . __LINE__);
         } elseif ($isAdmin) {
             $check_activity = "Y";
             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;
             }
             $CONTRACT_ID = $DB->Insert("b_adv_contract", $arFields_i, $err_mess . __LINE__);
         }
         $CONTRACT_ID = intval($CONTRACT_ID);
         if ($CONTRACT_ID > 0) {
             if ($isAdmin) {
                 if (in_array("arrSITE", $arrKeys)) {
                     CAdvContract::DeleteSiteLink($CONTRACT_ID);
                     if (is_array($arFields["arrSITE"])) {
                         $arrSite = array_unique($arFields["arrSITE"]);
                         foreach ($arrSite as $sid) {
                             if (strlen(trim($sid)) > 0) {
                                 $strSql = "INSERT INTO b_adv_contract_2_site(CONTRACT_ID, SITE_ID) VALUES ({$CONTRACT_ID}, '" . $DB->ForSql($sid, 2) . "')";
                                 $DB->Query($strSql, false, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrSHOW_PAGE", $arrKeys)) {
                     CAdvContract::DeletePageLink($CONTRACT_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("CONTRACT_ID" => $CONTRACT_ID, "PAGE" => "'" . $DB->ForSql($page, 255) . "'", "SHOW_ON_PAGE" => "'Y'");
                                 $DB->Insert("b_adv_contract_2_page", $arFields_i, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrNOT_SHOW_PAGE", $arrKeys)) {
                     CAdvContract::DeletePageLink($CONTRACT_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("CONTRACT_ID" => $CONTRACT_ID, "PAGE" => "'" . $DB->ForSql($page, 255) . "'", "SHOW_ON_PAGE" => "'N'");
                                 $DB->Insert("b_adv_contract_2_page", $arFields_i, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrTYPE", $arrKeys)) {
                     CAdvContract::DeleteTypeLink($CONTRACT_ID);
                     if (is_array($arFields["arrTYPE"])) {
                         $arrType = array_unique($arFields["arrTYPE"]);
                         foreach ($arrType as $type) {
                             if (strlen(trim($type)) > 0) {
                                 $strSql = "INSERT INTO b_adv_contract_2_type(CONTRACT_ID, TYPE_SID) VALUES ({$CONTRACT_ID}, '" . $DB->ForSql($type, 255) . "')";
                                 $DB->Query($strSql, false, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
                 if (in_array("arrWEEKDAY", $arrKeys)) {
                     CAdvContract::DeleteWeekdayLink($CONTRACT_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_contract_2_weekday (CONTRACT_ID, C_WEEKDAY, C_HOUR) VALUES (" . $CONTRACT_ID . ", '" . $DB->ForSql($weekday, 10) . "', " . $hour . ")";
                                             $DB->Query($strSql, false, $err_mess . __LINE__);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (in_array("arrUSER_VIEW", $arrKeys)) {
                 CAdvContract::DeleteUserLink($CONTRACT_ID, " and PERMISSION = 'VIEW'");
                 if (is_array($arFields["arrUSER_VIEW"])) {
                     $arrUser = array_unique($arFields["arrUSER_VIEW"]);
                     foreach ($arrUser as $user_id) {
                         if (intval($user_id) > 0) {
                             $arFields_i = array("CONTRACT_ID" => $CONTRACT_ID, "USER_ID" => intval($user_id), "PERMISSION" => "'VIEW'");
                             $DB->Insert("b_adv_contract_2_user", $arFields_i, $err_mess . __LINE__);
                         }
                     }
                 }
             }
             if (in_array("arrUSER_ADD", $arrKeys)) {
                 CAdvContract::DeleteUserLink($CONTRACT_ID, " and PERMISSION = 'ADD'");
                 if (is_array($arFields["arrUSER_ADD"])) {
                     $arrUser = array_unique($arFields["arrUSER_ADD"]);
                     foreach ($arrUser as $user_id) {
                         if (intval($user_id) > 0) {
                             $arFields_i = array("CONTRACT_ID" => $CONTRACT_ID, "USER_ID" => intval($user_id), "PERMISSION" => "'ADD'");
                             $DB->Insert("b_adv_contract_2_user", $arFields_i, $err_mess . __LINE__);
                         }
                     }
                 }
             }
             if ($isAdmin) {
                 if (in_array("arrUSER_EDIT", $arrKeys)) {
                     CAdvContract::DeleteUserLink($CONTRACT_ID, " and PERMISSION = 'EDIT'");
                     if (is_array($arFields["arrUSER_EDIT"])) {
                         $arrUser = array_unique($arFields["arrUSER_EDIT"]);
                         foreach ($arrUser as $user_id) {
                             if (intval($user_id) > 0) {
                                 $arFields_i = array("CONTRACT_ID" => $CONTRACT_ID, "USER_ID" => intval($user_id), "PERMISSION" => "'EDIT'");
                                 $DB->Insert("b_adv_contract_2_user", $arFields_i, $err_mess . __LINE__);
                             }
                         }
                     }
                 }
             }
             if ($check_activity == "Y") {
                 CTimeZone::Disable();
                 $rsContract = CAdvContract::GetByID($CONTRACT_ID);
                 CTimeZone::Enable();
                 $arContract = $rsContract->Fetch();
                 $str_CURRENT_LAMP = $arContract["LAMP"];
                 if ($str_PREV_LAMP != $str_CURRENT_LAMP) {
                     $mess = $str_CURRENT_LAMP == "red" ? "< " . GetMessage("AD_CONTRACT_NOT_ACTIVE") . " >" : "< " . GetMessage("AD_CONTRACT_ACTIVE") . " >";
                     CAdvContract::SendEMail($arContract, $mess);
                 }
                 if ($str_CURRENT_LAMP == "red") {
                     $arFields = array("EMAIL_COUNT" => "EMAIL_COUNT + 1");
                     $DB->Update("b_adv_contract", $arFields, "WHERE ID='" . $CONTRACT_ID . "'", $err_mess . __LINE__);
                 }
             }
         }
     }
     return $CONTRACT_ID;
 }