<?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 `VIDEOS` WHERE `USER_ID` = '".$user['ID']."' ORDER BY `TIME` DESC LIMIT ".$startIndex.", ".$countView."");
  
  WHILE ($list = $data->FETCH()){
    
    $video[] = $list;
    
  }
  
  IF (EMPTY($video)){
    
    ECHO JSON_ENCODE(ARRAY(
      
      'result' => 'finish'
    
    ));
  
  }ELSE{
    
    $html = NULL;
    
    $url = HTMLSPECIALCHARS(GET('url'));
    
    FOREACH($video AS $oneVideo){
      
      IF (IS_FILE(ROOT.'/files/upload/videos/screen/'.$oneVideo['ID'].'.jpg') && CONFIG('VIDEO_SCREEN') == 1){
        
        $vv = "/files/upload/videos/screen/240x240/".$oneVideo['ID'].".jpg";
      
      }ELSE{
        
        $vv = "/files/upload/videos/screen/no_video.jpg";
      
      }
      
      $html .= "<li class='photos-wrapper-avatar'>
      <a href='".BASE64_DECODE($url)."&add_atcom_videos=".$oneVideo['ID']."&url=".$url."' class='photos-avatar'>
      <span class='avatar-choose'><i class='fa fa-plus fa-lg'></i></span>
      <img src='{$vv}' style='max-width: 100%; position: absolute;'>
      </a></li>";
    
    }
    
    ECHO JSON_ENCODE(ARRAY(
      
      'result' => 'success',
      'html' => $html
    
    ));
  
  }
  
}ELSE{
  
  REDIRECT('/index');

}
  
?>