<?
if(time()<$row['kik']){
$re = mysql_query("SELECT name FROM rooms where rm = '9'");
$inam = mysql_fetch_array ($re);
$nam = $inam['name'];
$tyu='center';
$title="Стоп!";
head();
echo $fs1;
$tleft = $row['kik'] - time();
$tleft=ceil($tleft/ 60 / 60 / 24);
$whokik = $row['whokik'];
$whykik = $row['whykik'];
echo $div1.'<b>Ошибка!</b>'.$div9;
echo "<br />Вам запрещенно писать <b>".$tleft." дней</b><br/>";
echo "Причина: <b>".$whykik."</b><br/><br />";
echo $div1.'<a href="'.H2.'enter.php">На главную</a>'.$div9;
foot();
exit;
}

echo $fs1;
$mess0 = @mysql_query( @"select  *  from  `forum_message`  where `id`='".$m."';" );
$mess = @mysql_fetch_array($mess0);
if (mysql_affected_rows() == 0){
echo $fs1;
echo '<b>Такого сообщения не существует!</b>';
echo $fs2;
foot();
exit;
}
$id = $mess ['topic'];

$q1 = @mysql_query( @"select  *  from  `forum_topic` where `id`='".$id."' ;" );
$topic = @mysql_fetch_array(@$q1);
if (mysql_affected_rows() == 0){
echo $fs1;
echo '<b>Такой темы не существует!</b>';
echo $fs2;
foot();
exit;
}
$f = $topic ['section'];
$sf = $topic ['subfor'];

$que = @mysql_query( "select * from  `forum_subfor` where id='$sf';" );
$dtm = @mysql_fetch_array( @$que );
$s_name = $dtm['name'];

$que = @mysql_query( "select * from  `forum_sections` where id='$f';" );
$dtm = @mysql_fetch_array( @$que );
$f_name = $dtm['name'];

echo "<dl><dt></dt></dl><a href=\"".F."\">Форумы</a>|<a href=\"".F."subfs/$f\">$f_name</a>";
echo "|<a href=\"".F."temes/$sf\">$s_name</a>|<a href=\"".F."tema/$id/$page\">".$topic ['name']."</a><br /><dl><dt></dt></dl>";

$q1 = @mysql_query( @"select  *  from  `forum_topic`  where `id`='".$id."' and subfor = '".$sf."' ;" );
$topic = @mysql_fetch_array( @$q1 );
if ($topic['close']==0)
{


$q2 = @mysql_query( @"select * from  `users` WHERE id = '$nk' ;" );
$sect2 = @mysql_fetch_array( @$q2 );


if (empty($act)){

$mess0 = @mysql_query( @"select  *  from  `forum_message`  where `id`='".$m."';" );
$mess = @mysql_fetch_array($mess0);
echo "Цитирование сообощения:<br />";
$q3 = @mysql_query( @"select * from  `users` WHERE id = '".$mess['login']."' ;" );
$sect3 = @mysql_fetch_array( @$q3 );
echo "<i><b>".$sect3['user']."</b>".date("[d.m в H:i", $time)."]  ";
$cit=substr($mess['msg'], 0, 200);
$cit=preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,500}).*#s','$1',$cit);
echo esc(trim(br(bbcode(links($cit)))))."...<br /><br /></i>\n";

if ($wap==2||$wap==3) echo "<form form method=\"post\" enctype=\"multipart/form-data\" action=\"\">";
echo "Сообщение:<br/>";
echo'<textarea cols="60" rows="4" name="msg" ></textarea><br />';
echo "<input type=\"hidden\" name=\"f\" value=\"$f\"/>";
echo "<input type=\"hidden\" name=\"sf\" value=\"$sf\"/>";
echo "<input type=\"hidden\" name=\"t\" value=\"$id\"/>";
echo "<input type=\"hidden\" name=\"nk\" value=\"$nk\"/>";
echo "<input type=\"hidden\" name=\"mod\" value=\"$mod\"/>";
echo "<input type=\"hidden\" name=\"m\" value=\"$m\"/>";
echo "<input type=\"hidden\" name=\"act\" value=\"act\"/>";
if ($wap=="1"){
echo $fs1;
echo "<anchor title=\"go\">Написать<go href=\"\" method=\"post\">";
echo "<postfield name=\"msg\" value=\"$(msg)\"/>";
echo "<postfield name=\"file\" value=\"$(file)\"/>";
echo "<postfield name=\"f\" value=\"$f\"/>";
echo "<postfield name=\"m\" value=\"$m\"/>";
echo "<postfield name=\"sf\" value=\"$sf\"/>";
echo "<postfield name=\"t\" value=\"$id\"/>";
echo "<postfield name=\"nk\" value=\"$nk\"/>";
echo "<postfield name=\"mod\" value=\"$mod\"/>";
echo "<postfield name=\"act\" value=\"act\"/>";
echo "</go></anchor>";
echo $fs2;
echo "<br/>";

}else{
echo "<input type=\"submit\" class=\"ibutton\" value=\"Написать\" class=\"cp\"><br /><br />";
}

if (!empty($nk)) echo "<b><a href=\"".H2.$nk."\">Анкета ".nik($sect2['user'])."</a></b><br /> ";
echo "<br /><img src=\"".H2."img/naz.gif\" alt=\"[N]\"/><a href=\"".F."tema/$id/$page\"><b>В тему</b></a><br />";
}else{
$mess0 = @mysql_query( @"select  *  from  `forum_message`  where `id`='".$m."';" );
$mess = @mysql_fetch_array($mess0);
$q3 = @mysql_query( @"select * from  `users` WHERE id = '".$mess['login']."' ;" );
$sect3 = @mysql_fetch_array( @$q3 );

$cit=substr($mess['msg'], 0, 200);
$cit=preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,0}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,500}).*#s','$1',$cit);

$cit = "[b]".$sect3['user']."[/b]".date("[d.m в H:i", $time)."]  ".$cit."...";

//$msg = "[i][b]".$sect3['user']."[/b]".date("[d.m в H:i", $time)."]  ".$mess['msg']."[/i]\n\r".$msg."";
$msg = check($_POST['msg']);
if ($row["translit"]==1) $msg = translit($msg);

$add = "Insert into forum_message set topic='".$id."', login ='".$row['id']."', msg='".$msg."',time='".time()."', section='".$f."', subfor = '".$sf."', cit = '".$cit."'";
if (mysql_query($add))
{   echo $fs1;
echo "<div>Ваше сообщение добавленно!</div>";
mysql_query("update `forum_topic` set time='".time()."' where id='".$id."';");
$postsf =  $row['postsf'];
$postsf++;
$posts =  $row['posts'];
$posts++;
$dayp =  $row['dayp'];
$dayp++;
mysql_query ("Update users set posts='".$posts."', postsf='".$postsf."', dayp='".$dayp."' where id ='".$myid."'");
header("Location: ".F."tema/$id/end");
echo $fs2;
}
}
}


echo $fs2;

?>