<?php
  
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 22, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".TEXT_ABSOLUTE($account['LOGIN'])."</a>";
ECHO "".ICONS('angle-right', 22, 'fa-fw')."";
ECHO "".LG('Друзья')."";
ECHO "</div>";

IF ($user['ID'] != $account['ID']){
  
  REDIRECT('/users/profile/?path=friends&id='.$account['ID'].'');
  
}

ECHO "<div class='tmenu_body'>";

ECHO "<a href='/users/profile/?path=friends&id=".$account['ID']."&section=online' class='tmenu-33'>".LG('Онлайн')."</a>";
ECHO "<a href='/users/profile/?path=friends&id=".$account['ID']."' class='tmenu-33'>".LG('Все')."</a>";
ECHO "<a href='/users/profile/?path=friends&id=".$account['ID']."&section=applications' class='tmenu-33 tmenu-33-o'>".LG('Заявки')."</a>";

ECHO "</div>";

REQUIRE (ROOT.'/users/profile/friends/plugins/inc.php');

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

IF (GET('get') == "type"){
  
  $sql = "`MY_ID` = '".$account['ID']."'";
  $link = "&get=type";
  
  ECHO "<a class='h1' href='/users/profile/?path=friends&id=".$account['ID']."&section=applications'>".LG('Входящие')."</a>";
  ECHO "<a class='h1 h' href='/users/profile/?path=friends&id=".$account['ID']."&section=applications&get=type'>".LG('Исходящие')."</a>";
  
}ELSE{
  
  $sql = "`USER_ID` = '".$account['ID']."'";
  $link = NULL;
  
  ECHO "<a class='h1 h' href='/users/profile/?path=friends&id=".$account['ID']."&section=applications'>".LG('Входящие')."</a>";
  ECHO "<a class='h1' href='/users/profile/?path=friends&id=".$account['ID']."&section=applications&get=type'>".LG('Исходящие')."</a>";

}

ECHO "</div>";

$column = DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `FRIENDS` WHERE ".$sql." AND `ACT` = '1'");
$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 `FRIENDS` WHERE ".$sql." AND `ACT` = '1' ORDER BY `TIME` DESC LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH()){
  
  ECHO "<div class='list-menu'>";
  
  IF (GET('get') == "type"){
    
    ECHO "<a href='/id".$list['USER_ID']."'><table style='width: 100%;'><tr>";
    
    ECHO "<td class='us-avatar'>";
    ECHO USER::AVATAR($list['USER_ID'], 50, 0, 1)."";
    ECHO "</td>";
    
    ECHO "<td class='us-info'>";
    ECHO "".USER::LOGIN($list['USER_ID'])."";
    ECHO "</td>";
    
  }ELSE{
    
    ECHO "<a href='/id".$list['MY_ID']."'><table style='width: 100%;'><tr>";
    
    ECHO "<td class='us-avatar'>";
    ECHO USER::AVATAR($list['MY_ID'], 50, 0, 1)."";
    ECHO "</td>";
    
    ECHO "<td class='us-info'>";
    ECHO "".USER::LOGIN($list['MY_ID'])."";    
    ECHO "</td>"; 
  
  }
  
  ECHO "</tr></table></a>";
  
  ECHO "<div id='friends".$list['ID']."'>";
  
  ECHO "<br />";
  
  IF (GET('get') == "type"){
    
    IF (DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `FRIENDS` WHERE `USER_ID` = '".$list['USER_ID']."' AND `ACT` = '1' AND `MY_ID` = '".$list['MY_ID']."'")){
      
      ?><a class="btn" onclick="request('friends<?=$list['ID']?>', '/users/profile/?path=friends&id=<?=$account['ID']?>&section=applications&id_frend=<?=$list['USER_ID']?>&get=friends_cancel', '#friends<?=$list['ID']?>')" load="none"><?=ICONS('times', 15, 'fa-fw')?> <?=LG('Отменить')?></a><?
      
    }
    
  }ELSE{
    
    IF (DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `FRIENDS` WHERE `USER_ID` = '".$list['USER_ID']."' AND `ACT` = '1' AND `MY_ID` = '".$list['MY_ID']."'")){
      
      ?><a class="btn" onclick="request('friends<?=$list['ID']?>', '/users/profile/?path=friends&id=<?=$account['ID']?>&section=applications&id_frend=<?=$list['MY_ID']?>&get=friends_ok', '#friends<?=$list['ID']?>')" load="none"><?=ICONS('user', 15, 'fa-fw')?> <?=LG('Принять')?></a><?
        
      ?><a class="btn-o" onclick="request('friends<?=$list['ID']?>', '/users/profile/?path=friends&id=<?=$account['ID']?>&section=applications&id_frend=<?=$list['MY_ID']?>&get=friends_no', '#friends<?=$list['ID']?>')" load="none"><?=ICONS('user', 15, 'fa-fw')?> <?=LG('Отклонить')?></a><?
      
    }
  
  }
  
  ECHO "</div>";

  ECHO "</div>";
  
}

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

IF ($spage > 1){ ECHO STR_PAGE('/users/profile/?path=friends&section=applications&id='.$account['ID'].''.$link.'&', $spage, $page); }

ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 22, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".TEXT_ABSOLUTE($account['LOGIN'])."</a>";
ECHO "".ICONS('angle-right', 22, 'fa-fw')."";
ECHO "".LG('Друзья')."";
ECHO "</div>";
  
?>