<?php
  
$account = DB::GET_STRING("SELECT * FROM `USERS` WHERE `ID` = '".INTVAL(GET('id'))."' LIMIT 1");

IF (!$account['ID']){
  
  ERROR('Такого пользователя не существует', 'session');
  REDIRECT('/modules/?path=music');

}

IF (GET('dir') && DB::GET_COLUMN("SELECT COUNT(*) FROM `MUSIC_DIR` WHERE `ID` = '".INTVAL(GET('dir'))."' AND `USER_ID` = '".$account['ID']."' LIMIT 1") == 1){
  
  $dir = DB::GET_STRING("SELECT * FROM `MUSIC_DIR` WHERE `USER_ID` = '".$account['ID']."' AND `ID` = '".INTVAL(GET('dir'))."' LIMIT 1");
  
  $id_dir = INTVAL(GET('dir'));
  $nav = "<a href='/modules/?path=music&section=users&id=".$account['ID']."'>".LG('Музыка')."</a>".ICONS('angle-right', 20, 'fa-fw')."".TEXT_ABSOLUTE($dir['NAME'])."";
  $pr3 = $dir['PRIVATE'];

}ELSE{
  
  $id_dir = 0;
  $nav = "".LG('Музыка')."";
  $pr3 = 0;

}

/*
----------------------
Редактирование альбома
----------------------
*/

IF (GET('get') == "edit_dir" && $id_dir > 0 && $pr3 != 3){
  
  IF ($account['ID'] == $user['ID'] || MANAGEMENT == 1 || ACCESS('music_dir_edit', NULL, 1)){
    
    REQUIRE (ROOT.'/modules/music/plugins/edit_dir.php');
    
  }
  
}

/*
----------------
Удаление альбома
----------------
*/

IF (GET('get') == "delete_dir_ok" && $id_dir > 0 && $pr3 != 3){ 
  
  IF ($account['ID'] == $user['ID'] || ACCESS('music_dir_delete', NULL, 1) || MANAGEMENT == 1){
    
    REQUIRE (ROOT.'/modules/music/plugins/delete_dir.php');
    
  }
  
}

/*
------------------
Добавление альбома
------------------
*/

IF (GET('get') == "add_dir" && $account['ID'] == $user['ID'] && $pr3 != 3){
  
  REQUIRE (ROOT.'/modules/music/plugins/add_dir.php');
  
}

/*
-----------------
Добавление музыки
-----------------
*/

IF ($account['ID'] == $user['ID']){
  
  REQUIRE (ROOT.'/modules/music/plugins/add_music.php');
  
}

/*
---------------------
Редактирование музыки
---------------------
*/

