component.php
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?
/** @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);
}