use Bitrix\Sale\Location;
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
$saleModulePermissions = $APPLICATION->GetGroupRight("sale");
if ($saleModulePermissions < "W")
$APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
IncludeModuleLangFile(__FILE__);
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/sale/include.php");
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/sale/prolog.php");
$aTabs = array(
array(
"DIV" => "edit1",
"TAB" => GetMessage("SDEN_TAB_DELIVERY"),
"ICON" => "sale",
"TITLE" => GetMessage("SDEN_TAB_DELIVERY_DESCR"),
),
array(
"DIV" => "edit2",
"TAB" => GetMessage("SDEN_TAB_PAYSYSTEM"),
"ICON" => "sale",
"TITLE" => GetMessage("SDEN_TAB_PAYSYSTEM_DESCR"),
),
);
$tabControl = new CAdminTabControl("tabControl", $aTabs);
ClearVars();
$ID = intval($ID);
$strError = "";
$bInitVars = false;
$lpEnabled = !!CSaleLocation::isLocationProEnabled();
if ((strlen($save)>0 || strlen($apply)>0) && $_SERVER['REQUEST_METHOD']=="POST" && $saleModulePermissions=="W" && check_bitrix_sessid())
{
$store = "";
if (isset($_POST["STORE"]) && count($_POST["STORE"]) > 0)
$store = serialize($_POST["STORE"]);
$LID = Trim($LID);
if (strlen($LID)<=0)
$strError .= GetMessage("ERROR_NO_LID")."
";
$NAME = Trim($NAME);
if (strlen($NAME)<=0)
$strError .= GetMessage("ERROR_NO_NAME")."
";
$PRICE = str_replace(",", ".", $PRICE);
$PRICE = DoubleVal($PRICE);
if ($PRICE<0)
$strError .= GetMessage("ERROR_NO_PRICE")."
";
$CURRENCY = Trim($CURRENCY);
if (strlen($CURRENCY)<=0)
$strError .= GetMessage("ERROR_NO_CURRENCY")."
";
$ORDER_PRICE_FROM = str_replace(",", ".", $ORDER_PRICE_FROM);
$ORDER_PRICE_TO = str_replace(",", ".", $ORDER_PRICE_TO);
$ORDER_CURRENCY = Trim($ORDER_CURRENCY);
if ((DoubleVal($ORDER_PRICE_FROM)>0 || DoubleVal($ORDER_PRICE_TO)>0) && strlen($ORDER_CURRENCY)<=0)
$strError .= GetMessage("ERROR_PRICE_NO_CUR")."
";
if ($ACTIVE!="Y") $ACTIVE = "N";
$SORT = intval($SORT);
if ($SORT<=0) $SORT = 100;
$arLocation = array();
if($lpEnabled)
{
if(strlen($_REQUEST['LOCATION']['L']))
$LOCATION1 = explode(':', $_REQUEST['LOCATION']['L']);
if(strlen($_REQUEST['LOCATION']['G']))
$LOCATION2 = explode(':', $_REQUEST['LOCATION']['G']);
}
if (isset($LOCATION1) && is_array($LOCATION1) && count($LOCATION1)>0)
{
$locationCount = count($LOCATION1);
for ($i = 0; $i<$locationCount; $i++)
{
if (strlen($LOCATION1[$i]))
{
$arLocation[] = array(
"LOCATION_ID" => $LOCATION1[$i],
"LOCATION_TYPE" => "L"
);
}
}
}
if (isset($LOCATION2) && is_array($LOCATION2) && count($LOCATION2)>0)
{
$locationCount = count($LOCATION2);
for ($i = 0; $i<$locationCount; $i++)
{
if (strlen($LOCATION2[$i])>0)
{
$arLocation[] = array(
"LOCATION_ID" => $LOCATION2[$i],
"LOCATION_TYPE" => "G"
);
}
}
}
if (!is_array($arLocation) || count($arLocation)<=0)
$strError .= GetMessage("ERROR_NO_LOCATION")."
";
if ($strError == '')
{
unset($arFields);
//add logotip
$arPicture = array();
if(array_key_exists("LOGOTIP", $_FILES) && $_FILES["LOGOTIP"]["error"] == 0)
$arPicture = $_FILES["LOGOTIP"];
//$arPicture["old_file"] = $arPSAction["LOGOTIP"];
$arPicture["del"] = trim($_POST["LOGOTIP_del"]);
$arFields = array(
"NAME" => $NAME,
"LID" => $LID,
"PERIOD_FROM" => $PERIOD_FROM,
"PERIOD_TO" => $PERIOD_TO,
"PERIOD_TYPE" => $PERIOD_TYPE,
"WEIGHT_FROM" => $WEIGHT_FROM,
"WEIGHT_TO" => $WEIGHT_TO,
"ORDER_PRICE_FROM" => $ORDER_PRICE_FROM,
"ORDER_PRICE_TO" => $ORDER_PRICE_TO,
"ORDER_CURRENCY" => $ORDER_CURRENCY,
"ACTIVE" => $ACTIVE,
"PRICE" => $PRICE,
"CURRENCY" => $CURRENCY,
"SORT" => $SORT,
"DESCRIPTION" => $DESCRIPTION,
"LOGOTIP" => $arPicture,
"STORE" => $store,
"LOCATIONS" => $arLocation
);
//pay system for delivery
if (is_set($_POST["PAY_SYSTEM"]) && is_array($_POST["PAY_SYSTEM"]))
{
$arFields["PAY_SYSTEM"] = array();
$arPaySystem = $_POST["PAY_SYSTEM"];
if ($arPaySystem[0] == "")
unset($arPaySystem[0]);
$arFields["PAY_SYSTEM"] = $arPaySystem;
}
if ($ID>0)
{
$delivery = new CSaleDelivery();
if (!$delivery->Update($ID, $arFields, array("EXPECT_LOCATION_CODES" => $lpEnabled)))
$strError .= GetMessage("ERROR_EDIT_DELIVERY")."
";
}
else
{
$ID = CSaleDelivery::Add($arFields, array("EXPECT_LOCATION_CODES" => $lpEnabled));
if ($ID<=0)
$strError .= GetMessage("ERROR_ADD_DELIVERY")."
";
}
}
if ($strError != '')
{
$bInitVars = true;
}
else
{
if (strlen($apply) > 0)
LocalRedirect("sale_delivery_edit.php?ID=".$ID."&lang=".LANG."&".$tabControl->ActiveTabParam());
else
LocalRedirect("sale_delivery.php?lang=".LANG);
}
}
$oldLogo = 0;
if ($ID>0)
{
$db_delivery = CSaleDelivery::GetList(Array("SORT"=>"ASC"), Array("ID"=>$ID));
$db_delivery->ExtractFields("str_");
$oldLogo = (int)$str_LOGOTIP;
$arDeliveryDescription = CSaleDelivery::GetByID($ID);
$str_DESCRIPTION = $arDeliveryDescription["DESCRIPTION"];
}
else
{
$str_ACTIVE = 'Y';
}
if ($bInitVars)
{
$DB->InitTableVarsForEdit("b_sale_delivery", "", "str_");
$str_LOGOTIP = $oldLogo;
}
$sDocTitle = ($ID>0) ? str_replace("#ID#", $ID, GetMessage("SALE_EDIT_RECORD")) : GetMessage("SALE_NEW_RECORD");
$APPLICATION->SetTitle($sDocTitle);
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
/*********************************************************************/
/******************** BODY *****************************************/
/*********************************************************************/
?>
$aMenu = array(
array(
"TEXT" => GetMessage("SDEN_2FLIST"),
"LINK" => "/bitrix/admin/sale_delivery.php?lang=".LANGUAGE_ID.GetFilterParams("filter_"),
"ICON" => "btn_list"
)
);
if ($ID > 0 && $saleModulePermissions >= "W")
{
$aMenu[] = array("SEPARATOR" => "Y");
$aMenu[] = array(
"TEXT" => GetMessage("SDEN_NEW_DELIVERY"),
"LINK" => "/bitrix/admin/sale_delivery_edit.php?lang=".LANGUAGE_ID.GetFilterParams("filter_"),
"ICON" => "btn_new"
);
$aMenu[] = array(
"TEXT" => GetMessage("SDEN_DELETE_DELIVERY"),
"LINK" => "javascript:if(confirm('".GetMessage("SDEN_DELETE_DELIVERY_CONFIRM")."')) window.location='/bitrix/admin/sale_delivery.php?ID=".$ID."&action=delete&lang=".LANGUAGE_ID."&".bitrix_sessid_get()."#tb';",
"ICON" => "btn_delete"
);
}
$context = new CAdminContextMenu($aMenu);
$context->Show();
?>
0)
echo CAdminMessage::ShowMessage(Array("DETAILS"=>$strError, "TYPE"=>"ERROR", "MESSAGE"=>GetMessage("SDEN_ERROR"), "HTML"=>true));?>