Current Path : /var/www/html/clients/e-nkama.ru/e-nkama_bitrix/gorozhanam/ |
Current File : /var/www/html/clients/e-nkama.ru/e-nkama_bitrix/gorozhanam/feedback.php |
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); $subject = checkValue($_POST['subject']); if ($subject != 69) { $to = 'nmr_letters@mail.ru'; $message = $subject . '<br><br>'; foreach ($_POST as $key => $value) { if (!in_array($key, array('personal', 'subject')) && $value != '') { $temp = str_replace('_', ' ', $key) . ': ' . checkValue($value); $message = $message . $temp . '<br>'; } } $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type: text/html; charset=utf-8" . "\r\n"; $headers .= "From: <noreply@e-nkama.ru>" . "\r\n"; mail($to, $subject, $message, $headers); } CModule::IncludeModule('iblock'); $item = new CIBlockElement; if ($subject == 'Новое сообщение (Интернет-приемная)'){ // $post = array( // 'doc_id' => 149116398, // 'password' => "5296045354" // ); // $apiResult = messageApi('status', $post); // var_dump($apiResult); // exit; $fio = explode(' ', preg_replace('/ +/', ' ', $_POST['ФИО'])); $send = array( 'f' => $fio[0], 'i' => $fio[1] ? $fio[1] : $_POST['ФИО'], 'o' => $fio[2], 'fio' => $_POST['ФИО'], 'work' => $_POST['Кому_адресовано'], 'address' => $_POST['Адрес'], 'email' => $_POST['E-mail'], 'phone' => $_POST['Телефон'], 'message' => $_POST['Вопрос'] ); $apiResult = messageApi('send', $send); if ($apiResult['status'] != 'ok') { echo json_encode(array( 'success' => false, 'error' => $apiResult['message'] )); exit; } $fields = array( 'ACTIVE' => 'Y', 'MODIFIED_BY' => 29, 'IBLOCK_ID' => 65, 'NAME' => $subject, 'PREVIEW_TEXT' => $message, 'PREVIEW_TEXT_TYPE' => 'html' ); } elseif ($subject == 69) { $fields = array( 'ACTIVE' => 'Y', 'MODIFIED_BY' => 29, 'IBLOCK_ID' => 69, 'NAME' => checkValue($_POST['name']), 'PREVIEW_TEXT' => checkValue($_POST['desc']), 'ACTIVE_FROM' => date('d.m.Y H:i:s'), 'PROPERTY_VALUES' => array( 'POLL_ID' => (int)$_POST['poll_id'] ) ); } else { $fields = array( 'ACTIVE' => 'N', 'MODIFIED_BY' => 29, 'IBLOCK_ID' => 66, 'NAME' => checkValue($_POST['Имя']), 'PREVIEW_TEXT' => checkValue($_POST['Вопрос']), 'ACTIVE_FROM' => date('d.m.Y H:i:s') ); } if ($item->Add($fields)) echo (isset($apiResult) ? json_encode(array('success' => true, 'id' => $apiResult)) : true); } function checkValue($value) { return trim(strip_tags($value)); } function messageApi($type, $post) { if ($type == 'send') { $post = array_merge(array( 'dnform' => 'post', 'reception_category_id' => 951 ), $post); } $ch = curl_init("https://mg.tatar.ru/message-{$type}"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); return json_decode($result, true); } ?>