<?php
  
$section = DB::GET_STRING("SELECT * FROM `COMMUNITIES_FORUM_SECTION` WHERE `ID` = '".INTVAL(GET('id'))."' LIMIT 1");
$comm = DB::GET_STRING("SELECT * FROM `COMMUNITIES` WHERE `ID` = '".$section['COMMUNITY_ID']."' LIMIT 1");
$par = DB::GET_STRING("SELECT `ADMINISTRATION`,`USER_ID`,`ID`,`ACT` FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' AND `ACT` = '1' LIMIT 1");
  
IF (!ISSET($section['ID'])){
  
  ERROR('Неверная директива', 'session');
  REDIRECT('/index');
  
}

//Навигация
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=communities'>".LG('Сообщества')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=communities&section=show&id=".$comm['ID']."'>".TEXT_ABSOLUTE($comm['NAME'])."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=communities&section=forum_section&id=".$comm['ID']."'>".LG('Форум')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO TEXT_ABSOLUTE($section['NAME']);
ECHO "</div>";

IF (ISSET($par['ID']) && $par['ADMINISTRATION'] == 1 || MANAGEMENT == 1 || ACCESS('communities', NULL, 1)){
  
  //Редактирование раздела
  IF (GET('get') == "edit"){  
    
    REQUIRE (ROOT.'/modules/communities/plugins/forum_section_edit.php');
  
  }
  
  //Удаление раздела
  IF (GET('get') == "delete_ok"){
    
    CSRF::GET_CHECK_VALID(GET('get'));
    
    REQUIRE (ROOT.'/modules/communities/plugins/forum_section_delete.php');
  
  }
  
  IF (GET('get') == "delete"){
    
    CSRF::GET_CHECK_VALID(GET('get'));
    
    ECHO "<div class='list'>";
    ECHO "".LG('Вы действительно хотите удалить раздел')." <b>".TEXT_ABSOLUTE($section['NAME'])."</b>?<br /><br />";
    ECHO "<a href='/modules/?path=communities&section=forum_section_themes&id=".$section['ID']."&get=delete_ok&".$token_url."' class='btn'>".ICONS('trash', 15, 'fa-fw')." ".LG('Удалить')."</a>";
    ECHO "<a href='/modules/?path=communities&section=forum_section_themes&id=".$section['ID']."' class='btn-o'>".ICONS('times', 15, 'fa-fw')." ".LG('Отмена')."</a>";
    ECHO "</div>";
    
  }
  
}

IF (ISSET($user) && ISSET($par['ID'])){
  
  //Добавление темы
  IF (GET('them') == "add"){  
    
    REQUIRE (ROOT.'/modules/communities/plugins/forum_them_add.php');
    
  }
  
  ECHO "<div class='list'>";
  
  ECHO "<a href='/modules/?path=communities&section=forum_section_themes&id=".$section['ID']."&them=add' class='btn'>".ICONS('plus', 15, 'fa-fw')." ".LG('Создать тему')."</a>";
  
  IF ($par['ADMINISTRATION'] == 1 || MANAGEMENT == 1 || ACCESS('communities', NULL, 1)){
    
    ECHO "<a href='/modules/?path=communities&section=forum_section_themes&id=".$section['ID']."&get=edit' class='btn'>".ICONS('pencil', 15, 'fa-fw')." ".LG('Редактировать раздел')."</a>";
    
    ECHO "<a href='/modules/?path=communities&section=forum_section_themes&id=".$section['ID']."&get=delete&".$token_url."' class='btn'>".ICONS('times', 15, 'fa-fw')." ".LG('Удалить раздел')."</a>";
    
  }
  
  ECHO "</div>";
  
}
  
$column = DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_FORUM_THEM` WHERE `SECTION_ID` = '".$section['ID']."'");
$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 `COMMUNITIES_FORUM_THEM` WHERE `SECTION_ID` = '".$section['ID']."' ORDER BY `TIME` DESC LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH()){
  
  REQUIRE (ROOT.'/modules/communities/plugins/forum_them_list.php');

}

IF ($column > 0){
  
  ECHO "</div>";

}

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=communities&section=forum_section_themes&id='.$section['ID'].'&', $spage, $page); }

//Навигация
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=communities'>".LG('Сообщества')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=communities&section=show&id=".$comm['ID']."'>".TEXT_ABSOLUTE($comm['NAME'])."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=communities&section=forum_section&id=".$comm['ID']."'>".LG('Форум')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO TEXT_ABSOLUTE($section['NAME']);
ECHO "</div>";
  
?>