<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php
$jawab = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM jawaban"));
$temp = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM hasil_jawaban "));
?>
<?php if ($ac == '') { ?>

<div class='row'>
    <div class='col-md-12'>
 <div class='panel panel-default'>
               <div class="panel-heading" style="height:45px">
                  <h4 class='box-title'><i class="fas fa-reply"></i> Pindah Jawaban</h4></div>    
			  <div class='box-header with-border'>
			   <div class='box-tools pull-right '>
			   
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control'   >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control'   >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'  >
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'   >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			  <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Jawaban</a></li>
                        
                    </ul>
					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >
						<br>        
						<div class="panel panel-default">	
                      <div class='box-body'>			
                <div id="hasilkirim"></div>
				<div class='col-md-2'></div>
                <div class='col-md-10'>
                <div class="col-md-4 text-center">
				 <div class="knob-label"><h4 style="color:red"> Jawaban</h4></div>
				 <br>
                    <input type="text" class="knob" value="<?= $jawab ?>" data-min="0" data-max="10000" data-width="150" data-height="150" data-fgColor="#f56954">
                  </div>     

                  <div class="col-md-1 text-center">
				 
				 <br> <br> <br> 
                   <img src="../dist/img/arsip/panah.png" class="siskolah" width="150px" >
                  </div>     
				  
				  
						<div class="col-md-6 text-center">
						<div class="knob-label"><h4 style="color:blue">Temp Jawaban</h4></div>
						<br>
                    <input type="text" class="knob" value="<?= $temp ?>" data-min="0" data-max="10000" data-width="150" data-height="150" data-fgColor="#3c8dbc">                    
                  </div>
				  </div></div></div>
                    <div  class='table-responsive'>
                        <table id="example1" class='table table-bordered table-hover'>
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    <th>Jenis Ujian</th>
									<th>Level</th>
                                    <th>Kode Ujian</th>
                                    <th>Nilai</th>                                     
                                    <th>Temp</th>
                                    <th>Aksi</th>

                                </tr>
                            </thead>
                            <tbody>

                                <?php
                                if ($pengawas['level'] == 'guru') {
                                    $ujianQ = mysqli_query($koneksi, "SELECT * FROM nilai a join banksoal b ON a.id_bank=b.id_bank where b.idguru='$id_pengawas' 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 ujian_selesai is null"));
                                    $cek2 = mysqli_num_rows(mysqli_query($koneksi, "select * from jawaban where id_ujian='$ujian[id_ujian]'"));
                                    if ($cek2 == 0) {
                                        $dis = 'disabled';
                                    } else {
                                        $dis = '';
                                    }

                                    $no++;
                                    $tempjawaban = mysqli_num_rows(mysqli_query($koneksi, "select * from jawaban where id_ujian='$ujian[id_ujian]'"));

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

                                    <td>$no</td>
                                    
                                    <td>$ujian[kode_ujian]</td>
									<td>$ujian[level]</td>
                                    <td>$ujian[nama]</td>
                                    <td>$datanilai</td>
                                    <td>$tempjawaban</td>
                                    
                                    <td>
                                   
                                    <button data-id='$ujian[id_ujian]' class='pindahjwbn btn btn-sm btn-success' $dis><i class='fa fa-reply'></i> Pindah</button>
                                   
                                    </td>
                                </tr>
                                ";
                                }
                                ?>

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

                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div>
        <script>
            
			$('#example1').on('click', '.pindahjwbn', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'memindahkan dari jawaban ke temp jawaban?',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, pindah'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                     url: 'server/ambiljawaban.php',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                        Swal.fire({	
				title: '<a href="#" class="sandik" style="color:red;">Jawaban berhasil dipindahkan</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.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
        </script>
		
		<?php } elseif ($ac == 'kembali') { ?>
		
		 <div class='row'>
	 <div class='col-md-12'>
             <div class='panel panel-default'>
               <div class="panel-heading" style="height:45px">
			   <form id="formkembali" action=""  enctype="multipart/form-data">
                    <div class='box-tools pull-right '>
					<?php if($temp<>0){ ?>
					  <button type='submit' name='submit' class='btn btn-sm btn-success' ><i class='fa fa-check fa-lg'></i><span> Kembalikan</span></button>
                    <?php }else{ ?>
					<button  class='btn btn-sm btn-default' disabled><i class='fa fa-check fa-lg'></i><span> Kembalikan</span></button>
					<?php } ?>
					</div>
					</form>
					<h4 class='box-title'><i class="fas fa-check"></i> Kembali Jawaban</h4>
                </div>
				<div class='box-header with-border '>
			   <div class='box-tools pull-right '>
			   <table>
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control'   >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control'   >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'  >
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'   >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			  <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Jawaban</a></li>                        
                    </ul>					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >
						<br>
						<div class="panel panel-default">	
                  <div class='box-body'>			
                <div id="hasilkirim"></div>
				<div class='col-md-3'></div>
                <div class='col-md-6'>
                <div class="col-md-6 text-center">
				<div class="siskolah knob-label"><h4 style="color:blue">Temp Jawaban</h4></div>
				 <br>
                    <input type="text" class="knob" value="<?= $temp ?>" data-min="0" data-max="10000" data-width="200" data-height="200" data-fgColor="#3c8dbc">
                  </div> 
						<div class="col-md-6 text-center">
						<div class="knob-label"><h4 style="color:red">Jawaban</h4></div>
						<br>
                    <input type="text" class="knob" value="<?= $jawab ?>" data-min="0" data-max="10000" data-width="200" data-height="200" data-fgColor="#f56954">
                    
                  </div>
			   
			   </div>
				 </div>
				 </div>
				 </div>
				 </div> 
					<script>
    $('#formkembali').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
      
        $.ajax({
            type: 'POST',
            url: 'pengaturan/crud_kembali.php?pg=kembali',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                Swal.fire({	
				title: '<a href="#" class="sandik">Jawaban berhasil dikembalikan</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.reload();
                }, 2000);

            }
        });
        return false;
    });
   </script>
		
		<?php } ?>