<?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'"));
$download= mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM download"));
$lulus= mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE lulus='1' AND level='$skl[tingkat]'"));
$tidak= mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE lulus='0' AND level='$skl[tingkat]'"));
 ?>
 
							<div class='row'>
							 <div class="col-xl-4">
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-primary">
                                                <i class="material-icons-outlined">person</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">LULUS</span>
                                                <span class="widget-stats-amount"><?= $lulus ?></span>
                                                
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-4">
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-warning">
                                                <i class="material-icons-outlined">face</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">TIDAK LULUS</span>
                                                <span class="widget-stats-amount"><?= $tidak ?></span>
                                               
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-4">
                                <div class="card widget widget-stats">
                                    <div class="card-body">
                                        <div class="widget-stats-container d-flex">
                                            <div class="widget-stats-icon widget-stats-icon-danger">
                                                <i class="material-icons-outlined">file_download</i>
                                            </div>
                                            <div class="widget-stats-content flex-fill">
                                                <span class="widget-stats-title">Downloads</span>
                                                <span class="widget-stats-amount"><?= number_format($download); ?></span>
                                                <span class="widget-stats-info">3 items downloaded</span>
                                            </div>
                                            
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
							<div class='row'>
							<div class="col-md-8"> 
                       
						   <div class="card">
							 <div class="card-header">	
								  <h5 class='card-title'>
								  <i class="fas fa-trash"></i>DATA DOWNLOAD SKL</h5></div>   
                                       <div class="card-body">         
										<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered table-hover" style="width:100%">
                                            <thead>
                                                <tr>
                                                    <th>No</th>
                                                    <th>N I S</th>
                                                    <th>NAMA SISWA</th>
                                                    <th>FILE</th>
                                                    <th>BUKA</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											$query = mysqli_query($koneksi, "SELECT * FROM download GROUP BY idsiswa ORDER BY id DESC"); 
											  while ($data = mysqli_fetch_array($query)) :
											  $siswa = fetch($koneksi,'siswa',['id_siswa'=>$data['idsiswa']]);
											  $dow= mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM download WHERE idsiswa='$siswa[id_siswa]'"));
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                    <td><?= $siswa['nis'] ?></td>
                                                    <td><?= $siswa['nama'] ?></td>
                                                    <td><h5><span class="badge badge-success">SKL</span>  <span class="badge badge-primary">SKKB</span> <span class="badge badge-danger">TRANSKIP</span> </h5></td>
                                                 <td><h5><span class="badge badge-dark"><?= $dow ?> X</span></h5></td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												<br>
												 </div>	
                                   </div>
                                
								</div>
							</div>
					
						<div class="col-xl-4">
                                <div class="card widget widget-info">
                                    <div class="card-body">
                                        <div class="widget-info-container">
                                            <div class="widget-info-image" style="background: url('../images/<?= $setting[logo] ?>')"></div>
                                            <h6 class="widget-info-title">CBT SERVER ALL IN ONE</h6>
                                            <p class="widget-info-text"><b>SISTEM APLIKASI CBT SERVER</b><br>ALL IN ONE </p>
                                            <br>
                                        </div>
										 <div class="d-grid gap-2">
                                       <button id="confirm"  class="hapus btn btn-danger">RESET DATA SKL</button>
                           
                                            </div>
                                    </div>
                                </div>
							</div>
				
              </div>

          <script>
				$("#confirm").click(function(){
		    	Swal.fire({
				  title: 'Reset Data SKL',
				  text: "Data SKL akan dikosongkan !",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#3085d6',
				  cancelButtonColor: '#d33',
				  confirmButtonText: 'Yes, Reset!'
				}).then((result) => {
				  if (result.value) {
					$.ajax({
					url: 'cbtserver_skl/reset.php',
					success: function(data) {
						 Swal.fire(
				      'Deleted!',
				      'Your file has been deleted.',
				      'success'
				    )
				   setTimeout(function() {
					window.location.reload();
					}, 1000);
						}
					});
					}
					return false;
						})

						});
					</script>	
	