<?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-sync-alt"></i> Kirim Data Soal</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>Kode Mapel</th>
									 <th>Kode Soal</th> 
                                    <th>Group Soal</th>  
                                    <th>Jml Soal</th> 									
                                    <th width="10%">Terkirim</th>                                   
                                    <th width="10%">Aksi</th>
                                </tr>
                            </thead>
                            <tbody>

                                 <?php
                                if ($pengawas['level'] == 'guru') {
                                    $soalQ = mysqli_query($koneksi, "SELECT * FROM soal JOIN banksoal ON banksoal.id_bank=soal.id_bank where banksoal.idguru='$id_pengawas' group by banksoal.id_bank");
                                } else {
                                    $soalQ = mysqli_query($koneksi, "SELECT * FROM soal JOIN banksoal ON banksoal.id_bank=soal.id_bank group by banksoal.id_bank");
                                }
                                while ($soal = mysqli_fetch_array($soalQ)) {
                                    $terkirim = mysqli_num_rows(mysqli_query($koneksi, "select * from soal where id_bank='$soal[id_bank]' AND sts='1'"));
                                    $cek = mysqli_num_rows(mysqli_query($koneksi, "select * from soal where id_bank='$soal[id_bank]' AND sts='1'"));
                                    $jumsoal = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$soal[id_bank]'"));
                                    if ($cek <> 0) {
                                        $dis = 'disabled';
                                    } else {
                                        $dis = '';
                                    }

                                    $no++;
                                    $tempjawaban = mysqli_num_rows(mysqli_query($koneksi, "select * from soal where id_soal='$soal[id_soal]'"));
                              
                                    echo "
                                <tr>

                                    <td>$no</td>
                                    <td>$soal[nama]</td>
                                    <td>$soal[kode]</td>
                                    <td>$soal[groupsoal]</td>
                                     <td>$jumsoal</td>
                                    <td>$terkirim</td>
                                   
                                    <td>
									
                                    <button class='kirim btn btn-success btn-sm' data-id='$soal[id_bank]' $dis><i class='fa fa-sync-alt'></i> Kirim Soal</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 Bank Soal ke Sever Pusat!",
				  type: 'warning',
				  showCancelButton: true,
				  confirmButtonColor: '#3085d6',
				  cancelButtonColor: '#d33',
				  confirmButtonText: 'Yes, Kirim!'	
        }).then((result) => {
            if (result.value) {
                $.ajax({
                   url: 'server/kirimsoal.php',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                 Swal.fire({	
				title: '<a href="#" class="sandik" style="color:blue;">Data sedang di posess ...</a>',				
				showConfirmButton: false,
				 animation: false,
				  customClass: 'animated tada',				  
				  imageUrl: '../dist/img/sandik_kecil.gif',
                 footer: '<a href="#"><b style="color:red">Sistem Administrasi Pendidik (SANDIK)</b></a>'				  
                });
                        setTimeout(function() {
                            window.location.replace('?pg=kirimdata');
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });

        </script>
	