<?
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['mp']))
define('G', BASEDIR);
else
define('G', BASEDIR.'guest/');

if (!isset($user) || $user['level']<1)
{
header ("Location: ".G."index.php?".SID."");
exit;
}


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

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

exit;
}

if (isset($_GET['act']) && $_GET['act']=='del')
{
mysql_query("DELETE FROM `$mysql[pref]chat_main` WHERE `id` = '$id_post';");
header("Location: ".G."index.php?".SID."");
exit;
}

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

$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);}
mysql_query("UPDATE `$mysql[pref]chat_main` SET `text` = '$msg' WHERE `id` = '$id_post';");

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

exit;

}


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 "<form method=\"post\" action=\"set.php?act=set&amp;id_post=$id_post".((isset($_GET['mp'])) ? '&amp;mp' : '')."\">\n";
echo "<div class=\"menu\">";
echo "<div class=\"title\">Изменить</div>";
echo "<textarea name=\"msg\" class=\"form\" rows=\"3\">$post[text]</textarea><br />\n";
echo "<input value=\"Изменить\" class=\"form\" type=\"submit\" />\n";
echo "</div>";
echo "</form>\n";

echo "<form method=\"post\" action=\"set.php?act=del&amp;id_post=$id_post".((isset($_GET['mp'])) ? '&amp;mp' : '')."\">\n";
echo "<div class=\"menu\">";
echo "<div class=\"title\">Удалить</div>";
echo "<input value=\"Удалить\" class=\"form\" type=\"submit\" />\n";
echo "</div>";
echo "</form>\n";

echo "<a href=\"".G."index.php\">Вернуться</a><br />\n";
if(!isset($_GET['mp']))
echo "<a href=\"../index.php\">На главную</a><br />\n";

foot();
?>
