<?php 


/* ---------- 


Avtor: Nizomiddin

e-mail: programm011@gmail.com
telegram: https://t.me/programm011


--------------- */


define('_IN_JOHNCMS', 1);
$textl = 'Musiqa joylash';
require_once ('../incfiles/core.php');
require_once ('../incfiles/head.php');
include 'function.php';
    echo '<div class="phdr">Musiqa joylash</div>';
	if (!$user_id) {echo '<div class="rmenu">Faqat sayt foydalanuvchilar fayl yuklashi mumkin!</div>';
	require('../incfiles/end.php');	exit();}
	if(isset($_POST['submit']))
		{ $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp);
	if(empty($_POST['ijrochi']) || mb_strlen($_POST['ijrochi']) > 60) {
		echo '<div class="rmenu"> Ijrochi kiritilmadi, yoki 60 tadan ko`p belgi ishlatdingiz!</div> 
		<div class="menu"><a href="upload.php">Ortga</a></div>';
		require('../incfiles/end.php'); 
		exit();}
		if(empty($_POST['albom']) || mb_strlen($_POST['albom']) > 30) {
			echo '<div class="rmenu"> Albom kiritilmadi, yoki 30 tadan ko`p belgi ishlatdingiz!</div>
			<div class="menu"><a href="upload.php">Ortga</a></div>'; 
			require('../incfiles/end.php');  exit();}	
			if(empty($_POST['izoh']) || mb_strlen($_POST['izoh']) > 100) { 
			echo '<div class="rmenu"> Izoh kiritilmadi, yoki 100 tadan ko`p belgi ishlatdingiz!</div>
			<div class="menu"><a href="upload.php">Ortga</a></div>'; 
			require('../incfiles/end.php');  exit();}	
			if(empty($_POST['nomi']) || mb_strlen($_POST['nomi']) > 60) { 
			echo '<div class="rmenu"> Nomi kiritilmadi, yoki 60 tadan ko`p belgi ishlatdingiz!</div> 
			<div class="menu"><a href="upload.php">Ortga</a></div>';
			require('../incfiles/end.php');  exit();}
	if (($_FILES["file"]["type"] == "audio/mp3")) {  
	if ($_FILES["file"]["error"] > 0) 
		echo "Xato! KOD: " . $_FILES["file"]["error"] . "<br>"; else {
			if(($_FILES["file"]["size"] / (1024*1024)) < 12){ 
			$file_path = 'files/'.clean($_POST['ijrochi']).'_'.clean($_POST['nomi']).'.mp3'; 
			$file_path2 = 'files/'.clean($_POST['ijrochi']).'_'.clean($_POST['nomi']).'_cache.mp3';	  
			if (file_exists($file_path)) echo $file_path . " bu fayl avvaldan mavjud. ";  else {
				move_uploaded_file($_FILES["file"]["tmp_name"],$file_path); copy($file_path,$file_path2);  
				$sfile = $file_path2;  if(!empty($_FILES["covermusic"]["name"])){ 
				if(($_FILES["covermusic"]["size"] / 1024) < 1024 || $_FILES["covermusic"]["type"] == "audio/mp3"){
					$covermusic = 'files/'.clean($_POST['ijrochi']).'_'.clean($_POST['nomi']).'_covermusicfile.mp3';
	   move_uploaded_file($_FILES["covermusic"]["tmp_name"],$covermusic);
	   require_once('getid3/getid3.php'); 
	   $getID3 = new getID3; 
	   $znu_test = $getID3->analyze($file_path);  
	   $znu_test2 = $getID3->analyze($covermusic); 
	   $bit = ceil($znu_test['bitrate']/1000);  
	   $bit2 = ceil($znu_test2['bitrate']/1000); 
	   if($bit==$bit2 + 1 || $bit==$bit2 - 1 || $bit==$bit2 || $bit==$bit2 - 2 || $bit==$bit2 + 2 || $bit==$bit2 + 3 || $bit==$bit2 - 3 || $bit==$bit2 + 4 || $bit==$bit2 - 4){
		 

		   if($_POST['cover'] == 1){    $FilenamesIn[] = $covermusic;    $FilenamesIn[] = $file_path;  $FilenamesIn[] = $covermusic;  } 
		   if($_POST['cover'] == 2){    $FilenamesIn[] = array(''.$covermusic.'',    0,  10);    $FilenamesIn[] = $file_path; } 
		   if($_POST['cover'] == 3){    $FilenamesIn[] = array(''.$covermusic.'',     0, -10);    $FilenamesIn[] = $file_path; } 
	
		   if (CombineMultipleMP3sTo($sfile, $FilenamesIn)) {  
		   unlink($file_path); 
		   rename($sfile,$file_path); 
		   unlink($file_path2); 
		   unlink($covermusic);  }else { 
		   echo '<div class="menu"> <font color="red">Xatolik yuz berdi!</font></div><div class="menu"><a href="index.php">Ortga</a></div>'; require('../incfiles/end.php'); exit(); }     }else { unlink($file_path); unlink($file_path2); unlink($covermusic); echo '<div class="menu"> <font color="red">Yuklangan mp3 fayl va jingle  sifati bir xil emas! Tekshirib qaytadan urinib ko`ring!</font></div><div class="menu"><a href="index.php">Ortga</a></div>'; require('../incfiles/end.php'); exit(); }  }   else { echo '<div class="menu"> <font color="red">Xato! Yuklagan cover musiqangiz og`irligi 1MB dan kam va mp3 formatda bo`lishi kerak. Faylingizni tekshirib qaytadan urinib ko`ring.</font></div><div class="menu"><a href="index.php">Ortga</a></div>'; require('../incfiles/end.php'); exit(); }     }
	  require 'MP3Tool.class.php';  $mp3 = new MP3Tool();if(($_FILES["coverfile"]["size"] / 1024) < 100 || $_FILES["coverfile"]["type"] == "image/jpg"){   $cover = 'cover_images/'.clean($_POST['ijrochi']).'_'.clean($_POST['nomi']).'_coverfile.jpg';   move_uploaded_file($_FILES["coverfile"]["tmp_name"],$cover); }    else {echo '<div class="menu"> <font color="red">Xato! Yuklagan cover rasmingiz og`irligi 100kb dan kam va jpg formatda bo`lishi kerak. Rasmni tekshirib qaytadan urinib ko`ring.</font></div><div class="menu"><a href="index.php">Ortga</a></div>'; require('../incfiles/end.php'); exit(); }      $tags = array('album' => $_POST['albom'],'comment' => $_POST['izoh'],'artist' => $_POST['ijrochi'],  'title' => $_POST['nomi']);      $mp3->Write($file_path, $tags,$cover); $info = $mp3->GetMp3Info($file_path); $bitrate = ceil($info['bitrate']/1000); $duration = $info['duration']; $sam = $info['samplerate']; $albom = $info['album']; $izoh = $info['comment'];  $file_size = filesize($file_path); if(mysql_query("INSERT INTO `znu_music` SET  `time` = '".time()."',  `ijrochi` = '".mysql_real_escape_string($_POST['ijrochi'])."', `nomi` = '".mysql_real_escape_string($_POST['nomi'])."',  `albom` = '".mysql_real_escape_string($albom)."', `izoh` = '".mysql_real_escape_string($izoh)."',`path` = '".$file_path."', `coverpath` = '".$cover."', `bitrate` = '".$bitrate."', `sam` = '".$sam."', `duration` = '".$duration."',  `user_id` = '".$user_id."', `size` = '".$file_size."';"))  { echo '<div class="menu"> <font color="green">Fayl yuklandi! Faylingiz 30 daqiqadan keyin o`chadi.</font></div><div class="menu"><a href="index.php">Ortga</a></div>'; require('../incfiles/end.php'); exit(); } else {unlink($file_path);  unlink($cover);  echo '<div class="rmenu">Fayl yuklanmadi! :( Xatolik haqida sayt ma`muriyatiga xabar bering!</div> <div class="menu"><a href="upload.php">Qaytadan</a></div>'; exit();} }}else echo '<div class="rmenu">Yuklangan fayl maksimal hajmdan oshib ketdi!</div>'; } } else echo '<div class="rmenu">Faylni yuklashda xatolik yuz berdi! :(</div>';} // end if 
		 else {	
                 echo '<div class="menu">
				 <form method="post"  enctype="multipart/form-data">
                 <b>Ijrochi: </b> (Maks: 60 belgi.)<br /><input type="text" name="ijrochi"  placeholder="Tom Boxer"/><br />
                 <b>Nomi:</b> (Maks: 60 belgi.)<br /><input type="text" name="nomi"  placeholder="Give Me A Kiss [site.net]"/><br />
                 <b>Albom:</b> (Maks: 30 belgi.)<br /><input type="text" name="albom"  placeholder="Site.Net"/><br />
                 <b>Izoh:</b> (Maks: 100 belgi.)<br /><input type="text" name="izoh"  placeholder="Mening super saytim!"/><br />
                 <b>Cover musiqa(Jingle)tanlang:</b> (Ruhsat etilgan maksimal hajmi: 1MB.)<br /><input name="covermusic" type="file"/> 
                 <select name="cover">
                   <option value="1">Boshiga va oxiriga</option>
                   <option value="2">Boshiga </option>
                   <option value="3">Oxiriga</option>
                 </select>
                 <br>
                 <b>Cover tanlang:</b> (Rasm faqat jpg formatda va 100kb dan oshmasligi kerak.)<br /><input name="coverfile" type="file"/><br>
                 <b>Faylni tanlang:</b> (Ruhsat etilgan maksimal hajm: 12 mb.)<br /><input name="file" type="file" id="file"  /><br>
                 <input type="submit" name="submit" value="Yukla!" />
		         </form></div>';
		      }
 
    
 require('../incfiles/end.php');
 //auto_clean_cache(); 

?>