<?
/*
=====================================================
 Volkov NET!! - by SaNcHeS Group 
-----------------------------------------------------
 http://AllForCS.RU/
-----------------------------------------------------
 Copyright (c) 2009 SaNcHeS Group
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Файл: music.php
-----------------------------------------------------
 Назначение: Редактирование музыки
=====================================================
*/

include("./../inc/config.php");
include("./../inc/id3v2.php");
include("./passwd.php");
include("./generator.php");
include("./auth.php");
include("./html.php");

function fsize($str_size){
if ($str_size != ""){
$str_size=(int)$str_size;
$mpd="./../m3_files/".get_dir($str_size)."/".$str_size.".mp3";
@$blya=(int)(@filesize($mpd)/1024);
@$blya=$blya/1024;
list($mb,$kb) = @explode(".",$blya);
@$kb = substr($kb, 0, 2);
if ($kb==""){$kb="00";}
@$blyxa=$mb.".".$kb." Mb";
return $blyxa;
}
}

if ($_POST['refresh']){
@header("Location: music.php");
exit;
}

if ($_GET['event'] == 'update' && is_numeric($_GET['id']))
{

if ($_GET['upd'] == 1){
$sql = mysql_query("SELECT * FROM `m3_mp3` WHERE `id` = '$_GET[id]' LIMIT 1;") or die (mysql_error());
if ($sql && @mysql_num_rows($sql)>0){
while ($row = @mysql_fetch_array($sql, MYSQL_ASSOC)){
$bkv=substr($row['artist'], 0, 1);

}}}

if ($_POST['del']){
@mysql_query("DELETE FROM `m3_mp3` WHERE `id` = '$_GET[id]';");
@unlink("./../m3_files/".get_dir($_GET[id])."/".$_GET[id].".mp3");

if ($_GET['upd'] == 1){
@generate_new_mp3();                 // Генерим 5 новых песен
@generate_pop_mp3();                 // Генерим 5 популярных песен
@generate_lists($bkv);               // Генерим странцы листинга песен по буквам
@generate_new();                     // Генерим 100 новых песен
}

echo "<link rel=\"stylesheet\" href=\"../inc/comments.css\" type=\"text/css\">
<body bgcolor=#FFFFF4><table cellpadding=\"10\" cellspacing=\"10\" width=\"100%\" height=\"100%\"><tr><td valign=\"top\"><p align=\"left\">
<br><br><br><div align=\"center\">Файл успешно удален!</div>
</table>";
}

if ($_POST['ok']){
@mysql_query("UPDATE `m3_mp3` SET `size` = '".fsize($_GET['id'])."', `artist` = '$_POST[artist]', `track` = '$_POST[track]', `ip` = '$_POST[ip]' WHERE `id` = '$_GET[id]';");

if ($_GET['upd'] == 1){
@generate_new_mp3();                 // Генерим 5 новых песен
@generate_pop_mp3();                 // Генерим 5 популярных песен
@generate_lists($bkv);               // Генерим странцы листинга песен по буквам
@generate_new();                     // Генерим 100 новых песен
@generate_viewers($_GET[id],$_GET[id]);
}

echo "<link rel=\"stylesheet\" href=\"../inc/comments.css\" type=\"text/css\">
<body bgcolor=#FFFFF4><table cellpadding=\"10\" cellspacing=\"10\" width=\"100%\" height=\"100%\"><tr><td valign=\"top\"><p align=\"left\">
<br><br><div align=\"center\">Информация в базе данных успешно обновлена!</div>
</table>";
}

@mysql_free_result();
@mysql_close();
exit;}

