Файл: plugins/page/minichat.php
Строк: 27
<?php
$title = 'Мини-чат';
require (SYS.'head.php');
if (isset($user))
{
if (isset($_GET['delete']))
{
$post = $db->query("SELECT * FROM `minichat` WHERE `id` = '".intval($_GET['delete'])."' LIMIT 1")->fetch_assoc();
if ($user['id'] != $post['id_user'] && $user['level'] < 1)
{
$error = 'Недостаточно прав.';
}
elseif (empty($post))
{
$error = 'Сообщение не существует';
}
else
{
$db->query("DELETE FROM `minichat` WHERE `id` = '".$post['id']."' LIMIT 1");
core::go('/');
}
}
if (isset($_POST['text']))
{
if (core::strlen($_POST['text']) > 5000)
{
$error = 'Длинный текст.';
}
elseif (core::strlen($_POST['text']) < 1)
{
$error = 'Короткий текст.';
}
elseif ($db->query("SELECT * FROM `minichat` WHERE `text` = '".core::input($_POST['text'])."' AND `id_user` = '".$user['id']."'")->num_rows == 1)
{
$error = 'Сообщение уже существует.';
}
elseif (empty($error))
{
$db->query("INSERT INTO `minichat` SET `text` = '".core::input($_POST['text'])."', `id_user` = '".$user['id']."', `time` = '".TIME."'");
}
}
$elements[] = [
'type' => 'textarea',
'title' => 'Сообщение',
'br' => 1,
'info' => [
'name' => 'text',
]
];
$elements[] = [
'type' => 'submit',
'info' => [
'value' => 'Отправить'
]
];
$smarty->assign([
'method' => 'POST',
'action' => '?',
'el' => $elements
]);
$smarty->display('form.tpl');
}
else
$error = 'Для написания сообщения необходимо выполнить вход.';
core::show('error');
$all = core::count('minichat');;
$pages = new Paginator($all, $set['user_pages']);
$query = $db->query("SELECT * FROM `minichat` ORDER BY `id` DESC LIMIT $start, $set[user_pages]");
while ($list = $query->fetch_assoc())
{
$posts[] = [
'image' => user::photo($list['id_user']),
'title' => user::login($list['id_user']),
'time' => core::time($list['time']),
'post' => core::output($list['text']),
'action' => [
'delete' => (isset($user) && ($user['id'] == $list['id_user'] || $user['level'] > 1)) ? '?delete='.$list['id'] : NULL
]
];
}
if ($all == 0)
$posts[] = [
'title' => 'Нет сообщений.'
];
$smarty->assign('post', $posts);
$smarty->display('posts.tpl');
$pages->view('?');
require (SYS.'foot.php');