<?php
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");
include("../../../deppo/tools/script/SimpleImage.php");
function irep($metin){
	$metin = str_replace("'", "", $metin);
	$metin = str_replace("×", "x", $metin);
	return $metin;
}
if($_GET["ne"]=="sayfa" or $_GET["ne"]=="haber" or $_GET["ne"]=="msayfa" or $_GET["ne"]=="kayit"){
	$sql=mysqli_query($conn, "select * from ".$_SESSION['lang']." where id=".$_GET["id"].""); $rs=mysqli_fetch_assoc($sql);
	$risim=strtolower(cevir1(irep($rs["t1"])));
}else{
	$risim=strtolower(cevir1(irep($_GET["ne"])));
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<link href="//fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700" rel='stylesheet' />
	<link href="../../assets/ajax-upload/assets/css/style.css" rel="stylesheet" />
<style>
ul {padding:5px 0px}
ul li {list-style: none;padding: 5px; background: aliceblue;}
ul li canvas {width:34px; height:34px;}
ul li div input {margin-top: 10px !important; margin-left: -31px !important;}
ul li div {float: left;}
ul li p i {display: block;font-size: 11px;}
</style>
</head>
<body>
<?php if($_GET["ne"]=="sayfa" or $_GET["ne"]=="haber" or $_GET["ne"]=="msayfa" or $_GET["ne"]=="kayit"){?>
	<ol class="breadcrumb">
	  <li><a href="#"><?php echo $rs["t1"]?></a></li>
<?php if($_GET["ne"]=="kayit"){?>
	  <li class="active"><?php echo $rs["t4"]?></li>
<?php }?>
		<li style="float: right;"><a href="../../modules/upload/upload_image.php?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"]; ?>&s4=<?php echo $_GET["s4"]; ?>" target="modal"><?php echo ctranslate("Standart Upload")?></a></li>
	</ol>
<?php }?>
	<form id="upload" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"]; ?>&s4=<?php echo $_GET["s4"]; ?>&durum=yukle" enctype="multipart/form-data">
		<div id="drop" style="padding: 100px 0px;">
			<input type="hidden" name="i1" value="<?php echo $risim;?>">
			<?php if($a5<>0){?>
				<input type="checkbox" name="resize" value="ON" title="Boyutlandır" checked id="resize" class="mini-switch">
				<label for="resize" style="position: absolute; top:30px; right:30px;"></label>
			<?php }?>
			<br><i class="fa fa-cloud-upload" style="font-size:50px;"></i><br><span style="font-size:16px;">Yüklenecek Dosyaları <a style="font-color:#000;">Seçin</a></span><br><span style="">isterseniz resimleri sürükleyip bırakabilirsiniz</span>
			<input type="file" name="dosya" id="multiple" multiple />
			<input type="text" class="form-control" name="risim" value="<?php echo $risim;?>">
		</div>
		<ul></ul>
	</form>
	<!-- JavaScript Includes --> 
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
	<script src="../../assets/ajax-upload/assets/js/jquery.knob.js"></script>
	<!-- jQuery File Upload Dependencies --> 
	<script src="../../assets/ajax-upload/assets/js/jquery.ui.widget.js"></script>
	<script src="../../assets/ajax-upload/assets/js/jquery.iframe-transport.js"></script> 
	<script src="../../assets/ajax-upload/assets/js/jquery.fileupload.js"></script> 
	<!-- Our main JS file --> 
	<script>
