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

    $req = mysql_query("SELECT * FROM `dnevniki` WHERE `id` = '".$id."' AND `dnid` = 'txt' LIMIT 1"); 
    if (mysql_num_rows($req))
    {
      //метка о прочтении
      if (mysql_result(mysql_query("SELECT COUNT(*) FROM `dn_rdm` WHERE `dnid` = '".$id."' AND `user_id` = '".$user_id."'"), 0)==0)
        mysql_query("INSERT INTO `dn_rdm` SET `dnid` = '".$id."', `user_id` = '".$user_id."', `time` = '".time()."'");
        
      $res = mysql_fetch_assoc($req);
      $req_user = mysql_query("SELECT * FROM `users` WHERE `id` = '".$res['userid']."' LIMIT 1");
      $datauser = mysql_fetch_assoc($req_user);
      echo '<div class="phdr"><a href="./">Блоги</a> | '.($datauser['id'] ? '<a href="./?act=showdn&amp;id='.$res['userid'].'">'.$res['username'].'</a>' : $res['username']).'</div>';
      /*echo '<div class="topmenu">';
      $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>' : '').'';
      else
        echo 'Топ: <a href="./?act=top">голосов</a> | <a href="./?act=topview">прочтений</a><br/>';
      echo '</div>';
	  */
      echo '<div class="menu btop">';
	  
          $arg = array (
              'header' => ''.functions::display_date($res['vr']).'',
              'body' => $text,
              'iphide' => 1,
			  );
	   echo functions::display_user($datauser, $arg);
echo'<b>'.htmlentities($res['zag'], ENT_QUOTES, 'UTF-8').'</b><br />';
      $text=$res['text'];
      $text=functions::checkout($text, 1, 1);
      $text = functions::smileys($text, $datauser['rights'] ? 1 : 0);
      echo ''.$text.'';
      if ($res['last_mod']) echo '<br /><span class="gray"><small>Изм. <b>'.$res['mod_who'].'</b> ('.date("d.m.y | H:i", $res['last_mod']).')</small></span>';
      echo '</div><div class="gmenu">';
     //'.date("d.m.y / H:i", $res['vr']).' <br />
      echo '<i class="fa fa-eye" aria-hidden="true"></i> Просмотров: '.$res['views'].'';
      $cont = mysql_result(mysql_query("SELECT COUNT(*) FROM `dnevniki` WHERE `dnid` = 'com' AND `com_id` = '".$res['id']."'"), 0); 
	  echo '<br /><i class="fa fa-comments" aria-hidden="true"></i> Комментарии: '.$cont.dnevniki_com_new_local($res['id']).'</div>';
     echo '<div class="menu"><script src="//yastatic.net/es5-shims/0.0.2/es5-shims.min.js"></script>
<script src="//yastatic.net/share2/share.js"></script>
<div class="ya-share2" data-services="vkontakte,facebook,odnoklassniki,moimir,gplus,twitter,blogger,telegram"></div></div>';
	  echo '<div class="phdr"><a href="?act=com&amp;id='.$res['id'].'">Комментарии</a></div>';
       require_once ('com.php');
	  if ($user_id==$res['userid'] or (($rights >= 6) and $rights > $datauser['rights']))
      {
          echo '<img src="./img/edit.png" /> <a href="?act=edit&amp;id='.$id.'">Изменить</a> | ';
          echo '<a href="?act=delrec&amp;id='.$id.'">Удалить</a><br/>';
      }
         //счетчик +1
      mysql_query("UPDATE `dnevniki` SET `views` = '".($res['views']+1)."' WHERE `id` = '".$id."'");

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