<?php
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Музыка')."</a>";
ECHO "</div>";

ECHO "<div class='tmenu_body'>";

IF (GET('get') == 'rating'){
  
  $sql = "ORDER BY `MUSIC`.`RATING` DESC";
  $url = "&get=rating";
  $type = "main_rating";
  
  ECHO "<a href='/modules/?path=music' class='tmenu-33'>".LG('Новые')."</a>";
  ECHO "<a href='/modules/?path=music&get=all' class='tmenu-33'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=music&get=rating' class='tmenu-33 tmenu-33-o'>".LG('По рейтингу')."</a>";
  
}ELSEIF (GET('get') == 'all'){
  
  $sql = "ORDER BY `MUSIC`.`TIME` ASC";
  $url = "&get=all";
  $type = "main_all";
  
  ECHO "<a href='/modules/?path=music' class='tmenu-33'>".LG('Новые')."</a>";
  ECHO "<a href='/modules/?path=music&get=all' class='tmenu-33 tmenu-33-o'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=music&get=rating' class='tmenu-33'>".LG('По рейтингу')."</a>";
  
}ELSE{
  
  $sql = "ORDER BY `MUSIC`.`TIME` DESC";
  $url = NULL;
  $type = "main_new";
  
  ECHO "<a href='/modules/?path=music' class='tmenu-33 tmenu-33-o'>".LG('Новые')."</a>";
  ECHO "<a href='/modules/?path=music&get=all' class='tmenu-33'>".LG('Все')."</a>";
  ECHO "<a href='/modules/?path=music&get=rating' class='tmenu-33'>".LG('По рейтингу')."</a>";
  
}

ECHO "</div>";

//Поиск
REQUIRE (ROOT.'/modules/search/plugins/form/music.php');

$data2 = 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`");

$column = 0;

WHILE ($data2->FETCH())
{
  
  $column++;
  
}

$spage = SPAGE($column, $page_settings);
$page = PAGE($spage);
$limit = $page_settings * $page - $page_settings;

IF ($column == 0){ 
  
  HTML::EMPTY();
  
}ELSE{
  
  ECHO "<div class='list-body'>"; 
  
}

$s = 0;

$data = DB::GET_STRING_ALL("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`) WHERE `PRIVATE` = '0' GROUP BY `MUSIC`.`ID` ".$sql." LIMIT ".$limit.", ".$page_settings."");

WHILE ($list = $data->FETCH())
{
  
  $s++;
  
  ECHO "<div class='list-menu'>"; 
  
  ECHO "<table style='width: 100%;'><tr>";
    
  ECHO "<td class='td-file'>";
      
  ?>      
  <button action="/system/AJAX/AlphaPlayer/session.php?path=<?=$list['USER_ID']?>&type=<?=$type?>&dir=0&id_music=<?=$list['ID']?>" id="play-status<?=$list['ID']?>" onclick="MusicPlay(<?=$list['ID']?>)" class="play-status-off play-button-style"><i class="fa fa-play fa-fw"></i></button>
  <?
          
  ECHO FILE::ICONS('mp3'); 
    
  ECHO "</td>";
    
  ECHO "<td class='td-file2'>";
    
  ECHO "<b>".CROP_TEXT(TEXT_ABSOLUTE($list['NAME']), 0, 38)."</b><br />";
    
  ECHO "<font color='#686C6F'><small>".CROP_TEXT(TEXT_ABSOLUTE($list['ARTIST']), 0, 38)."</small></font><br />";
    
  ECHO "</td>";
    
  ECHO "</tr></table>";
  
  ECHO "</div>";
  
}

IF ($column > 0){

  ECHO "</div>";
  
}

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=music'.$url.'&', $spage, $page); }

IF (ISSET($user)){
  
  ECHO "<div class='list'>";
  ECHO "<a href='/modules/?path=music&section=users&id=".$user['ID']."'>".ICONS('arrow-left', 15, 'fa-fw')." ".LG('К моим альбомам')."</a>";
  ECHO "</div>";
  
}

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".LG('Музыка')."</a>";
ECHO "</div>"; 
  
?>