<?php
if (isset($_POST['submit']) and $user->isAuth()) {
$form = [
'value' => [
'text' => isset($_POST['text']) ? trim(htmlspecialchars($_POST['text'])) : null
],
'error' => [],
];
if (empty($form['value']['text'])) {
$form['error']['text'] = 'Введите текст сообщения';
}
if (count($form['error']) == 0) {
$sql = $db->prepare('insert into chat (user,text,time) values (?,?,?)');
$sql -> execute([$user->get()->user_id,$form['value']['text'],time()]);
} else {
Notif :: error($form['error']['text'],'/chat');
exit;
}
}
$all = $db->prepare('SELECT * FROM `chat` ORDER BY `id` DESC LIMIT 40');
$all -> execute();
$all = $all -> fetchAll();
echo $template->render('user.chat', [
'all' => $all
]);