<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>

 <div class='row'>
 <div class='col-md-12'>
   <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Rekap Absen</h4>
                </div>
				 <div class='card-body'>
                    <div class='table-responsive'>
                      <table id='tabelabsen' class='table table-hover'>
                            <thead>
                            <tr>
                                <th width="5%" class="text-center">
                                    #
                                </th>
                                <th width="20%">Nis</th>
                                <th>Nama Siswa</th>
								<th width="5%">Sakit</th>
								<th width="5%">Izin</th>
								<th width="5%">Alpha</th>
							<th width="5%">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * from siswa WHERE id_kelas='$_GET[kelas]' order by id_siswa ASC");
                            $no = 0;
                            while ($siswa = mysqli_fetch_array($query)) {
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $siswa['sakit'] ?></td>
									<td><?= $siswa['izin'] ?></td>
									<td><?= $siswa['alpha'] ?></td>
                                     <td>
										<button type="button" class="btn btn-sm btn-outline-success" data-bs-toggle="modal" data-bs-target="#modal-des<?= $no ?>">
                                            <i class="fas fa-edit"></i> 
                                        </button>
										</td>
									
                                       <div class="modal fade" id="modal-des<?= $no ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                            <div class="modal-dialog" role="document">
                                                <div class="modal-content">
                                                    <form id="form-des<?= $no ?>">
                                                        <div class="modal-header">
														<h5 class="card-title">Input Absen</h5>
                                                            <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                                                                <span aria-hidden="true">&times;</span>
                                                            </button>
                                                        </div>
                                                        <div class="modal-body">
                                                            <input type="hidden" value="<?= $siswa['id_siswa'] ?>" name="idd" class="form-control" >
                                                            <div class="form-group">
                                                                <label class="bold">Nama Siswa</label>
                                                                <input type="text" name="nama" value="<?= $siswa['nama'] ?>" class="form-control" readonly="">
                                                            </div>
                                                            <div class="form-group">
                                                                <label class="bold">Sakit</label>
                                                                <input type="number" name="sakit" value="<?= $siswa['sakit'] ?>" class="form-control" required="">
                                                            </div>
                                                            <div class="form-group">
                                                                <label class="bold">Izin</label>
                                                                <input type="number" name="izin" value="<?= $siswa['izin'] ?>" class="form-control" required="">
                                                            </div>
															<div class="form-group">
                                                                <label class="bold">Alpha</label>
                                                                <input type="number" name="alpha" value="<?= $siswa['alpha'] ?>" class="form-control" required="">
                                                            </div>
                                                      <p>
													   <div class='right'>
														  <button type='submit' name='submit' class='btn btn-sm btn-primary'><i class='fa fa-check-circle'></i> Simpan</button>
															
																 </div>
                                                    </form>
                                           
                                  <script>
                                   $('#form-des<?= $no ?>').submit(function(e) {
                                        e.preventDefault();
                                        $.ajax({
                                            type: 'POST',
                                            url: 'sandik_rapor/crud_walas.php?pg=absen',
                                            data: $(this).serialize(),
                                            success: function(data) {
                                                if (data == 'OK') {
                                                    iziToast.info(
												{
												title: 'Sukses!',
												message: 'Data berhasil disimpan',
												titleColor: '#FFFF00',
												messageColor: '#fff',
												backgroundColor: 'rgba(0, 0, 0, 0.5)',
												progressBarColor: '#FFFF00',
												position: 'topRight'
												}); 
                                                    setTimeout(function() {
                                                        window.location.reload();
                                                    }, 2000);
                                                    $('#modal-des<?= $no ?>').modal('hide');
                                                } else {
                                                    iziToast.error({
                                                        title: 'Maaf!',
                                                        message: 'Data Gagal diubah',
                                                        position: 'topRight'
                                                    });
                                                }

                                                //$('#bodyreset').load(location.href + ' #bodyreset');
                                            }
                                        });
                                        return false;
                                    });
								</script>
								<?php
                                    }
                                    ?>
                                </tr>
                        </tbody>
                    </table>
                </div>
            </div>
       </div>
           