<?
include 'function.php';
header("Content-type: text/html; charset=utf-8");
date_default_timezone_set('Asia/Tashkent');
$act = isset ($_GET['act']) ? trim($_GET['act']) : '';
switch ($act) {
	case 'view' :
	    define('_IN_JOHNCMS', 1);
	    require_once('../incfiles/core.php');
	$id = isset ($_GET['id']) ? intval($_GET['id']) : '';
		if (mysql_result(mysql_query("SELECT COUNT(*) FROM `znu_music` WHERE `id` = '$id'"),0)==1){	
		    mysql_query("UPDATE `znu_music` SET `view` = `view` + 1 WHERE `id` = '$id'");
			$muz = mysql_fetch_assoc(mysql_query("SELECT * FROM `znu_music` WHERE `id` = '$id' LIMIT 1"));
			$kim = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$muz['user_id']."'"), 0);			
		    $oy = array(  1 => 'Yanvar',   2 => 'Fevral',    3 => 'Mart',    4 => 'Aprel',    5 => 'May',    6 => 'Iyun',    7 => 'Iyul',    8 => 'Avgust',    9 => 'Sentyabr',    10 => 'Oktyabr',    11 => 'Noyabr',    12 => 'Dekabr',);
          $textl = $muz['ijrochi'].' - '.$muz['nomi'];
          require('../incfiles/head.php');
			echo '<div class="phdr"><b>'.$muz['ijrochi'].' - '.$muz['nomi'].'</b></div>';
			
            echo '<div class="menu"><img src="'.$muz['coverpath'].'" width="150px" heigth="150px"></div>';
			echo '<div class="menu"><span style="color: gray;">Ijrochi:</span> <b>'.$muz['ijrochi'].'</b><br>';
			echo '<span style="color: gray;">Nomi:</span> <b>'.$muz['nomi'].'</b><br>';
			 echo '<span style="color: gray;">Albom:</span> <b>'.$muz['albom'].'</b><br>';
			echo '<span style="color: gray;">Izoh:</span> <b>'.$muz['izoh'].'</b><br>';
			echo '<span style="color: gray;">O`girligi:</span> <b>'.size($muz['size']).'</b><br>';
            echo '<span style="color: gray;">Sifati:</span> <b>'.$muz['sam'].' Hz,'.$muz['bitrate'].' Kbps</b><br>';
            echo '<span style="color: gray;">Davomiyligi:</span> <b>'.date('i:s',$muz['duration']).' daqiqa</b><br>';
			echo '<span style="color: gray;">Qo\'shildi:</span> <b>'.(date('H:i, j',$muz['time'] + $set['timeshift'] * 3600)).'-' .$oy[(date('n',$muz['time'] + $set['timeshift'] * 3600))]. ' '.(date('Y',$muz['time'] + $set['timeshift'] * 3600)).'-yil</b><br>';
            if($rights >= 7) echo '<span style="color: gray;">Joyladi:</span> <b><a href="../users/profile.php?user='.$kim['id'].'">'.$kim['name'].'</a> </b>';
			echo '</div>';			
		    echo '<div class="menu"><b>Tinglash:</b> <br/>';
            echo '<object type="application/x-shockwave-flash" data="mp3player.swf" width="200" height="20" id="mp3player" name="mp3player">';
            echo '<param name="movie" value="mp3player.swf" /><param name="flashvars" value="mp3='.$muz['path'].'" />';
            echo '</object></div>';             
			echo '<div class="menu"><a href="index.php?act=download&id='.$muz['id'].'"> <b>Yuklab olish</b></a></div>';
			echo '<div class="menu">Import: <input type="text" value="' . $home .'/music/'.$muz['path'].'"/></div>';
			if($rights >= 7) echo '<div class="menu"><a href="index.php?act=delete&id='.$muz['id'].'"> <font color="red"><b>Faylni o`chirish</b></font></a></div>';
	}else echo functions::display_error('Fayl mavjud emas!');
			require('../incfiles/end.php');
	break;
	case 'delete' :
define('_IN_JOHNCMS', 1);
require_once('../incfiles/core.php');
$textl = 'Faylni o`chirish';
require('../incfiles/head.php');
$id = isset ($_GET['id']) ? intval($_GET['id']) : '';
	if($rights >= 7) {
					$q = mysql_query("SELECT * FROM `znu_music` WHERE `id`='$id' LIMIT 1;");
					$music = mysql_fetch_assoc($q);
					if (mysql_num_rows($q)) {
						if(isset($_POST['submit'])) {
							mysql_query("DELETE FROM `znu_music` WHERE `id`='$id'");
							unlink($music['path']);
							unlink($music['coverpath']);
							Header('Location: index.php?act=userfiles');
							exit;	}
						echo '<div class="rmenu">
						<form action="index.php?act=delete&amp;id=' . $id . '" method="post"  enctype="multipart/form-data"><div>
						O`chirishni tasdiqlash<br />
						<input type="submit" name="submit" value="O`chir"/>
						</div></form>
						</div>';
					} else echo functions::display_error('Fayl mavjud emas!');
				} else {
					Header('Location: ../?err');
					exit;
				}
				require('../incfiles/end.php');
	break;	
	case 'userfiles' :
