<?
require_once '../../../core/system.php';
echo only_reg();
echo moder();
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_topic` WHERE `id` = '".intval($_GET['id'])."'"),0) == true){
$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topic` WHERE `id`  = '".intval($_GET['id'])."'"));
}else{
$_SESSION['err'] = "Топик не найден!";
header('Location: /forum/');
exit();
}
$header = $topic[name];
require_once '../../../core/head.php';
if(isset($_POST['name']) && isset($_POST['msg'])) {
$name = check($_POST['name']);
$msg = check($_POST['msg']);
if(strlen($name) < 3 or strlen($name) > 40) $err =  'Длина названия должна быть в пределах 3 - 40 символов';
if(strlen($msg) < 10 or strlen($msg) > 2000) $err =  'Длина сообщения должна быть в пределах 10 - 2000 символов';
if(!isset($err)) {
mysql_query("UPDATE `forum_topic` SET `name` = '".mysql_real_escape_string($name)."', `msg` = '$msg' WHERE `id` = '$topic[id]' LIMIT 1");
header("Location: /forum/post/topic/$topic[id]/");
$_SESSION['message'] = 'Топик изменен!';
exit();
}else{
header("Location: /forum/post/topic/$topic[id]/");
$_SESSION['err'] = $err;
exit();
}
}
echo '<form class="player" method="post" action="?id='.$topic[id].'">
Введите Название<br /><input class="text large" value="'.$topic[name].'" type="text" name="name" /><br />
Введите сообщение<br /><textarea name="msg" class = "text large" rows="4" cols="55">'.$topic[msg].'</textarea>
<span class="btn"><span class="end"><input class="label" type="submit" value="Изменить">Изменить</span></span>
</form>';
require_once '../../../core/foot.php';
?>