
<?php
  
$fthem = DB::GET_STRING("SELECT * FROM `FORUM_THEM` WHERE `ID` = '".INTVAL(GET('id'))."' LIMIT 1");
$subsection = DB::GET_STRING("SELECT * FROM `FORUM_SUB_SECTION` WHERE `ID` = '".$fthem['SUB_SECTION_ID']."' LIMIT 1");
$section = DB::GET_STRING("SELECT * FROM `FORUM_SECTION` WHERE `ID` = '".$subsection['SECTION_ID']."' LIMIT 1");
$account = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".$fthem['USER_ID']."' LIMIT 1");

IF (!$fthem['ID']){
  
  ERROR('Неверная директива', 'session');
  REDIRECT('/modules/?path=forum');

}

/*
---------
Просмотры
---------
*/

IF (ISSET($user)){
  
  IF (DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `FORUM_THEM_EYE` WHERE `USER_ID` = '".$user['ID']."' AND `THEM_ID` = '".$fthem['ID']."' LIMIT 1") == 0){
    
    DB::GET_ADD("INSERT INTO `FORUM_THEM_EYE` (`USER_ID`, `TIME`, `THEM_ID`) VALUES ('".$user['ID']."', '".TIME()."', '".$fthem['ID']."')");
  
  }    

}

/*
-------------
Список лайков
-------------
*/

IF (GET('get') == "like_list"){
  
  REQUIRE (ROOT.'/modules/forum/plugins/like_list.php');
  
}

/*
---------------
Блокировка темы
---------------
*/

IF (ACCESS('forum_ban', NULL, 1) || MANAGEMENT == 1){
  
  IF (GET('them') == 'ban_off' || GET('them') == 'ban_on'){  
    
    REQUIRE (ROOT.'/modules/forum/plugins/them_ban.php');
    
  }
  
}

/*
----------------------
Закрытие/открытие темы
----------------------
*/

IF (ACCESS('forum_ban', NULL, 1) || MANAGEMENT == 1){
  
  IF (GET('them') == 'off' || GET('them') == 'on'){  
    
    REQUIRE (ROOT.'/modules/forum/plugins/them_on_off.php');
    
  }
  
}

/*
-------------------
Редактирование темы
-------------------
*/

