<?php

define('_IN_JOHNCMS', 1);

$textl = 'Блоги';
$headmod = 'dnevniki';


require_once ("../incfiles/core.php");
require_once ('inc.php');

if (!$user_id) {
    require_once ("../incfiles/head.php");
    echo '<div class="rmenu"><p>Доступ к Блогам открыт только <a href="../login.php">авторизованным</a> посетителям</p></div>';
    require_once ("../incfiles/end.php");
    exit;
}

require_once ("../incfiles/head.php");
$main_act = array('chancom', 'com', 'deldn', 'edit', 'editcom', 'new', 'say', 'showdn', 'view', 'wr','delcom', 'delrec', 'topview','vote','top','bad','newcm','reset','rescom','massdel');
if (in_array($act, $main_act))
{
   require_once ($act . '.php');
}
else
{
  echo '<div class="phdr">Блоги пользователей</div>';
    if (mysql_num_rows(mysql_query("SELECT * FROM `dnevniki` WHERE `userid` = '".$user_id."' AND `dnid` = 'dir' LIMIT 1"))) {
    $user = functions::get_user($user);
    echo '<div class="topmenu"><a href="?act=showdn&amp;id='.$user['id'].'">Мой блог</a></div>';
	echo '<div class="topmenu"><a href="?act=wr&amp;id='.$user['id'].'">Написать</a></div>';}
  else {
    echo '<div class="topmenu"><a href="?act=wr&amp;id='.$user_id.'"> Создать блог</a></div>';}
   /*echo '<div class="topmenu">';
 echo 'Топ: <a href="./?act=top">голосов</a> | <a href="./?act=topview">прочтений</a><br/>';
  $dn_new = blogs::dn_new();
  $dn_com = blogs::dnevniki_com_new();
  if($dn_new or $dn_com)
    echo 'Новые: '.($dn_new !=0 ? '<a href="?act=new">записи</a> <span class="red">('.$dn_new.')</span>' : '').(($dn_new and $dn_com) ? ' | ' : '').($dn_com !=0 ? '<a href="?act=newcm">комментарии</a> <span class="red">('.$dn_com.')</span>' : '').'';
  echo '</div>'; 
  */
  $total=mysql_result(mysql_query('SELECT COUNT(*) FROM `dnevniki` WHERE `dnid` = "txt" ;'), 0);

  if($total > 0)
{
   $res1 = mysql_query('SELECT * FROM `dnevniki` WHERE `dnid` = "txt" ORDER BY `id` DESC LIMIT '.$start.','.$kmess.';');
   $i=1;
  while($res = mysql_fetch_array($res1))
   {
      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-user"></i> '.$res['username'].' <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=topview&amp;id='.$id.'&amp;', $start, $total, $kmess) . '</div>';
}
else
{
  echo '<div class="menu">Нет записей!</div>';  
  echo '<div class="phdr">&nbsp;</div>';  
}
  if ($total > $kmess)
    echo '<div class="topmenu">' . functions::display_pagination('?', $start, $total, $kmess) . '</div>';


}
require_once ('../incfiles/end.php');
?> 