jQuery(function(){
    var ul = jQuery('#upload ul');
    jQuery('#drop a').click(function(){
        jQuery('#multiple').click();
    });
    jQuery('#upload').fileupload({
        dropZone: jQuery('#drop'),
        add: function (e, data) {
            var tpl = jQuery('<li class="working"><input type="text" value="0" data-width="48" data-height="48"'+
                ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
            tpl.find('p').text(data.files[0].name)
                         .append('<i>' + formatFileSize(data.files[0].size) + '</i>');
            data.context = tpl.appendTo(ul);
            tpl.find('input').knob();
            tpl.find('span').click(function(){
                if(tpl.hasClass('working')){
                    jqXHR.abort();
                }
                tpl.fadeOut(function(){
                    tpl.remove();
                });
            });
            var jqXHR = data.submit();
        },
        progress: function(e, data){
            var progress = parseInt(data.loaded / data.total * 100, 10);
            data.context.find('input').val(progress).change();
            if(progress == 100){
                data.context.removeClass('working');
            }
        },
        fail:function(e, data){
            data.context.addClass('error');
        }
    });
    jQuery(document).on('drop dragover', function (e) {
        e.preventDefault();
    });
    function formatFileSize(bytes) {
        if (typeof bytes !== 'number') {
            return '';
        }
        if (bytes >= 1000000000) {
            return (bytes / 1000000000).toFixed(2) + ' GB';
        }
        if (bytes >= 1000000) {
            return (bytes / 1000000).toFixed(2) + ' MB';
        }
        return (bytes / 1000).toFixed(2) + ' KB';
    }
});
</script>
</body>
</html>
<?php
if($_GET["durum"]=="yukle"){
	if(!empty($_GET["id"])){$ID=$_GET["id"];}else{$ID="0";}
	if(!empty($_GET["s4"])){$s4=$_GET["s4"];}else{$s4=0;}
	if(!empty($_SESSION["user_id"])){$s19=$_SESSION["user_id"];}else{$s19=0;}
	$allowed= array('png', 'jpg', 'jpeg', 'gif');
	$uzanti = explode('.',$_FILES['dosya']['name']);
	$isim   = $_FILES['dosya']['name'];
	$rand  = substr(md5(uniqid(rand())),0,10);
	if($_POST["i1"]<>"") { $i1isim=substr(cevir($_POST["i1"]),0,30); }
	$yeni  = "".$i1isim."-".$rand.".".$uzanti[count($uzanti)-1]."";
	$sqlk=mysqli_query($conn, "select * from medya where ne='resim' and t3='".$_GET['ne']."' and s1='".$_GET['id']."'"); $rski=mysqli_fetch_assoc($sqlk);
	if(mysqli_num_rows($sqlk)>0){$ks2="0";}else{$ks2="1";}
	
	if(isset($_FILES['dosya']) && $_FILES['dosya']['error'] == 0){
		$extension = pathinfo($_FILES['dosya']['name'], PATHINFO_EXTENSION);
		if(!in_array(strtolower($extension), $allowed)){
			echo '{"status":"error"}';
			exit;
		}
		if(move_uploaded_file($_FILES['dosya']['tmp_name'], "../../../deppo/image/".$yeni."")){
//-------------------------------------------------------------
			if ($_POST["resize"]<>""){
				$image = new SimpleImage();
				$image->load("../../../deppo/image/".$yeni."");
				$image->resizeToWidth("".$a9."");
				$image->save("../../../deppo/image/".$yeni."");
				$image->resizeToWidth("".$a10."");
				$image->save("../../../deppo/image/k_".$yeni."");
			}else{
				$image = new SimpleImage();
				$image->load("../../../deppo/image/".$yeni."");
				$image->resizeToWidth("".$a10."");
				$image->save("../../../deppo/image/k_".$yeni."");
			}
			if ($_POST["resize"]<>"" and $e1==1){
				$damga = imagecreatefrompng("../../../deppo/image/".$t47."");
				$oyeni = imagecreatefromjpeg("../../../deppo/image/".$yeni."");
				$msag = 10;
				$malt = 10;
				$sx = imagesx($damga);
				$sy = imagesy($damga);
				imagecopy($oyeni, $damga, imagesx($oyeni) - $sx - $msag, imagesy($oyeni) - $sy - $malt, 0, 0, imagesx($damga), imagesy($damga));
				$wyeni = "../../../deppo/image/".$yeni."";
				imagepng($oyeni, $wyeni);
				imagedestroy($oyeni);
			}
//-------------------------------------------------------------
			echo '{"status":"success"}';

			if ($module["webp"] == 1) {
				towebp("k_{$yeni}", "../../../deppo/image/");
				$yeni = towebp($yeni, "../../../deppo/image/");
			}

			$conn->query("insert INTO medya (ne,s1,s2,s3,s4,t1,t3,t6,t2,n3,s13,s19) VALUES ('resim', '".$ID."', '".$ks2."', '0', '".$s4."', '".addslashes($yeni)."', '".$_GET['ne']."', '".$_SESSION["lang"]."', '".$_POST['i1']."', '".$_POST['ia1']."','1','".$s19."')");
			exit;
		}
	}
	echo '{"status":"error"}';
	exit;	
}

?>