<?php
  
/*
----------------------------------------
Определяем параметры плеера для удобства
----------------------------------------
*/
  
IF (ISSET($_SESSION['id_music']) && ISSET($_SESSION['type']) && ISSET($_SESSION['path']) && ISSET($_SESSION['dir'])){
  
  $play_type = HTMLSPECIALCHARS($_SESSION['type']);
  $play_id_music = INTVAL($_SESSION['id_music']);
  $play_path = HTMLSPECIALCHARS($_SESSION['path']);
  $play_dir = INTVAL($_SESSION['dir']);
  
}ELSE{
  
  $play_type = NULL;
  $play_id_music = 0;
  $play_path = NULL;
  $play_dir = 0;
  
}

/*
--------------------------
Личная музыка пользователя
--------------------------
*/

IF ($play_type == "users"){
  
  $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID` = '".$play_id_music."' AND `ID_DIR` = '".$play_dir."' LIMIT 1");
  $pforward = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID` < '".$play_id_music."' AND `ID_DIR` = '".$play_dir."' ORDER BY `ID` DESC LIMIT 1");  
  $pback = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID` > '".$play_id_music."' AND `ID_DIR` = '".$play_dir."' ORDER BY `ID` ASC LIMIT 1");
  $p1 = DB::GET_COLUMN("SELECT COUNT(*) FROM `MUSIC` WHERE `ID` > '".$play_id_music."' AND `USER_ID` = '".$play_path."' AND `ID_DIR` = '".$play_dir."'") + 1; 
  $p2 = DB::GET_COLUMN("SELECT COUNT(*) FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID_DIR` = '".$play_dir."'");
    
  $play_list_link = "/modules/?path=music&section=users&id=".$play_path."&dir=".$music['ID_DIR']."";
  
/*
--------------
Музыка - новые
--------------
*/
  
}ELSEIF ($play_type == "main_new"){
  
  $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `ID` = '".$play_id_music."' LIMIT 1");
  
  $pforward = DB::GET_STRING("SELECT `MUSIC`.`ID`,`MUSIC`.`ID_DIR`,`MUSIC`.`EXT`,`MUSIC`.`NAME`,`MUSIC`.`ARTIST`,`MUSIC`.`USER_ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) AND `MUSIC`.`ID` < '".$play_id_music."' WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID` ORDER BY `MUSIC`.`ID` DESC LIMIT 1");
  
  $pback = DB::GET_STRING("SELECT `MUSIC`.`ID`,`MUSIC`.`ID_DIR`,`MUSIC`.`EXT`,`MUSIC`.`NAME`,`MUSIC`.`ARTIST`,`MUSIC`.`USER_ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) AND `MUSIC`.`ID` > '".$play_id_music."' WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID` ORDER BY `MUSIC`.`ID` ASC LIMIT 1");
  
  $data = DB::GET_STRING_ALL("SELECT `MUSIC`.`ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) AND `MUSIC`.`ID` > '".$play_id_music."' WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID`");
  
  $column = 0;
  
  WHILE ($data->FETCH()){
    
    $column++;
  
  }
  
  $data = DB::GET_STRING_ALL("SELECT `MUSIC`.`ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID`");
  
  $column2 = 0;
  
  WHILE ($data->FETCH()){
    
    $column2++;
  
  }  
  
  $p1 = $column + 1; 
  $p2 = $column2;
    
  $play_list_link = "/modules/?path=music";
  
/*
------------
Музыка - все
------------
*/

}ELSEIF ($play_type == "main_all"){
  
  $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `ID` = '".$play_id_music."' LIMIT 1");
  
  $pforward = DB::GET_STRING("SELECT `MUSIC`.`ID`,`MUSIC`.`ID_DIR`,`MUSIC`.`EXT`,`MUSIC`.`NAME`,`MUSIC`.`ARTIST`,`MUSIC`.`USER_ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) AND `MUSIC`.`ID` > '".$play_id_music."' WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID` ORDER BY `MUSIC`.`ID` ASC LIMIT 1");
  
  $pback = DB::GET_STRING("SELECT `MUSIC`.`ID`,`MUSIC`.`ID_DIR`,`MUSIC`.`EXT`,`MUSIC`.`NAME`,`MUSIC`.`ARTIST`,`MUSIC`.`USER_ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) AND `MUSIC`.`ID` < '".$play_id_music."' WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID` ORDER BY `MUSIC`.`ID` DESC LIMIT 1");
  
  $data = DB::GET_STRING_ALL("SELECT `MUSIC`.`ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) AND `MUSIC`.`ID` < '".$play_id_music."' WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID`");
  
  $column = 0;
  
  WHILE ($data->FETCH()){
    
    $column++;
  
  }
  
  $data = DB::GET_STRING_ALL("SELECT `MUSIC`.`ID` FROM `MUSIC` LEFT JOIN `MUSIC_DIR` ON (`MUSIC_DIR`.`ID` = `MUSIC`.`ID_DIR` OR `MUSIC_DIR`.`ID_DIR` = `MUSIC`.`ID_DIR`) WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID`");
  
  $column2 = 0;
  
  WHILE ($data->FETCH()){
    
    $column2++;
  
  }  
  
  $p1 = $column + 1; 
  $p2 = $column2;
    
  $play_list_link = "/modules/?path=music&get=all";
  
/*
--------------------
Музыка - по рейтингу
--------------------
*/

}ELSEIF ($play_type == "main_rating"){
  
  $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `ID` = '".$play_id_music."' LIMIT 1");
  
  $pforward = DB::GET_STRING("SELECT `music`.*, `dir`.`PRIVATE` FROM `MUSIC` `music` JOIN `MUSIC_DIR` `dir` WHERE `dir`.`PRIVATE` = '0' AND `music`.`ID` < '".$play_id_music."' GROUP BY `music`.`ID` ORDER BY `music`.`ID` DESC, `music`.`RATING` DESC LIMIT 1");
  
  $pback = DB::GET_STRING("SELECT `music`.*, `dir`.`PRIVATE` FROM `MUSIC` `music` JOIN `MUSIC_DIR` `dir` WHERE `dir`.`PRIVATE` = '0' AND `music`.`ID` > '".$play_id_music."' GROUP BY `music`.`ID` ORDER BY `music`.`ID` ASC, `music`.`RATING` DESC LIMIT 1");
  
  $data = DB::GET_STRING_ALL("SELECT `music`.*, `dir`.`PRIVATE` FROM `MUSIC` `music` JOIN `MUSIC_DIR` `dir` WHERE `dir`.`PRIVATE` = '0' AND `music`.`ID` > '".$play_id_music."' GROUP BY `music`.`ID` ORDER BY `music`.`RATING` DESC");
  
  $column = 0;
  
  WHILE ($data->FETCH()){
    
    $column++;
  
  }
  
  $data = DB::GET_STRING_ALL("SELECT `music`.*, `dir`.`PRIVATE` FROM `MUSIC` `music` JOIN `MUSIC_DIR` `dir` WHERE `dir`.`PRIVATE` = '0' GROUP BY `music`.`ID`");
  
  $column2 = 0;
  
  WHILE ($data->FETCH()){
    
    $column2++;
  
  }  
  
  $p1 = $column + 1; 
  $p2 = $column2;
    
  $play_list_link = "/modules/?path=music&get=rating";

}ELSE{
  
  $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID` = '".$play_id_music."' AND `ID_DIR` = '".$play_dir."' LIMIT 1");
  $pforward = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID` < '".$play_id_music."' AND `ID_DIR` = '".$play_dir."' ORDER BY `ID` DESC LIMIT 1");  
  $pback = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID` > '".$play_id_music."' AND `ID_DIR` = '".$play_dir."' ORDER BY `ID` ASC LIMIT 1");
  $p1 = DB::GET_COLUMN("SELECT COUNT(*) FROM `MUSIC` WHERE `ID` > '".$play_id_music."' AND `USER_ID` = '".$play_path."' AND `ID_DIR` = '".$play_dir."'") + 1; 
  $p2 = DB::GET_COLUMN("SELECT COUNT(*) FROM `MUSIC` WHERE `USER_ID` = '".$play_path."' AND `ID_DIR` = '".$play_dir."'");
  
  $play_list_link = "/modules/?path=music&section=users&id=".$play_path."&dir=".$music['ID_DIR']."";
  
}
  
?>