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


	if(!isset($_SESSION['login_user'])){
		header('location: ../../../login.php'); // Mengarahkan ke Home Page
	}

	if(isset($_SESSION['jabatan']) AND $_SESSION['jabatan'] <> 'TRUE')
	{
		?>
		  <div class="alert alert-danger alert-dismissible" id="succsess-alert">
	        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
	        <h4><i class="icon fa fa-ban"></i> Alert!</h4>
	        Dilarang mengakses file ini.
	      </div>
		<?php
		die();
	}

	if(isset($_GET['mod']) && isset($_GET['act']))
	{
		$mod = $_GET['mod'];
		$act = $_GET['act'];
	}
	else
	{
		$mod = "";
		$act = "";
	}

	if($mod == "jabatan" AND $act == "simpan")
	{
		//variable input
		$nama= anti_inject($_POST['nama']);
		$keterangan= $_POST['keterangan'];
		$status= anti_inject($_POST['status']);
		$petugas= $_SESSION['login_user'];

		mysqli_query($conn,"INSERT INTO `tb_jabatan`(`nama`, `status`, `keterangan`, `petugas`)
										 VALUES ('$nama',
										 		 '$status',
										 		 '$keterangan',
										 		 '$petugas')") or die(mysqli_error());
		log_insert($nama,"tb_jabatan","Menambahakan Data jabatan",$_SESSION['login_user'] );
		flash('example_message', 'Berhasil menambah Data jabatan.' );

		
		header("location: ../../../med.php?mod=jabatan&idmx=".$_GET['idmx']);
	}

	elseif ($mod == "jabatan" AND $act == "edit") 
	{
		//variable input
		$nama= anti_inject($_POST['nama']);
		$keterangan= $_POST['keterangan'];
		$status= anti_inject($_POST['status']);
		$petugas= $_SESSION['login_user'];

		mysqli_query($conn,"UPDATE `tb_jabatan` SET `nama`='$nama',
												 `status`='$status',
												 `keterangan`='$keterangan',
												 `petugas`='$petugas' WHERE `id` = '$_POST[id]'") or die(mysqli_error());
		log_update($nama,"tb_jabatan","Mengubah Data jabatan",$_SESSION['login_user'] );
		flash('example_message', 'Berhasil mengubah Data jabatan.');

		
		header("location: ../../../med.php?mod=jabatan&idmx=".$_GET['idmx']);
	}

	elseif ($mod == "jabatan" AND $act == "hapus") 
	{
		$query = "SELECT * FROM `tb_jabatan` WHERE id = '$_GET[id]'";
		$sql_kul = mysqli_query($conn,$query);	
		$m = mysqli_fetch_assoc($sql_kul);
		log_delete($m['nama'],"tb_jabatan","Menghapus Data jabatan",$_SESSION['login_user'] );
		mysqli_query($conn,"DELETE FROM tb_jabatan WHERE id = '$_GET[id]'") or die(mysqli_error());

		flash('example_message', 'Berhasil menghapus Data jabatan.' );
		
		header("location: ../../../med.php?mod=jabatan&idmx=".$_GET['idmx']);
	}

?>