<?php
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Гостевая')."</a>";
ECHO "</div>";

IF (GET('comment_edit')){
  
  IF (MANAGEMENT == 1 || ACCESS('guestbook', NULL, 1)){
    
    //Редактирование комментариев
    REQUIRE (ROOT.'/modules/guestbook/plugins/comments_edit_get.php');
  
  }
  
}

REQUIRE (ROOT.'/modules/guestbook/plugins/comments.php');

$column = DB::GET_COLUMN("SELECT COUNT(*) FROM `GUESTBOOK`");
$spage = SPAGE($column, $page_settings);
$page = PAGE($spage);
$limit = $page_settings * $page - $page_settings;

IF ($column == 0){ 
  
  HTML::EMPTY();
  
}ELSE{
  
  ECHO "<div class='list-body'>"; 
  
}

$data = DB::GET_STRING_ALL("SELECT * FROM `GUESTBOOK` ORDER BY `TIME` DESC LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH())
{
  
  ECHO "<div class='list-menu'>";
  
  ECHO "<table style='width: 100%;'><tr>";
  
  ECHO "<td class='comments-avatar'>";
  ECHO USER::AVATAR($list['USER_ID'], 50);
  ECHO "</td>";
  
  ECHO "<td class='comments-info'>";
  ECHO USER::LOGIN($list['USER_ID'], 0, 1);
  
  //Лайки для комментариев
  REQUIRE (ROOT.'/modules/guestbook/plugins/comment_like.php');
  
  ECHO "<br /><span class='time'>".STIME($list['TIME'])."</span>";
  ECHO "</td>";
  
  ECHO "</tr></table>";
  
  IF ($list['REPLY'] > 0){
    
    $comment = DB::GET_STRING("SELECT `USER_ID`,`ID`,`MESSAGE` FROM `GUESTBOOK` WHERE `ID` = '".$list['REPLY']."' LIMIT 1");
    $us_comment = DB::GET_STRING("SELECT `LOGIN`,`ID` FROM `USERS` WHERE `ID` = '".$list['REPLY_USER_ID']."' LIMIT 1");
    
    ECHO "<div class='comments-reply'>";
    
    ECHO "<div class='comments-reply-user'>".LG('Ответ')." <b>".$us_comment['LOGIN']."</b></div>";
    
    IF (ISSET($comment['ID'])){
      
      ECHO TEXT_ABSOLUTE(CROP_TEXT($comment['MESSAGE'], 0, 90)); 
    
    }ELSE{
      
      ECHO "<span class='comments-reply-no'>".LG('Комментарий удален')."</span>";
    
    }
    
    ECHO "</div>";
  
  }
  
  ECHO '<div class="comments-optimize">';
  
  IF (STR($list['MESSAGE']) > 120){
    
    ECHO "<div id='guest_comm".$list['ID']."' style='margin-top: 5px;'>";
    
    ECHO TEXT(CROP_TEXT($list['MESSAGE'], 0, 120));
    
    ECHO "</div>";
    
    ECHO "<div id='guest_comm2".$list['ID']."' style='display: none; margin-top: 5px;'>";
    
    ECHO TEXT($list['MESSAGE']);
    
    ECHO "</div>";
    
    ?><a onclick="show_or_hide('guest_comm<?=$list['ID']?>', 'guest_comm2<?=$list['ID']?>', 'chevron<?=$list['ID']?>', 'opacity_message<?=$list['ID']?>')" load="none"><?
    
    ECHO "<div id='chevron".$list['ID']."' class='chevron'><i class='fa fa-chevron-down fa-fw'></i></div>";
    
    ECHO "</a>";
    
  }ELSE{
    
    ECHO TEXT($list['MESSAGE']);
  
  }
  
  /*
  -------------------
  Прикрепленные файлы
  -------------------
  */
  
  ECHO "<br />";
  
  $f_data = DB::GET_STRING_ALL("SELECT * FROM `ATTACHMENTS` WHERE `ID_POST` = '".$list['ID']."' AND `TYPE_POST` = 'guestbook' ORDER BY `TIME` DESC");
  
  WHILE ($f_list = $f_data->FETCH()){
    
    REQUIRE (ROOT.'/users/attachments/plugins/inc_files.php');
    
  }
  
  ECHO "</div>";
  
  /*-----------------------*/
  
  IF (ISSET($user)){
    
    IF ($list['USER_ID'] != $user['ID']){
      
      ECHO "<a href='/modules/?path=guestbook&page=".$page."&reply=".$list['ID']."' class='btn-o'>".ICONS('mail-forward', 12, 'fa-fw')." ".LG('Ответить')."</a>";
    
    }
    
    IF (MANAGEMENT == 1 || ACCESS('guestbook', NULL, 1)){
      
      //Редактирование комментариев
      REQUIRE (ROOT.'/modules/guestbook/plugins/comments_edit.php');
      
      //Удаление комментариев
      REQUIRE (ROOT.'/modules/guestbook/plugins/comments_delete.php');
    
    }
    
  }
  
  ECHO "</div>"; 
  
}

IF ($column > 0){

  ECHO "</div>";
  
}

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=guestbook&', $spage, $page); }

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Гостевая')."</a>";
ECHO "</div>"; 
  
?>