Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<? namespace sm; class Handler { function CurrencyFormatHandler($fSum, $strCurre..

Decoded Output download

<? 
namespace sm; 
 
class Handler 
{ 
    function CurrencyFormatHandler($fSum, $strCurrency) 
    { 
        if ($strCurrency == 'RUB') return number_format($fSum, 2, ',', ' ') . ' .'; 
    } 
     
    function OnBeforePrologHandler() 
    { 
        global $USER; 
 
        if ($USER->IsAuthorized()) { 
            \sm\User::setUser($USER->GetID()); 
        } 
    } 
     
    function OnBeforeEventAddHandler(&$event, &$lid, &$arFields) 
    { 
        if ($arFields['ORDER_ID']) { 
            $order = \Bitrix\Sale\Order::load($arFields['ORDER_ID']); 
            $userId = $order->getUserId(); 
             
            if ($userId) { 
                $res = \Bitrix\Main\UserTable::getList(array( 
                    'select' => array('ID', 'UF_COMPANY'), 
                    'filter' => array('=ID' => $userId) 
                )); 
                $arUser = $res->fetch(); 
                 
                if ($arUser['UF_COMPANY']) { 
                    \CModule::IncludeModule('iblock'); 
 
                    $arFilter = array('IBLOCK_ID' => COMPANY_IBLOCK_ID, '=ID' => $arUser['UF_COMPANY']); 
                    $res = \CIBlockElement::GetList(array(), $arFilter, false, false, array('ID', 'PROPERTY_VIP')); 
                    $arCompany = $res->fetch(); 
                     
                    $onlyVipEvents = array('SALE_STATUS_CHANGED_R', 'SALE_STATUS_CHANGED_F'); 
                    if (!$arCompany['PROPERTY_VIP_VALUE'] && in_array($event, $onlyVipEvents)) { 
                        return false; 
                    } 
                } 
            } 
        } 
    } 
     
    function OnBeforeEventSendHandler(&$arFields, &$arTemplate) 
    { 
        if ($arTemplate['EVENT_NAME'] == 'FORM_FILLING_SIMPLE_FORM_2') { 
            if ($arFields['RS_USER_ID']) { 
                $res = \Bitrix\Main\UserTable::getList(array( 
                    'select' => array('ID', 'UF_COMPANY'), 
                    'filter' => array('=ID' => $arFields['RS_USER_ID']) 
                )); 
                $arUser = $res->fetch(); 
                if ($arUser['UF_COMPANY']) { 
                    \CModule::IncludeModule('iblock'); 
 
                    $arFilter = array('IBLOCK_ID' => COMPANY_IBLOCK_ID, '=ID' => $arUser['UF_COMPANY']); 
                    $res = \CIBlockElement::GetList(array(), $arFilter, false, false, array('ID', 'PROPERTY_MANAGER', 'PROPERTY_OPERATOR')); 
                    $arCompany = $res->fetch(); 
 
                    $managerFlag = preg_replace('/[^0-9]/', '', $arFields['SIMPLE_QUESTION_832']); 
                    $managerId = $managerFlag == 6 ? $arCompany['PROPERTY_OPERATOR_VALUE'] : $arCompany['PROPERTY_MANAGER_VALUE']; 
 
                    if ($managerId) { 
                        $res = \Bitrix\Main\UserTable::getList(array( 
                            'select' => array('ID', 'EMAIL'), 
                            'filter' => array('=ID' => $managerId, "Bitrix\Main\UserGroupTable:USER.GROUP_ID" => MANAGER_USER_GROUP_ID), 
                            'data_doubling' => false 
                        )); 
                        $row = $res->fetch(); 
                        if ($row['EMAIL']) $arTemplate["EMAIL_TO"] = $row['EMAIL']; 
                    } 
                } 
            } 
        } 
 
         
        if ($arFields['ORDER_ID']) { 
            $order = \Bitrix\Sale\Order::load($arFields['ORDER_ID']); 
            if ($order) { 
                $userId = $order->getUserId(); 
 
                if ($userId) { 
                    $res = \Bitrix\Main\UserTable::getList(array( 
                        'select' => array('ID', 'UF_COMPANY'), 
                        'filter' => array('=ID' => $userId) 
                    )); 
                    $arUser = $res->fetch(); 
 
                    if ($arUser['UF_COMPANY']) { 
                        \CModule::IncludeModule('iblock'); 
 
                        $arFilter = array('IBLOCK_ID' => COMPANY_IBLOCK_ID, '=ID' => $arUser['UF_COMPANY']); 
                        $res = \CIBlockElement::GetList(array(), $arFilter, false, false, array('ID', 'PROPERTY_MANAGER', 'PROPERTY_VIP')); 
                        $arCompany = $res->fetch(); 
 
                        if ($arCompany['PROPERTY_VIP_VALUE'] && $arCompany['PROPERTY_MANAGER_VALUE']) { 
                            $res = \Bitrix\Main\UserTable::getList(array( 
                                'select' => array('ID', 'EMAIL'), 
                                'filter' => array('=ID' => $arCompany['PROPERTY_MANAGER_VALUE'], "Bitrix\Main\UserGroupTable:USER.GROUP_ID" => MANAGER_USER_GROUP_ID), 
                                'data_doubling' => false 
                            )); 
                            $row = $res->fetch(); 
                            if ($row['EMAIL']) $arTemplate["BCC"] = $row['EMAIL']; 
                        } 
                    } 
                } 
            } 
        } 
    } 
 
    function OnBeforeUserRegisterHandler(&$args) 
    { 
        if ($_POST) { 
            foreach($_POST as $key => $val) { 
                if (is_array($val)) { 
                    foreach ($val as $k => $v) { 
                        if (empty($v)) unset($_POST[$key][$k]); 
                    } 
                } 
            } 
        } 
 
        // recaptcha 
        $recaptchaError = false; 
 
        if (isset($_POST['g-recaptcha-response'])) { 
            $resp = recaptcha_verify(); 
            if (!$resp->success) { 
                $recaptchaError = true; 
            } 
        } else { 
            $recaptchaError = true; 
        } 
 
        if ($recaptchaError) { 
            $GLOBALS['APPLICATION']->ThrowException(',    '); 
            return false; 
        } 
 
        if (!$_POST['CONSENT']) { 
            $GLOBALS['APPLICATION']->ThrowException('     '); 
            return false; 
        } 
 
        // fields 
        $args['LOGIN'] = $args['EMAIL']; 
 
 
        $requiredFields = array( 
            'UF_PHONE[]', 
            'COMPANY_NAME', 'COMPANY_EMAIL', 'COMPANY_PHONE[]', 'COMPANY_ZIP', 'COMPANY_ADDRESS', 
            'PERSON_NAME', 'PERSON_INN', 'PERSON_BIK', 'PERSON_ACCOUNT', 
            'ADDRESS_ZIP[]', 'ADDRESS_ADDRESS[]', 
            'STORE', 
        ); 
        foreach ($requiredFields as $req) { 
            $multiFlag = false; 
            if (strpos($req, '[]') !== false) $multiFlag = true; 
            if ((!$multiFlag && !$_POST[$req]) || ($multiFlag && !$_POST[str_replace('[]', '', $req)][0])) { 
                $GLOBALS['APPLICATION']->ThrowException('  '); 
                return false; 
            } 
        } 
 
        $args['ACTIVE'] = 'N'; 
 
 
        $arMessage = array(); 
        $arMessage[] = '<b> </b>'; 
        $arMessage[] = ' : ' . $_POST['COMPANY_NAME']; 
        $arMessage[] = ' .: ' . $_POST['PERSON_TYPE'] . ' ' . $_POST['PERSON_NAME']; 
        $arMessage[] = ' e-mail: ' . $_POST['COMPANY_EMAIL']; 
        $arMessage[] = ' : ' . $_POST['COMPANY_SITE']; 
        $arMessage[] = ': ' . implode(', ', $_POST['COMPANY_PHONE']); 
        $arMessage[] = ': ' . $_POST['COMPANY_CITY']; 
        $arMessage[] = ' : ' . $_POST['COMPANY_ZIP'] . ', ' . $_POST['COMPANY_ADDRESS']; 
 
        if ($_POST['ADDRESS_ADDRESS']) { 
            $arMessage[] = ' :'; 
            foreach($_POST['ADDRESS_ADDRESS'] as $arAddressKey => $arAddressItem) { 
                $arMessage[] = ($arAddressKey + 1) . ') ' . $_POST['ADDRESS_ZIP'][$arAddressKey] . ', ' . $arAddressItem; 
            } 
        } 
 
        if ((int)$_POST['STORE']) { 
            \CModule::IncludeModule("catalog"); 
 
            $res = \Bitrix\Catalog\StoreTable::getList(array( 
                'select' => array('ID', 'TITLE'), 
                'filter' => array('=ID' => (int)$_POST['STORE']) 
            )); 
            $arStore = $res->fetch(); 
            $arMessage[] = '  : ' . $arStore['TITLE']; 
        } 
 
        $arMessage[] = ': ' . $_POST['PERSON_INN']; 
        $arMessage[] = ': ' . $_POST['PERSON_OGRN']; 
        $arMessage[] = ' : ' . $_POST['PERSON_BANK']; 
        $arMessage[] = ' : ' . $_POST['PERSON_BIK']; 
        $arMessage[] = '  : ' . $_POST['PERSON_ACCOUNT']; 
 
        $arMessage[] = '<b> </b>'; 
        $arMessage[] = ': ' . $args['NAME']; 
        $arMessage[] = 'E-mail: ' . $args['LOGIN']; 
        $arMessage[] = ': ' . implode(', ', $args['UF_PHONE']); 
        $arMessage[] = ': ' . $args['UF_POST']; 
 
        $args['USER_DATA'] = implode('<br />', $arMessage); 
 
        return true; 
    } 
     
    function OnAfterUserRegisterHandler(&$args) 
    { 
        if ($args['USER_ID']) { 
 
            $arAddress = array(); 
 
            foreach($_POST as $key => $val) { 
                if ($_POST['ADDRESS_ADDRESS']) { 
                    foreach($_POST['ADDRESS_ADDRESS'] as $k => $v) { 
                        if ($v) { 
                            $arAddress[$k]['UF_ADDRESS'] = $v; 
                            if ($_POST['ADDRESS_ZIP'][$k]) $arAddress[$k]['UF_ZIP'] = $_POST['ADDRESS_ZIP'][$k]; 
                        } 
                    } 
                } 
            } 
 
 
            \CModule::IncludeModule('highloadblock'); 
 
            $personClass = GetHlClass(PERSON_HLBLOCK_ID); 
 
            //     
            $res = $personClass::getList(array( 
                'select' => array('ID'), 
                'filter' => array('=UF_INN' => $_POST['PERSON_INN']), 
                'limit' => 1 
            )); 
            $arPerson = $res->fetch(); 
            $personId = $arPerson['ID']; 
 
            //   ,  
            if (!$personId) { 
 
                //   
                \CModule::IncludeModule('iblock'); 
                $el = new \CIBlockElement; 
                $arCompany = Array( 
                    'IBLOCK_ID'  => COMPANY_IBLOCK_ID, 
                    'PROPERTY_VALUES' => array( 
                        210 => $_POST['PERSON_INN'], 
                        88 => $_POST['COMPANY_EMAIL'], 
                        91 => $_POST['COMPANY_SITE'], 
                        89 => $_POST['COMPANY_PHONE'], 
                        85 => $_POST['COMPANY_CITY'], 
                        95 => $_POST['COMPANY_ZIP'], 
                        90 => $_POST['COMPANY_ADDRESS'], 
                    ), 
                    'NAME' => $_POST['COMPANY_NAME'], 
                ); 
                $companyId = $el->Add($arCompany); 
 
                //   
                $arPerson = array( 
                    'UF_NAME' => $_POST['PERSON_TYPE'] . ' ' . $_POST['PERSON_NAME'], 
                    'UF_INN' => $_POST['PERSON_INN'], 
                    'UF_INN_MAIN' => $_POST['PERSON_INN'], 
                    'UF_OGRN' => $_POST['PERSON_OGRN'], 
                    'UF_BANK' => $_POST['PERSON_BANK'], 
                    'UF_BIK' => $_POST['PERSON_BIK'], 
                    'UF_ACCOUNT' => $_POST['PERSON_ACCOUNT'], 
                    'UF_COMPANY' => $companyId, 
                ); 
                $personClass::add($arPerson); 
 
                //   
                $addressClass = GetHlClass(ADDRESS_HLBLOCK_ID); 
 
                if ($arAddress) { 
                    foreach ($arAddress as $adr) { 
                        $adr['UF_COMPANY'] = $companyId; 
                        $addressClass::add($adr); 
                    } 
                } 
 
                //   
                \CModule::IncludeModule("catalog"); 
 
                $storeIds = array_unique(array((int)$_POST['STORE'], MAIN_STORE_ID)); 
                if ($storeIds) { 
                    $res = \Bitrix\Catalog\StoreTable::getList(array( 
                        'select' => array('ID', 'UF_COMPANY'), 
                        'filter' => array('=ID' => $storeIds) 
                    )); 
                    while ($row = $res->fetch()) { 
                        $storeCompanies = $row['UF_COMPANY']; 
                        $storeCompanies[] = $companyId; 
                        \Bitrix\Catalog\StoreTable::update($row['ID'], array('UF_COMPANY' => $storeCompanies)); 
                    } 
                } 
            } 
 
        } 
    } 
     
    function OnBeforeUserUpdateHandler(&$arFields) 
    { 
        global $USER; 
        $user_id = $arFields['ID']; 
        if (in_array(SUSPENDED_USER_GROUP_ID, \CUser::GetUserGroup($user_id)) && $USER->GetID() == $user_id) { 
            global $APPLICATION; 
            $APPLICATION->throwException("  "); 
            return false; 
        } 
         
         
        if ($arFields['ACTIVE'] == 'Y') { 
            $res = \Bitrix\Main\UserTable::getList(array( 
                'select' => array('ID', 'ACTIVE', 'LOGIN', 'EMAIL', 'NAME'), 
                'filter' => array('=ID' => $arFields['ID']) 
            )); 
            while ($arUser = $res->fetch()) { 
                if ($arUser['ACTIVE'] == 'N') { 
                    \Bitrix\Main\Mail\Event::send(array( 
                        "EVENT_NAME" => "USER_INFO", 
                        "LID" => "s1", 
                        "C_FIELDS" => array( 
                            "USER_ID" => $arUser['ID'], 
                            "LOGIN" => $arUser['LOGIN'], 
                            "EMAIL" => $arUser['EMAIL'], 
                            "NAME" => $arUser['NAME'], 
                            "MESSAGE" => "  ." 
                        ), 
                    )); 
                } 
            } 
        } 
    } 
 
    function onBeforeResultAddHandler($WEB_FORM_ID, &$arFields, &$arrVALUES) 
    { 
        global $APPLICATION; 
 
        if ($WEB_FORM_ID == 1) { 
            $recaptchaError = false; 
 
            if (isset($_POST['g-recaptcha-response'])) { 
                $resp = recaptcha_verify(); 
                if (!$resp->success) { 
                    $recaptchaError = true; 
                } 
            } else { 
                $recaptchaError = true; 
            } 
 
            if ($recaptchaError) { 
                $GLOBALS['APPLICATION']->ThrowException(',    '); 
                return false; 
            } 
        } 
    } 
 
    function OnGetOptimalPriceHandler($productId, $quantity = 1, $arUserGroups = [], $renewal = "N", $arPrices = [], $siteID = false, $arDiscountCoupons = false) 
    { 
        $prices = array(); 
        $base_catalog_group_id = 1; 
        $catalog_group_id = (int)$GLOBALS['curUser']['CATALOG_GROUP_ID']; 
        if (!$catalog_group_id) $catalog_group_id = $base_catalog_group_id; 
         
        $dbPrice = \Bitrix\Catalog\PriceTable::getList(array( 
            'select' => array('CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'), 
            'filter' => array('=PRODUCT_ID' => (int)$productId, 'CATALOG_GROUP_ID' => array($base_catalog_group_id, $catalog_group_id)), 
        )); 
        while($arPrice = $dbPrice->Fetch()) { 
            $prices[$arPrice['CATALOG_GROUP_ID']] = $arPrice; 
        } 
         
        if (!isset($prices[$catalog_group_id])) { 
            $prices[$catalog_group_id] = array( 
                'CATALOG_GROUP_ID' => $catalog_group_id, 
                'PRICE' => 0, 
                'CURRENCY' => $prices[$base_catalog_group_id]['CURRENCY'], 
            ); 
        } 
        $prices[$catalog_group_id]['INIT_PRICE'] = $prices[$catalog_group_id]['PRICE']; 
         
         
        \Bitrix\Main\Loader::includeModule('highloadblock'); 
        $discountClass = GetHlClass(DISCOUNT_HLBLOCK_ID); 
         
        $today = date(\CDatabase::DateFormatToPHP(\CLang::GetDateFormat("FULL", LANG)), time()); 
         
        $res = $discountClass::getList(array( 
            'select' => array('ID', 'UF_PERCENT'), 
            'filter' => array( 
                '=UF_ELEMENT' => array((int)$productId, '', 0), 
                '=UF_COMPANY' => array((int)$GLOBALS['curUser']['UF_COMPANY'], '', 0), 
                '<=UF_ACTIVE_FROM' => $today, 
                '>=UF_ACTIVE_TO' => $today 
            ), 
            'order' => array('UF_ACTIVE_FROM' => 'ASC'), 
            'limit' => 1 
        )); 
        $arDiscount = $res->fetch(); 
        if ($arDiscount['ID'] && $arDiscount['UF_PERCENT']) { 
            $prices[$catalog_group_id]['PRICE'] = $prices[$catalog_group_id]['PRICE'] * ((100 - (float)$arDiscount['UF_PERCENT']) / 100); 
            $prices[$catalog_group_id]['DISCOUNT'] = (float)$arDiscount['UF_PERCENT']; 
        } 
         
 
        return [ 
            'PRICE' => [ 
                'ID' => $productId, 
                'CATALOG_GROUP_ID' => $prices[$catalog_group_id]['CATALOG_GROUP_ID'], 
                'PRICE' => $prices[$catalog_group_id]['PRICE'], 
                'PRINT_PRICE' => ($prices[$catalog_group_id]['PRICE'] ? CurrencyFormat($prices[$catalog_group_id]['PRICE'], $prices[$catalog_group_id]['CURRENCY']) : '  '), 
                'BASE_PRICE' => $prices[$base_catalog_group_id]['PRICE'], 
                'PRINT_BASE_PRICE' => ($prices[$base_catalog_group_id]['PRICE'] ? CurrencyFormat($prices[$base_catalog_group_id]['PRICE'], $prices[$base_catalog_group_id]['CURRENCY']) : '  '), 
                'INIT_PRICE' => $prices[$catalog_group_id]['INIT_PRICE'], 
                'DISCOUNT' => $prices[$catalog_group_id]['DISCOUNT'], 
                'CURRENCY' => $prices[$catalog_group_id]['CURRENCY'], 
                'ELEMENT_IBLOCK_ID' => $productId, 
                'VAT_INCLUDED' => "Y", 
                'VAT_RATE' => $GLOBALS['curUser']['VAT_RATE'] 
            ] 
        ]; 
 
    } 
     
    function OnSaleBasketItemRefreshDataHandler(\Bitrix\Main\Event $event) { 
        global $USER; 
        if (in_array(SUSPENDED_USER_GROUP_ID, \CUser::GetUserGroup($USER->GetID()))) { 
            return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR); 
        } 
    } 
function OnEpilogHandler(){ 
  if(defined('ERROR_404') && ERROR_404 == 'Y'){ 
    global $APPLICATION; 
    $APPLICATION->RestartBuffer(); 
	  include $_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/header.php'; 
    include $_SERVER['DOCUMENT_ROOT'].'/404.php'; 
	  include $_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/footer.php'; 
 
  } 
 
} 
} 
 ?>

Did this file decode correctly?

Original Code

<?
namespace sm;

class Handler
{
    function CurrencyFormatHandler($fSum, $strCurrency)
    {
        if ($strCurrency == 'RUB') return number_format($fSum, 2, ',', ' ') . ' .';
    }
    
    function OnBeforePrologHandler()
    {
        global $USER;

        if ($USER->IsAuthorized()) {
            \sm\User::setUser($USER->GetID());
        }
    }
    
    function OnBeforeEventAddHandler(&$event, &$lid, &$arFields)
    {
        if ($arFields['ORDER_ID']) {
            $order = \Bitrix\Sale\Order::load($arFields['ORDER_ID']);
            $userId = $order->getUserId();
            
            if ($userId) {
                $res = \Bitrix\Main\UserTable::getList(array(
                    'select' => array('ID', 'UF_COMPANY'),
                    'filter' => array('=ID' => $userId)
                ));
                $arUser = $res->fetch();
                
                if ($arUser['UF_COMPANY']) {
                    \CModule::IncludeModule('iblock');

                    $arFilter = array('IBLOCK_ID' => COMPANY_IBLOCK_ID, '=ID' => $arUser['UF_COMPANY']);
                    $res = \CIBlockElement::GetList(array(), $arFilter, false, false, array('ID', 'PROPERTY_VIP'));
                    $arCompany = $res->fetch();
                    
                    $onlyVipEvents = array('SALE_STATUS_CHANGED_R', 'SALE_STATUS_CHANGED_F');
                    if (!$arCompany['PROPERTY_VIP_VALUE'] && in_array($event, $onlyVipEvents)) {
                        return false;
                    }
                }
            }
        }
    }
    
    function OnBeforeEventSendHandler(&$arFields, &$arTemplate)
    {
        if ($arTemplate['EVENT_NAME'] == 'FORM_FILLING_SIMPLE_FORM_2') {
            if ($arFields['RS_USER_ID']) {
                $res = \Bitrix\Main\UserTable::getList(array(
                    'select' => array('ID', 'UF_COMPANY'),
                    'filter' => array('=ID' => $arFields['RS_USER_ID'])
                ));
                $arUser = $res->fetch();
                if ($arUser['UF_COMPANY']) {
                    \CModule::IncludeModule('iblock');

                    $arFilter = array('IBLOCK_ID' => COMPANY_IBLOCK_ID, '=ID' => $arUser['UF_COMPANY']);
                    $res = \CIBlockElement::GetList(array(), $arFilter, false, false, array('ID', 'PROPERTY_MANAGER', 'PROPERTY_OPERATOR'));
                    $arCompany = $res->fetch();

                    $managerFlag = preg_replace('/[^0-9]/', '', $arFields['SIMPLE_QUESTION_832']);
                    $managerId = $managerFlag == 6 ? $arCompany['PROPERTY_OPERATOR_VALUE'] : $arCompany['PROPERTY_MANAGER_VALUE'];

                    if ($managerId) {
                        $res = \Bitrix\Main\UserTable::getList(array(
                            'select' => array('ID', 'EMAIL'),
                            'filter' => array('=ID' => $managerId, "Bitrix\Main\UserGroupTable:USER.GROUP_ID" => MANAGER_USER_GROUP_ID),
                            'data_doubling' => false
                        ));
                        $row = $res->fetch();
                        if ($row['EMAIL']) $arTemplate["EMAIL_TO"] = $row['EMAIL'];
                    }
                }
            }
        }

        
        if ($arFields['ORDER_ID']) {
            $order = \Bitrix\Sale\Order::load($arFields['ORDER_ID']);
            if ($order) {
                $userId = $order->getUserId();

                if ($userId) {
                    $res = \Bitrix\Main\UserTable::getList(array(
                        'select' => array('ID', 'UF_COMPANY'),
                        'filter' => array('=ID' => $userId)
                    ));
                    $arUser = $res->fetch();

                    if ($arUser['UF_COMPANY']) {
                        \CModule::IncludeModule('iblock');

                        $arFilter = array('IBLOCK_ID' => COMPANY_IBLOCK_ID, '=ID' => $arUser['UF_COMPANY']);
                        $res = \CIBlockElement::GetList(array(), $arFilter, false, false, array('ID', 'PROPERTY_MANAGER', 'PROPERTY_VIP'));
                        $arCompany = $res->fetch();

                        if ($arCompany['PROPERTY_VIP_VALUE'] && $arCompany['PROPERTY_MANAGER_VALUE']) {
                            $res = \Bitrix\Main\UserTable::getList(array(
                                'select' => array('ID', 'EMAIL'),
                                'filter' => array('=ID' => $arCompany['PROPERTY_MANAGER_VALUE'], "Bitrix\Main\UserGroupTable:USER.GROUP_ID" => MANAGER_USER_GROUP_ID),
                                'data_doubling' => false
                            ));
                            $row = $res->fetch();
                            if ($row['EMAIL']) $arTemplate["BCC"] = $row['EMAIL'];
                        }
                    }
                }
            }
        }
    }

    function OnBeforeUserRegisterHandler(&$args)
    {
        if ($_POST) {
            foreach($_POST as $key => $val) {
                if (is_array($val)) {
                    foreach ($val as $k => $v) {
                        if (empty($v)) unset($_POST[$key][$k]);
                    }
                }
            }
        }

        // recaptcha
        $recaptchaError = false;

        if (isset($_POST['g-recaptcha-response'])) {
            $resp = recaptcha_verify();
            if (!$resp->success) {
                $recaptchaError = true;
            }
        } else {
            $recaptchaError = true;
        }

        if ($recaptchaError) {
            $GLOBALS['APPLICATION']->ThrowException(',    ');
            return false;
        }

        if (!$_POST['CONSENT']) {
            $GLOBALS['APPLICATION']->ThrowException('     ');
            return false;
        }

        // fields
        $args['LOGIN'] = $args['EMAIL'];


        $requiredFields = array(
            'UF_PHONE[]',
            'COMPANY_NAME', 'COMPANY_EMAIL', 'COMPANY_PHONE[]', 'COMPANY_ZIP', 'COMPANY_ADDRESS',
            'PERSON_NAME', 'PERSON_INN', 'PERSON_BIK', 'PERSON_ACCOUNT',
            'ADDRESS_ZIP[]', 'ADDRESS_ADDRESS[]',
            'STORE',
        );
        foreach ($requiredFields as $req) {
            $multiFlag = false;
            if (strpos($req, '[]') !== false) $multiFlag = true;
            if ((!$multiFlag && !$_POST[$req]) || ($multiFlag && !$_POST[str_replace('[]', '', $req)][0])) {
                $GLOBALS['APPLICATION']->ThrowException('  ');
                return false;
            }
        }

        $args['ACTIVE'] = 'N';


        $arMessage = array();
        $arMessage[] = '<b> </b>';
        $arMessage[] = ' : ' . $_POST['COMPANY_NAME'];
        $arMessage[] = ' .: ' . $_POST['PERSON_TYPE'] . ' ' . $_POST['PERSON_NAME'];
        $arMessage[] = ' e-mail: ' . $_POST['COMPANY_EMAIL'];
        $arMessage[] = ' : ' . $_POST['COMPANY_SITE'];
        $arMessage[] = ': ' . implode(', ', $_POST['COMPANY_PHONE']);
        $arMessage[] = ': ' . $_POST['COMPANY_CITY'];
        $arMessage[] = ' : ' . $_POST['COMPANY_ZIP'] . ', ' . $_POST['COMPANY_ADDRESS'];

        if ($_POST['ADDRESS_ADDRESS']) {
            $arMessage[] = ' :';
            foreach($_POST['ADDRESS_ADDRESS'] as $arAddressKey => $arAddressItem) {
                $arMessage[] = ($arAddressKey + 1) . ') ' . $_POST['ADDRESS_ZIP'][$arAddressKey] . ', ' . $arAddressItem;
            }
        }

        if ((int)$_POST['STORE']) {
            \CModule::IncludeModule("catalog");

            $res = \Bitrix\Catalog\StoreTable::getList(array(
                'select' => array('ID', 'TITLE'),
                'filter' => array('=ID' => (int)$_POST['STORE'])
            ));
            $arStore = $res->fetch();
            $arMessage[] = '  : ' . $arStore['TITLE'];
        }

        $arMessage[] = ': ' . $_POST['PERSON_INN'];
        $arMessage[] = ': ' . $_POST['PERSON_OGRN'];
        $arMessage[] = ' : ' . $_POST['PERSON_BANK'];
        $arMessage[] = ' : ' . $_POST['PERSON_BIK'];
        $arMessage[] = '  : ' . $_POST['PERSON_ACCOUNT'];

        $arMessage[] = '<b> </b>';
        $arMessage[] = ': ' . $args['NAME'];
        $arMessage[] = 'E-mail: ' . $args['LOGIN'];
        $arMessage[] = ': ' . implode(', ', $args['UF_PHONE']);
        $arMessage[] = ': ' . $args['UF_POST'];

        $args['USER_DATA'] = implode('<br />', $arMessage);

        return true;
    }
    
    function OnAfterUserRegisterHandler(&$args)
    {
        if ($args['USER_ID']) {

            $arAddress = array();

            foreach($_POST as $key => $val) {
                if ($_POST['ADDRESS_ADDRESS']) {
                    foreach($_POST['ADDRESS_ADDRESS'] as $k => $v) {
                        if ($v) {
                            $arAddress[$k]['UF_ADDRESS'] = $v;
                            if ($_POST['ADDRESS_ZIP'][$k]) $arAddress[$k]['UF_ZIP'] = $_POST['ADDRESS_ZIP'][$k];
                        }
                    }
                }
            }


            \CModule::IncludeModule('highloadblock');

            $personClass = GetHlClass(PERSON_HLBLOCK_ID);

            //    
            $res = $personClass::getList(array(
                'select' => array('ID'),
                'filter' => array('=UF_INN' => $_POST['PERSON_INN']),
                'limit' => 1
            ));
            $arPerson = $res->fetch();
            $personId = $arPerson['ID'];

            //   , 
            if (!$personId) {

                //  
                \CModule::IncludeModule('iblock');
                $el = new \CIBlockElement;
                $arCompany = Array(
                    'IBLOCK_ID'  => COMPANY_IBLOCK_ID,
                    'PROPERTY_VALUES' => array(
                        210 => $_POST['PERSON_INN'],
                        88 => $_POST['COMPANY_EMAIL'],
                        91 => $_POST['COMPANY_SITE'],
                        89 => $_POST['COMPANY_PHONE'],
                        85 => $_POST['COMPANY_CITY'],
                        95 => $_POST['COMPANY_ZIP'],
                        90 => $_POST['COMPANY_ADDRESS'],
                    ),
                    'NAME' => $_POST['COMPANY_NAME'],
                );
                $companyId = $el->Add($arCompany);

                //  
                $arPerson = array(
                    'UF_NAME' => $_POST['PERSON_TYPE'] . ' ' . $_POST['PERSON_NAME'],
                    'UF_INN' => $_POST['PERSON_INN'],
                    'UF_INN_MAIN' => $_POST['PERSON_INN'],
                    'UF_OGRN' => $_POST['PERSON_OGRN'],
                    'UF_BANK' => $_POST['PERSON_BANK'],
                    'UF_BIK' => $_POST['PERSON_BIK'],
                    'UF_ACCOUNT' => $_POST['PERSON_ACCOUNT'],
                    'UF_COMPANY' => $companyId,
                );
                $personClass::add($arPerson);

                //  
                $addressClass = GetHlClass(ADDRESS_HLBLOCK_ID);

                if ($arAddress) {
                    foreach ($arAddress as $adr) {
                        $adr['UF_COMPANY'] = $companyId;
                        $addressClass::add($adr);
                    }
                }

                //  
                \CModule::IncludeModule("catalog");

                $storeIds = array_unique(array((int)$_POST['STORE'], MAIN_STORE_ID));
                if ($storeIds) {
                    $res = \Bitrix\Catalog\StoreTable::getList(array(
                        'select' => array('ID', 'UF_COMPANY'),
                        'filter' => array('=ID' => $storeIds)
                    ));
                    while ($row = $res->fetch()) {
                        $storeCompanies = $row['UF_COMPANY'];
                        $storeCompanies[] = $companyId;
                        \Bitrix\Catalog\StoreTable::update($row['ID'], array('UF_COMPANY' => $storeCompanies));
                    }
                }
            }

        }
    }
    
    function OnBeforeUserUpdateHandler(&$arFields)
    {
        global $USER;
        $user_id = $arFields['ID'];
        if (in_array(SUSPENDED_USER_GROUP_ID, \CUser::GetUserGroup($user_id)) && $USER->GetID() == $user_id) {
            global $APPLICATION;
            $APPLICATION->throwException("  ");
            return false;
        }
        
        
        if ($arFields['ACTIVE'] == 'Y') {
            $res = \Bitrix\Main\UserTable::getList(array(
                'select' => array('ID', 'ACTIVE', 'LOGIN', 'EMAIL', 'NAME'),
                'filter' => array('=ID' => $arFields['ID'])
            ));
            while ($arUser = $res->fetch()) {
                if ($arUser['ACTIVE'] == 'N') {
                    \Bitrix\Main\Mail\Event::send(array(
                        "EVENT_NAME" => "USER_INFO",
                        "LID" => "s1",
                        "C_FIELDS" => array(
                            "USER_ID" => $arUser['ID'],
                            "LOGIN" => $arUser['LOGIN'],
                            "EMAIL" => $arUser['EMAIL'],
                            "NAME" => $arUser['NAME'],
                            "MESSAGE" => "  ."
                        ),
                    ));
                }
            }
        }
    }

    function onBeforeResultAddHandler($WEB_FORM_ID, &$arFields, &$arrVALUES)
    {
        global $APPLICATION;

        if ($WEB_FORM_ID == 1) {
            $recaptchaError = false;

            if (isset($_POST['g-recaptcha-response'])) {
                $resp = recaptcha_verify();
                if (!$resp->success) {
                    $recaptchaError = true;
                }
            } else {
                $recaptchaError = true;
            }

            if ($recaptchaError) {
                $GLOBALS['APPLICATION']->ThrowException(',    ');
                return false;
            }
        }
    }

    function OnGetOptimalPriceHandler($productId, $quantity = 1, $arUserGroups = [], $renewal = "N", $arPrices = [], $siteID = false, $arDiscountCoupons = false)
    {
        $prices = array();
        $base_catalog_group_id = 1;
        $catalog_group_id = (int)$GLOBALS['curUser']['CATALOG_GROUP_ID'];
        if (!$catalog_group_id) $catalog_group_id = $base_catalog_group_id;
        
        $dbPrice = \Bitrix\Catalog\PriceTable::getList(array(
            'select' => array('CATALOG_GROUP_ID', 'PRICE', 'CURRENCY'),
            'filter' => array('=PRODUCT_ID' => (int)$productId, 'CATALOG_GROUP_ID' => array($base_catalog_group_id, $catalog_group_id)),
        ));
        while($arPrice = $dbPrice->Fetch()) {
            $prices[$arPrice['CATALOG_GROUP_ID']] = $arPrice;
        }
        
        if (!isset($prices[$catalog_group_id])) {
            $prices[$catalog_group_id] = array(
                'CATALOG_GROUP_ID' => $catalog_group_id,
                'PRICE' => 0,
                'CURRENCY' => $prices[$base_catalog_group_id]['CURRENCY'],
            );
        }
        $prices[$catalog_group_id]['INIT_PRICE'] = $prices[$catalog_group_id]['PRICE'];
        
        
        \Bitrix\Main\Loader::includeModule('highloadblock');
        $discountClass = GetHlClass(DISCOUNT_HLBLOCK_ID);
        
        $today = date(\CDatabase::DateFormatToPHP(\CLang::GetDateFormat("FULL", LANG)), time());
        
        $res = $discountClass::getList(array(
            'select' => array('ID', 'UF_PERCENT'),
            'filter' => array(
                '=UF_ELEMENT' => array((int)$productId, '', 0),
                '=UF_COMPANY' => array((int)$GLOBALS['curUser']['UF_COMPANY'], '', 0),
                '<=UF_ACTIVE_FROM' => $today,
                '>=UF_ACTIVE_TO' => $today
            ),
            'order' => array('UF_ACTIVE_FROM' => 'ASC'),
            'limit' => 1
        ));
        $arDiscount = $res->fetch();
        if ($arDiscount['ID'] && $arDiscount['UF_PERCENT']) {
            $prices[$catalog_group_id]['PRICE'] = $prices[$catalog_group_id]['PRICE'] * ((100 - (float)$arDiscount['UF_PERCENT']) / 100);
            $prices[$catalog_group_id]['DISCOUNT'] = (float)$arDiscount['UF_PERCENT'];
        }
        

        return [
            'PRICE' => [
                'ID' => $productId,
                'CATALOG_GROUP_ID' => $prices[$catalog_group_id]['CATALOG_GROUP_ID'],
                'PRICE' => $prices[$catalog_group_id]['PRICE'],
                'PRINT_PRICE' => ($prices[$catalog_group_id]['PRICE'] ? CurrencyFormat($prices[$catalog_group_id]['PRICE'], $prices[$catalog_group_id]['CURRENCY']) : '  '),
                'BASE_PRICE' => $prices[$base_catalog_group_id]['PRICE'],
                'PRINT_BASE_PRICE' => ($prices[$base_catalog_group_id]['PRICE'] ? CurrencyFormat($prices[$base_catalog_group_id]['PRICE'], $prices[$base_catalog_group_id]['CURRENCY']) : '  '),
                'INIT_PRICE' => $prices[$catalog_group_id]['INIT_PRICE'],
                'DISCOUNT' => $prices[$catalog_group_id]['DISCOUNT'],
                'CURRENCY' => $prices[$catalog_group_id]['CURRENCY'],
                'ELEMENT_IBLOCK_ID' => $productId,
                'VAT_INCLUDED' => "Y",
                'VAT_RATE' => $GLOBALS['curUser']['VAT_RATE']
            ]
        ];

    }
    
    function OnSaleBasketItemRefreshDataHandler(\Bitrix\Main\Event $event) {
        global $USER;
        if (in_array(SUSPENDED_USER_GROUP_ID, \CUser::GetUserGroup($USER->GetID()))) {
            return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR);
        }
    }
function OnEpilogHandler(){
  if(defined('ERROR_404') && ERROR_404 == 'Y'){
    global $APPLICATION;
    $APPLICATION->RestartBuffer();
	  include $_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/header.php';
    include $_SERVER['DOCUMENT_ROOT'].'/404.php';
	  include $_SERVER['DOCUMENT_ROOT'].SITE_TEMPLATE_PATH.'/footer.php';

  }

}
}

Function Calls

None

Variables

None

Stats

MD5 1b8154b82eb6a1bb8b51b008d0ae084a
Eval Count 0
Decode Time 98 ms