<?php
/**
 * =====================================================
 * SIMPAS v1.0
 * Modul : Data Absensi
 * File   : index.php
 * =====================================================
 */

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

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

$query = mysqli_query($conn,"
SELECT
a.*,
s.nama_siswa,
s.nis,
k.nama_kelas

FROM absensi a

LEFT JOIN siswa s
ON a.id_siswa=s.id_siswa

LEFT JOIN kelas k
ON s.id_kelas=k.id_kelas

ORDER BY
a.tanggal DESC,
a.jam_masuk DESC
");

?>

<div class="content-wrapper">

<section class="content-header">

<div class="container-fluid">

<div class="row mb-2">

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

<h1>

<i class="fas fa-clipboard-check"></i>

Data Absensi
<a href="generate_alfa.php"
class="btn btn-danger"
onclick="return confirm('Generate Alfa untuk siswa yang belum absen hari ini?')">

<i class="fas fa-user-times"></i>

Generate Alfa

</a>

</h1>

</div>

</div>

</div>

</section>

<section class="content">

<div class="container-fluid">

<div class="card shadow">

<div class="card-header">

<h3 class="card-title">

Daftar Absensi Siswa

</h3>

</div>

<div class="card-body">

<div class="table-responsive">

<table
id="tabelAbsensi"
class="table table-bordered table-striped table-hover">

<thead class="bg-primary">

<tr>

<th width="50">

No

</th>

<th>

Tanggal

</th>

<th>

NIS

</th>

<th>

Nama

</th>

<th>

Kelas

</th>

<th>

Masuk

</th>

<th>

Pulang

</th>

<th>

Status

</th>

</tr>

</thead>

<tbody>

<?php

$no=1;

while($row=mysqli_fetch_assoc($query)):

?>

<tr>

<td class="text-center">

<?= $no++; ?>

</td>

<td>

<?= date('d-m-Y',strtotime($row['tanggal'])); ?>

</td>

<td>

<?= htmlspecialchars($row['nis']); ?>

</td>

<td>

<strong>

<?= htmlspecialchars($row['nama_siswa']); ?>

</strong>

</td>

<td>

<?= htmlspecialchars($row['nama_kelas']); ?>

</td>

<td class="text-center">

<?= $row['jam_masuk']; ?>

</td>

<td class="text-center">
    <?= empty($row['jam_pulang']) ? '-' : $row['jam_pulang']; ?>

</td>

<td class="text-center">

<?php

if($row['status']=="Hadir"){

    echo '<span class="badge badge-success">Hadir</span>';

}elseif($row['status']=="Terlambat"){

    echo '<span class="badge badge-warning">Terlambat</span>';

}elseif($row['status']=="Izin"){

    echo '<span class="badge badge-info">Izin</span>';

}elseif($row['status']=="Sakit"){

    echo '<span class="badge badge-primary">Sakit</span>';

}else{

    echo '<span class="badge badge-danger">Alpa</span>';

}

?>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</div>

</div>

</section>

</div>

<script>

$(document).ready(function(){

    $('#tabelAbsensi').DataTable({

        responsive:true,

        autoWidth:false,

        pageLength:10,

        order:[[1,'desc']],

        language:{

            search:"Cari :",

            lengthMenu:"Tampilkan _MENU_ data",

            zeroRecords:"Data tidak ditemukan",

            info:"Menampilkan _START_ - _END_ dari _TOTAL_ data",

            infoEmpty:"Belum ada data",

            infoFiltered:"(difilter dari _MAX_ data)",

            paginate:{

                first:"Awal",

                last:"Akhir",

                next:"›",

                previous:"‹"

            }

        }

    });

});

</script>

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