IF (GET('get') == "music_edit"){  
  
  IF (ACCESS('music_edit', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `ID` = '".INTVAL(GET('music_id'))."' LIMIT 1");
    
    IF (!$music['ID']){
      
      ERROR('Неизвестная ошибка', 'session');
      REDIRECT('/modules/?path=music');
    
    }
    
    REQUIRE (ROOT.'/modules/music/plugins/edit_music.php');
    
  }
  
}

/*
---------------
Удаление музыки
---------------
*/

IF (GET('get') == "music_delete_ok"){ 
  
  IF (ACCESS('music_delete', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
    
    $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `ID` = '".INTVAL(GET('music_id'))."' LIMIT 1");
    
    IF (!$music['ID']){
      
      ERROR('Неизвестная ошибка', 'session');
      REDIRECT('/modules/?path=music');
    
    }
    
    REQUIRE (ROOT.'/modules/music/plugins/delete_music.php');
    
  }
  
}

/*
---------------
Список альбомов
---------------
*/
  
//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO $nav;
ECHO "</div>";

IF (GET('get') == "music_delete"){ 
  
  IF ($account['ID'] == $user['ID'] || ACCESS('music_delete', NULL, 1) || MANAGEMENT == 1){
    
    $music = DB::GET_STRING("SELECT * FROM `MUSIC` WHERE `ID` = '".INTVAL(GET('music_id'))."' LIMIT 1");
    
    IF (!$music['ID']){
      
      ERROR('Неизвестная ошибка', 'session');
      REDIRECT('/modules/?path=music');
    
    }
    
    ECHO "<div class='list'>";
    ECHO "".LG('Вы действительно хотите удалить музыку')." <b>".TEXT_ABSOLUTE($music['FACT_NAME'])."</b>?<br /><br />";
    
    ECHO "<a href='/modules/?path=music&section=users&page=".INTVAL(GET('page'))."&music_id=".$music['ID']."&id=".$account['ID']."&get=music_delete_ok&dir=".$id_dir."' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
    ECHO "<a href='/modules/?path=music&section=users&page=".INTVAL(GET('page'))."&id=".$account['ID']."&dir=".$id_dir."' class='btn-o'>".LG('Отменить')."</a>";
    
    ECHO "</div>";
  
  }
  
}

IF ($id_dir > 0){
  
  IF (MANAGEMENT == 0){
    
    IF (ACCESS('music_private_show', NULL, 1) == FALSE){
      
      REQUIRE (ROOT.'/modules/music/plugins/private_dir.php');
      
    }
  
  }
  
}

IF (GET('get') == "delete_dir" && $id_dir > 0 && $pr3 != 3){ 
  
  IF ($account['ID'] == $user['ID'] || ACCESS('music_dir_delete', NULL, 1) || MANAGEMENT == 1){
    
    ECHO "<div class='list'>";
    ECHO "".LG('Вы действительно хотите удалить альбом')." <b>".TEXT_ABSOLUTE($dir['NAME'])."</b>?<br /><br />";
    
    ECHO "<a href='/modules/?path=music&section=users&page=".INTVAL(GET('page'))."&id=".$account['ID']."&get=delete_dir_ok&dir=".$id_dir."' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
    ECHO "<a href='/modules/?path=music&section=users&page=".INTVAL(GET('page'))."&id=".$account['ID']."&dir=".$id_dir."' class='btn-o'>".LG('Отменить')."</a>";
    
    ECHO "</div>";
  
  }
  
}

IF ($account['ID'] == $user['ID']){
  
  ECHO "<div class='list'>";
  
  IF ($pr3 != 3){
    
    ECHO "<a href='/modules/?path=music&section=users&id=".$account['ID']."&get=add_dir&dir=".$id_dir."' class='btn'>".ICONS('plus', 15, 'fa-fw')."".LG('Создать альбом')."</a>";
    
  }
  
  ?><a id="upload-music" action="/system/AJAX/php/music.php?dir=<?=$id_dir?>" class="btn" onclick="modal_open('#add_music')" load="none"><?=ICONS('music', 15, 'fa-fw')?> <?=LG('Добавить музыку')?></a><?
    
  IF ($id_dir > 0 && $pr3 != 3){
    
    ECHO "<a href='/modules/?path=music&section=users&id=".$account['ID']."&get=edit_dir&dir=".$id_dir."' class='btn'>".ICONS('pencil', 15, 'fa-fw')."".LG('Редактировать альбом')."</a>"; 
    
    ECHO "<a href='/modules/?path=music&section=users&id=".$account['ID']."&get=delete_dir&dir=".$id_dir."' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить альбом')."</a>";
    
  }
  
  ECHO "</div>";
  
}ELSE{
  
  IF ($id_dir > 0 && $pr3 != 3){
    
    IF (ACCESS('music_dir_edit', NULL, 1) || MANAGEMENT == 1 || ACCESS('music_dir_delete', NULL, 1)){
      
      ECHO "<div class='list'>";
      
      IF (ACCESS('music_dir_edit', NULL, 1) || MANAGEMENT == 1){
        
        ECHO "<a href='/modules/?path=music&section=users&id=".$account['ID']."&get=edit_dir&dir=".$id_dir."' class='btn'>".ICONS('pencil', 15, 'fa-fw')."".LG('Редактировать альбом')."</a>"; 
      
      }
      
      IF (ACCESS('music_dir_delete', NULL, 1) || MANAGEMENT == 1){
        
        ECHO "<a href='/modules/?path=music&section=users&id=".$account['ID']."&get=delete_dir&dir=".$id_dir."' class='btn'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить альбом')."</a>";
      
      }
      
      ECHO "</div>";
    
    }
  
  }
  
}

ECHO "<div id='music_upgrade'>";

$array = ARRAY();

$data = DB::GET_STRING_ALL("SELECT * FROM `MUSIC_DIR` WHERE `USER_ID` = '".$account['ID']."' AND `ID_DIR` = '".$id_dir."' ORDER BY `ID` DESC");
WHILE ($list = $data->FETCH())
{

  $array[] = ARRAY('dir' => 1, 'list' => $list);

}

$data = DB::GET_STRING_ALL("SELECT * FROM `MUSIC` WHERE `USER_ID` = '".$account['ID']."' AND `ID_DIR` = '".$id_dir."' ORDER BY `TIME` DESC");
WHILE ($list = $data->FETCH())
{

  $array[] = ARRAY('dir' => 0, 'list' => $list);

}

$column = SIZEOF($array);
$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'>"; 
  
}

$p = 0;

FOR ($i = $limit; $i < $column && $i < $page_settings * $page; $i++){
  
  ECHO "<div class='list-menu'>";
  
  $list = $array[$i]['list'];
  
  IF ($array[$i]['dir'] == 1) {
    
    /*
    -------
    Альбомы
    -------
    */
    
    $count = DB::GET_COLUMN("SELECT COUNT(`ID`) FROM `MUSIC` WHERE `ID_DIR` = '".$list['ID']."' AND `USER_ID` = '".$account['ID']."' LIMIT 1");
    
    ECHO "<a href='/modules/?path=music&section=users&id=".$account['ID']."&dir=".$list['ID']."'>";
    
    ECHO "<table style='width: 100%;'><tr>";
    
    ECHO "<td class='td-file'>";

    ECHO "<font color='#CEC66A'>".ICONS('folder', 45, 'fa-fw')."</font>";
    
    ECHO "</td>";
    
    ECHO "<td class='td-file2'>";
    
    ECHO "<font color='#535D61'>".CROP_TEXT(TEXT_ABSOLUTE($list['NAME']), 0, 38)."";
    
    IF (STR($list['PASSWORD']) > 0 && $list['PRIVATE'] == 4){
      
      ECHO " ".ICONS('key', 15, 'fa-fw')."";
    
    }ELSEIF ($list['PRIVATE'] == 1){
      
      ECHO " ".ICONS('users', 15, 'fa-fw')."";
    
    }ELSEIF ($list['PRIVATE'] == 2){
      
      ECHO " ".ICONS('lock', 15, 'fa-fw')."";
    
    }ELSEIF ($list['PRIVATE'] == 3){
      
      ECHO " ".ICONS('lock', 15, 'fa-fw')."";
    
    }
    
    ECHO "<span style='position: relative; top: 4px;'>";
      
    ECHO "<br /><small><b>".LG('Аудиофайлов').": ".$count."</b></small>";
    
    ECHO "</span></font></td>";
    
    ECHO "</tr></table>";
    
    ECHO "</a>";
  
  }ELSE{
    
    /*
    ------
    Музыка
    ------
    */
    
    ECHO "<table style='width: 100%;'><tr>";
    
    ECHO "<td class='td-file'>";
      
    ?>      
    <button action="/system/AJAX/AlphaPlayer/session.php?path=<?=$account['ID']?>&type=users&dir=<?=$id_dir?>&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>";
    
    IF (ACCESS('music_edit', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
      
      ECHO "<a href='/modules/?path=music&section=users&page=".$page."&id=".$account['ID']."&music_id=".$list['ID']."&get=music_edit&dir=".$id_dir."' class='btn-o'>".ICONS('pencil', 15, 'fa-fw')."".LG('Редактировать')."</a>";
    
    }
    
    IF (ACCESS('music_delete', NULL, 1) || MANAGEMENT == 1 || $account['ID'] == $user['ID']){
      
      ECHO "<a href='/modules/?path=music&section=users&page=".$page."&id=".$account['ID']."&music_id=".$list['ID']."&get=music_delete&dir=".$id_dir."' class='btn-o'>".ICONS('trash', 15, 'fa-fw')."".LG('Удалить')."</a>";
    
    }
    
  }
  
  ECHO "</div>";

}

IF ($column > 0){
  
  ECHO "</div>";
  
}

IF ($spage > 1){ ECHO STR_PAGE('/modules/?path=music&section=users&id='.$account['ID'].'&dir='.$id_dir.'&', $spage, $page); }

ECHO "</div>";

IF ($id_dir == 0){
  
  ECHO "<div class='list'>";
  ECHO "<a href='/modules/?path=music'>".ICONS('arrow-left', 15, 'fa-fw')." ".LG('К альбомам')."</a>";
  ECHO "</div>";
  
}ELSE{
  
  ECHO "<div class='list'>";
  ECHO "<a href='/modules/?path=music&section=users&id=".$account['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 "<a href='/id".$account['ID']."'>".$account['LOGIN']."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO $nav;
ECHO "</div>"; 

?>