-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
106 lines (99 loc) · 3.17 KB
/
index.php
File metadata and controls
106 lines (99 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
session_start();
function konversiNilai($angka) {
if ($angka >= 85) return "A";
elseif ($angka >= 70) return "B";
elseif ($angka >= 60) return "C";
elseif ($angka >= 50) return "D";
else return "E";
}
// Membaca data dari file JSON
$jsonFile = "data_mahasiswa.json";
if (file_exists($jsonFile)) {
$jsonContent = file_get_contents($jsonFile);
$mahasiswa = json_decode($jsonContent, true) ?: [];
} else {
$mahasiswa = [];
}
// Menampilkan pesan berdasarkan status
if (isset($_GET['status'])) {
$message = '';
$type = 'success';
switch ($_GET['status']) {
case 'success':
$message = 'Data berhasil disimpan!';
break;
case 'updated':
$message = 'Data berhasil diperbarui!';
break;
case 'deleted':
$message = 'Data berhasil dihapus!';
$type = 'warning';
break;
}
if ($message) {
echo "<div class='alert alert-{$type}'>{$message}</div>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Daftar Mahasiswa</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<nav>
<a href="index.php">Daftar Mahasiswa</a> |
<a href="tambah.php">Tambah Mahasiswa</a>
</nav>
<h2>Daftar Mahasiswa</h2>
<table>
<thead>
<tr>
<th>Nama</th>
<th>NIM</th>
<th>Mata Kuliah</th>
<th>Nilai Angka</th>
<th>Nilai Huruf</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php foreach ($mahasiswa as $mhs): ?>
<?php
$firstRow = true;
$rowspan = count($mhs['mk']);
foreach ($mhs['mk'] as $matkul):
?>
<tr>
<?php if ($firstRow): ?>
<td rowspan="<?= $rowspan ?>"><?= htmlspecialchars($mhs['nama']) ?></td>
<td rowspan="<?= $rowspan ?>"><?= htmlspecialchars($mhs['nim']) ?></td>
<?php endif; ?>
<td><?= htmlspecialchars($matkul['nama']) ?></td>
<td><?= htmlspecialchars($matkul['nilai']) ?></td>
<td><?= konversiNilai($matkul['nilai']) ?></td>
<?php if ($firstRow): ?>
<td rowspan="<?= $rowspan ?>" class="action-buttons">
<a href="edit.php?nim=<?= urlencode($mhs['nim']) ?>" class="btn btn-edit">Edit</a>
<a href="javascript:void(0);" onclick="confirmDelete('<?= htmlspecialchars($mhs['nim']) ?>')" class="btn btn-delete">Hapus</a>
</td>
<?php endif; ?>
</tr>
<?php
$firstRow = false;
endforeach;
?>
<?php endforeach; ?>
</tbody>
</table>
<script>
function confirmDelete(nim) {
if (confirm('Apakah Anda yakin ingin menghapus data mahasiswa ini?')) {
window.location.href = 'delete.php?nim=' + encodeURIComponent(nim);
}
}
</script>
</body>
</html>