<?php
session_start();
//error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
include"../../../../inc/conn.php";

// CEK HAK AKSES DISINI

$id_unit	= str_replace("'","`",(isset($_POST['id_unit'])) ? $_POST['id_unit'] : "");

$q=mysqli_query($connect,"select * from tb_unit where id_unit='".$id_unit."'");
$r=mysqli_fetch_array($q);

$target_dir_foto    = "../../../../assets/banner/";
$target_file_foto   = $target_dir_foto . basename($_FILES["foto"]["name"]);
$imageFileTypeFoto  = pathinfo($target_file_foto,PATHINFO_EXTENSION);

if($r['banner']==''){
    $namafile 			= "g-".date('Ymds')."-".md5($id_unit).".".$imageFileTypeFoto;
}else{
    $namafile 			= $r['banner'];
}

if(($_FILES['foto']['name']!="")&&($imageFileTypeFoto!="jpg")){
    echo"<script>alert('Please select jpg file !');history.go(-1)</script>";
}elseif(($_FILES['foto']['name']!="")&&($_FILES['foto']['size']>400000)){
    echo"<script>alert('Max size 400Kb !');history.go(-1)</script>";
}else{

	$update = mysqli_query($connect,"update tb_unit set 

		banner 				= '".$namafile."'

	where id_unit='$id_unit'")or die(mysqli_error($connect));


	if($update){
		move_uploaded_file($_FILES['foto']['tmp_name'],"../../../../assets/banner/$namafile");
		echo"<script>alert('Banner berhasil disimpan !');</script>";
		echo"<script>document.location.href='datamodul'</script>";
	}else{
		echo"<script>alert('Gagal mengeksekusi perintah ini !');history.go(-1)</script>";
	}


}
?>