<?php
  
$yes = DB::GET_STRING("SELECT `ID`,`USER_ID`,`COMMUNITY_ID` FROM `COMMUNITIES_PAR` WHERE `USER_ID` = '".$user['ID']."' AND `ACT` = '2' AND `ID` = '".INTVAL(GET('yes'))."' LIMIT 1");
  
IF (GET('yes') && ISSET($yes['ID'])){
  
  CSRF::GET_CHECK_VALID(GET('yes'));
  
  DB::GET_SET("UPDATE `COMMUNITIES_PAR` SET `ACT` = '1' WHERE `ID` = '".$yes['ID']."' LIMIT 1");
  
  SUCCESS('Вы успешно вступили в сообщество', 'session');
  REDIRECT('/modules/?path=communities&section=show&id='.$yes['COMMUNITY_ID']);
  
}

$no = DB::GET_STRING("SELECT `ID`,`USER_ID` FROM `COMMUNITIES_PAR` WHERE `USER_ID` = '".$user['ID']."' AND `ACT` = '2' AND `ID` = '".INTVAL(GET('no'))."' LIMIT 1");

IF (GET('no') && ISSET($no['ID'])){
  
  CSRF::GET_CHECK_VALID(GET('no'));
  
  DB::GET_SET("DELETE FROM `COMMUNITIES_PAR` WHERE `ID` = '".INTVAL(GET('no'))."' LIMIT 1");
  
  REDIRECT('/modules/?path=communities&section=users&id='.$account['ID'].'&get=inv');
  
}
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Сообщества')." ".$account['LOGIN']."";
ECHO "</div>";
  
ECHO "<div class='tmenu_body'>";
ECHO "<a href='/modules/?path=communities&section=users&id=".$account['ID']."' class='tmenu-50'>".LG('Все')."</a>";
ECHO "<a href='/modules/?path=communities&section=users&id=".$account['ID']."&get=inv' class='tmenu-50 tmenu-50-o'>".LG('Приглашения')."</a>";
ECHO "</div>";

$column = DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `COMMUNITIES_PAR` WHERE `USER_ID` = '".$user['ID']."' AND `ACT` = '2'");
$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_PAR` WHERE `USER_ID` = '".$user['ID']."' AND `ACT` = '2' ORDER BY `ID` DESC LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH()){
  
  $comm = DB::GET_STRING("SELECT `NAME`,`ID` FROM `COMMUNITIES` WHERE `ID` = '".$list['COMMUNITY_ID']."' LIMIT 1");
  
  ECHO "<div class='list-menu'>";
  
  ECHO "<span class='icons'>".ICONS('users', 17, 'fa-fw')."</span> <b><a href='/modules/?path=communities&section=show&id=".$comm['ID']."'>".TEXT_ABSOLUTE($comm['NAME'])."</a></b><br /><br />";
  
  ECHO "<a class='btn' href='/modules/?path=communities&section=users&id=".$user['ID']."&get=inv&yes=".$list['ID']."&".$token_url."'>".ICONS('plus', 15, 'fa-fw')." ".LG('Принять')."</a>";
  
  ECHO "<a class='btn' href='/modules/?path=communities&section=users&id=".$user['ID']."&get=inv&no=".$list['ID']."&".$token_url."'>".ICONS('times', 15, 'fa-fw')." ".LG('Отклонить')."</a>";
  
  ECHO "</div>";
  
}

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

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=communities&section=users&id='.$account['ID'].'&get=inv&', $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='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Сообщества')." ".$account['LOGIN']."";
ECHO "</div>";

REQUIRE (ROOT.'/system/connections/footer.php');
EXIT;

?>