<?php
require_once('../classes/body.class.php');
require_once('../classes/db.class.php');
require_once('../classes/system.class.php');
$title= new Body;

if (!isset ($_GET['id'])) { 
        header ('location: /'); 
        exit; 
} 

$query = DB :: $dbs -> query ("SELECT * FROM `blogger` WHERE (`id`=?)", array ((int) $_GET['id'])); 
if ($query -> rowCount () == 0) { 
        header ('location: /'); 
        exit; 
} 

$u = $query -> fetch (); 

$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new` WHERE (`us`='" . $u['id'] . "')");

$title->SetTitle('Новости ' .$u['nick'] .' (' . $items . ')'); 
$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']).'  (' . $items . ')</div>';


if ($u['id']==$b['id']) { 

        echo '<div class="list-group-item media">'; 
        echo '<form action="/feed/news.php?id=' . $u['id'] . '&send" method="post">'; 
        echo 'Новости:<br/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea name="text"class="form-control" rows="5"></textarea><br/>'; 
        echo '<input class="btn btn-primary btn-block" type="submit" name="add" value="Написать"/>'; 
        echo '</form>'; 
        echo '</div>'; 


        if (isset ($_GET['send'])) { 
                $_POST['text'] = htmlspecialchars (addslashes (trim ($_POST['text']))); 
                if (empty ($_POST['text'])) { 
                        echo '<div class="alert alert-danger" role="alert">Вы не ввели текст новости..</div>'; 
                }  else { 
if (DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new` WHERE (`us`='" . $b['id'] . "') AND (`t`>'" . (time () - 0) . "')") != 0) { 
                    echo '<div class="alert alert-danger" role="alert">Вы пишите слишком часто!</div>'; 
                        } 
                        else { 
                                DB :: $dbs -> query ("INSERT INTO `new` (`us`,`kem`,`text`,`t`) VALUES ('" . $u['id'] . "', '" . $b['id'] . "', ?, '" . time () . "')", array ($_POST['text'])); 
                                header ('location: /feed/news.php?id=' . $u['id']); 
                        } 
                } 
        }         
} 

if (isset ($_GET['del'])) { 
        if ($u['id']==$b['id'] || $u['level']<$b['level'] && $b['level']>1) { 

                $query = DB :: $dbs -> query ("SELECT * FROM `new` WHERE (`id`=?)", array (intval ($_GET['del']))); 
                if ($query -> rowCount () != 0) { 
                        $new = $query -> fetch (); 
                        if ($new['us']==$u['id']) { 
                                DB :: $dbs -> query ("DELETE FROM `new` WHERE (`id`='" . $new['id'] . "')"); 
                                DB :: $dbs -> query ("DELETE FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "')"); 
                        } 
                } 
         
        } 
        header ('location: /feed/news.php?id=' . $u['id']); 
} 

$num = 10;
$k_page = k_page($items, $num);
$page = page($k_page);
$start = $num*$page-$num;
if ($items == 0) { 
        echo '<div class="alert alert-danger" role="alert">У <b>' . Nick ($u['id']) . '</b> пока нет новостей!</div>'; 
} 
else { 
         echo'<div class="catSides"><i class="md md-comment"></i> Все новости</div>';

  $query = DB :: $dbs -> query ("SELECT * FROM `new` WHERE (`us`='" . $u['id'] . "') ORDER BY `id` DESC LIMIT $start, $num"); 
        while ($new = $query -> fetch ()) { 
                 
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>';

               
                if ($u['id']==$b['id'] || $u['level']<$b['level'] && $b['level']>1) { 
                        $D = ('<a href="/feed/news.php?id=' . $u['id'] . '&del=' . $new['id'] . '">[Удл]</a>'); 
                }
                     
                if (!empty ($new['text'])) { 
                        echo '<div class="citat">'.text ($new['text']).' '.$D.'</div>'; 
                } 

            
   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">'.$reply.'</textarea><br/><input class="btn btn-primary btn-block" type="submit" name="add" value="Написать"/></form></div>';
                 
                $itemss = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "')"); 
                if ($itemss != 0) { 
                        
                         
        $q = DB :: $dbs -> query ("SELECT * FROM `new_komm` WHERE (`id_new`='" . $new['id'] . "') ORDER BY `id` DESC LIMIT 3"); 
                        while ($komm = $q -> fetch ()) { 
                                echo '<div class="row text_box">'; 
                                echo Nick ($komm['us']) . ' (' . vr($komm['t']) . ')'; 

                                if ($komm['us']!=$b['id']) { 
                                        echo ' [<a href="/newkomm.php?id=' . $new['id'] . '&komu=' . $komm['us'] . '">Отв</a>] '; 
                                } 

                                if ($komm['us']==$b['id'] && $b['level']>1 || $u['level']<$b['level'] && $b['level']>1) { 
                                        echo ' [<a href="/newkomm.php?id=' . $new['id'] . '&del=' . $komm['id'] . '">Удл</a>] '; 
                                } 
                                 
                                echo '</div><div class="citat">'; 
                                echo text ($komm['text']); 
                                echo '</div>'; 
                        } 
                        if ($itemss>5) { 
echo '<div class="catSides"><i class="md md-comment"></i>  <a href="/feed/komm.php?id=' . $new['id'] . '"style="text-decoration:none; color:white;">Показать все комментарии</a> (' . $itemss . ')</div>'; 
                        } 
                          
                } 
        } 
         if ($k_page>1) {
str('news.php?id='.$id.'&', $k_page,$page);
}
} 

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

?>
