<?php
  
$yes = DB::GET_STRING("SELECT `ID`,`USER_ID` FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `ACT` = '0' 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");
  
  $message = "Поздравляем! Вы приняты в сообщество [b][a href=/modules/?path=communities&section=show&id=".$comm['ID']."]".ADSL($comm['NAME'])."[/a][/b].";
  
  DB::GET_ADD("INSERT INTO `MAIL_MESSAGE` (`USER_ID`, `MY_ID`, `TIME`, `MESSAGE`, `USER`) VALUES ('".CONFIG('SYSTEM')."', '".$yes['USER_ID']."', '".TIME()."', '".$message."', '".CONFIG('SYSTEM')."'),('".$yes['USER_ID']."', '".CONFIG('SYSTEM')."', '".TIME()."', '".$message."', '".$yes['USER_ID']."')");
  
  REDIRECT('/modules/?path=communities&section=show&id='.$comm['ID'].'&get=plus');
  
}

$no = DB::GET_STRING("SELECT `ID`,`USER_ID` FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `ACT` = '0' 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");
  
  $message = "Сожалеем, но ваша заявка на вступление в сообщество [b][a href=/modules/?path=communities&section=show&id=".$comm['ID']."]".ADSL($comm['NAME'])."[/a][/b] было отклонено.";
  
  DB::GET_ADD("INSERT INTO `MAIL_MESSAGE` (`USER_ID`, `MY_ID`, `TIME`, `MESSAGE`, `USER`) VALUES ('".CONFIG('SYSTEM')."', '".$no['USER_ID']."', '".TIME()."', '".$message."', '".CONFIG('SYSTEM')."'),('".$no['USER_ID']."', '".CONFIG('SYSTEM')."', '".TIME()."', '".$message."', '".$no['USER_ID']."')");
  
  REDIRECT('/modules/?path=communities&section=show&id='.$comm['ID'].'&get=plus');
  
}
  
ECHO "<div class='list'>";
ECHO "<center><b>".LG('Пользователи, ждущие одобрения заявки')."</b></center>";
ECHO "</div>";

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

WHILE ($list = $data->FETCH()){
  
  ECHO "<div class='list-menu'>";
  
  USER::LOGIN($list['USER_ID'], 1, 1);
  
  ECHO "<br /><br /><a class='btn' href='/modules/?path=communities&section=show&id=".$comm['ID']."&get=plus&yes=".$list['ID']."&".$token_url."'>".ICONS('plus', 15, 'fa-fw')." ".LG('Одобрить')."</a>";
  
  ECHO "<a class='btn' href='/modules/?path=communities&section=show&id=".$comm['ID']."&get=plus&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=show&id='.$comm['ID'].'&get=plus&', $spage, $page); }

ECHO "<div class='list'>";
ECHO "<a href='/modules/?path=communities&section=show&id=".$comm['ID']."'>".ICONS('arrow-left', 15, 'fa-fw')." ".LG('Назад')."</a>";
ECHO "</div>";

//Навигация
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 "".TEXT_ABSOLUTE($comm['NAME'])."";
ECHO "</div>";

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

?>