if ($_GET['event'] == 'edit' && is_numeric($_GET['id']))
{
$nj=$_GET['id'];
if ($_GET['we']){
$nj=$_POST['id'];
}

if ($nj == 0){
echo "<link rel=\"stylesheet\" href=\"../inc/comments.css\" type=\"text/css\">
<body bgcolor=#FFFFF4><table cellpadding=\"10\" cellspacing=\"10\" width=\"100%\" height=\"100%\"><tr><td valign=\"top\"><p align=\"left\">
<br><br><div align=\"center\">Не задан ID песни!</div>
</table>";
exit;
}

$sql = mysql_query("SELECT * FROM `m3_mp3` WHERE `id` = '$nj' LIMIT 1;") or die (mysql_error());
if ($sql && @mysql_num_rows($sql)>0){
while ($row = @mysql_fetch_array($sql, MYSQL_ASSOC)){

$p_id=$row['id'];
$p_active=$row['active'];
$p_artist=$row['artist'];
$p_track=$row['track'];
$p_ip=$row['ip'];
$p_size=fsize($row['id']);

}}

echo "<link rel=\"stylesheet\" href=\"../inc/comments.css\" type=\"text/css\">
<body bgcolor=#FFFFF4><table cellpadding=\"10\" cellspacing=\"10\" width=\"100%\" height=\"100%\"><tr><td valign=\"top\"><p align=\"left\">
<form name=\"update\" action=\"music.php?event=update&id=$nj&upd=$_GET[upd]\" method=\"post\">
<div align=\"center\"><input name=\"artist\" type=\"text\" size=\"38\" value=\"".ucwords($p_artist)."\"><br><br>
<input name=\"track\" type=\"text\" size=\"38\" value=\"".ucwords($p_track)."\"><br><br>
<input name=\"ip\" type=\"text\" size=\"38\" value=\"$p_ip\"><br><br>
<input type=\"reset\" value=\"Сброс\"> <input type=\"submit\" name=\"del\" value=\"Удалить\"> <input type=\"submit\" name=\"ok\" value=\"Применить\">

</div>
</form>
</table>";

@mysql_free_result();
@mysql_close();
exit;
}


$JS_POPUP2=<<<java_2
<script language="JavaScript">
<!--
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  if (document.search_id.id.value == '')document.search_id.id.value = 0;
  if (name == 'edit2')window.open(url+document.search_id.id.value, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
  if (name != 'edit2')window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}
// -->
</script>
<script language='JavaScript' type="text/javascript">
<!--

var ie  = document.all  ? 1 : 0;
//var ns4 = document.layers ? 1 : 0;

function hl(cb)
{
   if (ie)
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentElement;
           }
   }
   else
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentNode;
           }
   }
   cb.className = 'hlight';
}

function hl2(cb)
{
   if (ie)
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentElement;
           }
   }
   else
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentNode;
           }
   }
   cb.className = 'hlight2';
}

function dl(cb) {
   if (ie)
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentElement;
           }
   }
   else
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentNode;
           }
   }
   cb.className = 'dlight';
}

function dl2(cb) {
   if (ie)
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentElement;
           }
   }
   else
   {
           while (cb.tagName != "TR")
           {
                   cb = cb.parentNode;
           }
   }
   cb.className = 'dlight2';
}

function cca(cb) {
   if (cb.checked)
   {
           hl(cb);
   }
   else
   {
           dl(cb);
   }
}

function cca2(cb) {
   if (cb.checked)
   {
           hl2(cb);
   }
   else
   {
           dl2(cb);
   }
}

function CheckAll(cb) {
        var fmobj = document.mutliact;
        for (var i=0;i<fmobj.elements.length;i++) {
                var e = fmobj.elements[i];
                if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
                        e.checked = fmobj.allbox.checked;
                        if (fmobj.allbox.checked)
                        {
                           hl(e);
                        }
                        else
                        {
                           dl(e);
                        }
                }
        }
}
function CheckCheckAll(cb) {
        var fmobj = document.mutliact;
        var TotalBoxes = 0;
        var TotalOn = 0;
        for (var i=0;i<fmobj.elements.length;i++) {
                var e = fmobj.elements[i];
                if ((e.name != 'allbox') && (e.type=='checkbox')) {
                        TotalBoxes++;
                        if (e.checked) {
                                TotalOn++;
                        }
                }
        }
        if (TotalBoxes==TotalOn) {fmobj.allbox.checked=true;}
        else {fmobj.allbox.checked=false;}
}

function select_read() {
        var fmobj = document.mutliact;
        for (var i=0;i<fmobj.elements.length;i++) {
                var e = fmobj.elements[i];
                if ((e.type=='hidden') && (e.value == 1) && (! isNaN(e.name) ))
                {
                        eval("fmobj.msgid_" + e.name + ".checked=true;");
                        hl(e);
                }
        }
}

function unselect_all() {
        var fmobj = document.mutliact;
        for (var i=0;i<fmobj.elements.length;i++) {
                var e = fmobj.elements[i];
                if (e.type=='checkbox') {
                        e.checked=false;
                        dl(e);
                }
        }
}

//-->
</script>
java_2;

echo $HEAD;
echo $JS_POPUP2;
echo $STYLE;
echo $BODY;

