<?php
chdir('..');
require_once('view/View.php');
$view = new View();

$feedback           = new stdClass();
$feedback->visible  = 0;
$feedback->name     = $view->request->post('name');
$feedback->email    = $view->request->post('email');
$feedback->telegram = $view->request->post('telegram');
$feedback->whatsapp = $view->request->post('whatsapp');
$feedback->phone    = $view->request->post('phone');
$feedback->message  = $view->request->post('message');
$feedback->url      = $view->request->post('url');
$feedback->city     = $view->custom->get_city();
$feedback->ip       = $view->request->ip();

//тип заявки: обратный звонок, нашли дешевле, консультация, обратная связь, калькулятор и тп
$feedback->type     = $view->request->post('type');

$result = new stdClass;
$result->text = null;
$result->type = 'error';

// Recaptcha
if($view->custom->is_bot())
    $result->text = "captcha_failed";

//Ещё какие то проверки
if(empty($feedback->name) || empty($feedback->phone))
    $result->text = "required_fields";

if(!$result->text)
{
    $feedback_id = $view->feedbacks->add_feedback($feedback);
    $view->notify->email_feedback_admin($feedback_id);
}

$view->request->set_header('json');
print json_encode($result);
