<?
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;}
$news=mysql_fetch_array(mysql_query("SELECT * FROM `news` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
if (isset($_POST['msg']))
{
$msg=$_POST['msg'];
$msg = strtr($msg, array('B'=>'', 'b'=>'', 'C'=>'', 'c'=>'', 'D'=>'', 'd'=>'', 'F'=>'', 'f'=>'', 'G'=>'', 'g'=>'', 'H'=>'http://love.soclive.ru', 'h'=>'http://soclive.ru/', 'I'=>'', 'i'=>'', 'J'=>'', 'j'=>'', 'K'=>'', 'k'=>'', 'L'=>'', 'l'=>'', 'M'=>'', 'm'=>'', 'N'=>'', 'n'=>'', 'O'=>'', 'o'=>'', 'P'=>'', 'p'=>'', 'Q'=>'', 'q'=>'', 'R'=>'', 'r'=>'', 'S'=>'', 's'=>'', 'T'=>'', 't'=>'', 'U'=>'', 'u'=>'', 'V'=>'', 'v'=>'', 'W'=>'', 'w'=>'', 'X'=>'', 'x'=>'', 'Y'=>'', 'y'=>'', 'Z'=>'', 'z'=>''));

if (isset($_POST['translit']) && $_POST['translit']==1)$msg=translit($msg);
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` = '".mysql_real_escape_string($msg)."' LIMIT 1"),0)!=0){$err='Ваше сообщение повторяет предыдущее';}
else{
$msgfotokom="Обитатель $user[nick], Оставил коментарий в новости [b]$news[title][/b]";
if (isset($user))
{
mysql_query("INSERT INTO `jurnal` (`id_user`, `id_kont`, `msg`, `time`) values('0', '1', '$msgfotokom', '$time')");
}
mysql_query("INSERT INTO `news_komm` (`id_user`, `time`, `msg`, `id_news`) values('$user[id]', '$time', '".mysql_real_escape_string($msg)."', '".intval($_GET['id'])."')");
mysql_query("UPDATE `user` SET `balls` = '".($user['balls']+1)."' WHERE `id` = '$user[id]' LIMIT 1");
msg('Ваш комментарий успешно принят');
}
}

err();

aut(); // форма авторизации

if (isset($access['news_komm']))
{
echo "<form method=\"post\" name='message' action=\"?id=".intval($_GET['id'])."&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 '<div class="p_m">';
echo "Сообщение:<br />\n<textarea name=\"msg\"></textarea><br />\n";

echo "<input value=\"Отправить\" type=\"submit\" />\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]");
if ($k_post==0)
{

echo "Нет комментариев<br>\n";

}
while ($post = mysql_fetch_array($q))
{
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = $post[id_user] LIMIT 1"));

if($num==1){ echo "<div class='rowup'>"; 
$num=0;}
else
{echo "<div class='str'>";
$num=1;}
echo "".online($ank['id'])." ";

echo "<a href='/info.php?id=$ank[id]'><span style='color:$ank[ncolor]'>$ank[nick]</span></a> (".vremja($post['time']).")\n";
echo "<br>\n";
echo "<span style='color:$ank[color]'>\n";
echo output_text($post['msg'])."<br />\n";
echo "</span>\n";
if (isset($user) && ($user['level']>$ank['level'] || $user['level']==4))
echo "<a href='delete.php?id=$post[id]'>Удалить</a><br />\n";
echo "</div>\n";
}



if ($k_page>1)str("komm.php?id=".intval($_GET['id']).'&',$k_page,$page); // Вывод страниц




}

include_once '../sys/inc/tfoot.php';
?>