<?
include $_SERVER['DOCUMENT_ROOT']."/anti_ hacker.php"; 
if (isset($user)  && ($them['close']==0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid']) && isset($_GET['act']) && $_GET['act']=='new' && isset($_POST['msg']))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
if (strlen2($msg)<2)$err='Короткое сообщение';
if (strlen2($msg)>10000)$err='Длина сообщения превышает предел в 10000 символов';

$mat=antimat($msg);
if ($mat)$err[]='В тексте сообщения обнаружен мат: '.$mat;

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_mess` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_soo` = '$soo[id]' AND `id_user` = '$user[id]' AND `mess` = '".my_esc($msg)."' LIMIT 1"),0)!=0)$err='Ваше сообщение повторяет предыдущее';

if (!isset($err))
{

if (isset($_POST['cit']) && is_numeric($_POST['cit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_mess` WHERE `id` = '".intval($_POST['cit'])."' AND `id_them` = '".intval($_GET['id_them'])."' AND `id_soo` = '".intval($_GET['s'])."' AND `id_forum` = '".intval($_GET['id_forum'])."'"),0)==1)
$cit=intval($_POST['cit']); else $cit='null';
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("INSERT INTO `soo_forum_mess` (`id_forum`, `id_soo`, `id_them`, `id_user`, `mess`, `time`, `cit`) values('$forum[id]', '$soo[id]', '$them[id]', '$user[id]', '".my_esc($msg)."', '$time', '$cit')");

$post_id=mysql_insert_id();

unset($_SESSION['msg']);

mysql_query("UPDATE `soo_forum_thems` SET `time` = '$time' WHERE `id` = '$them[id]' LIMIT 1");
msg('Сообщение успешно добавлено');
 

aut();

header("Refresh: 1; url=?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&page=end&".SID);
echo "<div class='menu'>\n";
echo "<a style='font-weight:bold;' href=\"?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&page=end\" title='Перейти в тему'>Перейти в тему</a><br />\n";
echo "<a href=\"?s=$soo[id]&id_forum=$forum[id]\" title='Вернуться в раздел'>".filter_var($forum['name'], FILTER_SANITIZE_SPECIAL_CHARS)."</a><br />\n";
echo "<a href=\"forum.php?s=$soo[id]\">К списку форумов</a><br />\n";
echo "<a href=\"index.php?s=$soo[id]\">В сообщество</a><br />\n";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';


}

}

if ($them['close']==1)
msg('Тема закрыта для обсуждения');

err();
aut();




$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_mess` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_soo` = '$soo[id]'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
echo "<table class='post'>\n";
if ((isset($user) && $user['id']==$soo['admid'] || isset($user) && $ank2['id']==$user['id']) && isset($_GET['act']) && $_GET['act']=='post_delete'){$lim=NULL;}else $lim=" LIMIT $start, $set[p_str]";
$q=mysql_query("SELECT * FROM `soo_forum_mess` WHERE `id_them` = '$them[id]' AND `id_forum` = '$forum[id]' AND `id_soo` = '$soo[id]' ORDER BY `time` ASC$lim");
if (mysql_num_rows($q)==0) {
echo "   <tr>\n";
echo "  <td class='p_t'>\n";
echo "Нет сообщений в теме \"".filter_var($them['name'], FILTER_SANITIZE_SPECIAL_CHARS)."\"\n";
echo "  </td>\n";
echo "   </tr>\n";
}
$post_k=$start;
while ($post = mysql_fetch_assoc($q))
{



$ank=get_user($post['id_user']);
$post_k++;

echo "   <tr>\n";




if ($set['set_show_icon']==2){
echo "  <td class='icon48' rowspan='2'>\n";

if ((isset($user) && $user['id']==$soo['admid'] || isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `mod`='1' LIMIT 1"),0)==1) && isset($_GET['act']) && $_GET['act']=='post_delete')
{
echo "<input type='checkbox' name='post_$post[id]' value='1' />";
}
else
///avatar($ank['id']);
///avatar4($ank['id']);

echo "  </td>\n";
}
elseif ($set['set_show_icon']==1)
{
echo "  <td class='icon14'>\n";
if ((isset($user) && $user['id']==$soo['admid'] || isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `mod`='1' LIMIT 1"),0)==1) && isset($_GET['act']) && $_GET['act']=='post_delete')
{
echo "<input type='checkbox' name='post_$post[id]' value='1' />";
}
else
echo "<img src='/style/themes/$set[set_them]/user/$ank[pol].png' alt='' />";
echo "  </td>\n";
}



if ($set['show_num_post']==1)$num_post=$post_k.') '; else $num_post=NULL;

echo "  <td class='p_t'>\n";
if (isset($user) && $them['close']==0 && (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid']))
echo "$num_post<a href='?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&id_post=$post[id]&act=msg' title='Ответить $ank[nick]'><span style=\"color:$ank[color]\">$ank[nick]</span></a>".online($ank['id'])." (".vremja($post['time']).")\n";
else
echo "$num_post<a href='/info.php?id=$ank[id]' title='Анкета $ank[nick]'>$ank[nick]</a> ".online($ank['id'])." (".vremja($post['time']).")\n";
echo "  </td>\n";
echo "   </tr>\n";
echo "   <tr>\n";
if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";
if ($post['cit']!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_forum_mess` WHERE `id` = '$post[cit]'"),0)==1)
{
$cit=mysql_fetch_assoc(mysql_query("SELECT * FROM `soo_forum_mess` WHERE `id` = '$post[cit]' LIMIT 1"));
//$ank_c=mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = $cit[id_user] LIMIT 1"));
$ank_c=get_user($cit['id_user']);
echo "<div class='cit'>\n";
echo "<b>$ank_c[nick] (".vremja($cit['time'])."):</b><br />\n";
echo output_text($cit['mess'])."<br />\n";
echo "</div>\n";
}

echo output_text($post['mess'])."<br />\n";


if (isset($user) && $user['id']==$soo['admid'])
echo "<a href='?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&id_post=$post[id]&act=edit'>Редактировать</a>\n";
elseif (isset($user) && $user['id']==$post['id_user'] && $post['time']>time()-600 && $post_k==$k_post)
echo "<a href='?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&id_post=$post[id]&act=edit'>Редактировать (".($post['time']+600-time())." сек)</a>\n";



if (isset($user) && $them['close']==0 && $user['id']==$post['id_user'] && $post['time']>time()-600 && $post_k==$k_post)
echo ' | ';
elseif ($them['close']==0 && isset($user) && $user['id']==$soo['admid'])
echo ' | ';



if ($them['close']==0 && isset($user) && (mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid']))
echo "<a href='?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&id_post=$post[id]&act=cit' title='Цитировать $ank[nick]'>&ldquo;Цитировать&rdquo;</a><br />\n";






echo "  </td>\n";
echo "   </tr>\n";
}
echo "</table>\n";
if ((isset($user) && $user['id']==$soo['admid'] || isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `mod`='1' LIMIT 1"),0)==1) && isset($_GET['act']) && $_GET['act']=='post_delete'){}
elseif ($k_page>1)str("?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&",$k_page,$page); // Вывод страниц

if ((isset($user) && $user['id']==$soo['admid'] || isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `mod`='1' LIMIT 1"),0)==1) && isset($_GET['act']) && $_GET['act']=='post_delete'){}
elseif (isset($user) && ($them['close']==0 && mysql_result(mysql_query("SELECT COUNT(*) FROM `soo_users` WHERE `id_soo` = '$soo[id]' AND `id_user`='$user[id]' AND `invit`='0' AND `activate`='0' LIMIT 1"),0)==1 || $user['id']==$soo['admid']))
{
echo "<form method='post' name='message' action='?s=$soo[id]&id_forum=$forum[id]&id_them=$them[id]&act=new&$passgen'>\n";
if (isset($_POST['msg']))$msg2=output_text($_POST['mess'],false,true,false,false,false); else $msg2=NULL;


if ($set['web'] && is_file(H.'style/themes/'.$set['set_them'].'/altername_post_form.php'))
include_once H.'style/themes/'.$set['set_them'].'/altername_post_form.php';
else
echo "Сообщение:<br />\n<textarea name=\"msg\">$msg2</textarea><br />\n";

if ($user['set_translit']==1)echo "<label><input type=\"checkbox\" name=\"translit\" value=\"1\" /> Транслит</label><br />\n";

echo "<input name='post' value='Отправить' type='submit' /><br />\n";
echo "</form>\n";
}
echo "<div class=\"foot\">\n";
echo "&raquo;<a href=\"/smiles.php\">Смайлы</a><br />\n";
echo "&raquo;<a href=\"/rules.php\">Правила</a><br />\n";
echo "</div>\n";


?>