<?php 
include '../koneksi.php';
$id     = $_POST['id'];
$nama   = $_POST['nama'];
$alamat = $_POST['alamat'];
$jabatan= $_POST['jabatan'];
$nip    = $_POST['nip'];
$hp     = $_POST['hp'];
$kdm    = $_POST['kdm'];
$acc  = $_POST['acc'];
$tanggal= $_POST['tanggal'];
$status = $_POST['status'];
$k_latitude= $_POST['k_latitude'];
$k_longitude= $_POST['k_longitude'];
$foto   = $_POST['foto'];

$foto_lama = $_POST['foto_lama'];

$jam= date('d-m-Y  H:i:s'); //kombinasi jam dan tanggal
$cek='';

mysqli_query($koneksi, "update karyawan set nama='$nama',alamat='$alamat',jabatan='$jabatan',jab='$kdm',acc='$acc',jam_input='(now())' where id='$id'");
mysqli_query($koneksi, "update karyawan_iden set nip='$nip',hp='$hp',tanggal='$tanggal',status='$status',k_latitude='$k_latitude',k_longitude='$k_longitude',jam='(now())' where id='$id'");

// cek gambar
$rand = rand();
$allowed =  array('png','bmp','jpg','jpeg');
$filename = basename($_FILES['foto']['name']);
$ext = pathinfo($filename, PATHINFO_EXTENSION);

    $xfoto_lama = "../gambar/karyawan/".$foto_lama ;
    
    if (file_exists($xfoto_lama)) { ;
        unlink($xfoto_lama) ;
        }     

if($filename==""){


}else{
	if(!in_array($ext,$allowed) ) {
		header("location:b_karyawan_top?alert=gagal");
	}else{
	    if($ukuran < 5000000){
    		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/karyawan/'.$filename);
    		$x = $filename;
    		mysqli_query($koneksi, "update karyawan_iden set foto='$x' where id='$id'");
    		header("location:b_karyawan_top?alert=berhasil");
	    }else{
	        	header("location:b_karyawan_top?alert=gagal"); 
	    }
	}
}

header("location:b_karyawan_top.php");