<?php
require_once '../core/system.php';
echo only_reg();
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_comm` WHERE `id` = '$get_id'"),0) == true){
$post_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_comm` WHERE `id`  = '$get_id'"));
$id_topic_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topic` WHERE `id`  = '".num($post_msg['id_topic'])."'"));
$id_razdel_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_razdel` WHERE `id`  = '".num($id_topic_msg['id_razdel'])."'"));
$id_parent_razdel_msg = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_razdel` WHERE `id`  = '".num($id_razdel_msg['attached_to'])."' And `main_forum` = '1'"));
if ($id_razdel_msg['clan_forum'] == '1' || $id_parent_razdel_msg['clan_forum'] == '1') {
include 'include_edit_clan_forum_message.php';
}elseif ($id_razdel_msg['clan_forum'] == '0' || $id_parent_razdel_msg['clan_forum'] == '0') {
include 'include_edit_forum_message.php';
}else{
$_SESSION['err'] = "Сообщение не найдено!";
header("Location: /forum");
exit();
}
if (check(isset($_GET['page']))) {
$page = intval($_GET['page']);
}
if ($post_msg['deleted'] == '1') {
header("Location: /topic?id=$post_msg[id_topic]&page=$page");
$_SESSION['err'] = 'Сообщение не найдено';
exit();
}
$header = 'Редактирование сообщения';
require_once '../core/head.php';
if(isset($_POST['msg'])) {
$msg = check(filter($_POST['msg']));
if(mb_strlen($_POST['msg']) < 2 or mb_strlen($_POST['msg']) > 2500) $err =  'Длина сообщения должна быть в пределах 2 - 2500 символов';
if(!isset($err)) {
mysql_query("UPDATE `forum_comm` SET `msg` = '$msg', `edited` = '1', `editor_id` = '$user[id]', `edit_time` = '".time()."'  WHERE `id` = '$post_msg[id]'");
header("Location: /topic?id=$post_msg[id_topic]&page=$page");
$_SESSION['message'] = 'Сообщение было изменено!';
exit();
}else{
header("Location: ");
$_SESSION['err'] = $err;
exit();
}
}
echo '<form class="player" method="post" action="?id='.$post_msg[id].'&page='.$page.'">
Сообщение<br /><textarea name="msg" class = "text large" rows="4" cols="55">'.rawuridecode($post_msg[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="/topic?id='.$post_msg[id_topic].'&page='.$page.'"><img src="/images/icon/section.png">Назад в топик</a></li></div>';
require_once '../core/foot.php';

}
?>