<?php
  
FOREACH (ARRAY('config', 'connect', 'users') AS $connect) {
  
  INCLUDE_ONCE ("../../../system/connections/global/$connect.php"); 
  
}

ACCESS('users');

IF (AJAX() == TRUE){
  
  $countView = INTVAL(POST('count_add'));  // количество записей, получаемых за один раз
  $startIndex = INTVAL(POST('count_show')); // с какой записи начать выборку
  
  $data = DB::GET_STRING_ALL("SELECT * FROM `PHOTOS` WHERE `USER_ID` = '".$user['ID']."' ORDER BY `TIME` DESC LIMIT ".$startIndex.", ".$countView."");
  
  WHILE ($list = $data->FETCH()){
    
    $photo[] = $list;
    
  }
  
  IF (EMPTY($photo)){
    
    ECHO JSON_ENCODE(ARRAY(
      
      'result' => 'finish'
    
    ));
  
  }ELSE{
    
    $html = NULL;
    
    $url = HTMLSPECIALCHARS(GET('url'));
    
    FOREACH($photo AS $onePhoto){
      
      $html .= "<li class='photos-wrapper-avatar'>
      <a href='".BASE64_DECODE($url)."&add_atcom_photos=".$onePhoto['ID']."&url=".$url."' class='photos-avatar'>
      <span class='avatar-choose'><i class='fa fa-plus fa-lg'></i></span>
      <img src='/photo/150x150/{$onePhoto['ID_DIR']}/{$onePhoto['ID']}/' style='max-width: 100%; position: absolute;'>
      </a></li>";
    
    }
    
    ECHO JSON_ENCODE(ARRAY(
      
      'result' => 'success',
      'html' => $html
    
    ));
  
  }
  
}ELSE{
  
  REDIRECT('/index');

}
  
?>