89 lines
3.8 KiB
PHP
89 lines
3.8 KiB
PHP
<?php
|
|
// Handle actions from the form
|
|
$notification = handle_matapelajaran_action();
|
|
|
|
// Get data for the view
|
|
$all_matapelajaran = get_all_matapelajaran();
|
|
|
|
// Determine form action (add or edit)
|
|
$form_action = 'add';
|
|
$form_title = "Tambah Mata Pelajaran Baru";
|
|
$nama_matapelajaran_value = '';
|
|
$id_value = '';
|
|
|
|
if (isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id'])) {
|
|
$matapelajaran = get_matapelajaran_by_id($_GET['id']);
|
|
if ($matapelajaran) {
|
|
$form_action = 'edit';
|
|
$form_title = "Ubah Data Mata Pelajaran";
|
|
$nama_matapelajaran_value = $matapelajaran['nama_matapelajaran'];
|
|
$id_value = $matapelajaran['id'];
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<!-- Form to Add/Edit Subject -->
|
|
<div class="col-md-4">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title"><?= $form_title ?></h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (isset($notification)): ?>
|
|
<div class="alert alert-<?= $notification['success'] ? 'success' : 'danger' ?>">
|
|
<?= $notification['message'] ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<form action="index.php?page=subjects" method="POST">
|
|
<input type="hidden" name="action" value="<?= $form_action ?>">
|
|
<input type="hidden" name="id" value="<?= $id_value ?>">
|
|
<div class="form-group">
|
|
<label for="nama_matapelajaran">Nama Mata Pelajaran</label>
|
|
<input type="text" class="form-control" id="nama_matapelajaran" name="nama_matapelajaran" value="<?= htmlspecialchars($nama_matapelajaran_value) ?>" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Simpan</button>
|
|
<?php if ($form_action === 'edit'): ?>
|
|
<a href="index.php?page=subjects" class="btn btn-secondary">Batal</a>
|
|
<?php endif; ?>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Table of Subjects -->
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">Daftar Mata Pelajaran</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<table id="matapelajaranTable" class="table table-bordered table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Nama Mata Pelajaran</th>
|
|
<th>Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($all_matapelajaran as $index => $mapel): ?>
|
|
<tr>
|
|
<td><?= $index + 1 ?></td>
|
|
<td><?= htmlspecialchars($mapel['nama_matapelajaran']) ?></td>
|
|
<td>
|
|
<a href="index.php?page=subjects&action=edit&id=<?= $mapel['id'] ?>" class="btn btn-sm btn-warning">Ubah</a>
|
|
<a href="index.php?page=subjects&action=delete&id=<?= $mapel['id'] ?>" class="btn btn-sm btn-danger" onclick="return confirm('Apakah Anda yakin ingin menghapus mata pelajaran ini?')">Hapus</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|