148 lines
7.4 KiB
PHP
148 lines
7.4 KiB
PHP
<?php
|
|
// templates/attendance.php
|
|
|
|
// Handle attendance form submission
|
|
$feedback = handle_absensi_action();
|
|
|
|
// Get all classes for the selection dropdown
|
|
$all_kelas = get_all_kelas();
|
|
|
|
// Get filter values from GET request
|
|
$selected_kelas_id = $_GET['kelas_id'] ?? null;
|
|
$selected_tanggal = $_GET['tanggal'] ?? date('Y-m-d'); // Default to today
|
|
|
|
$murid_list = [];
|
|
$jadwal_hari_ini = [];
|
|
$absensi_data = [];
|
|
|
|
// Indonesian day name mapping
|
|
$day_map = [
|
|
'Sunday' => 'Minggu',
|
|
'Monday' => 'Senin',
|
|
'Tuesday' => 'Selasa',
|
|
'Wednesday' => 'Rabu',
|
|
'Thursday' => 'Kamis',
|
|
'Friday' => 'Jumat',
|
|
'Saturday' => 'Sabtu'
|
|
];
|
|
$day_of_week = date('l', strtotime($selected_tanggal));
|
|
$hari_indonesia = $day_map[$day_of_week];
|
|
|
|
if ($selected_kelas_id) {
|
|
$murid_list = get_murid_by_kelas($selected_kelas_id);
|
|
$jadwal_hari_ini = get_jadwal_by_kelas_and_hari($selected_kelas_id, $hari_indonesia);
|
|
$absensi_data = get_absensi($selected_kelas_id, $selected_tanggal);
|
|
}
|
|
|
|
$statuses = ['Hadir', 'Izin', 'Sakit', 'Alpa'];
|
|
|
|
?>
|
|
|
|
<main class="main-content">
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
|
<h1 class="h2">Manajemen Absensi</h1>
|
|
</div>
|
|
|
|
<?php if (isset($feedback['message'])): ?>
|
|
<div class="alert alert-<?php echo $feedback['success'] ? 'success' : 'danger'; ?>">
|
|
<?php echo htmlspecialchars($feedback['message']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- Filter Form -->
|
|
<div class="card mb-4">
|
|
<div class="card-header">
|
|
<h5 class="card-title">Pilih Kelas dan Tanggal</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="index.php" method="GET">
|
|
<input type="hidden" name="page" value="attendance">
|
|
<div class="row">
|
|
<div class="col-md-5 mb-3">
|
|
<label for="kelas_id" class="form-label">Kelas</label>
|
|
<select class="form-select" id="kelas_id" name="kelas_id" required>
|
|
<option value="">-- Pilih Kelas --</option>
|
|
<?php foreach ($all_kelas as $kelas): ?>
|
|
<option value="<?php echo $kelas['id']; ?>" <?php echo ($selected_kelas_id == $kelas['id']) ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($kelas['nama_kelas']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-5 mb-3">
|
|
<label for="tanggal" class="form-label">Tanggal</label>
|
|
<input type="date" class="form-control" id="tanggal" name="tanggal" value="<?php echo htmlspecialchars($selected_tanggal); ?>" required>
|
|
</div>
|
|
<div class="col-md-2 d-flex align-items-end mb-3">
|
|
<button type="submit" class="btn btn-primary w-100">Tampilkan</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($selected_kelas_id): ?>
|
|
<?php if (empty($murid_list) || empty($jadwal_hari_ini)): ?>
|
|
<div class="alert alert-warning">
|
|
<?php if (empty($murid_list)): ?>
|
|
Tidak ada murid di kelas ini.
|
|
<?php else: ?>
|
|
Tidak ada jadwal pelajaran untuk hari <strong><?php echo htmlspecialchars($hari_indonesia); ?></strong> di kelas ini.
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<!-- Attendance Table -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title">Formulir Absensi - <?php echo htmlspecialchars($hari_indonesia . ', ' . date('d M Y', strtotime($selected_tanggal))); ?></h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="index.php?page=attendance&kelas_id=<?php echo $selected_kelas_id; ?>&tanggal=<?php echo $selected_tanggal; ?>" method="POST">
|
|
<input type="hidden" name="action" value="save_absensi">
|
|
<input type="hidden" name="id_kelas" value="<?php echo $selected_kelas_id; ?>">
|
|
<input type="hidden" name="tanggal" value="<?php echo $selected_tanggal; ?>">
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th scope="col" style="width: 25%;">Nama Murid</th>
|
|
<?php foreach ($jadwal_hari_ini as $jadwal): ?>
|
|
<th scope="col" class="text-center">
|
|
<?php echo htmlspecialchars($jadwal['mata_pelajaran']); ?><br>
|
|
<small class="text-muted"><?php echo htmlspecialchars(date('H:i', strtotime($jadwal['jam_mulai']))) . ' - ' . htmlspecialchars(date('H:i', strtotime($jadwal['jam_selesai']))); ?></small>
|
|
</th>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($murid_list as $murid): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($murid['nama_lengkap']); ?></td>
|
|
<?php foreach ($jadwal_hari_ini as $jadwal): ?>
|
|
<td class="text-center">
|
|
<select class="form-select form-select-sm" name="absensi[<?php echo $murid['id']; ?>][<?php echo $jadwal['id']; ?>]">
|
|
<option value="">-</option>
|
|
<?php
|
|
$current_status = $absensi_data[$murid['id']][$jadwal['id']] ?? null;
|
|
foreach ($statuses as $status):
|
|
?>
|
|
<option value="<?php echo $status; ?>" <?php echo ($current_status === $status) ? 'selected' : ''; ?>>
|
|
<?php echo $status; ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</td>
|
|
<?php endforeach; ?>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<button type="submit" class="btn btn-success mt-3">Simpan Absensi</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</main>
|