<?php

include "../../config/koneksi.php";
include "../../config/session.php";

$id = intval($_POST['id_jadwal']);

$hari = mysqli_real_escape_string($conn, $_POST['hari']);

$jam_masuk_mulai = mysqli_real_escape_string($conn, $_POST['jam_masuk_mulai']);

$jam_masuk_selesai = mysqli_real_escape_string($conn, $_POST['jam_masuk_selesai']);

$jam_pulang_mulai = mysqli_real_escape_string($conn, $_POST['jam_pulang_mulai']);

$jam_pulang_selesai = mysqli_real_escape_string($conn, $_POST['jam_pulang_selesai']);

$aktif = mysqli_real_escape_string($conn, $_POST['aktif']);

$cek = mysqli_query($conn,"
SELECT id_jadwal
FROM jadwal_absensi
WHERE hari='$hari'
AND id_jadwal<>'$id'
");

if(mysqli_num_rows($cek)>0){

    echo "<script>
    alert('Hari sudah digunakan.');
    history.back();
    </script>";

    exit;

}

$update = mysqli_query($conn,"
UPDATE jadwal_absensi SET

hari='$hari',

jam_masuk_mulai='$jam_masuk_mulai',

jam_masuk_selesai='$jam_masuk_selesai',

jam_pulang_mulai='$jam_pulang_mulai',

jam_pulang_selesai='$jam_pulang_selesai',

aktif='$aktif'

WHERE id_jadwal='$id'
");

if(!$update){

    die(mysqli_error($conn));

}

header("Location:index.php");

exit;

?>