<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$skl = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM skl  WHERE id_skl='1'"));
?>
<?php if ($ac == '') : ?>
    <div class='row'>
        <div class='col-md-12'>
            <div class="card">
             <div class="card-header">									
                  
					<h5 class="card-title"><i class="fas fa-user-friends fa-fw"></i> DATA KELULUSAN</h5>
					<div class='pull-right'>
                        <?php if ($user['level'] == 'admin' OR $user['walas']<>'-') : ?>                         
                            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModalLive">UPDATE</button>                                          
                        <?php endif ?>
                </div>
			  </div>
                <div class='card-body'>
                    <div class='table-responsive'>
                        <table  id='datatable1' class='table table-bordered'>
                            <thead>
                                <tr>
                                    <th width='3px'></th>
                                     <th>NIS</th>
                                <th>NAMA SISWA</th>
                                <th>JK</th>
                               
                                <th>ROMBEL</th>
                                <th>STATUS</th>
                                <th>CETAK</th>
                              
                                </tr>
                            </thead>
							 <tbody>
                            <?php
							$no = 0;
                            $query = mysqli_query($koneksi, "select * from siswa WHERE level='$skl[tingkat]'");
                            while ($siswa = mysqli_fetch_array($query)) {							
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $siswa['jk'] ?> </td>
									
									<td><?= $siswa['kelas'] ?></td>
									
									<td>
                                        <?php if ($siswa['lulus'] == 1) { ?>
                                            <b style="color:blue">LULUS</b>
                                        <?php } elseif ($siswa['lulus'] == 2) { ?>
                                            LULUS BERSYARAT
										 <?php } elseif ($siswa['lulus'] == '0') { ?>	
										   <b style="color:red">TIDAK LULUS</b>
                                        <?php } elseif ($siswa['lulus'] == NULL) { ?>	
                                            <b style="color:red">BELUM DI ISI</b>
                                        <?php } ?>
                                    </td>
                                    <td>
									<a href="cbtserver_skl/print_skl.php?nis=<?= $siswa['nis'] ?>" target="_blank" class='btn btn-sm btn-danger'  data-bs-placement="top" data-bs-toggle="tooltip" title="Print SKL"><i class='material-icons'>print</i></a>				
									<a href="cbtserver_skl/cetakskkb.php?nis=<?= $siswa['nis']  ?>" target="_blank" class='btn btn-sm btn-primary'  data-bs-placement="top" data-bs-toggle="tooltip" title="Print SKKB"><i class='material-icons'>print</i></a>				
									
									</td>
                                   
							       <?php } ?>  
                                </tr>
                        </tbody>
                        </table>
                    </div>
                   
                </div>
            </div>
        </div>
    </div>
	
											<div class="modal fade" id="exampleModalLive" tabindex="-1" aria-labelledby="exampleModalLiveLabel" aria-hidden="true">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5 class="modal-title" id="exampleModalLiveLabel">UPLOAD DATA SKL</h5>
                                                                <div class="kanan">
																<a href="cbtserver_skl/proses.php" id="blockui-2" class="btn btn-success"><i class="material-icons">download</i>Format</a>       
															</div>
																
                                                            </div>
                                                            <div class="modal-body">
                                                               <form id='formsiswa' >	
																  <label>Pilih File Excel</label>
																  <div class="input-group mb-3">
																   <input type='file' name='file' class='form-control' required='true' />
																	<span class="input-group-text">
																		<button type="submit" id="blockui-3" class="btn btn-primary"><i class="material-icons">upload</i></button>
																	</span>
																	</div>	
															</form> 
                                                            </div>
                                                            
                                                        </div>
                                                    </div>
                                                </div>
                                          <script>
										$('#formsiswa').submit(function(e){
											e.preventDefault();
											var data = new FormData(this);
											$.ajax(
											{
												type: 'POST',
												 url: 'cbtserver_skl/import_siswa.php',
												data: data,
												cache: false,
												contentType: false,
												processData: false,
												success: function(data){   		
												setTimeout(function()
													{
													window.location.replace('?pg=siswa');
															}, 1500);
																		  
															}
														});
													return false;
												});
											</script>	
<?php endif ?>

<script>
   
 
    $('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        Swal.fire({
				  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: 'cbtserver_ujian/crud_siswa.php?pg=hapus',
                    method: "POST",
                    data: 'id_siswa=' + id,
                    success: function(data) {
                  iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berasil 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>