<?
include_once '../../core/system.php';
echo only_reg();
echo ban();
if (isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `news` WHERE `id` = '$get_id'"),0) == true){
$news = mysql_fetch_assoc(mysql_query("SELECT * FROM `news` WHERE `id`  = '$get_id'"));
mysql_query("UPDATE `user` SET `news_read` = '0' WHERE `id` = '$user[id]' LIMIT 1");

}else{
$_SESSION['err'] = "Новость не найдена";
header('Location: /news/');
exit();
} 

$header = $news[title];
include_once '../../core/head.php';
//Комментарии
if(isset($_POST['msg'])){
$msg = check($_POST['msg']);
if(strlen($msg) < 2 or strlen($msg) > 3000) $err =  'Длина сообщения должна быть в пределах 2 - 3000 символов';
if(!isset($err)) {
mysql_query("INSERT INTO `news_kom` SET `id_user` = '$user[id]', `id_news` = '$news[id]', `msg` = '$msg', `time` = '".time()."'");
header("Location: /news/post/$news[id]/");
$_SESSION['message'] = 'Сообщение добавлено!';
exit();
}else{
header("Location: /news/post/$news[id]/");
$_SESSION['err'] = $err;
// Вывод ошибки 
exit();
}
}

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_kom` 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_kom` WHERE `id_news` = '$news[id]' ORDER BY `time` ASC LIMIT $start, $set[p_str]");
echo "<div class='dot-line'></div>";
echo "<div class='player'>";
if($k_post == 0)echo "<span class='center grey'>Нет комментариев</div>";
while($post = mysql_fetch_assoc($q)) {
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[id_user]' LIMIT 1"));
if($ank[prava] == 5 )$color = 'Admin';
if($ank[prava] == 7 )$color = 'red';
if($ank[prava] == 4 )$color = 'Moder';
if($ank[prava] == 0 )$color = 'white';
echo "<div class='player'>";
if ($post['deleted'] == 1){
if ($ank['storona'] == '0') {?><img src="/images/icon/0.png" height="11" alt="a"/> <?php }
    if ($ank['storona'] == '1') {?><img src="/images/icon/1.png" height="11" alt="d"/> <?php }
echo online($ank[id]);
echo " <a href='/user/$ank[id]/'>$ank[nick] </a>";
echo "<a href='?comm=$ank[id]'>(»)</a>";
echo "<span class='white'> ".vremja($post[time])."</span><br>";
echo "<span class='grey'>Сообщение было удалено</span>";
}else{
if ($ank['storona'] == '0') {?><img src="/images/icon/0.png" height="11" alt="a"/> <?php }
    if ($ank['storona'] == '1') {?><img src="/images/icon/1.png" height="11" alt="d"/> <?php }
echo online($ank[id]);
echo " <a href='/user/$ank[id]/'>$ank[nick]</a> ";


if ($user['prava'] >= 4){
echo " / /";
echo "<a href='?post_del=".$post['id']."'> x </a>";
echo "//"; 
echo "<a href='/news/post/message_edit?id=".$post[id]."'> edit </a>";

echo "  // ";
}

echo "<a href='?comm=$ank[id]'>(»)</a> ".($user['prava'] == 5?'(<a href="?id='.$topic['id'].'&postd='.$post['id'].'">x</a>)':null).", ";
echo "<span class='white'>".vremja($post[time])."</span><br />";
if ($ank['prava'] >= '4') {
echo '<span class="'.$color.'">'.moder_smiles($post['msg']).'</span>';
}elseif ($ank['prava'] <= '3'){ 
echo '<span class="'.$color.'">'.smiles($post['msg']).'</span>';
}
if ($post[edited] == 1){
$post_editor = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id`  = '$post[editor_id]'"));
echo "<br /><span class='edited_post'>Отредактированно модератором $post_editor[nick]<br /> ".vremja($post[edit_time])." </span>";
}
}
echo "</div>";
echo "<div class='dot-line'></div>";
}
$us = mysql_fetch_assoc(mysql_query("SELECT * FROM `us_ban` where `usid` = '".$user['id']."' and `type` = 'forum' and `time`>'".time()."' "));
$nick = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` where `id` = '".$us['usban']."'"));
if($us['time'] > time())
{
$ban_time=$us['time']-time();
echo '<div class="line"></div><b><span class="red">Вам выдан бан на общение в чате<br><div class="dot-line"></div>До конца осталось:</span>
'.(int)($ban_time/3600).' час. '.($ban_time/60%60).' мин. '.($ban_time%60).' сек.
<br/><div class="dot-line"></div><span class="blue">Заблокировал:<a href="/user/'.$nick['id'].'/"><img src="/images/icon/user.png"/>'.$nick['nick'].' </span></a><br/><div class="dot-line"></div><span class="blue">Причина: </span>'.htmlentities($us['prich']).'</b><div class="line"></div>';
echo "</div>";
}else{
if($topic[close] == 0){
if(isset($_GET['comm'])){
$ank2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '$_GET[comm]'"));
echo '<form class="player" method="post" action="/news/post/'.$news[id].'/">
<textarea name="msg" rows = "4" cols ="15" class = "text large">'.$ank2[nick].', </textarea><br />
<span class="btn"><span class="end"><input class="label" type="submit" value="Отправить"></span></span>
</form>';
}else{
echo '<form class="player" method="post" action="/news/post/'.$news[id].'/">
<textarea name="msg" rows = "4" cols ="15" class = "text large"></textarea><br />
<span class="btn"><span class="end"><input class="label" type="submit" value="Отправить"></span></span>
</form>';
}
}else{
echo "<div class='center player red'>Топик закрыт!</div>";
}
}
if ($k_page>1)str('index.php?id=' . $news['id'] . '&amp;',$k_page,$page); // Вывод страниц
echo "<div class='mini-line'></div>";
echo "<div class='player menuList'>";
echo "<li><a href='/news/'><img src='/images/icon/arrow.png'>Назад</a></li>";
echo "</div></div>";
include_once '../../core/foot.php';
?>