<?php
	
	
	include "koneksi.php";
	$id=mysqli_real_escape_string($conn,$_GET["id"]);
    echo "ini".$id;	
    $tanggal_disetujui = date('d / m / yy');
						
		$d="SELECT * FROM data_purchasing_requisition WHERE id='$id'";
       	$resi=mysqli_query($conn,$d);
        $data = mysqli_fetch_assoc($resi);
        $nik = $data["user_request"];
        echo "nik =".$nik;

        $j="SELECT * FROM user WHERE nik_data_karyawan =".$nik;
       	$resd=mysqli_query($conn,$j);
        $datad = mysqli_fetch_assoc($resd);
        $level = $datad["level"];
        echo "level =".$level;

    if($level == 4)
	{
		//disetujui = 2, ditolak = 1
		$q = "UPDATE data_purchasing_requisition SET status_spv='2', status_operasional='2',tgl_disetujui_operasional='$tanggal_disetujui' WHERE id=".$id;
		$result = mysqli_query($conn, $q);

		if($result)
		{
			echo "berhasil";
			header("location:persetujuanPrOperasional.php?p=1");
		}
		else
		{
			echo "gagal";
			header("location:persetujuanPrOperasional.php?p=3");
		}
	}
	if($level == 7)
	{
		//disetujui = 2, ditolak = 1
		$q = "UPDATE data_purchasing_requisition SET status_spv='2', status_operasional='2',tgl_disetujui_operasional='$tanggal_disetujui' WHERE id=".$id;
		$result = mysqli_query($conn, $q);

		if($result)
		{
			echo "berhasil";
			header("location:persetujuanPrOperasional.php?p=1");
		}
		else
		{
			echo "gagal";
			header("location:persetujuanPrOperasional.php?p=3");
		}
	}
	if($level == 5)
	{
		//disetujui = 2, ditolak = 1
		$q = "UPDATE data_purchasing_requisition SET status_spv='2', status_operasional='2',tgl_disetujui_operasional='$tanggal_disetujui' WHERE id=".$id;
		$result = mysqli_query($conn, $q);

		if($result)
		{
			echo "berhasil";
			header("location:persetujuanPrOperasional.php?p=1");
		}
		else
		{
			echo "gagal";
			header("location:persetujuanPrOperasional.php?p=3");
		}
	}
	if($level >= 1000)
	{
		//disetujui = 2, ditolak = 1
		$q = "UPDATE data_purchasing_requisition SET status_spv='2', status_operasional='2',tgl_disetujui_operasional='$tanggal_disetujui' WHERE id=".$id;
		$result = mysqli_query($conn, $q);

		if($result)
		{
			echo "berhasil";
			header("location:persetujuanPrOperasional.php?p=1");
		}
		else
		{
			echo "gagal";
			header("location:persetujuanPrOperasional.php?p=3");
		}
	}
	else
	{
		//disetujui = 2, ditolak = 1
		$q = "UPDATE data_purchasing_requisition SET status_operasional='2',tgl_disetujui_operasional='$tanggal_disetujui' WHERE id=".$id;
		$result = mysqli_query($conn, $q);

		if($result)
		{
			echo "berhasil";
			header("location:persetujuanPrOperasional.php?p=1");
		}
	    else
	    {
		echo "gagal";
		header("location:persetujuanPrOperasional.php?p=3");
	    }
	}		
	
	
		

?>