<?php 
include '../koneksi.php';
$id  = $_POST['id'];
$nama  = $_POST['nama'];
$nip = $_POST['nip'];
$username = $_POST['username'];
$pwd = $_POST['password'];
$password = md5($_POST['password']);

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

if($pwd=="" && $filename==""){
	mysqli_query($koneksi, "update guru set guru_nama='$nama', guru_username='$username', guru_nip='$nip' where guru_id='$id'");
	header("location:guru.php");
}elseif($pwd==""){
	if(!in_array($ext,$allowed) ) {
		header("location:guru.php?alert=gagal");
	}else{
		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/guru/'.$rand.'_'.$filename);
		$x = $rand.'_'.$filename;
		mysqli_query($koneksi, "update guru set guru_nama='$nama', guru_username='$username', guru_foto='$x', guru_nip='$nip' where guru_id='$id'");		
		header("location:guru.php?alert=berhasil");
	}
}elseif($filename==""){
	mysqli_query($koneksi, "update guru set guru_nama='$nama', guru_username='$username', guru_password='$password', guru_nip='$nip' where guru_id='$id'");
	header("location:guru.php");
}else{
	if(!in_array($ext,$allowed) ) {
		header("location:guru.php?alert=gagal");
	}else{
		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/guru/'.$rand.'_'.$filename);
		$x = $rand.'_'.$filename;
		mysqli_query($koneksi, "update guru set guru_nama='$nama', guru_username='$username', guru_password='$password', guru_foto='$x', guru_nip='$nip' where guru_id='$id'");		
		header("location:guru.php?alert=berhasil");
	}
}

