-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditdatakelas.php
162 lines (140 loc) · 5.79 KB
/
editdatakelas.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php include 'header.php';
include 'koneksi.php';
if(isset($_GET['id_kelas'])){
$id_kelas = $_GET['id_kelas'];
$exec = mysqli_query($conn, "DELETE FROM kelas WHERE id_kelas='$id_kelas'");
if($exec){
echo "<script>alert('data kelas berhasil dihapus');
document.location = 'editdatakelas.php';
</script>";
}
else{
echo "<script>alert('data kelas gagal dihapus');
document.location = 'editdatakelas.php';
</script>";
}
}
?>
<!-- button triger -->
<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#exampleModal">Tambah Data</button>
<!-- button triger -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Data Kelas</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>No</th>
<th>Nama Kelas</th>
<th>Aksi</th>
</tr>
</thead>
<?php
$no = 1;
$query = "SELECT * FROM kelas";
$exec = mysqli_query($conn,$query);
while($res = mysqli_fetch_assoc($exec)):
?>
<tbody>
<tr>
<td><?= $no++ ?></td>
<td><?= $res['nama_kelas'] ?></td>
<td>
<a href="editdatakelas.php?id_kelas=<?= $res['id_kelas']?>" class="btn btn-sm btn-danger" onclick='return confirm("Apakah yakin ingin menghapus data?")'>Hapus</a>
<a href="#" class="view_data btn btn-sm btn-warning" data-bs-toggle="modal" data-bs-target="#myModal" id="
<?php
echo $res['id_kelas'];
?>">Edit</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Data Kelas</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">x</button>
</div>
<div class="modal-body">
<form action="" method="POST">
<input type="text" name="nama_kelas" placeholder="Nama Kelas" class="form-control mb-2">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="Submit" name="simpan" class="btn btn-primary">Simpan</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Data Kelas</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close">x</button>
</div>
<div class="modal-body" id="datakelas">
</div>
</div>
</div>
</div>
<?php
if(isset($_POST['simpan'])){
$nama_kelas = htmlentities(strip_tags($_POST['nama_kelas']));
$query = "INSERT INTO kelas(nama_kelas) VALUES ('$nama_kelas')";
$exec = mysqli_query($conn, $query);
if($exec){
echo "<script>alert('data kelas berhasil disimpan');
document.location = 'editdatakelas.php';
</script>";
}
else{
echo "<script>alert('data kelas gagal disimpan');
document.location = 'editdatakelas.php';
</script>";
}
}
?>
<?php include 'footer.php'; ?>
<script>
$('.view_data').click(function(){
var id_kelas = $(this).attr('id');
$.ajax({
url:'view.php',
method:'post',
data:{id_kelas:id_kelas},
success:function(data){
$('#datakelas').html(data);
$('#myModal').modal('show');
}
})
})
</script>
<?php
if(isset($_POST['edit'])){
$id_kelas = $_POST['id_kelas'];
$nama_kelas = htmlentities(strip_tags(strtoupper($_POST['nama_kelas'])));
$query = "UPDATE kelas SET nama_kelas = '$nama_kelas' WHERE id_kelas = '$id_kelas'";
$exec = mysqli_query($conn,$query);
if($exec){
echo "<script>alert('data kelas berhasil diubah');
document.location = 'editdatakelas.php';
</script>";
}
else{
echo "<script>alert('data kelas gagal diubah');
document.location = 'editdatakelas.php';
</script>";
}
}
?>