<?
include 'config.php';
include 'func.php';
head();
aut();
ban();
####################Запись онлайна##################
mysql_query("UPDATE `profile` SET `online` = 'news' WHERE `id` = '".$id_session."'");
####################################################

echo head . "<b>Новости чата</b>" . div;   

switch($_GET['act']){
default:


$kol_news = mysql_result(mysql_query("SELECT count(*) FROM `news`"), 0);


if($kol_news == 0){


echo link2 . "Новостей нет" . div;

}else{

$limit = 10;//Лимит новостей на страницу
$result = mysql_query("SELECT * FROM news order by id desc limit ".$limit."");

while($news = mysql_fetch_assoc($result)){

echo link1 . "
Новость: <b>".html($news['name'])."</b> | ".strftime("%d.%m.%y",$news['date'])."" . div;

echo link2.smile(parsebb(adminbb(nl2br($news[msg]))))."<br/>
Разместил: <a href=\"profile.php?id=".html($news['razmestil_id'])."\"><b>".html($news['razmestil'])."</b></a>" . div;

$all = mysql_result(mysql_query("SELECT count(*) FROM news_coment WHERE `news` = '".$news['id']."'"), 0);
echo link1 . "<a href=\"news.php?act=coment&id=".$news['id']."\">Коментарии</a> [".$all."]" . div;


}
}
break;

case 'coment':
$id=(int)mysql_real_escape_string($_GET[id]);
$new = mysql_fetch_assoc(mysql_query("SELECT * FROM `news` WHERE `id` = '".$id."'"));

if ( $kik_session > time()) {
    echo link1;
    echo 'Вы заблокированы. По причине: '.$whykik_session.', администратором/модератором: '.user($whokik_session).'. Осталось ждать: '.t($kik_session-time()).'<br/>';
    navig();
    foot();
    exit();
}

if (isset($_GET['del']) AND $id_session >= 2) {
    $a = num($_GET['del']);
    mysql_query("DELETE FROM `news_coment` WHERE `id` = '".$a."'");
}
if ( isset($_POST['submit']) ) {
    
    $coment = html($_POST['msg']);
    $result = mysql_query("INSERT INTO `news_coment` SET `user_id` = '".$id_session."', `msg` = '".$coment."', `date` = '".$date."', `news` = '".$id."'");
    mysql_query("UPDATE `profile` SET `many` = '".($many_session+2)."' WHERE `id` = '".$id_session."'");
    if ( $result != NULL )
    echo link1 . 'Коментарий добавлен' . div;
    else
    echo link1 . 'Возникла ошибка' . div;
}
echo link2 . '<b>Коментарии к новости: '.$new['name']. '</b>' . div;

$all = mysql_result(mysql_query("SELECT count(*) FROM news_coment WHERE `news` = ".$id.""), 0);
if($all){
$onpage = 5;
$allpage = ceil($all/$onpage);
$this_page = (isset($_GET['p'])) ? intval($_GET['p']) : 1 ;
if($this_page < 1 || $this_page > $allpage)$this_page = 1;
$start = $this_page*$onpage - $onpage;
$result = mysql_query("SELECT * FROM news_coment WHERE `news` = ".$id." order by id desc limit ".$start.",".$onpage."");
while($coment = mysql_fetch_assoc($result)){
$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '".$coment[user_id]."'"));


echo link1 . "
<b>".html($user['login'])."</b> | ".date2($coment['date']). div  . link2 . mat(adminbb(parsebb(html($coment[msg])))). '';
if ($level_session >= 2) echo '<a href="news.php?act=coment&del='.$coment['id'].'&id='.$id.'"> [x]</a></div>';
}

echo link1 . '<b>Страницы:</b> ';
navigation($allpage,"news.php?act=coment&id=".$id."&p={p}",1,1);
echo div;
}

echo link2 . '<form action="news.php?act=coment&id='.$id.'" method="post" name="form">';
echo '<textarea id="tarea" name="msg" cols="30" rows="5" style="width: 99%;"></textarea><br/ >';
echo '<input name="submit" type="submit" class="button" value="Написать" /></form>' . div;
break;




}

navig();
foot();
?>