arParams,
				function(result){
					BX('convert_result_div').innerHTML = result;
					if(BX('cat_disc_convert_finish') != null)
					{
						BX.closeWait();
						StopConvert();
					}
				}
			);
		}

		return false;
	}
	</script><?php 
    $intCountOld = CCatalogDiscountConvert::GetCountOld();
    if ($intCountOld <= 0) {
        CAdminMessage::ShowMessage(array("MESSAGE" => GetMessage("CAT_DISC_CONVERT_COMPLETE"), "DETAILS" => GetMessage("ICAT_DISC_CONVERT_COMPLETE_ALL_OK"), "HTML" => true, "TYPE" => "OK"));
        CAdminNotify::DeleteByTag("CATALOG_DISC_CONVERT");
    }
    ?>
<div id="convert_result_div" style="margin:0;"></div>
	<form method="POST" action="<?php 
    echo $APPLICATION->GetCurPage();
    ?>
" name="fs1"><?php 
    $tabControl->Begin();
    $tabControl->BeginNextTab();
    $max_execution_time = intval(COption::GetOptionString("catalog", "max_execution_time", 10));
    if ($max_execution_time <= 0) {
        $max_execution_time = '';
				function(result){
					BX('convert_result_div').innerHTML = result;
					if(BX('cat_disc_convert_finish') != null)
					{
						BX.closeWait();
						StopConvert();
					}
				}
			);
		}

		return false;
	}
	</script><?php 
    $strChangeFormat = COption::GetOptionString('catalog', 'discount_format', 'N');
    $intCountFormat = CCatalogDiscountConvert::GetCountFormat();
    if (false === $intCountFormat) {
        ShowError(GetMessage('CAT_DISC_FATAL_ERR'));
        require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
        die;
    }
    $intCountFormat = intval($intCountFormat);
    if ('Y' == $strChangeFormat || 0 >= $intCountFormat) {
        CAdminMessage::ShowMessage(array("MESSAGE" => GetMessage("CAT_DISC_CONVERT_COMPLETE"), "DETAILS" => GetMessage("ICAT_DISC_CONVERT_COMPLETE_ALL_OK"), "HTML" => true, "TYPE" => "OK"));
        CAdminNotify::DeleteByTag("CATALOG_DISC_FORMAT");
        COption::SetOptionString('catalog', 'discount_format', 'Y');
    }
    ?>
<div id="convert_result_div" style="margin:0;"></div>
	<form method="POST" action="<?php 
    echo $APPLICATION->GetCurPage();
 public static function ConvertFormatDiscount($intStep = 20, $intMaxExecutionTime = 15)
 {
     global $DBType;
     global $DB;
     global $APPLICATION;
     self::InitStep();
     $intStep = intval($intStep);
     if (0 >= $intStep) {
         $intStep = 20;
     }
     $startConvertTime = getmicrotime();
     $obDiscount = new CCatalogDiscount();
     $strTableName = '';
     switch (ToUpper($DBType)) {
         case 'MYSQL':
             $strTableName = 'b_catalog_discount';
             break;
         case 'MSSQL':
             $strTableName = 'B_CATALOG_DISCOUNT';
             break;
         case 'ORACLE':
             $strTableName = 'B_CATALOG_DISCOUNT';
             break;
     }
     if (!CCatalogDiscountConvertTmp::CreateTable()) {
         return false;
     }
     if (0 >= self::$intLastConvertID) {
         self::$intLastConvertID = CCatalogDiscountConvertTmp::GetLastID();
     }
     CTimeZone::Disable();
     self::$boolEmptyList = true;
     $rsDiscounts = CCatalogDiscount::GetList(array('ID' => 'ASC'), array('>ID' => self::$intLastConvertID, 'TYPE' => DISCOUNT_TYPE_STANDART, 'VERSION' => CATALOG_DISCOUNT_NEW_VERSION), false, array('nTopCount' => $intStep), array('ID', 'MODIFIED_BY', 'TIMESTAMP_X', 'CONDITIONS', 'NAME'));
     while ($arDiscount = $rsDiscounts->Fetch()) {
         $mxExist = CCatalogDiscountConvertTmp::IsExistID($arDiscount['ID']);
         if (false === $mxExist) {
             self::$intErrors++;
             return false;
         }
         self::$boolEmptyList = false;
         if (0 < $mxExist) {
             self::$intConverted++;
             self::$intConvertPerStep++;
             self::$intLastConvertID = $arDiscount['ID'];
             continue;
         }
         $arFields = array();
         $arFields['MODIFIED_BY'] = $arDiscount['MODIFIED_BY'];
         $arFields['CONDITIONS'] = $arDiscount['CONDITIONS'];
         $mxRes = $obDiscount->Update($arDiscount['ID'], $arFields);
         if (!$mxRes) {
             self::$intErrors++;
             $strError = '';
             if ($ex = $APPLICATION->GetException()) {
                 $strError = $ex->GetString();
             }
             if (empty($strError)) {
                 $strError = GetMessage('BT_MOD_CAT_DSC_FORMAT_ERR');
             }
             self::$arErrors[] = array('ID' => $arDiscount['ID'], 'NAME' => $arDiscount['NAME'], 'ERROR' => $strError);
             if (!CCatalogDiscountConvertTmp::SetID($arDiscount['ID'])) {
                 return false;
             }
             self::$intConverted++;
             self::$intConvertPerStep++;
             self::$intLastConvertID = $arDiscount['ID'];
         } else {
             $arTimeFields = array('~TIMESTAMP_X' => $DB->CharToDateFunction($arDiscount['TIMESTAMP_X'], "FULL"));
             $strUpdate = $DB->PrepareUpdate($strTableName, $arTimeFields);
             if (!empty($strUpdate)) {
                 $strQuery = "UPDATE " . $strTableName . " SET " . $strUpdate . " WHERE ID = " . $arDiscount['ID'] . " AND TYPE = " . DISCOUNT_TYPE_STANDART;
                 $DB->Query($strQuery, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
             if (!CCatalogDiscountConvertTmp::SetID($arDiscount['ID'])) {
                 return false;
             }
             self::$intConverted++;
             self::$intConvertPerStep++;
             self::$intLastConvertID = $arDiscount['ID'];
         }
         if ($intMaxExecutionTime > 0 && getmicrotime() - $startConvertTime > $intMaxExecutionTime) {
             break;
         }
     }
     CTimeZone::Enable();
     if ($intMaxExecutionTime > 2 * (getmicrotime() - $startConvertTime)) {
         self::$intNextConvertPerStep = $intStep * 2;
     } else {
         self::$intNextConvertPerStep = $intStep;
     }
     self::SaveStep();
     return true;
 }