<?

include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';
$set['title']='Новости - обсуждения';
include_once '../sys/inc/thead.php';
title();


if (!isset($_GET['id']) && !is_numeric($_GET['id'])){header("Location: index.php?".SID);exit;}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `news` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1",$db), 0)==0){header("Location: index.php?".SID);exit;}


if (isset($_POST['msg']) && isset($user))
{
$msg=$_POST['msg'];
if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);

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

if (strlen2($msg)>1024){$err='Сообщение слишком длинное';}
elseif (strlen2($msg)<2){$err='Короткое сообщение';}
elseif (mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '".intval($_GET['id'])."' AND `id_user` = '$user[id]' AND `msg` = '".my_esc($msg)."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
elseif(!isset($err)){
mysql_query("INSERT INTO `news_komm` (`id_user`, `time`, `msg`, `id_news`) values('$user[id]', '$time', '".my_esc($msg)."', '".intval($_GET['id'])."')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+5)."' WHERE `id` = '$user[id]' LIMIT 1");
$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '$user[id]' AND `lenta_forum` = '1' AND `i` = '1'");
while ($f = mysql_fetch_array($q))
{
$a = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$f[frend]' LIMIT 1"));

$msg_obsuzh="Принял участие в обсуждении [url=/news/]новостей[/url] Xhata.Su";

mysql_query("INSERT INTO `obsuzh` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$a[id]', '$msg_obsuzh', '$time')"); 
}
msg('Спасибо за комментарий +5 LM =)');
}
}

err();
if (isset($user))
{
echo "<div class='textmes'>"; 
echo "<form method=\"post\" name='message' action=\"?id=".intval($_GET['id'])."&amp;page=$page\">\n";
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 "Сообщение | <a href='/smiles/index.php'>Смайлы</a><br />\n<input name=\"msg\" type=\"text\" maxlength='600' value='' />\n";

echo "<input value=\"Оk\" type=\"submit\" /><br/>\n";
if ($user['set_translit']==1)echo "<label><input type=\"checkbox\" name=\"translit\" value=\"1\" /> Транслит</label><br />\n";
echo "</form>\n";
echo "</div>\n";
}
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `news_komm` WHERE `id_news` = '".intval($_GET['id'])."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `news_komm` WHERE `id_news` = '".intval($_GET['id'])."' ORDER BY `id` DESC LIMIT $start, $set[p_str]");
echo "<table class='post'>\n";
if ($k_post==0)
{

echo "Новость еще не обсуждали<br/>\n";

}
while ($post = mysql_fetch_assoc($q))
{

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

echo "   <tr>\n";
if($num==1){ 
echo "<div class='linechat'>"; 
$num=0;
}else{ 
echo "<div class='linechat'>"; 
$num=1;}

echo "".online($ank['id'])." <a href='/info.php?id=$ank[id]'><span style=\"color:$ank[ncolor]\">$ank[nick]</span></a> \n";


echo "<br/> \n";
echo "<span style=\"color:$ank[mcolor]\">\n";
echo output_text($post['msg'])."<br />\n";
echo "</span>\n";
echo "<div style='text-align: right;'><font color='#afb0a3'> ".vremja($post['time'])." </font><img src='/style/icons/clock.png'></img>\n";
if (isset($user) && ($user['level']>$ank['level'] || $user['level']!=0 && $user['id']==$ank['id']))
echo " <a href='delete.php?id=$post[id]'><b><font color='red'><img src='/style/icons/bdel.png' alt='' class='icon'/></font></b></a>\n";
echo "</div>\n";
}
echo "</div>\n";

if ($k_page>1)str("komm.php?id=".intval($_GET['id']).'&amp;',$k_page,$page); // Вывод страниц
echo "<div class='rekl'>"; 
echo "<img src='/style/back.gif' alt='' class='icon'/>\n";
echo "<a href='index.php'>Все новости</a><br />\n";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';
?>