<?php
session_start();
include"../../../../inc/conn.php";

// CEK HAK AKSES DISINI

$id  		= str_replace("'","`",(isset($_SESSION['id_admin'])) ? $_SESSION['id_admin'] : "");

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


$cek=mysqli_query($connect,"select * from tb_admin where id_admin='".$id."'");
$rcek=mysqli_fetch_array($cek);



if($rcek['password']!=md5($password_lama)){
	echo"<script>alert('Password lama salah !!!');history.go(-1)</script>";
}elseif(($password_baru1)!=($password_baru2)){
	echo"<script>alert('Password baru harus sama !!!');history.go(-1)</script>";
}else{




$update = mysqli_query($connect,"update tb_admin set password = '".md5($password_baru1)."' where id_admin='".$id."'")or die(mysqli_error($connect));


if($update){
	echo"<script>alert('Password berhasil diperbarui !');history.go(-1)</script>";
	echo"<script>document.location.href='../../gantipassword'</script>";
}else{
	echo"<script>alert('Gagal mengeksekusi perintah ini !');history.go(-1)</script>";
}





}
?>