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

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

	if(isset($_GET['mod']) && isset($_GET['act']))
	{
		$mod = $_GET['mod'];
		$act = $_GET['act'];
	}
	else
	{
		$mod = "";
		$act = "";
	}
    $linkaksi="med.php?mod=setting_absensi&idmx=69";
	if ($mod == "setting_absensi" AND $act == "simpan") 
	{
		$tempat= $_POST['tempat'];
		$jam_masuk= $_POST['jam_masuk'];
		$jam_pulang= $_POST['jam_pulang'];
		$jarak= anti_inject($_POST['jarak']);
		$latitude= $_POST['latitude'];
		$longitude= $_POST['longitude'];
		
		mysqli_query($conn,"INSERT INTO `tb_setting_absensi`(`tempat`, `jam_masuk`, `jam_pulang`, `jarak`, `latitude`, `longitude`, `petugas`) VALUES ('$tempat','$jam_masuk','$jam_pulang','$jarak','$latitude','$longitude','$_SESSION[login_user]')") or die(mysqli_error());

		flash('example_message', 'Berhasil mengubah Data Setting Absensi.');
        log_update($tempat,"setting_absensi","Menambahakan Data Setting Absensi",$_SESSION['login_user'] );
		header("location: ../../".$linkaksi);
	}elseif ($mod == "setting_absensi" AND $act == "edit") 
	{
		$tempat= $_POST['tempat'];
		$jam_masuk= $_POST['jam_masuk'];
		$jam_pulang= $_POST['jam_pulang'];
		$jarak= anti_inject($_POST['jarak']);
		$latitude= $_POST['latitude'];
		$longitude= $_POST['longitude'];
		
		mysqli_query($conn,"UPDATE `tb_setting_absensi` SET `tempat` = '$tempat',`jam_masuk`='$jam_masuk',`jam_pulang`='$jam_pulang',`jarak`='$jarak',`latitude`='$latitude',`longitude`='$longitude' WHERE `id`= '$_POST[id]'") or die(mysqli_error());

		flash('example_message', 'Berhasil mengubah Data Setting Absensi.');
        log_update($tempat,"setting_absensi","Mengubah Data Setting Absensi",$_SESSION['login_user'] );
		header("location: ../../".$linkaksi);
		// code...
	}

	elseif ($mod == "setting_absensi" AND $act == "hapus") 
	{
        $sql = "select * from tb_setting_absensi where id = '$_GET[id]'";
		$result = mysqli_query($conn, $sql);
		$row = mysqli_fetch_assoc($result);
        
        log_delete($row['tempat'],"setting_absensi","Menghapus Data Setting Absensi",$_SESSION['login_user'] );
		mysqli_query($conn,"DELETE FROM tb_setting_absensi WHERE id = '$_GET[id]'") or die(mysqli_error());
		flash('example_message', 'Berhasil menghapus Data Setting Absensi.' );
		header('Location: ' . $_SERVER["HTTP_REFERER"] );
	}

?>