<?php
defined('_IN_JOHNCMS') or die('Error: restricted access');
    $req222 = mysql_query("SELECT * FROM `dnevniki` WHERE `dnid` = 'txt' AND `id` = '".$id."' ORDER BY `vr` DESC LIMIT 1");
    if (mysql_num_rows($req222))
    {
      $res222 = mysql_fetch_assoc($req222);
      $req_user222 = mysql_query("SELECT * FROM `users` WHERE `id` = '".$res222['userid']."' LIMIT 1");
      $datauser222 = mysql_fetch_assoc($req_user222);
      //echo '<div class="phdr"><a href="./">Блоги</a> | '.$res222['username'].'</div>';
     // echo '<div class="phdr"><img src="img/dn.png" width="16" height="16" />  <b><a href="?act=view&amp;id='.$res222['id'].'">'.htmlentities($res222['zag'], ENT_QUOTES, 'UTF-8').'</a></b> | Комментарии</div>';
      if(!$ban['1'] and !$ban['16'] and !$ban['10'])
      {
        echo '<div class="gmenu"><form name="mess" action="?act=say&amp;id='.$id.'" method="post">Ваш комментарий (max. 2000):<br/>';
        echo bbcode::auto_bb('mess', 'msg').'<textarea class="form-control" rows="' . $set_user['field_h'] . '" name="msg"></textarea><br/>';
        //echo '<input type="checkbox" name="msgtrans" value="1" /> Транслит сообщения<br/>';
        echo '<input class="btn btn-default" style="width:100%;" type="submit" title="Нажмите для отправки" name="submit" value="Отправить"/>';
        echo '</form></div>';
      }
      $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `dnevniki` WHERE `dnid` = 'com' AND `com_id` = '".$id."'"), 0);       
      $req = mysql_query("SELECT * FROM `dnevniki` WHERE `dnid` = 'com' AND `com_id` = '".$id."' ORDER BY `vr` DESC LIMIT $start,$kmess");
      if (($rights >= 6) and $total)
        echo '<form action="index.php?act=massdel" method="post">';

      while ($res = mysql_fetch_assoc($req))
      {
         $req_user = mysql_query("SELECT * FROM `users` WHERE `id` = '". $res['userid'] ."' LIMIT 1");
         $user = mysql_fetch_assoc($req_user);
         echo ($i % 2) ? '<div class="menu">' : '<div class="menu">';

          $text = $res['text'];
          $text = functions::checkout($text, 1, 1);
          $text = functions::smileys($text, $datauser['rights'] ? 1 : 0);

          $arg = array (
              'header' => ''.functions::display_date($res['vr']).'',
              'body' => $text,
              'iphide' => 1,
              'footer' => ''. ((($rights >= 6) || $rights >= $user['rights']) ? '<input type="checkbox" name="delch[]" value="' . $res['id'] . '"/>&nbsp;<a href="?act=editcom&amp;id='.$res['id'].'">Изменить</a> | <a href="?act=delcom&amp;id='.$res['id'].'">Удалить</a>' : '') .''
          );

          echo functions::display_user($user, $arg);
          echo '</div>';
          ++$i;
      }
       if(!$total)
       {
         echo '<div class="menu"><p>Нет записей</p></div>';    
       }
       if($user_id)
       { 
          $old = time() - (3 * 24 * 3600);
          $read1 = mysql_query("SELECT * FROM `dnevniki` LEFT JOIN `dnevniki_com_rdm` ON `dnevniki`.`id` = `dnevniki_com_rdm`.`comid` AND `dnevniki_com_rdm`.`userid` = '" . $user_id . "' WHERE `dnevniki_com_rdm`.`userid` IS NULL AND `dnevniki`.`dnid` = 'com' AND `dnevniki`.`com_id` = '".$id."' AND `dnevniki`.`time` > '".$old."' ORDER BY `dnevniki`.`time`;");
          while($read = mysql_fetch_array($read1))
          {
            mysql_query("INSERT INTO `dnevniki_com_rdm` SET `comid` = '".$read['id']."', `recordid` = '".$id."', `type` = '0', `userid` = '".$user_id."', `time` = '".time()."';");
          }
       }
       if (($rights >= 6) and $total)
       {
         echo '<div class="rmenu"><input type="submit" value=" Удалить "/></div>';
         echo '</form>';
       }
        if ($total > $kmess)
        echo '<div class="topmenu">' . functions::display_pagination('?act=com&amp;id='.$id.'&amp;', $start, $total, $kmess) . '</div>';
      //echo '<a href="?act=view&amp;id='.$res222['id'].'"><img src="./img/edit.png" /> К записи</a><br />';
      //echo '<a href="?act=showdn&amp;id='.$res222['userid'].'"><img src="./img/folder_user.png" /> Блог '.$datauser222['name'].'</a><br />';
      //echo '<a href="./"><img src="./img/folder.png" /> Блоги</a>';
  }
  else
  {
    echo functions::display_error('Такой записи не существует!', '<a href="./">Назад</a>');
    require_once ('../incfiles/end.php');
    exit;
  }  
?>
