<?
include_once "../SYSTEM/include/functions.php";
include_once "../SYSTEM/include/mysql.php";
include_once "../SYSTEM/include/param.php";
include_once "../SYSTEM/include/ban.php";
include_once "../SYSTEM/include/sess.php";
include_once "../SYSTEM/include/ban_2.php";
include_once "../SYSTEM/include/theme.php";
$title='Изменить пост';
$mesto='Меняет пост в форуме';
head();

if (isset($_GET['page']))
{
$page=$_GET['page'];
}else{$page=1;}



if (!isset($_GET['id_forum']))
{
header ("Location: index.php?".SID."&");

exit;
}
if (!isset($_GET['id_forum']))
{
header ("Location: index.php?".SID."&");

exit;
}
$id_forum=intval($_GET['id_forum']);
$q = mysql_query("SELECT * FROM `$mysql[pref]forum_f` WHERE `id` = '$id_forum';");
if(mysql_num_rows($q) != 0)
{
$forum = mysql_fetch_array($q);
}
else
{
header ("Location: index.php?".SID."&");

exit;
}

if (!isset($_GET['id_razd']))
{
header ("Location: index.php?".SID."&id_forum=$id_forum");

exit;
}
$id_razd=intval($_GET['id_razd']);
$q = mysql_query("SELECT * FROM `$mysql[pref]forum_r` WHERE `id_f` = '$id_forum' AND `id` = '$id_razd';");
if(mysql_num_rows($q) != 0)
{
$razd = mysql_fetch_array($q);
}
else
{
header ("Location: index.php?".SID."&id_forum=$id_forum");

exit;
}

if (!isset($_GET['id_them']))
{
header ("Location: index.php?".SID."&id_forum=$id_forum&id_razd=$id_razd");

exit;
}
$id_them=intval($_GET['id_them']);
$q = mysql_query("SELECT * FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd' AND `id` = '$id_them';");
if(mysql_num_rows($q) != 0)
{
$thema = mysql_fetch_array($q);
}
else
{
header ("Location: index.php?".SID."&id_forum=$id_forum&id_razd=$id_razd");

exit;
}

if (!isset($_GET['id_post']))
{
header ("Location: index.php?".SID."&id_forum=$id_forum&id_razd=$id_razd");

exit;
}
$id_post=intval($_GET['id_post']);
$q = mysql_query("SELECT * FROM `$mysql[pref]forum_p` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd' AND `id_t` = '$id_them' AND `id` = '$id_post';");
if(mysql_num_rows($q) != 0)
{
$post = mysql_fetch_array($q);
}
else
{
header ("Location: index.php?".SID."&id_forum=$id_forum&id_razd=$id_razd&id_them=$id_them&page=$page");

exit;
}


if (!isset($user) || $user['level']<1 && $user['id']!=$post['id_us'] || $them['close']==1 || $them['time_mod']!=0)

{

header ("Location: index.php?".SID."");


exit;

}






if (isset($_GET['act']) && $_GET['act']=='set')

{

if (isset($_POST['del']) && $_POST['del']==1 && $user['level']>0)

{

mysql_query("DELETE FROM `$mysql[pref]forum_p` WHERE `id` = '$id_post';");

action("Удаление поста в форуме");

header("Location: index.php?".SID."&act=set&id_forum=$id_forum&id_razd=$id_razd&id_them=$id_them&page=$page");

exit;

}

$msg=$_POST['msg'];

$msg=stripslashes(htmlspecialchars($msg));


$msg=str_replace("\r\n","<br />",$msg);

$msg=str_replace("\r","<br />",$msg);

$msg=str_replace("\n","<br />",$msg);

if (isset($_POST['tr'])){$msg=translit($msg);}

$msg=$msg;

mysql_query("UPDATE `$mysql[pref]forum_p` SET `msg` = '$msg', `time_mod` = '$time', `id_mod` = '$user[id]', `nick_mod` = '$user[nickname]' WHERE `id` = '$id_post';");

action("Изменение поста в форуме");

header("Location: index.php?act=set&id_forum=$id_forum&id_razd=$id_razd&id_them=$id_them&page=$page");


exit;


}




$msg=str_replace("<br />","\n",$post[msg]);




echo "<div class=\"h\">Редактировать пост $post[nick]</div><hr />\n";


if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";


echo "<br /><form method=\"post\" action=\"set_p.php?act=set&amp;id_forum=$id_forum&amp;id_razd=$id_razd&amp;id_them=$id_them&amp;id_post=$id_post&amp;page=$page\">\n";

echo "<div class=\"menu\">";

echo "<div class=\"title\">Параметры</div>";

echo "<textarea name=\"msg\" class=\"form\" rows=\"3\">$msg</textarea><br />\n";

if ($user['level']>0)echo "<input type=\"checkbox\" name=\"del\"  value=\"1\" /> Удалить пост<br />\n";

echo "<input value=\"Изменить\" class=\"form\" type=\"submit\" />\n";


echo "</div>\n";

echo "</form>\n";












echo "<a href=\"index.php?id_forum=$id_forum&amp;id_razd=$id_razd&amp;id_them=$id_them&amp;page=$page\">Вернуться</a>\n";

echo "<br /><a href=\"../index.php\">На главную</a><br />\n";


foot();

?>

