<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;
$query = DB :: $dbs -> query ("SELECT * FROM `new` WHERE (`id`=?)", array (intval ($_GET['id'])));
if ($query -> rowCount () == 0) { 
        header ('location: /'); 
        exit; 
} 
$new = $query -> fetch (); 
$u   = DB :: $dbs -> queryFetch ("SELECT * FROM `blogger` WHERE (`id`='" . $new['us'] . "')"); 
$title->SetTitle('Личные новости ' . $u['nick']); 
$title->GetHeader();
echo '<div class="container-fluid page_header"><div class="container"><div class="row"><div class="col-xs-12 col-sm-8 col-md-9 col-lg-9"><h1>Просмотр новостей ' . $u['nick'].' </h1><ol class="breadcrumb" xmlns:v="http://'.homeurl.'/#"><li typeof="v:Breadcrumb"><a href="/" rel="v:url" property="v:title">'.homeurl.'</a></li><li class="active" typeof="v:Breadcrumb"><span property="v:title">Новости ' . $u['nick'].'</span></li></ol></div></div></div></div>';
echo'<div class="container page_body"><div class="row"><div class="col-xs-12 page_content col-lg-9"><div class="navbar page_content_navbar collapse hidden-lg"><div class="container-fluid"><div class="navbar-collapse"></div></div></div><div class="text_box hidden-lg pr_block_small hidden"></div><div class="container-fluid cols_table">';
echo '<div class="catSides"><a href="/"><i class="md-format-list-bulleted"></i> Главная </a> - Личные новости ' . Nick ($u['id']).'</div>';

echo '<div class="row text_box"><a href="/users/'.$new['kem'].'"><div class="pull-left"><img class="img-circle pull-left" src="/'.$u['ava'].'" alt="" width="40" height="40"></div><div class="media-body"><div class="list-group-item-heading">  '.Nick($new['kem']).'  ('.vr($new['t']).')</div></a></div></div>';

echo '<div class="row text_box">'; 
if (!empty ($new['komm'])) { 
echo 'Комментарий: <b>' . text ($new['komm']) . '</b><br/>'; 
} 

if (!empty ($new['text'])) { 
    echo text ($new['text']); 
} 
echo '</div>'; 

$_GET['komu'] = isset ($_GET['komu']) ? intval ($_GET['komu']) : 0; 

if ($_GET['komu']!=0) { 
        $query = DB :: $dbs -> query ("SELECT * FROM `blogger` WHERE (`id`=?)", array (intval ($_GET['komu']))); 
        if ($query -> rowCount () == 0) { 
                header ('location: /feed/komm.php?id=' . $new['id']); 
                exit; 
        } 
        $komu = $query -> fetch (); 
        if ($komu['id']==$b['id']) { 
                header ('location: /feed/komm.php?id=' . $new['id']); 
                exit; 
        } 
} 
echo'<div class="catSides"><i class="md md-comment"></i> Добавить комментарий</div>';
echo '<div class="row text_box"><form name="form" method="post" action="/feed/komm.php?id=' . $new['id'] . '&add" ><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea class="form-control" rows="3"name="komm" value="' . ($_GET['komu']!=0 ? '[b]' . $komu['nick'] . '[/b], ' : '') . '">'.$reply.'</textarea><br/><input class="btn btn-primary btn-block" type="submit" name="add" value="Написать"/></form></div>';

if (isset ($_GET['add'])) { 
        $_POST['komm'] = htmlspecialchars (addslashes (trim ($_POST['komm']))); 

  if (DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new_komm` WHERE (`us`='" . $b['id'] . "') AND (`t`>'" . (time () - 0) . "')") != 0) { 
                echo '<div class="alert alert-danger" role="alert">Вы пишите слишком часто..</div>'; 
        } 
        elseif (empty ($_POST['komm'])) { 
                echo '<div class="alert alert-danger" role="alert">Вы не ввели текст комментария..</div>'; 
        } 
        else { 
                DB :: $dbs -> query ("INSERT INTO `new_komm` (`id_new`, `us`,`text`,`t`, `komu`) VALUES ('" . $new['id'] . "', '" . $b['id'] . "', ?, '" . time () . "', '" . $komu['id'] . "')", array ($_POST['komm'])); 
                if ($new['kem']!=$b['id']) { 
$mess1 = 'Вам ответили в комментариях к вашей <a href="/feed/komm.php?id=' . $new['id'] . '"><b>новости</b></a>!';
jurnal($new['kem'],$mess1,3);
                } 
                if ($_GET['komu']!=0) { 
$mess = 'Вам ответили в комментариях к <a href="/feed/komm.php?id=' . $new['id'] . ']<b>новости</b></a>!';
jurnal($komu['id'],$mess,3);
                } 
                header ('location: /feed/komm.php?id=' . $new['id']); 
        } 
} 

if (isset ($_GET['del'])) { 
        $query = DB :: $dbs -> query ("SELECT * FROM `new_komm` WHERE (`id`=?)", array (intval ($_GET['del']))); 
        if ($query -> rowCount () == 0) { 
                header ('location: /feed/komm.php?id=' . $new['id']); 
                exit; 
        } 
        $komm = $query -> fetch (); 
        $u    = DB :: $dbs -> queryFetch ("SELECT * FROM `blogger` WHERE (`id`='" . $komm['us'] . "')"); 
         
        if ($komm['us']!=$b['id'] && $b['level']<2 || $u['level']>$b['level']) { 
                header ('location: /feed/komm.php?id=' . $new['id']); 
                exit; 
        } 
         
        DB :: $dbs -> query ("DELETE FROM `new_komm` WHERE (`id`='" . $komm['id'] . "')"); 
        header ('location: /feed/komm.php?id=' . $new['id']); 
} 

$k_mess = DB::$dbs->querySingle("SELECT COUNT(*) FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "')"); 
$num = 10;
$k_page = k_page($k_mess, $num);
$page = page($k_page);
$start = $num*$page-$num;
if ($k_mess == 0) { 
        err('Комментариев нет..'); 
} 
else { 
$query = DB :: $dbs -> query ("SELECT * FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "') ORDER BY `id` DESC LIMIT $start, $num"); 
        while ($komm = $query -> fetch ()) { 
         
                $u   = DB :: $dbs -> queryFetch ("SELECT * FROM `blogger` WHERE (`id`='" . $komm['us'] . "')"); 
                echo '<div class="row text_box">'; 
                echo Nick ($komm['us']) . ' (' . vr ($komm['t']) . ')'; 
                if ($komm['us']!=$b['id']) { 
                        echo ' [<a href="/feed/komm.php?id=' . $new['id'] . '&komu=' . $komm['us'] . '">Отв</a>] '; 
                } 
                if ($komm['us']==$b['id'] && $b['level']>1 || $new['us']==$b['id'] || $u['level']<$b['level'] && $b['level']>1) { 
                        echo ' [<a href="/feed/komm.php?id=' . $new['id'] . '&del=' . $komm['id'] . '">Удл</a>] '; 
                } 
                echo '</div><div class="citat">'; 
                echo text ($komm['text']); 
                echo'</div>';
        } 
} 

$title->GetMenu();
$title->GetFooter();

?>