-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsiswa.php
More file actions
208 lines (206 loc) · 9.69 KB
/
Copy pathsiswa.php
File metadata and controls
208 lines (206 loc) · 9.69 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
require 'modules/databases.php';
$TITLE = "SISWA";
include 'elements/header.php';
?>
<!-- Modal -->
<div class="modal fade" id="editSiswa" tabindex="-1" aria-labelledby="editSiswaLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editSiswaLabel">EDIT SISWA</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="input-group mb-3 row">
<label for="" class="col-form-label col-2">Nama</label>
<div class="col-10">
<input type="hidden" id="Inis">
<input type="text" id="nama" class="form-control" placeholder="Nama">
</div>
</div>
<div class="input-group mb-3 row">
<label for="" class="col-form-label col-2">Gender</label>
<div class="col-10">
<select id="gender">
<option value="L">Laki-Laki</option>
<option value="P">Perempuan</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" id="btnUpdate" class="btn btn-primary">Update</button>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="offset-md-3 col-md-6 col-12">
<div class="card">
<div class="card-header">
<h3>CARI SISWA</h3>
<div class="input-group">
<input type="text" class="form-control" id="nis" placeholder="NIS">
<div class="input-group-append" id="search">
<div class="input-group-text">
<i class="fa-solid fa-magnifying-glass"></i>
</div>
</div>
</div>
</div>
<div class="card-body card-siswa">
</div>
<div class="card-footer">
</div>
</div>
</div>
</div>
</div>
<script>
function edit(NIS){
const form = new FormData();
form.append('nis', NIS);
fetch('ajax/dataSiswa.php', {
method: 'POST',
body: form
}).then(async (r)=>{
const resp = await r.json();
const isempty = JSON.stringify(resp) === '[]';
document.getElementById('nama').value = isempty?'':resp.Nama;
$('#gender').val(isempty?'L':resp.Gender).niceSelect('update');
document.getElementById('Inis').value = isempty?'':NIS;
document.getElementById('btnUpdate').onclick = function (){
const form = new FormData();
form.append('nis', document.getElementById('Inis').value);
form.append('nama', document.getElementById('nama').value);
form.append('gender', $('#gender').val());
fetch('ajax/update.php', {
method: 'POST',
body: form
}).then(async (r)=>{
const res = await r.json();
const form1 = new FormData();
form1.append('nis', document.getElementById('Inis').value);
if(res.status){
fetch('ajax/dataSiswa.php', {
method: 'POST',
body: form1
}).then(async (resp)=>{
const json = await resp.json();
if(JSON.stringify(json) === '[]'){
Swal.fire({
position: 'top-end',
icon: 'error',
title: 'NIS tidak ditemukan',
showConfirmButton: false,
timer: 1500
});
}else{
Swal.fire({
position: 'top-end',
icon: 'success',
title: 'Berhasil Di Update!',
showConfirmButton: false,
timer: 1500
});
$('#editSiswa').modal('hide');
$('.card-siswa').empty();
$('.card-footer').empty();
$('.card-siswa').append(` <div class="row">
<div class="col-md-4 pt-md-3 col-sm-12">
<img src="img/${json.Gender === 'P'?'fe':''}male.png" class="img-thumbnail" alt="" srcset="">
</div>
<div class="col-md-8 col-sm-12">
<p class="pt-3">NIS: ${json.NIS}</p>
<p>Nama: <span id="dnama">${json.Nama}</span></p>
<p>Kelas: ${json.Kelas} ${json.nama}</p>
<p>Gender: <span id="dkelas">${{L: 'Laki-Laki', P: 'Perempuan'}[json.Gender]}</span></p>
<p>Absensi: ${json.Izin} Izin, ${json.Sakit} Sakit, ${json.Hadir} Hadir, ${json.Alpa} Alpa </p>
</div>
</div>`)
$('.card-footer').append(`<button onclick="edit('${document.getElementById('nis').value}');" class="btn btn-primary" style="float: right;"><i class="fas fa-trash"></i> Edit</button>
<button onclick="hapusSiswa('${document.getElementById('nis').value}');" class="btn btn-danger mx-2" style="float: right;"><i class="fas fa-trash"></i> Hapus</button>`)
}
})
}
})
}
$('#editSiswa').modal('show');
})
}
function hapusSiswa(NIS){
Swal.fire({
title: 'Apakah Anda yakin?',
showDenyButton: true,
confirmButtonText: 'Hapus',
denyButtonText: 'Batal',
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
const form = new FormData();
form.append('nis', NIS);
fetch('ajax/hapusSiswa.php',{
method: 'POST',
body: form
}).then(async (resp)=>{
const resjs = await resp.json();
Swal.fire(resjs.status?'Terhapus!':'Gagal!', '', resjs.status?'success':'error');
resjs.status && $('.card-siswa').empty() && $('.card-footer').empty();
})
}
})
}
$(document).ready(function() {
$('select').niceSelect();
document.getElementById('nis').onkeyup = (el) => {
console.log(el.target.value.length);
if(el.key === 'Enter' || el.target.value.length === 10) {
document.getElementById('search').click();
}
}
document.getElementById('search').onclick = () => {
const form = new FormData();
form.append('nis', document.getElementById('nis').value);
fetch('ajax/dataSiswa.php', {
method: 'POST',
body: form
}).then(async (resp)=>{
const json = await resp.json();
if(JSON.stringify(json) === '[]'){
Swal.fire({
position: 'top-end',
icon: 'error',
title: 'NIS tidak ditemukan',
showConfirmButton: false,
timer: 1500
});
}else{
$('.card-siswa').empty();
$('.card-footer').empty();
$('.card-siswa').append(` <div class="row">
<div class="col-md-4 pt-md-3 col-sm-12">
<img src="img/${json.Gender === 'P'?'fe':''}male.png" class="img-thumbnail" alt="" srcset="">
</div>
<div class="col-md-8 col-sm-12">
<p class="pt-3">NIS: ${json.NIS}</p>
<p>Nama: <span id="dnama">${json.Nama}</span></p>
<p>Kelas: ${json.Kelas} ${json.nama}</p>
<p>Gender: <span id="dkelas">${{L: 'Laki-Laki', P: 'Perempuan'}[json.Gender]}</span></p>
<p>Absensi: ${json.Izin} Izin, ${json.Sakit} Sakit, ${json.Hadir} Hadir, ${json.Alpa} Alpa </p>
</div>
</div>`)
$('.card-footer').append(`<button onclick="edit('${document.getElementById('nis').value}');" class="btn btn-primary" style="float: right;"><i class="fas fa-trash"></i> Edit</button>
<button onclick="hapusSiswa('${document.getElementById('nis').value}');" class="btn btn-danger mx-2" style="float: right;"><i class="fas fa-trash"></i> Hapus</button>`)
}
})
}
})
</script>
<?php
include 'elements/footer.php';
?>