<?php
  
IF (ISSET($user['ID'])){ 
  
  ECHO "<div class='list'>";
  
  ECHO "<span id='int'>";
  
  IF ($comm['PRIVATE'] == 0){
    
    /*
    -------------------
    Открытое сообщество
    -------------------
    */
    
    IF (GET('get') == "int_go" && !ISSET($par['ID'])){
      
      CSRF::GET_CHECK_VALID(GET('get'));
      
      DB::GET_ADD("INSERT INTO `COMMUNITIES_PAR` (`USER_ID`, `COMMUNITY_ID`) VALUES ('".$user['ID']."', '".$comm['ID']."')");
    
    }
    
    IF (GET('get') == "int_stop" && ISSET($par['ID']) && $par['ADMINISTRATION'] != 1){
      
      CSRF::GET_CHECK_VALID(GET('get'));
      
      DB::GET_SET("DELETE FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."'");
    
    }
    
    IF (DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' LIMIT 1") == 0){
      
      ?><a class="btn" onclick="request('int', '/modules/?section=show&path=communities&id=<?=$comm['ID']?>&get=int_go&<?=$token_url?>', '#int')" load="none"><?=ICONS('plus', 15, 'fa-fw')?> <?=LG('Вступить')?></a><? 
      
    }ELSEIF (DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' AND `ADMINISTRATION` != '1' LIMIT 1") == 1){
      
      ?><a class="btn-o" onclick="request('int', '/modules/?section=show&path=communities&id=<?=$comm['ID']?>&get=int_stop&<?=$token_url?>', '#int')" load="none"><?=ICONS('minus', 15, 'fa-fw')?> <?=LG('Покинуть')?></a><?
      
    }
    
    /*
    -----------------------
    Сообщество по интересам
    -----------------------
    */
  
  }ELSEIF ($comm['PRIVATE'] == 2){
    
    IF (GET('get') == "int_go" && !ISSET($par['ID'])){
      
      CSRF::GET_CHECK_VALID(GET('get'));
      
      DB::GET_ADD("INSERT INTO `COMMUNITIES_PAR` (`USER_ID`, `COMMUNITY_ID`, `ACT`) VALUES ('".$user['ID']."', '".$comm['ID']."', '0')");
      
      $message = "Пользователь [b]".$user['LOGIN']."[/b] хочет вступить в ваше сообщество [b]".ADSL($comm['NAME'])."[/b].
      
      [a href=/modules/?path=communities&section=show&id=".$comm['ID']."&get=plus]Перейти к заявкам >>>[/a]
      ";
      
      DB::GET_ADD("INSERT INTO `MAIL_MESSAGE` (`USER_ID`, `MY_ID`, `TIME`, `MESSAGE`, `USER`) VALUES ('".$comm['USER_ID']."', '".CONFIG('SYSTEM')."', '".TIME()."', '".$message."', '".$comm['USER_ID']."'),('".CONFIG('SYSTEM')."', '".$comm['USER_ID']."', '".TIME()."', '".$message."', '".CONFIG('SYSTEM')."')");
    
    }
    
    IF (GET('get') == "int_cancel"){
      
      CSRF::GET_CHECK_VALID(GET('get'));
      
      DB::GET_SET("DELETE FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' AND `ACT` = '0'");
    
    }
    
    IF (GET('get') == "int_stop" && ISSET($par['ID']) && $par['ADMINISTRATION'] != 1){
      
      CSRF::GET_CHECK_VALID(GET('get'));
      
      DB::GET_SET("DELETE FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."'");
    
    }
    
    IF (DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' LIMIT 1") == 0){
      
      ?><a class="btn" onclick="request('int', '/modules/?section=show&path=communities&id=<?=$comm['ID']?>&get=int_go&<?=$token_url?>', '#int')" load="none"><?=ICONS('plus', 15, 'fa-fw')?> <?=LG('Отправить заявку')?></a><? 
        
    }ELSEIF (DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' AND `ADMINISTRATION` != '1' AND `ACT` = '0' LIMIT 1") == 1){
      
      ?><a class="btn-o" onclick="request('int', '/modules/?section=show&path=communities&id=<?=$comm['ID']?>&get=int_cancel&<?=$token_url?>', '#int')" load="none"><?=ICONS('times', 15, 'fa-fw')?> <?=LG('Отменить заявку')?></a><? 
      
    }ELSEIF (DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."' AND `ADMINISTRATION` != '1' LIMIT 1") == 1){
      
      ?><a class="btn-o" onclick="request('int', '/modules/?section=show&path=communities&id=<?=$comm['ID']?>&get=int_stop&<?=$token_url?>', '#int')" load="none"><?=ICONS('minus', 15, 'fa-fw')?> <?=LG('Покинуть')?></a><?
      
    }
    
    /*
    --------------------
    Анонимное сообщество
    --------------------
    */
  
  }ELSEIF ($comm['PRIVATE'] == 1){
    
    IF (GET('get') == "int_stop" && ISSET($par['ID']) && $par['ADMINISTRATION'] != 1){
      
      CSRF::GET_CHECK_VALID(GET('get'));
      
      DB::GET_SET("DELETE FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `USER_ID` = '".$user['ID']."'");
    
    }
    
    IF (DB::GET_COLUMN("SELECT COUNT(*) FROM `COMMUNITIES_PAR` WHERE `COMMUNITY_ID` = '".$comm['ID']."' AND `ACT` = '1' AND `USER_ID` = '".$user['ID']."' AND `ADMINISTRATION` != '1' LIMIT 1") == 1){
      
      ?><a class="btn-o" onclick="request('int', '/modules/?section=show&path=communities&id=<?=$comm['ID']?>&get=int_stop&<?=$token_url?>', '#int')" load="none"><?=ICONS('minus', 15, 'fa-fw')?> <?=LG('Покинуть')?></a><?
      
    }
    
  }
  
  ECHO "</span>";
  
  ECHO "<a class='btn' href='/modules/?path=communities&section=show&id=".$comm['ID']."&get=inv&inv=go'>".ICONS('plus', 15, 'fa-fw')." ".LG('Пригласить')."</a>";
  
  ECHO "</div>";
  
}
  
?>