37138-vm/templates/schedule.php
Flatlogic Bot bb0884a9fc SIAKAD 1.0
2025-12-24 04:07:02 +00:00

160 lines
8.0 KiB
PHP

<?php
// Handle form submission
$status_message = handle_jadwal_action();
// Determine if we are in edit mode
$edit_mode = false;
$jadwal_to_edit = null;
if (isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id'])) {
$jadwal_to_edit = get_jadwal_by_id($_GET['id']);
if ($jadwal_to_edit) {
$edit_mode = true;
}
}
// Fetch all required data
$all_jadwal = get_all_jadwal();
$all_kelas = get_all_kelas();
$all_guru = get_all_guru();
$all_matapelajaran = get_all_matapelajaran(); // Fetch subjects
$days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu'];
?>
<div class="container-fluid">
<h1 class="h3 mb-4 text-gray-800"><?php echo $edit_mode ? 'Ubah Jadwal Pelajaran' : 'Tambah Jadwal Pelajaran'; ?></h1>
<?php if ($status_message): ?>
<div class="alert alert-<?php echo $status_message['success'] ? 'success' : 'danger'; ?>">
<?php echo $status_message['message']; ?>
</div>
<?php endif; ?>
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Formulir Jadwal</h6>
</div>
<div class="card-body">
<form action="index.php?page=schedule" method="POST">
<input type="hidden" name="action" value="<?php echo $edit_mode ? 'edit' : 'add'; ?>">
<?php if ($edit_mode): ?>
<input type="hidden" name="id" value="<?php echo $jadwal_to_edit['id']; ?>">
<?php endif; ?>
<div class="form-row">
<div class="form-group col-md-6">
<label for="id_kelas">Kelas</label>
<select id="id_kelas" name="id_kelas" class="form-control" required>
<option value="" disabled selected>-- Pilih Kelas --</option>
<?php foreach ($all_kelas as $kelas): ?>
<option value="<?php echo $kelas['id']; ?>" <?php echo ($edit_mode && $jadwal_to_edit['id_kelas'] == $kelas['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($kelas['nama_kelas']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-6">
<label for="id_guru">Guru Pengajar</label>
<select id="id_guru" name="id_guru" class="form-control" required>
<option value="" disabled selected>-- Pilih Guru --</option>
<?php foreach ($all_guru as $guru): ?>
<option value="<?php echo $guru['id']; ?>" <?php echo ($edit_mode && $jadwal_to_edit['id_guru'] == $guru['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($guru['nama']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group">
<label for="id_matapelajaran">Mata Pelajaran</label>
<select id="id_matapelajaran" name="id_matapelajaran" class="form-control" required>
<option value="" disabled selected>-- Pilih Mata Pelajaran --</option>
<?php foreach ($all_matapelajaran as $mapel): ?>
<option value="<?php echo $mapel['id']; ?>" <?php echo ($edit_mode && $jadwal_to_edit['id_matapelajaran'] == $mapel['id']) ? 'selected' : ''; ?>>
<?php echo htmlspecialchars($mapel['nama_matapelajaran']); ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="hari">Hari</label>
<select id="hari" name="hari" class="form-control" required>
<option value="" disabled selected>-- Pilih Hari --</option>
<?php foreach ($days as $day): ?>
<option value="<?php echo $day; ?>" <?php echo ($edit_mode && $jadwal_to_edit['hari'] == $day) ? 'selected' : ''; ?>>
<?php echo $day; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group col-md-4">
<label for="jam_mulai">Jam Mulai</label>
<input type="time" class="form-control" id="jam_mulai" name="jam_mulai"
value="<?php echo $edit_mode ? $jadwal_to_edit['jam_mulai'] : ''; ?>" required>
</div>
<div class="form-group col-md-4">
<label for="jam_selesai">Jam Selesai</label>
<input type="time" class="form-control" id="jam_selesai" name="jam_selesai"
value="<?php echo $edit_mode ? $jadwal_to_edit['jam_selesai'] : ''; ?>" required>
</div>
</div>
<button type="submit" class="btn btn-primary">
<?php echo $edit_mode ? 'Simpan Perubahan' : 'Tambah Jadwal'; ?>
</button>
<?php if ($edit_mode): ?>
<a href="index.php?page=schedule" class="btn btn-secondary">Batal</a>
<?php endif; ?>
</form>
</div>
</div>
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Daftar Jadwal Pelajaran</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Kelas</th>
<th>Hari</th>
<th>Waktu</th>
<th>Mata Pelajaran</th>
<th>Guru</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php if (empty($all_jadwal)): ?>
<tr>
<td colspan="6" class="text-center">Belum ada data jadwal.</td>
</tr>
<?php else: ?>
<?php foreach ($all_jadwal as $jadwal): ?>
<tr>
<td><?php echo htmlspecialchars($jadwal['nama_kelas']); ?></td>
<td><?php echo htmlspecialchars($jadwal['hari']); ?></td>
<td><?php echo htmlspecialchars(date('H:i', strtotime($jadwal['jam_mulai']))) . ' - ' . htmlspecialchars(date('H:i', strtotime($jadwal['jam_selesai']))); ?></td>
<td><?php echo htmlspecialchars($jadwal['nama_matapelajaran']); ?></td>
<td><?php echo htmlspecialchars($jadwal['nama_guru']); ?></td>
<td>
<a href="index.php?page=schedule&action=edit&id=<?php echo $jadwal['id']; ?>" class="btn btn-warning btn-sm">Ubah</a>
<a href="index.php?page=schedule&action=delete&id=<?php echo $jadwal['id']; ?>" class="btn btn-danger btn-sm" onclick="return confirm('Apakah Anda yakin ingin menghapus jadwal ini?');">Hapus</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>