<?php
define('NTLCMS', 1);
$module = 'edit';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
include ('../system/head.php');
if (!$active){
header('Location: '.URL);
$_SESSION['fail'] = 'Вы не авторизированы!';
exit;
}
echo '<div class="title"><b>'.razd.' Редактирование</b></div>';
$id = isset($_GET['id']) ? filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `chat` where `id` = ?", array($id));
$who = DB :: run() -> query("select * from `chat` where `id` = ? limit 1", array($id)) -> fetch(PDO::FETCH_OBJ);
if ($_USER['admin'] == '1' || $ulogin == $who -> login){
if (DB :: run() -> querySingle("select * from `chat` where `id` = ?", array($id))){
$error = null;
if (isset($_POST['text'])){
$text = isset($_POST['text']) ? filter_var($_POST['text'], FILTER_SANITIZE_STRING) : false;
if (empty($text)){
$error.= 'Пост не должен быть пуст!<br/>';
} elseif (mb_strlen($text, 'UTF-8') < 1 or mb_strlen($text, 'UTF-8') > 2500){
$error.= 'Пост должен содержать от 1 до 2500 символов!<br/>';
}
if ($error){
echo '<div class="post"><center><i class="fa fa-close fa-fw"></i> '.$error.'</center></div>';
} else {
if (DB :: run() -> query("update `chat` set `elogin` = ?, `edate` = ?, `edit` = ?, `text` = ? where `id` = ?", array($ilogin, TIME, 1, $text, $id))){
header('Location: '.URL.'/chats');
$_SESSION['success'] = 'Пост успешно отредактирован!';
} else {
header('Location: '.URL.'/chats');
$_SESSION['fail'] = 'Пост не отредактирован!';
}
}
}
$row = $sql -> fetch(PDO::FETCH_OBJ);
echo '<div class="menu"><form name="form" action="'.URL.'/chat_edit'.((int) $row -> id).'" method="post">
'.fast_smile() . panel('text').'* <b>Введите текст:</b><br/><textarea cols="40" rows="4" name="text">'.checkout($row -> text).'</textarea><br/>
<input type="submit" value="Редактировать"/></form></div>';
}
} else {
header('Location: '.URL.'/chats');
$_SESSION['fail'] = 'Действие запрещено!';
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a> | <a href="'.URL.'/chats">В беседку</a></div>';
include ('../system/foot.php');
?>