<?php
  
ECHO "<div id='like_id'>"; 

IF (ISSET($user)){
  
  IF (GET('get') == 'like' && DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `NEWS_LIKES` WHERE `USER_ID` = '".$user['ID']."' AND `NEWS_ID` = '".$news['ID']."' LIMIT 1") == 0){
    
    DB::GET_ADD("INSERT INTO `NEWS_LIKES` (`USER_ID`, `TIME`, `NEWS_ID`) VALUES ('".$user['ID']."', '".TIME()."', '".$news['ID']."')");
    
    IF ($news['USER_ID'] != $user['ID'] && DB::GET_COLUMN("SELECT COUNT(*) FROM `NOTIFICATIONS_SETTINGS` WHERE `USER_ID` = '".$news['USER_ID']."' AND `NEWS_LIKES` = '1' LIMIT 1") == 1){ 
      
      DB::GET_ADD("INSERT INTO `NOTIFICATIONS` (`USER_ID`, `OBJECT_ID`, `OBJECT_ID_LIST`, `TIME`, `TYPE`) VALUES ('".$news['USER_ID']."', '".$user['ID']."', '".$news['ID']."', '".TIME()."', 'news_likes')");
    
    }    
  
  }
  
  IF (GET('get') == 'like_no' && DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `NEWS_LIKES` WHERE `USER_ID` = '".$user['ID']."' AND `NEWS_ID` = '".$news['ID']."' LIMIT 1") == 1){
    
    DB::GET_SET("DELETE FROM `NEWS_LIKES` WHERE `USER_ID` = '".$user['ID']."' AND `NEWS_ID` = '".$news['ID']."' LIMIT 1");
  
  }
  
  IF (DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `NEWS_LIKES` WHERE `USER_ID` = '".$user['ID']."' AND `NEWS_ID` = '".$news['ID']."' LIMIT 1") == 0){
    
    ?><a class="btn-request-likes-photo heartwrap" onclick="request('news', '/modules/?path=news&section=show&id=<?=$news['ID']?>&get=like', '#like_id')" load="none"><span style='position: relative; top: 1px;'><?=ICONS('heart-o', 18, 'fa-fw')?></span></a><?
    
  }ELSE{
   
    ?><a class="btn-request-likes-photo heartwrap" style="background-color: #F5574C;" onclick="request('news', '/modules/?path=news&section=show&id=<?=$news['ID']?>&get=like_no', '#like_id')" load="none"><span style='position: relative; top: 1px;'><?=ICONS('heart', 18, 'fa-fw')?></span></a><?
  
  }
  
}

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

$count_eye = DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `NEWS_EYE` WHERE `NEWS_ID` = '".$news['ID']."'");

ECHO "<span class='icons'>".ICONS('eye', 17, 'fa-fw')."</span> ".LG('Просмотров').": ".$count_eye."";

IF (DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `NEWS_LIKES` WHERE `NEWS_ID` = '".$news['ID']."'") > 0){
  
  ECHO "<br /><a href='/modules/?path=news&section=show&id=".$news['ID']."&get=like_list'><span class='icons'>".ICONS('heart', 17, 'fa-fw')."</span> ".LG('Понравилось')." ";
  
  $s = 0;
  
  $data = DB::GET_STRING_ALL("SELECT `USER_ID` FROM `NEWS_LIKES` WHERE `NEWS_ID` = '".$news['ID']."' ORDER BY `TIME` DESC");
  
  WHILE ($list = $data->FETCH()){
    
    $s++;
    
    IF ($s >= 1 && $s <= 5){
      
      ECHO " ".USER::AVATAR($list['USER_ID'], 25)." ";
      
    }
    
  }
  
  IF ($s > 5){
    
    $count = $s - 5;
    
    ECHO "".LG('и ещё')." ".$count." ".LG('чел.')."";
    
  }
  
  ECHO "</a>";
  
}

ECHO "</div>";

ECHO "</div>";
  
?>