<?php
require_once '../core/system.php';
echo only_reg();
if (isset($_GET['id'])){
include '1.2.3_include.php';
if ($topic_razdel['clan_forum'] == '1' || $topic_parent_razdel['clan_forum'] == '1') {
include 'include_clan_forum_topic_edit.php';
}elseif ($topic_razdel['clan_forum'] == '0' || $topic_parent_razdel['clan_forum'] == '0'){
include 'include_forum_topic_edit.php';
}else{
$_SESSION['err'] = "Топик не найден!";
header('Location: /forum');
exit();
}
}
$header = rawuridecode($topic[name]);
$content = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_comm` WHERE `id_topic`  = '$topic[id]' AND `topic_content` = '1'"));
require_once '../core/head.php';

if(isset($_POST['name']) && isset($_POST['msg'])) {
$name = check(filter($_POST['name']));
$msg = check(filter($_POST['msg']));
if(mb_strlen($_POST['name']) < 3 or mb_strlen($_POST['name']) > 20) $err =  'Длина названия должна быть в пределах 3 - 20 символов';
if(mb_strlen($_POST['msg']) < 2 or mb_strlen($_POST['msg']) > 2500) $err =  'Длина сообщения должна быть в пределах 2 - 2500 символов';
if(!isset($err)) {
mysql_query("UPDATE `forum_topic` SET `name` = '$name' WHERE `id` = '$topic[id]' LIMIT 1");
mysql_query("UPDATE `forum_comm` SET `msg` = '$msg' WHERE `id_topic` = '$topic[id]' AND `topic_content` = '1' LIMIT 1");
header("Location: /topic?id=$topic[id]");
$_SESSION['message'] = 'Топик изменен!';
exit();
}else{
header("Location: /topic?id=$topic[id]");
$_SESSION['err'] = $err;
exit();
}
}
echo '<form class="player" method="post" action="?id='.$topic[id].'">
Введите Название<br /><input class="text large" value="'.rawuridecode($topic[name]).'" type="text" name="name" /><br />
Введите сообщение<br /><textarea name="msg" class = "text large" rows="4" cols="55">'.rawuridecode($content[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='.$topic[id].'"><img src="/images/icon/arrow.png">Назад в топик</a></li></div>';
require_once '../core/foot.php';
?>