<?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 `MUSIC` WHERE `USER_ID` = '".$user['ID']."' ORDER BY `TIME` DESC LIMIT ".$startIndex.", ".$countView."");
  
  WHILE ($list = $data->FETCH()){
    
    $music[] = $list;
    
  }
  
  IF (EMPTY($music)){
    
    ECHO JSON_ENCODE(ARRAY(
      
      'result' => 'finish'
    
    ));
  
  }ELSE{
    
    $html = NULL;
    
    $url = HTMLSPECIALCHARS(GET('url'));
    
    FOREACH($music AS $oneMusic){
      
      $html .= "<div class='list-menu'>".FILE::ICONS($oneMusic['EXT'], 'small')." <b>".TEXT_ABSOLUTE($oneMusic['FACT_NAME'])."</b><br /><a href='".BASE64_DECODE($url)."&add_atcom_music=".$oneMusic['ID']."&url=".$url."' class='btn-o'>".ICONS('plus', 15, 'fa-fw')." ".LG('Выбрать')."</a></div>";
    
    }
    
    ECHO JSON_ENCODE(ARRAY(
      
      'result' => 'success',
      'html' => $html
    
    ));
  
  }
  
}ELSE{
  
  REDIRECT('/index');

}
  
?>