<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php if ($ac == '') : ?>
    <div class='row'>
        <div class='col-md-8'>
           <div class="card">
             <div class="card-header">	      
                    <div class='right' id="tarik">
                        <?php if ($user['level'] == 'admin') : ?>
			           <button class='btn btn-sm btn-default' data-toggle='modal' data-target='#newsandik'><i class='fa fa-sync'></i> Tarik Nilai</button>	                  
                          
                        <?php endif ?>
                    </div>
					<h5 class='card-title'><i class="fas fa-file-signature fa-fw"></i> NILAI UJIAN</h5>
                </div>
						 
                <div class='card-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px'></th>
                                    <th>NIS</th>
                                    <th width="30%">Nama</th>
                                    <th>Tingkat</th>
                                    <th>Rombel</th>
                                    <th>Mapel</th>
									<th>Nilai</th>
                                    
                                </tr>
                            </thead>
							 <tbody>
                            <?php
							$no = 0;
                            $query = mysqli_query($koneksi, "select * from nilai");
                            while ($nilai = mysqli_fetch_array($query)) {
                            $siswa = fetch($koneksi,'siswa',['id_siswa'=>$nilai['id_siswa']]);	
                            $mapel = fetch($koneksi,'banksoal',['id_bank'=>$nilai['id_bank']]);
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $siswa['level'] ?> </td>
									<td><?= $siswa['id_kelas'] ?></td>
									<td><?= $mapel['nama'] ?></td>
									<td><?= $nilai['total'] ?></td>
									 </tr>
								
							       <?php } ?>  
                               
                        </tbody>
						
                        </table>
                    </div>
					  </div>
					   </div>
					     </div>
					 <div class='col-md-4'>	
                  <div class="card">
               	 
                <div class='card-body'>
					<div class='table-responsive'>
                        <table style="font-size: 11px" id='example' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px'></th>
                                    <th>Mata Pelajaran</th>
                     
                                   <th width='5%' class="text-center">Action</th>
                                </tr>
                            </thead>
							 <tbody>
                            <?php
							$no = 0;
                            $queryQ = mysqli_query($koneksi, "select * from mata_pelajaran");
                            while ($r = mysqli_fetch_array($queryQ)) {							
                                $no++;
                            ?>
							<tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $r['nama_mapel'] ?></td>
                                    <td><a href="?pg=nilaiujian&ac=mapel&mapel=<?= $r['kode_mapel'] ?>" class="btn btn-xs btn-primary"><i class='fa fa-eye'></i></a></td>
									 </tr>
									 <?php } ?>  
							
                               
                        </tbody>
                        </table>
					      </div>
					        </div>
					          </div>
					
<div id="newsandik" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Sinkron Nilai Ujian</h5>
                
            </div>
            <div class="modal-body">
                <h5 class="text-center" style="color:green">Tarik Nilai Ujian Dari Server CBT - AKM</h5>
                
                <div class="form-group text-center" id="server">
                  </div>
				  <div class="form-group text-center">
                 <button id="btntarik" class="btn btn-sm btn-success"> Tarik Data</button>
            </div>
        </div>
    </div>
