<?php
defined('_IN_JOHNCMS') or die('Error: restricted access');

  $dn1 = mysql_query("SELECT * FROM `dnevniki` WHERE `userid` = '".$id."' AND `dnid` = 'dir' LIMIT 1");
  if (mysql_num_rows($dn1))
  {
    $req_user = mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."' LIMIT 1");
    $datauser = mysql_fetch_assoc($req_user);  
    $dn = mysql_fetch_assoc($dn1);
    if ($user_id==$id)
      echo '<div class="phdr"><a href="./">Блоги</a> | Мой блог</div>';
    else
      echo '<div class="phdr"><a href="./">Блоги</a> | Блог <b>'.($datauser['id'] ? '<a  href="../users/profile.php?user='.$id.'">'.$dn['username'].'</a>' : $dn['username'] ).'</b></div>';
    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `dnevniki` WHERE `dnid` = 'txt' AND `userid` = '".$id."'"), 0); 
    $req = mysql_query("SELECT * FROM `dnevniki` WHERE `dnid` = 'txt' AND `userid` = '".$id."' ORDER BY `vr` DESC LIMIT $start,$kmess"); 
    while ($res = mysql_fetch_assoc($req))
    {
     
      echo ($i % 2) ? '<div class="menu">' : '<div class="menu">';
      echo '<a href="/blogs?act=view&amp;id='.$res['id'].'"> '.htmlentities($res['zag'], ENT_QUOTES, 'UTF-8').'</a><br />';
         $cont = mysql_result(mysql_query("SELECT COUNT(*) FROM `dnevniki` WHERE `dnid` = 'com' AND `com_id` = '".$res['id']."'"), 0);

      echo '<i class="fa fa-clock-o"></i> '.date("d.m.y / H:i", $res['vr']).'  <i class="fa fa-eye" aria-hidden="true"></i> '.$res['views'].' <i class="fa fa-comments" aria-hidden="true"></i> '.$cont.'</div>';
      echo '';
      $i++;
   }
    echo '<div class="phdr">Всего записей: <b>'.$total.'</b></div>';
    if ($total > $kmess)
       echo '<div class="topmenu">' . functions::display_pagination('?act=showdn&amp;id='.$id.'&amp;', $start, $total, $kmess) . '</div>';
    if ($user_id==$id and !$ban[1] and !$ban[16])
       echo '<div class="topmenu"><a href="?act=wr&amp;id='.$id.'">Написать</a></div>';
    if (($user_id==$id or (($rights==2 or $rights >= 6) and $rights > $datauser['rights'])))
       echo '<div class="topmenu"><a href="?act=deldn&amp;id='.$id.'">Удалить блог</a></div>';
    echo '<div class="topmenu"><a href="./"> Блоги</a></div>';

  }
  else
  {
      echo functions::display_error('Такого Блога не существует!','<div class="topmenu"><a href="./">Назад</a><div>');
      require_once ('../incfiles/end.php');
      exit;
  }
?>
