<?
require_once '../../core/system.php';
echo only_reg();
echo moder();
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `news_kom` WHERE `id` = '".intval($_GET['id'])."'"),0) == true){
$message = mysql_fetch_assoc(mysql_query("SELECT * FROM `news_kom` WHERE `id`  = '".intval($_GET['id'])."'"));
}else{
$_SESSION['err'] = "Сообщение не найдено!";
header("Location: /forum/");
exit();
}
if (isset($_GET['news_post']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_topic` WHERE `id` = '".intval($_GET['topic'])."'"),0) == true){
$back = mysql_fetch_assoc(mysql_query("SELECT * FROM `news` WHERE `id`  = '".intval($_GET['topic'])."'"));
// back = check($_GET['topic']);
}

$header = 'Редактирование сообщения';
require_once '../../core/head.php';
if(isset($_POST['msg'])) {
$msg = check($_POST['msg']);
if(strlen($msg) < 2 or strlen($msg) > 2500) $err =  'Длина сообщения должна быть в пределах 2 - 2500 символов';
if(!isset($err)) {
mysql_query("UPDATE `news_kom` SET `msg` = '$msg', `edited` = '1', `editor_id` = '$user[id]', `edit_time` = '".time()."'  WHERE `id` = '$message[id]'");
header("Location: $message[id_topic]/");
$_SESSION['message'] = 'Сообщение было изменено!';
exit();
}else{
header("Location: ");
$_SESSION['err'] = $err;
exit();
}
}
echo '<form class="player" method="post" action="?id='.$message[id].'">
Сообщение<br /><textarea name="msg" class = "text large" rows="4" cols="55">'.$message[msg].'</textarea>
<span class="btn"><span class="end"><input class="label" type="submit" value="Изменить">Изменить</span></span>
</form><div class="mini-line"></div><div class="player menuList"><li><a href="'.$message[id_topic].'/"><img src="/images/icon/section.png">Назад в топик</a></li></div>';
require_once '../../core/foot.php';
?>