244 lines
13 KiB
PHP
244 lines
13 KiB
PHP
<?php
|
|
// templates/murid.php
|
|
|
|
// Handle form submissions and actions
|
|
$feedback = handle_murid_action();
|
|
|
|
// Get the current action from URL, default to 'list'
|
|
$action = $_GET['action'] ?? 'list';
|
|
$id = $_GET['id'] ?? null;
|
|
|
|
// Get data for a single student if editing
|
|
$murid = null;
|
|
if ($action === 'edit' && $id) {
|
|
$murid = get_murid_by_id($id);
|
|
if (!$murid) {
|
|
// If student not found, redirect to list with an error
|
|
header("Location: index.php?page=murid&status=not_found");
|
|
exit();
|
|
}
|
|
}
|
|
|
|
// Get all classes for the dropdown
|
|
$all_kelas = get_all_kelas();
|
|
|
|
?>
|
|
|
|
<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 Murid</h1>
|
|
<?php if ($action === 'list'): ?>
|
|
<div class="btn-toolbar mb-2 mb-md-0">
|
|
<a href="export_murid.php" class="btn btn-outline-success me-2">Ekspor ke XLSX</a>
|
|
<a href="index.php?page=murid&action=add" class="btn btn-primary">Tambah Murid</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<a href="index.php?page=murid" class="btn btn-outline-secondary">Kembali ke Daftar</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if (isset($feedback['message'])): ?>
|
|
<div class="alert alert-<?php echo $feedback['success'] ? 'success' : 'danger'; ?>">
|
|
<?php echo $feedback['message']; // Allow HTML for error details ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($_GET['status']) && $_GET['status'] == 'deleted'): ?>
|
|
<div class="alert alert-success">Data murid berhasil dihapus.</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_GET['status']) && $_GET['status'] == 'error'): ?>
|
|
<div class="alert alert-danger">Terjadi kesalahan saat menghapus data.</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_GET['status']) && $_GET['status'] == 'not_found'): ?>
|
|
<div class="alert alert-warning">Data murid tidak ditemukan.</div>
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if ($action === 'add' || $action === 'edit'): ?>
|
|
|
|
<!-- Form for Adding and Editing Students -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title"><?php echo $action === 'add' ? 'Tambah Murid Baru' : 'Ubah Data Murid'; ?></h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="index.php?page=murid" method="POST" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="<?php echo $action; ?>">
|
|
<?php if ($id): ?>
|
|
<input type="hidden" name="id" value="<?php echo $id; ?>">
|
|
<?php endif; ?>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="nis" class="form-label">NIS (Nomor Induk Siswa)</label>
|
|
<input type="text" class="form-control" id="nis" name="nis" value="<?php echo htmlspecialchars($murid['nis'] ?? ''); ?>" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="nisn" class="form-label">NISN</label>
|
|
<input type="text" class="form-control" id="nisn" name="nisn" value="<?php echo htmlspecialchars($murid['nisn'] ?? ''); ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="nama_lengkap" class="form-label">Nama Lengkap</label>
|
|
<input type="text" class="form-control" id="nama_lengkap" name="nama_lengkap" value="<?php echo htmlspecialchars($murid['nama_lengkap'] ?? ''); ?>" required>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="kelas_id" class="form-label">Kelas</label>
|
|
<select class="form-select" id="kelas_id" name="kelas_id">
|
|
<option value="">-- Pilih Kelas --</option>
|
|
<?php foreach ($all_kelas as $kelas): ?>
|
|
<option value="<?php echo $kelas['id']; ?>" <?php echo (isset($murid['kelas_id']) && $murid['kelas_id'] == $kelas['id']) ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($kelas['nama_kelas']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="tempat_lahir" class="form-label">Tempat Lahir</label>
|
|
<input type="text" class="form-control" id="tempat_lahir" name="tempat_lahir" value="<?php echo htmlspecialchars($murid['tempat_lahir'] ?? ''); ?>">
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="tanggal_lahir" class="form-label">Tanggal Lahir</label>
|
|
<input type="date" class="form-control" id="tanggal_lahir" name="tanggal_lahir" value="<?php echo htmlspecialchars($murid['tanggal_lahir'] ?? ''); ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="jenis_kelamin" class="form-label">Jenis Kelamin</label>
|
|
<select class="form-select" id="jenis_kelamin" name="jenis_kelamin">
|
|
<option value="Laki-laki" <?php echo (isset($murid['jenis_kelamin']) && $murid['jenis_kelamin'] === 'Laki-laki') ? 'selected' : ''; ?>>Laki-laki</option>
|
|
<option value="Perempuan" <?php echo (isset($murid['jenis_kelamin']) && $murid['jenis_kelamin'] === 'Perempuan') ? 'selected' : ''; ?>>Perempuan</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="no_telepon" class="form-label">No. Telepon</label>
|
|
<input type="tel" class="form-control" id="no_telepon" name="no_telepon" value="<?php echo htmlspecialchars($murid['no_telepon'] ?? ''); ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Email</label>
|
|
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($murid['email'] ?? ''); ?>">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="alamat" class="form-label">Alamat</label>
|
|
<textarea class="form-control" id="alamat" name="alamat" rows="3"><?php echo htmlspecialchars($murid['alamat'] ?? ''); ?></textarea>
|
|
</div>
|
|
|
|
<hr>
|
|
<h5 class="mb-3">Foto dan Lokasi</h5>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="foto" class="form-label">Foto Murid</label>
|
|
<input class="form-control" type="file" id="foto" name="foto" accept="image/jpeg, image/png">
|
|
<?php if (!empty($murid['foto'])): ?>
|
|
<div class="mt-2">
|
|
<img src="assets/uploads/murid/<?php echo htmlspecialchars($murid['foto']); ?>" alt="Foto saat ini" style="max-height: 100px; border-radius: 4px;">
|
|
<input type="hidden" name="foto_existing" value="<?php echo htmlspecialchars($murid['foto']); ?>">
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="latitude" class="form-label">Latitude</label>
|
|
<input type="text" class="form-control" id="latitude" name="latitude" value="<?php echo htmlspecialchars($murid['latitude'] ?? ''); ?>">
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="longitude" class="form-label">Longitude</label>
|
|
<input type="text" class="form-control" id="longitude" name="longitude" value="<?php echo htmlspecialchars($murid['longitude'] ?? ''); ?>">
|
|
</div>
|
|
</div>
|
|
|
|
<div id="map" style="height: 300px;" class="mb-3"></div>
|
|
<p class="form-text text-muted">Klik pada peta untuk mengatur koordinat Latitude dan Longitude.</p>
|
|
|
|
<button type="submit" class="btn btn-success">Simpan Data</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php else: ?>
|
|
|
|
<!-- Import Form -->
|
|
<div class="card mb-4">
|
|
<div class="card-header">
|
|
<h5 class="card-title">Impor Data dari XLSX</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p>Pastikan urutan kolom di file Excel Anda adalah: NIS, NISN, Nama Lengkap, Tanggal Lahir, Alamat.</p>
|
|
<form action="index.php?page=murid&action=import" method="POST" enctype="multipart/form-data">
|
|
<input type="hidden" name="action" value="import">
|
|
<div class="mb-3">
|
|
<label for="file_murid" class="form-label">Pilih file .xlsx</label>
|
|
<input class="form-control" type="file" id="file_murid" name="file_murid" accept=".xlsx" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-info">Impor</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Table of Students -->
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th scope="col">#</th>
|
|
<th scope="col">Foto</th>
|
|
<th scope="col">NIS</th>
|
|
<th scope="col">Nama Lengkap</th>
|
|
<th scope="col">Kelas</th>
|
|
<th scope="col">Jenis Kelamin</th>
|
|
<th scope="col">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$all_murid = get_all_murid();
|
|
if (count($all_murid) > 0):
|
|
$i = 1;
|
|
foreach ($all_murid as $m):
|
|
$foto_path = 'assets/uploads/murid/' . ($m['foto'] ?? 'default.png');
|
|
if (empty($m['foto']) || !file_exists($foto_path)) {
|
|
$foto_path = 'assets/images/placeholder.png'; // Fallback to a placeholder
|
|
}
|
|
?>
|
|
<tr>
|
|
<td><?php echo $i++; ?></td>
|
|
<td>
|
|
<img src="<?php echo htmlspecialchars($foto_path); ?>" alt="Foto <?php echo htmlspecialchars($m['nama_lengkap']); ?>" style="width: 50px; height: 50px; object-fit: cover; border-radius: 50%;">
|
|
</td>
|
|
<td><?php echo htmlspecialchars($m['nis']); ?></td>
|
|
<td><?php echo htmlspecialchars($m['nama_lengkap']); ?></td>
|
|
<td><?php echo htmlspecialchars($m['nama_kelas'] ?? '<em>Belum diatur</em>'); ?></td>
|
|
<td><?php echo htmlspecialchars($m['jenis_kelamin']); ?></td>
|
|
<td>
|
|
<a href="index.php?page=murid&action=edit&id=<?php echo $m['id']; ?>" class="btn btn-sm btn-warning">Ubah</a>
|
|
<a href="index.php?page=murid&action=delete&id=<?php echo $m['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Apakah Anda yakin ingin menghapus data ini?');">Hapus</a>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
endforeach;
|
|
else:
|
|
?>
|
|
<tr>
|
|
<td colspan="7" class="text-center">Belum ada data murid.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<?php endif; ?>
|
|
</main>
|