</div>
	<script>
   $("#btntarik").click(function() {
        var id = $(this).data('id');
        swal({
            title: 'Tarik Data Nilai',
            text: 'Akan Tarik Data Nilai CBT - AKM ??',
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Ya, Tarik!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'server/tariknilai.php',
                  
                    type: "POST",
                    success: function(respon) {
                        iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data Siswa berhasil ditarik',
				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 elseif ($ac == 'mapel') : ?>
    <div class='row'>
        <div class='col-md-12'>
           <div class="card">
             <div class="card-header">	
					 <h5 class='card-title'><i class="fas fa-file-signature fa-fw"></i> MAPEL <?= $_GET['mapel'] ?></h5>
                </div>
				
						<div class="row">
                     <div class='col-md-8'>	
                 				 
                <div class='card-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px'></th>
                                    <th>NIS</th>
                                    <th width="30%">Nama</th>
                                    <th>Tingkat</th>
                                    <th>Rombel</th>
									 <?php
									$query = mysqli_query($koneksi, "select * from banksoal WHERE nama='$_GET[mapel]'");
									while ($bank = mysqli_fetch_array($query)) {
									?>
                                    <th><?= $bank['nama'] ?></th>
									<?php } ?>
                                     
                                    
                                </tr>
                            </thead>
							 <tbody>
                            <?php
							$no = 0;
                            $query = mysqli_query($koneksi, "select * from nilai");
                            while ($nilai = mysqli_fetch_array($query)) {
                            $siswa = fetch($koneksi,'siswa',['id_siswa'=>$nilai['id_siswa']]);	
                           								
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $siswa['level'] ?> </td>
									<td><?= $siswa['id_kelas'] ?></td>
									<td><?= $nilai['total'] ?></td>
									 </tr>
								
							       <?php } ?>  
                               
                        </tbody>
						
                        </table>
                    </div>
					  </div>
					   </div>
					  
					 <div class='col-md-4'>	
                  <div class="panel panel-default">					 
                <div class='box-body'>
					<div class='table-responsive'>
                        <table style="font-size: 11px" id='example' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px'></th>
                                    <th>Mapel  Kelas</th>
                     
                                   <th width='5%' class="text-center">Action</th>
                                </tr>
                            </thead>
							 <tbody>
                            <?php
							$no = 0;
                            $queryQ = mysqli_query($koneksi, "select * from banksoal");
                            while ($r = mysqli_fetch_array($queryQ)) {
                            $kelas = unserialize($r['kelas']);
                           foreach ($kelas as $key => $value):							
                                $no++;
                            ?>
							<tr>
                                    <td><?= $no; ?></td>
                                    <td><span class="label label-info"><?= $r['nama'] ?></span> <?= $value ?></td>
									
                                    <td><a href="?pg=nilaiujian&ac=detail&mapel=<?= $r['id_bank'] ?>&kelas=<?= $value ?>" class="btn btn-xs btn-primary"><i class='fa fa-eye'></i></a></td>
									 </tr>
									 <?php endforeach; ?>
									 <?php } ?>  
							
                               
                        </tbody>
                        </table>
					      </div>
					        </div>
					          </div>
							  
	 <?php elseif ($ac == 'detail') : ?>
	 <?php $mapel = fetch($koneksi,'banksoal',['id_bank'=>$_GET['mapel']]); ?>
    <div class='row'>
        <div class='col-md-12'>
            <div class='panel panel-default'>
               <div class="panel-heading">
                  
                    <div class='box-tools pull-right' id="tarik">
                      <a class='btn btn-sm btn-success' href='sandik_nilai/prosesujian.php?m=<?= $_GET['mapel'] ?>&k=<?= $_GET['kelas'] ?>' data-placement="top" data-toggle="tooltip" data-original-title="Ekspor Excel"><i class='fa fa-download'></i> </a>
                    </div>
					 <h4 class='box-title'><i class="fas fa-file-signature fa-fw"></i> <?= $mapel['nama'] ?> - <?= $_GET['kelas'] ?></h4>
                </div>
				
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Nilai</a></li>
                        
                    </ul>
					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >
						<br>
						<div class="row">
                     <div class='col-md-12'>	
                  <div class="panel panel-default">					 
                <div class='box-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px'></th>
                                    <th>NIS</th>
                                    <th>Nama</th>
                                    <th width="5%">Tingkat</th>
                                    <th width="10%">Rombel</th>
									 <?php
									$query = mysqli_query($koneksi, "select * from banksoal WHERE id_bank='$_GET[mapel]'");
									while ($bank = mysqli_fetch_array($query)) {
									?>
                                    <th width="15%"><?= $bank['nama'] ?></th>
									<?php } ?>
                                     
                                    
                                </tr>
                            </thead>
							 <tbody>
                            <?php
							$no = 0;
                            $query = mysqli_query($koneksi, "select * from siswa a join nilai b ON a.id_siswa=b.id_siswa where b.id_bank='$_GET[mapel]' and a.id_kelas='$_GET[kelas]'");
                            while ($siswa = mysqli_fetch_array($query)) {
                            							
                                $no++;
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $siswa['level'] ?> </td>
									<td><?= $siswa['id_kelas'] ?></td>
									<td><?= $siswa['total'] ?></td>
									 </tr>
								
							       <?php } ?>  
                               
                        </tbody>
						
                        </table>
                    </div>
					  </div>
					   </div>
					     </div>
					 
<?php endif ?>
