52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
$b->router_add("/appeals/", function () { appeal_save(); }, array("post"));
|
|
|
|
function appeal_save()
|
|
{
|
|
$appeal_title = $_POST["title"];
|
|
$appeal = new Appeals(0);
|
|
$appeal->create("Заявка - " . $appeal_title, "");
|
|
foreach ($_POST as $key => $value)
|
|
$appeal->set_prop($key, $value);
|
|
appeal_send($appeal->item_id);
|
|
echo json_encode(array("ok" => true));
|
|
exit();
|
|
}
|
|
|
|
function appeal_send($appeal_id)
|
|
{
|
|
global $b;
|
|
$root_url = $b->router_get_root_uri();
|
|
$text = "<b> 💬 Новое обращение: ";
|
|
$text .= $b->get_view($_POST["title"]) . "</b>\n\n";
|
|
if(isset($_POST["name"])) $text .= "<b>Имя:</b> " . $b->get_view($_POST["name"]) . "\n";
|
|
if(isset($_POST["email"])) $text .= "<b>Email:</b> " . $b->get_view($_POST["email"]) . "\n";
|
|
if(isset($_POST["phone"])) $text .= "<b>Телефон:</b> " . $b->get_view($_POST["phone"]) . "\n";
|
|
if(isset($_POST["message"])) $text .= "\n<b>Сообщение:</b> " . $b->get_view($_POST["message"]) . "\n";
|
|
if(isset($_POST["url"])) $text .= "\n<b>Страница пользователя:</b> " . $b->get_view($_POST["url"]) . "\n";
|
|
$text .= "\n<a href='" . $root_url . "/admin/?page=item_Appeals&item_id=" . $appeal_id . "'>Полная информация</a> ";
|
|
appeal_send_tg($text);
|
|
}
|
|
|
|
function appeal_send_tg($text)
|
|
{
|
|
// $tg_chat_id = "-1001914432978";
|
|
// $tg_token = "6133273622:AAEhbwiXUV89XGw3KumQPKWQIrYkh8p8LwY";
|
|
// $apiUrl = "https://api.telegram.org/bot" . $tg_token . "/sendMessage";
|
|
//
|
|
// $postData = array(
|
|
// 'chat_id' => $tg_chat_id,
|
|
// 'text' => $text,
|
|
// 'parse_mode' => "HTML",
|
|
// 'disable_web_page_preview' => true
|
|
// );
|
|
//
|
|
// $ch = curl_init();
|
|
// curl_setopt($ch, CURLOPT_URL, $apiUrl);
|
|
// curl_setopt($ch, CURLOPT_POST, 1);
|
|
// curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
// curl_exec($ch);
|
|
// curl_close($ch);
|
|
} |