<?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> Prestasi</h5>
                </div>
			
				 <div class='card-body'>
                    <div class='table-responsive'>
                      <table id='tabelwalas' class='table  table-hover'>
                            <thead>
                            <tr>
                                <th width="2%" class="text-center">
                                    #
                                </th>
                                <th width="7%">Nis</th>
                                <th>Nama Siswa</th>
								<th>Jenis Prestasi</th>
								<th>Keterangan</th>
								
							<th width="15%">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['prestasi'] ?> </td>
									<td><?= $siswa['ket_prestasi'] ?></td>
									
                                     <td>
										<button type="button" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#modal-des<?= $no ?>">
                                            <i class="fas fa-edit"></i>
                                        </button>
										 <button data-id="<?= $siswa['nis'] ?>" class="hapus btn-sm btn btn-outline-danger"><i class="fas fa-trash"></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 Prestasi</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">
														 <form role="form"  method="POST">														
                                                            <div class="form-group">
                                                                <label><b>Jenis Prestasi</b></label>
                                                               <input type="text" name="pres"  class="form-control" autocomplete="off" required>
                                                            </div>
                                                            
                                                            
															 <div class="form-group">
                                                                <label><b>Keterangan</b></label>
                                                          <input type="hidden" value="<?= $siswa['nis'] ?>" name="nis" class="form-control" >
														  <input type="text" name="ket"  class="form-control" autocomplete="off"  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=tambahprestasi',
            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);
                    $('#editdata').modal('hide');
                } else {
                    iziToast.error({
                        title: 'Maaf!',
                        message: 'Data Gagal disimpan',
                        position: 'topRight'
                    });
                }
              
            }
        });
        return false;
    });
	
	 $('#tabelwalas').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
				  text: "You won't be able to revert this!",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#3085d6',
				  cancelButtonColor: '#d33',
				  confirmButtonText: 'Yes, delete it!'	
         }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_rapor/crud_walas.php?pg=hapusprestasi',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                       iziToast.info(
												{
												title: 'Sukses!',
												message: 'Data berhasil dihapus',
												titleColor: '#FFFF00',
												messageColor: '#fff',
												backgroundColor: 'rgba(0, 0, 0, 0.5)',
												progressBarColor: '#FFFF00',
												position: 'topRight'
												}); 
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
	
	
</script>
                 
				<?php
                                    }
                                    ?>
                                </tr>
                        </tbody>
                    </table>
					</div>
					</div>
					</div>
		  
		  