You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.6 KiB
88 lines
2.6 KiB
<?
|
|
const PUBLIC_AJAX_MODE = true;
|
|
const NO_KEEP_STATISTIC = "Y";
|
|
const NO_AGENT_STATISTIC = "Y";
|
|
const NO_AGENT_CHECK = true;
|
|
const DisableEventsCheck = true;
|
|
|
|
use Bitrix\Main\Application;
|
|
use Bitrix\Main\Rating\Internal\Action;
|
|
use Bitrix\Main\Web\Json;
|
|
use Bitrix\Main\Config\Option;
|
|
|
|
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
|
|
|
|
$request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();
|
|
$isHttps = $request->isHttps();
|
|
$isAjax = $request->isAjaxRequest();
|
|
$isPost = $request->isPost();
|
|
|
|
$protocol = $request->isHttps() ? 'https' : 'http';
|
|
$site_url= $protocol.'://'.$request->getHttpHost();
|
|
$recaptcha_response = (string)$request->getPost('recaptcha_response');
|
|
|
|
if(!check_bitrix_sessid()) return;
|
|
|
|
if ($recaptcha_response){
|
|
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
|
|
$recaptcha_secret_key = '6LcSCXArAAAAAEdhWbATecK4jwMK9WvZbUV2szrY';
|
|
|
|
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret_key . '&response=' . $recaptcha_response);
|
|
$recaptcha = json_decode($recaptcha);
|
|
|
|
//score от 0.1 до 1.0
|
|
if ($recaptcha->score <= 0.4) return;
|
|
}
|
|
|
|
if($isPost) {
|
|
$name = (string)$request->getPost('name');
|
|
$phone = (string)$request->getPost('phone');
|
|
$page = (string)$request->getPost('page');
|
|
|
|
if (empty($name) || empty($phone)) {
|
|
$response = array(
|
|
'success' => false,
|
|
'message' => 'Заполните все поля'
|
|
);
|
|
} else {
|
|
$to = Option::get("main", "email_from");
|
|
|
|
|
|
if (empty($to)) {
|
|
$response = array(
|
|
'success' => false,
|
|
'message' => 'Ошибка конфигурации почты'
|
|
);
|
|
} else {
|
|
// Отправка почты через почтовое событие Битрикс
|
|
CEvent::Send(
|
|
"CALCULATION_REQUEST",
|
|
SITE_ID,
|
|
array(
|
|
"NAME" => $name,
|
|
"PHONE" => $phone,
|
|
"PAGE" => $site_url.$page,
|
|
)
|
|
);
|
|
|
|
$response = array(
|
|
'success' => true,
|
|
'message' => 'Заявка успешно отправлена'
|
|
);
|
|
}
|
|
}
|
|
} else {
|
|
$response = array(
|
|
'success' => false,
|
|
'message' => 'Неверный метод запроса'
|
|
);
|
|
}
|
|
$application = Application::getInstance();
|
|
$response = new \Bitrix\Main\Engine\Response\Json(
|
|
$response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION
|
|
);
|
|
$application->getContext()->setResponse($response);
|
|
$response->send();
|
|
$application->terminate(0);
|
|
// header('Content-Type: application/json');
|
|
// echo json_encode($response);
|