component.php 1.45 KB
<?
/** @var $this \CBitrixComponent */

$template = $this->getTemplateName();
if(!$template) {
    $template = strtolower(trim($_REQUEST['form-id']));
    $template = preg_replace('/[^a-z.-]+/', '', $template);
    $this->setTemplateName($template);
}

$result = array();




try {

    if(!$template) throw new Exception('form-id empty');

    include "templates/$template/result_modifier.php";

    if (!empty($arParams['IS_HANDLER'])) {


//        if(!check_bitrix_sessid()) throw new Exception('Сообщение не отправлено, т.к. ваша сессия истекла. Попробуйте отправить еще раз, перезагрузив страницу.');
        if(!isset($_REQUEST['sp']) || intval($_REQUEST['sp']) < 2) throw new Exception('Сообщение похоже на спам. Повторите попытку познее.');

        require "templates/$template/handler.php";

        $result['success'] = true;

    } else {


        require "templates/$template/template.php";

    }

} catch(Exception $e) {

    if(!empty($arParams['IS_AJAX'])) {
        $result['success'] = false;
        $result['error'] = $e->getMessage();
    } else {
        echo $e->getMessage();
    }

}

if (!empty($arParams['IS_HANDLER']) && !empty($arParams['IS_AJAX'])) {
    $APPLICATION->RestartBuffer();
    header('Content-Type: application/json');
    echo json_encode($result);
}