define('_IN_JOHNCMS', 1);
require_once('../incfiles/core.php');
$textl = 'Foydalanuvchilar yuklagan fayllar';
require('../incfiles/head.php');
echo '<div class="phdr">Foydalanuvchi fayllari</div>';
if($rights >= 7){
	 $jami = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `znu_music`"),0);		
		$q = mysql_query("SELECT * FROM `znu_music` ORDER BY `id` DESC LIMIT $start, $kmess");
		if ($jami==0)echo '<div class="menu">Fayllar yo`q :(</div>';
		while ($music = mysql_fetch_assoc($q)){
		   $kim = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$music['user_id']."'"), 0);
		   echo '<div class="menu"><img style="float: left; height: 50px; line-height: 17px;" src="'.$music['coverpath'].'"> <a href="'.$music['id'].'_'.clean($music['ijrochi']).'_'.clean($music['nomi']).'.html"><div style="min-height: 52px; margin-left: 54px;">  '.$music['ijrochi'].' - '.$music['nomi'].'</a> <br><span style="font-size: small;"><div style="color: gray;">Joyladi: <a href="../users/profile.php?user='.$kim['id'].'">'.$kim['name'].'</a> <a href="?act=delete&id='.$music['id'].'"><font color="red">O`chirish</font></a></div></span></div></div>';
		}
		if ($jami > $kmess) echo '<div class="topmenu">' . functions::display_pagination('index.php?act=mod&', $start, $jami, $kmess) . '</div>';
		require('../incfiles/end.php');
}else
{
	echo '<div class="menu"> <font color="red"> Bu sahifani faqat sayt ma`muriyati ko`rishi mumkin!</font></div><div class="menu"><a href="index.php">Ortga</a></div>';
	require('../incfiles/end.php');
	exit();
}
	break;
	case 'download' :
define('_IN_JOHNCMS', 1);
require_once('../incfiles/core.php');
$id = isset ($_GET['id']) ? intval($_GET['id']) : '';
					$q = mysql_query("SELECT * FROM `znu_music` WHERE `id`='$id' LIMIT 1;");
					$music = mysql_fetch_assoc($q);
					if (mysql_num_rows($q)) {						
							if(mysql_query("UPDATE `znu_music` SET `download` = `download`+1 WHERE `id` = '$id'"))
							Header('Location: '.$music['path']);
							exit;						
						
					} else echo functions::display_error('Fayl mavjud emas!');
	break;
	default :
	    define('_IN_JOHNCMS', 1);
require_once('../incfiles/core.php');
$textl = 'Media xizmat';
require('../incfiles/head.php');
$qq = mysql_query("SELECT * FROM `znu_music` where `time` + 1800 < '".time()."'");
		while ($mus = mysql_fetch_assoc($qq)){
		  mysql_query("DELETE FROM `znu_music` WHERE `id`='".$mus['id']."'");
		  unlink($mus['path']);
		  unlink($mus['coverpath']);
		}
$j = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `znu_music` where `time` + 1800 > '".time()."'"),0);
if ($rights >= 7 && $j>0) 
    echo '<div class="menu"> <a href="index.php?act=userfiles">Foydalanuvchi fayllari</a> <font color="red">+'.$j.'</font></div>';
    
echo '<div class="phdr"><b>Qayta ishlangan mediafayllar</b></div>';

    $jami = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `znu_music` where `user_id` = '".$user_id."'"),0);
    $q = mysql_query("SELECT * FROM `znu_music` where `user_id` = '".$user_id."' ORDER BY `id` DESC LIMIT $start, $kmess");
    if ($jami==0) 
        echo '<div class="menu" align="center">Qayta ishlangan fayllar mavjud emas.</div>';
		while ($music = mysql_fetch_assoc($q)) {
        $kim = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$music['user_id']."'"), 0);
        echo '
            <div class="menu">
                <img style="float: left; height: 60px; line-height: 17px;" src="'.$music['coverpath'].'"> 
                <div style="min-height: 60px; margin-left: 68px;">
                <a href="'.$music['id'].'_'.clean($music['ijrochi']).'_'.clean($music['nomi']).'.html">'.$music['ijrochi'].' - '.$music['nomi'].'</a> <b>('.size($music['size']).')</b>';
                
            echo '<br /><span style="color: gray;">Sifati:</span> <b>'.$music['sam'].' Hz,'.$music['bitrate'].' Kbps</b><br>';
            echo '<span style="color: gray;">Davomiyligi:</span> <b>'.date('i:s',$music['duration']).' min</b><br>';
            
            echo '
                </div>
            </div>
        ';		}
		if ($jami > $kmess) echo '<div class="topmenu">' . functions::display_pagination('index.php?', $start, $jami, $kmess) . '</div>';
        echo '<div class="menu">- <a href="upload.php"> Fayl yuklash</a> / <a href="import.php">import qilish</a></div> ';
		require('../incfiles/end.php');
	break;

}