print <<<vivod
<style>
.hlight { background-color: #A3B0BB }
.dlight { background-color: #FFFFFF }
.hlight2 { background-color: #F96A6A }
.dlight2 { background-color: #FFFFFF }
</style>
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<p>
vivod;

if ($_POST[del_s]){
$dela=array_keys($_POST);
for ($i=0; $i<count($dela)-1; $i++) {
@unlink("./../m3_files/".get_dir(pos($dela))."/".pos($dela).".mp3");
@unlink("./../pages/".get_dir(pos($dela))."/".pos($dela).".shtml");
@mysql_query("DELETE FROM `m3_mp3` WHERE `id` = '".pos($dela)."';");
next($dela);}

@generate_new_mp3();                 // Генерим 5 новых песен
@generate_pop_mp3();                 // Генерим 5 популярных песен
@generate_lists();                   // Генерим странцы листинга песен по буквам
@generate_new();                     // Генерим 100 новых песен

echo "<div align=\"center\">Файлы успешно удалены!</div>
</table>";

@mysql_free_result();
@mysql_close();
exit;}

if ($_GET['event'] == 'sort'){

$dela=array_keys($_POST);
for ($i=0; $i<count($dela); $i++) {

if ($_POST[pos($dela)] == "OFF"){
@mysql_query("DELETE FROM `m3_mp3` WHERE `id` = '".pos($dela)."';");
@unlink("./../m3_files/".get_dir(pos($dela))."/".pos($dela).".mp3");
}

if ($_POST[pos($dela)] == "ON"){
@mysql_query("UPDATE `m3_mp3` SET `active` = '1', `size` = '".fsize(pos($dela))."' WHERE `id` = '".pos($dela)."';");
@generate_viewers(pos($dela), pos($dela));
}

next($dela);}

@generate_new_mp3();                 // Генерим 5 новых песен
@generate_pop_mp3();                 // Генерим 5 популярных песен
@generate_lists();                   // Генерим странцы листинга песен по буквам
@generate_new();                     // Генерим 100 новых песен

print "<div align=\"center\">Действие успешно завершено!</div>";

}



if ($_GET['event'] == 'search'){
if ($_POST['searcher'] == ""){echo "Не введен запрос.";exit;}
?>
<table border="0">
    <tr>
        <td width="250">
            <p align="center">
              <form name="search" action="music.php?event=search" method="post">
                Поиск: <input name="searcher" type="text" value="<?=$_POST[searcher];?>">&nbsp;<input type="submit" value="Найти">
              </form>
            </p>
        </td>
        <td width="280">
            <p align="center">
              <form name="search_id" action="javascript:na_open_window('edit2', 'music.php?event=edit&upd=1&id=', 150, 150, 300, 150, 0, 0, 0, 1, 0)" method="post">
               ID: <input name="id" type="text">&nbsp;<input type="submit" value="Редактировать">
              </form>
            </p>
        </td>
    </tr>
</table><form name="sort" action="music.php" method="post">
<table style="border-collapse:collapse;" cellspacing="0" width="100%">
    <tr bgcolor=#EAEAEA>
        <td width="50" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">ID</p>
        </td>
        <td width="133" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Исполнитель - Песня</p>
        </td>
        <td width="133" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Тэги</p>
        </td>
        <td width="80" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Размер</p>
        </td>
        <td width="100" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Загрузил</p>
        </td>
        <td width="120" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">IP</p>
        </td>
        <td width="100" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center"></p>
        </td>
        <td width="80" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Удалить</p>
        </td>
    </tr>


<?
if (strstr($_POST[searcher], " - ")){list($a_artist, $a_track) = explode(" - ",$_POST[searcher]);
$sql = mysql_query("SELECT * FROM `m3_mp3` WHERE `artist` LIKE '%$a_artist%' AND `track` LIKE '%$a_track%' ORDER BY `id` DESC;") or die (mysql_error());
}else{
$sql = mysql_query("SELECT * FROM `m3_mp3` WHERE `artist` LIKE '%$_POST[searcher]%' OR `track` LIKE '%$_POST[searcher]%' ORDER BY `id` DESC;") or die (mysql_error());
}

if ($sql && @mysql_num_rows($sql)>0){
while ($row = @mysql_fetch_array($sql, MYSQL_ASSOC)){

$p_id=$row['id'];
$p_active=$row['active'];
$p_artist=$row['artist'];
$p_track=$row['track'];
$p_uploader=$row['uploader'];
$p_date=$row['date'];
$p_ip=$row['ip'];
$p_size=fsize($row['id']);
@$id3 = new id3("./../m3_files/".get_dir($p_id)."/".$p_id.".mp3");
@$id_artist = $id3->artist();
@$id_title = $id3->title();
@$id_bitrate = $id3->bitrate();

print "<tr>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\">$p_id</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p>&nbsp;&nbsp;$p_artist - $p_track&nbsp;&nbsp;</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p>&nbsp;&nbsp;$id_artist - $id_title ($id_bitrate kbps)&nbsp;&nbsp;</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\">$p_size</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\">&nbsp;&nbsp;$p_uploader&nbsp;&nbsp;</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\"><a href=\"javascript:na_open_window('IP', 'ip.php?ip=$p_ip', 150, 200, 200, 25, 0, 0, 0, 0, 0)\">$p_ip</a></p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\"><a href=\"javascript:na_open_window('edit', 'music.php?event=edit&upd=1&id=$p_id', 150, 150, 300, 150, 0, 0, 0, 1, 0)\">редактировать</a></p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\"><input name=\"$p_id\" type=\"checkbox\" onclick=\"cca2(this);\" value=\"OFF\"></p>
        </td>
    </tr>";


}}

echo "</table><p align=right><input type=\"submit\" name=\"del_s\" value=\"Удалить\"></p></form>";
}


if (!isset($_GET['event'])){
?>
<table border="0">
    <tr>
        <td width="250">
            <p align="center">
              <form name="search" action="music.php?event=search" method="post">
                Поиск: <input name="searcher" type="text" value="">&nbsp;<input type="submit" value="Найти">
              </form>
            </p>
        </td>
        <td width="280">
            <p align="center">
              <form name="search_id" action="javascript:na_open_window('edit2', 'music.php?event=edit&upd=1&id=', 150, 150, 300, 150, 0, 0, 0, 1, 0)" method="post">
               ID: <input name="id" type="text">&nbsp;<input type="submit" value="Редактировать">
              </form>
            </p>
        </td>
    </tr>
</table><form name="sort" action="music.php?event=sort" method="post">
<table style="border-collapse:collapse;" cellspacing="0" width="100%">
    <tr bgcolor=#EAEAEA>
        <td width="50" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">ID</p>
        </td>
        <td width="133" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Исполнитель - Песня</p>
        </td>
        <td width="133" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Тэги</p>
        </td>
        <td width="80" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Размер</p>
        </td>
        <td width="100" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Загрузил</p>
        </td>
        <td width="120" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">IP</p>
        </td>
        <td width="100" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center"></p>
        </td>
        <td width="80" style="border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;">
            <p align="center">Доб. / Удал.</p>
        </td>
    </tr>


<?

$sql = mysql_query("SELECT * FROM `m3_mp3` WHERE `active` = '0' ORDER BY `id` DESC;") or die (mysql_error());
if ($sql && @mysql_num_rows($sql)>0){
while ($row = @mysql_fetch_array($sql, MYSQL_ASSOC)){

$p_id=$row['id'];
$p_active=$row['active'];
$p_artist=$row['artist'];
$p_track=$row['track'];
$p_uploader=$row['uploader'];
$p_date=$row['date'];
$p_ip=$row['ip'];
$p_size=fsize($row['id']);
@$id3 = new id3("./../m3_files/".get_dir($p_id)."/".$p_id.".mp3");
@$id_artist = $id3->artist();
@$id_title = $id3->title();
@$id_bitrate = $id3->bitrate();

print "<tr>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\">$p_id</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p>&nbsp;&nbsp;".unsafe_str($p_artist)." - ".unsafe_str($p_track)."&nbsp;&nbsp;</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p>&nbsp;&nbsp;$id_artist - $id_title ($id_bitrate kbps)&nbsp;&nbsp;</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\">$p_size</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\">&nbsp;&nbsp;$p_uploader&nbsp;&nbsp;</p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\"><a href=\"javascript:na_open_window('IP', 'ip.php?ip=$p_ip', 150, 200, 200, 25, 0, 0, 0, 0, 0)\">$p_ip</a></p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\"><a href=\"javascript:na_open_window('edit', 'music.php?event=edit&id=$p_id', 150, 150, 300, 150, 0, 0, 0, 1, 0)\">редактировать</a></p>
        </td>
        <td nowrap style=\"border-top-width:1; border-right-width:1; border-bottom-width:1; border-left-width:1; border-color:black; border-style:solid;\">
            <p align=\"center\"><input name=\"$p_id\" type=\"checkbox\" onclick=\"cca(this);\" value=\"ON\">&nbsp;<input name=\"$p_id\" type=\"checkbox\" onclick=\"cca2(this);\" value=\"OFF\"></p>
        </td>
    </tr>";


}}

echo "</table><p align=right><input type=\"submit\" name=\"refresh\" value=\"Обновить\"> <input type=\"submit\" value=\"Выполнить\"></p></form>";
}







print "</pre></p></td></tr></table>";
echo $FOOT;
@mysql_free_result();
@mysql_close();
?>