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

<?php if ($ac == '') { ?>

		 <div class='row'>
	 <div class='col-md-12'>
             <div class="card">
             <div class="card-header">
			 
                    <div class='right '>
					<a href="?pg=dh" class="btn btn-sm btn-success"><i class="fas fa-sync-alt"></i> Daftar Hadir</a>
					<a href="?pg=ba" class="btn btn-sm btn-danger"><i class="fas fa-sync-alt"></i> Berita Acara</a>
					</div>
					
					 <h5 class='card-title'><i class="fas fa-sync-alt"></i> Kirim Nilai Ujian, Berita Acara, Daftar Hadir</h5>
                </div>
				
                <div class='card-body'>
               
                    <div id='tabledataujian' class='table-responsive'>
                        <table id="example1" class='table table-hover'>
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
									 <th>Satuan Pendidikan</th>
									  <th>N P S N</th>
									   <th>Kode Server</th>
                                    <th>Jenis Ujian</th>
                                    <th>Kode Ujian</th>
                                    <th width="5%">Nilai</th>
                                    <th width="5%">Terkirim</th>
                        
                                    <th>Aksi</th>

                                </tr>
                            </thead>
                            <tbody>

                                <?php
                                if ($user['level'] == 'guru') {
                                    $ujianQ = mysqli_query($koneksi, "SELECT * FROM nilai a join banksoal b ON a.id_bank=b.id_bank where b.idguru='$id_user' group by id_ujian");
                                } else {
                                    $ujianQ = mysqli_query($koneksi, "SELECT * FROM nilai a join banksoal b ON a.id_bank=b.id_bank  group by id_ujian");
                                }
                                while ($ujian = mysqli_fetch_array($ujianQ)) {
                                    $terkirim = mysqli_num_rows(mysqli_query($koneksi, "select * from nilai where id_ujian='$ujian[id_ujian]' and status='1'"));
                                    $cek = mysqli_num_rows(mysqli_query($koneksi, "select * from nilai where id_ujian='$ujian[id_ujian]' and status='1'"));
                                   
                                    if ($cek <> 0) {
                                        $dis = 'disabled';
                                    } else {
                                        $dis = '';
                                    }

                                    $no++;
                                    
                                    $datanilai = mysqli_num_rows(mysqli_query($koneksi, "select * from nilai where id_ujian='$ujian[id_ujian]'"));
                                    echo "
                                <tr>

                                    <td>$no</td>
                                     <td>$setting[sekolah]</td>
									 <td>$setting[npsn]</td>
									  <td>$setting[id_server]</td>
                                    <td>$ujian[kode_ujian]</td>
                                    <td>$ujian[nama]</td>
                                    <td>$datanilai</td>
                                    <td>$terkirim </td>
                                   
                                    <td>
                                    <button class='kirim btn btn-success btn-sm' data-id='$ujian[id_ujian]' $dis><i class='fa fa-sync-alt'></i> Nilai</button>
                                   
                                    </td>
                                </tr>
                                ";
                                }
                                ?>

                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
        </div>
        <script>
            $('#example1').on('click', '.kirim', function() {
        var id = $(this).data('id');
        console.log(id);
        Swal.fire({
				  title: 'Are you sure?',
				  text: "Kirim Nilai ke Sever Pusat!",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#3085d6',
				  cancelButtonColor: '#d33',
				  confirmButtonText: 'Yes, Kirim!'	
        }).then((result) => {
            if (result.value) {
                $.ajax({
                   url: 'server/kirimnilai.php',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                 iziToast.info(
				{
				title: 'Sukses!',
				message: 'Data sedang di prosess....',
				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 } ?>