require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/sale/include.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/sale/prolog.php";
$ID = IntVal($ID);
$z = CGroup::GetByID($ID);
if (!$z->ExtractFields("f_")) {
    LocalRedirect("sale_tax_exempt.php?lang=" . LANG . GetFilterParams("filter_", false));
}
$strError = "";
$bInitVars = false;
if ((strlen($save) > 0 || strlen($apply) > 0) && $REQUEST_METHOD == "POST" && $saleModulePermissions == "W" && check_bitrix_sessid()) {
    $arTAX = array();
    CSaleTax::DeleteExempt(array("GROUP_ID" => $ID));
    if (isset($TAX_ID) && is_array($TAX_ID) && count($TAX_ID) > 0) {
        for ($i = 0; $i < count($TAX_ID); $i++) {
            if (IntVal($TAX_ID[$i]) > 0) {
                CSaleTax::AddExempt(array("GROUP_ID" => $ID, "TAX_ID" => IntVal($TAX_ID[$i])));
            }
        }
    }
    if (strlen($strError) > 0) {
        $bInitVars = True;
    }
    if (strlen($save) > 0 && strlen($strError) <= 0) {
        LocalRedirect("sale_tax_exempt.php?lang=" . LANG . GetFilterParams("filter_", false));
    }
}
$sDocTitle = GetMessage("EXEMPT_EDIT_RECORD", array("#ID#" => $ID));
$APPLICATION->SetTitle($sDocTitle);
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
/*********************************************************************/
/********************  BODY  *****************************************/