Joywork/ajax/addReview.php
2026-05-22 21:21:54 +03:00

69 lines
2.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
require_once($_SERVER['DOCUMENT_ROOT']."/engine/functions.php");
if(isset($_POST['REVIEW_SUBMIT'])){
$name = htmlspecialchars(trim($_POST['name']));
$company = htmlspecialchars(trim($_POST['company']));
$city = htmlspecialchars(trim($_POST['city']));
$text = htmlspecialchars(trim($_POST['text']));
$error = '';
$success = '';
if(!$name) $error = 'Введите имя';
if(!$company) $error = 'Введите название компании';
if(!$city) $error = 'Введите город';
if(!$text) $error = 'Введите текст отзыва';
if(isset($_FILES['file']) && !empty($_FILES['file']['name'])){
$file = $_FILES['file'];
$fileName = $file['name'];
$parts = pathinfo($fileName);
$path = $_SERVER['DOCUMENT_ROOT'] . '/upload/';
$allow = array('png','jpg','jpeg','webp','svg');
if(empty($fileName) || empty($parts['extension'])){
$error = "Не удалось загрузить файл";
}elseif(!in_array(strtolower($parts['extension']), $allow)){
$error = "Недопустимый тип файла - ".$parts['extension'];
}else{
if(move_uploaded_file($file['tmp_name'], $path.$fileName)){
// TO-DO: save name file to database
}else{
$error = 'Не удалось загрузить файл. Ошибка загрузки.';
}
}
}
if(!empty($error)){
$error = '<p style="color: red; padding: 0 15px;">'.$error.'</p>';
}else{
// TO-DO: save review to database
$msg = '<h1>Новый отзыв</h1>';
$msg .= '<p>Имя: '.$name.'</p>';
$msg .= '<p>Компания: '.$company.'</p>';
$msg .= '<p>Город: '.$city.'</p>';
$msg .= '<p>Текст отзыва: '.$text.'</p>';
if(isset($fileName)){
$msg .= '<p>Изображение: /upload/'.$fileName.'</p>';
}
$res = mailClientFromJoywork('support@joywork.ru', "Отзыв JW", $msg);
if($res)
$success = '<p style="color: #43a047; padding: 0 15px;">Спасибо за ваш отзыв!' . $res . '</p>';
else
$error = '<p style="color: red; padding: 0 15px;">Не удалось разместить отзыв, попробуйте позже' . $res .'</p>';
}
$data = array(
'error' => $error,
'success' => $success
);
header('Content-Type: application/json');
echo json_encode($data);
exit();
}
exit();
?>