IF (GET('get') == "edit" && $fthem['BAN'] == 0){  
  
  IF (ACCESS('forum_edit', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    REQUIRE (ROOT.'/modules/forum/plugins/them_edit.php');
    
  }
  
}

/*
-------------
Удаление темы
-------------
*/

IF (GET('get') == "delete_ok"){ 
  
  IF (ACCESS('forum_edit', NULL, 1) || MANAGEMENT == 1){
    
    REQUIRE (ROOT.'/modules/forum/plugins/them_delete.php');
    
  }
  
}

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=forum'>".LG('Форум')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=forum&section=subsection&id=".$section['ID']."'>".TEXT_ABSOLUTE($section['NAME'])."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=forum&section=subsection_themes&id=".$subsection['ID']."'>".TEXT_ABSOLUTE($subsection['NAME'])."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".TEXT_ABSOLUTE($fthem['NAME'])."";
ECHO "</div>";

//Редактировать комментарий
$comment = DB::GET_STRING("SELECT * FROM `FORUM_THEM_COMMENTS` WHERE `ID` = '".INTVAL(GET('comment_edit'))."' LIMIT 1");
IF ($comment['USER_ID'] == $user['ID'] || MANAGEMENT == 1 || ACCESS('forum_edit', NULL, 1)){
  
  REQUIRE (ROOT.'/modules/forum/plugins/comments_edit_get.php');
  
}

IF (GET('get') == "delete"){ 
  
  IF (ACCESS('forum_edit', NULL, 1) || MANAGEMENT == 1){
    
    ECHO "<div class='list'>";
    ECHO "".LG('Вы действительно хотите удалить тему')." <b>".TEXT_ABSOLUTE($fthem['NAME'])."</b>?<br /><br />";
    
    ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&get=delete_ok' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
    ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."' class='btn-o'>".LG('Отменить')."</a>";
    
    ECHO "</div>";
  
  }
  
}

IF (ACCESS('forum_edit', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
  
  ECHO "<div class='list'>";
  
  ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&get=edit' class='btn'>".ICONS('pencil', 15, 'fa-fw')." ".LG('Редактировать')."</a>";
  
  IF (ACCESS('forum_edit', NULL, 1) || MANAGEMENT == 1){
    
    ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&get=delete' class='btn'>".ICONS('trash', 15, 'fa-fw')." ".LG('Удалить')."</a>";
    
  }
  
  IF (ACCESS('forum_ban', NULL, 1) || MANAGEMENT == 1){
    
    IF ($fthem['ACTIVE'] == 1){
      
      ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&them=off' class='btn'>".ICONS('lock', 15, 'fa-fw')." ".LG('Закрыть')."</a>";
      
    }ELSE{
      
      ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&them=on' class='btn'>".ICONS('unlock', 15, 'fa-fw')." ".LG('Открыть')."</a>";
      
    }
    
    IF ($fthem['BAN'] == 0){
      
      ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&them=ban_on' class='btn'>".ICONS('ban', 15, 'fa-fw')." ".LG('Заблокировать')."</a>";
      
    }ELSE{
      
      ECHO "<a href='/modules/?path=forum&section=show&id=".$fthem['ID']."&them=ban_off' class='btn'>".ICONS('ban', 15, 'fa-fw')." ".LG('Разблокировать')."</a>";
      
    }
    
  }
  
  ECHO "</div>";

}

//Блокировка темы
REQUIRE (ROOT.'/modules/forum/plugins/them_banned.php');

ECHO "<div class='list-body' style='position: relative; z-index: 0;'>";

ECHO "<div class='list-menu'>";

ECHO "<table style='width: 100%;'><tr>";

ECHO "<td class='comments-avatar'>";
ECHO USER::AVATAR($fthem['USER_ID'], 50);
ECHO "</td>";
  
ECHO "<td class='comments-info'>";
ECHO USER::LOGIN($fthem['USER_ID'], 0, 1);
  
ECHO "<br /><span class='time'>".STIME($fthem['TIME'])."</span>";
ECHO "</td>";
  
ECHO "</tr></table>";

ECHO "<div style='margin-top: 8px; margin-bottom: 8px;'>";

IF ($fthem['ACTIVE'] == 0){

  ECHO "".ICONS('lock', 17, 'fa-fw')." ";
  
}

ECHO "<b>".TEXT_ABSOLUTE($fthem['NAME'])."</b></div>";

$data2 = DB::GET_STRING_ALL("SELECT * FROM `ATTACHMENTS` WHERE `USER_ID` = '".$fthem['USER_ID']."' AND `ID_POST` = '".$fthem['ID']."' AND `FORUM` = '1' AND `ACT` = '1' ORDER BY `TIME` DESC LIMIT 3");
WHILE ($list2 = $data2->FETCH()){
  
  REQUIRE (ROOT.'/users/attachments/plugins/inc_forum_list.php');

}

ECHO "<div style='margin-top: 8px; margin-bottom: 8px;'>";

IF (STR($fthem['MESSAGE']) > 1000){
  
  ECHO "<div id='forum".$fthem['ID']."' style='margin-top: 5px;'>";
    
  ECHO CROP_TEXT(TEXT($fthem['MESSAGE']), 0, 1000);
  
  ECHO "</div>";
    
  ECHO "<div id='forum2".$fthem['ID']."' style='display: none; margin-top: 5px;'>";
    
  ECHO TEXT($fthem['MESSAGE']);
    
  ECHO "</div>";
    
  ?><a onclick="show_or_hide('forum<?=$fthem['ID']?>', 'forum2<?=$fthem['ID']?>', 'chevron<?=$fthem['ID']?>', 'opacity_message<?=$fthem['ID']?>')" load="none"><?
      
  ECHO "<div id='chevron".$fthem['ID']."' class='chevron'><i class='fa fa-chevron-down fa-fw'></i></div>";
    
  ECHO "</a>";

}ELSE{
  
  ECHO TEXT($fthem['MESSAGE']);

}

ECHO "</div>";

ECHO "</div>";

IF ($fthem['ACTIVE'] == 0 || $fthem['EDIT_TIME'] > 0){
  
  ECHO "<div class='list-menu'><small>";
  
  IF ($fthem['EDIT_TIME'] > 0){
    
    $account2 = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".$fthem['EDIT_USER_ID']."' LIMIT 1");
    ECHO "".LG('Последний раз тему редактировал')." <a href='/id".$account2['ID']."'>".$account2['LOGIN']."</a>";
    ECHO " - ".FTIME($fthem['EDIT_TIME'])."<br />";
    
  }
  
  IF ($fthem['ACTIVE'] == 0){
    
    $account2 = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".$fthem['ACTIVE_USER_ID']."' LIMIT 1");
    ECHO "".LG('Тема закрыта пользователем')." <a href='/id".$account2['ID']."'>".$account2['LOGIN']."</a>";
    ECHO " - ".FTIME($fthem['ACTIVE_TIME'])."<br />";
    
  }
  
  ECHO "</small></div>";
  
}

//Лайки
REQUIRE (ROOT.'/modules/forum/plugins/likes.php');

ECHO "</div>";

//Комментарии
REQUIRE (ROOT.'/modules/forum/plugins/comments.php');

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=forum'>".LG('Форум')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=forum&section=subsection&id=".$section['ID']."'>".TEXT_ABSOLUTE($section['NAME'])."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=forum&section=subsection_themes&id=".$subsection['ID']."'>".TEXT_ABSOLUTE($subsection['NAME'])."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".TEXT_ABSOLUTE($fthem['NAME'])."";
ECHO "</div>";
  
?>