<?php
/**
 * =====================================================
 * SIMPAS v1.0
 * Modul : Jadwal Absensi
 * File   : edit.php
 * =====================================================
 */

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

include "../../templates/header.php";
include "../../templates/navbar.php";
include "../../templates/sidebar.php";

$id = intval($_GET['id']);

$query = mysqli_query($conn,"
SELECT *
FROM jadwal_absensi
WHERE id_jadwal='$id'
");

$data = mysqli_fetch_assoc($query);

if(!$data){

    echo "<script>
    alert('Data tidak ditemukan');
    window.location='index.php';
    </script>";

    exit;

}
?>

<div class="content-wrapper">

<section class="content-header">

<div class="container-fluid">

<div class="row">

<div class="col-sm-6">

<h1>

<i class="fas fa-edit"></i>

Edit Jadwal Absensi

</h1>

</div>

<div class="col-sm-6 text-right">

<a href="index.php" class="btn btn-secondary">

<i class="fas fa-arrow-left"></i>

Kembali

</a>

</div>

</div>

</div>

</section>

<section class="content">

<div class="container-fluid">

<div class="card">

<div class="card-header bg-primary">

<h3 class="card-title">

Form Edit Jadwal

</h3>

</div>

<div class="card-body">

<form
action="update.php"
method="POST">

<input
type="hidden"
name="id_jadwal"
value="<?= $data['id_jadwal']; ?>">

<div class="form-group">

<label>Hari</label>

<select
name="hari"
class="form-control"
required>

<?php

$hari=[
"Senin",
"Selasa",
"Rabu",
"Kamis",
"Jumat",
"Sabtu"
];

foreach($hari as $h){

?>

<option
value="<?= $h; ?>"
<?= ($data['hari']==$h)?'selected':''; ?>>

<?= $h; ?>

</option>

<?php } ?>

</select>

</div>

<div class="form-group">

<label>Jam Masuk Mulai</label>

<input
type="time"
name="jam_masuk_mulai"
class="form-control"
value="<?= $data['jam_masuk_mulai']; ?>"
required>

</div>

<div class="form-group">

<label>Jam Masuk Selesai</label>

<input
type="time"
name="jam_masuk_selesai"
class="form-control"
value="<?= $data['jam_masuk_selesai']; ?>"
required>

</div>

<div class="form-group">

<label>Jam Pulang Mulai</label>

<input
type="time"
name="jam_pulang_mulai"
class="form-control"
value="<?= $data['jam_pulang_mulai']; ?>"
required>

</div>

<div class="form-group">

<label>Jam Pulang Selesai</label>

<input
type="time"
name="jam_pulang_selesai"
class="form-control"
value="<?= $data['jam_pulang_selesai']; ?>"
required>

</div>

<div class="form-group">

<label>Status</label>

<select
name="aktif"
class="form-control">

<option
value="Y"
<?= ($data['aktif']=="Y")?'selected':'';?>>

Aktif

</option>

<option
value="N"
<?= ($data['aktif']=="N")?'selected':'';?>>

Nonaktif

</option>

</select>

</div>

<hr>
<button
type="submit"
class="btn btn-primary">

<i class="fas fa-save"></i>

Update

</button>

<a
href="index.php"
class="btn btn-secondary">

Batal

</a>

</form>

</div>

</div>

</div>

</section>

</div>

<?php
include "../../templates/footer.php";
?>