<?php
require("config/koneksi.php");
require("config/function.php");
require("config/crud.php");
require("config/apk.php");
?>
<?php
(isset($_SESSION['id_siswa'])) ? $id_siswa = $_SESSION['id_siswa'] : $id_siswa = 0;
if($menu['soal']==1){
($id_siswa == 0) ?  header("Location:$homeurl/konfirmasi_peserta.php") : null;
}elseif($menu['soal']==0){
($id_siswa == 0) ?  header("Location:$homeurl/login.php") : null;
}	
	
($pg == 'testongoing') ? $sidebar = 'sidebar-collapse' : $sidebar = '';
($pg == 'testongoing') ? $disa = '' : $disa = 'offcanvas';
$siswa = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_siswa='$id_siswa'"));
$idsesi = $siswa['sesi'];
$idpk = $siswa['idpk'];
$level = $siswa['level'];
$pk = fetch($koneksi, 'pk', array('id_pk' => $idpk));
$tglsekarang = time();
?>

 <?php if ($pg == 'testongoing') : ?>
  <?php include"navcbt.php"; ?>
  <?php else: ?>
   <?php include"nav.php"; ?>
  <?php endif; ?>

       <?php if ($pg == '') : ?>
				
	<?php $token=fetch($koneksi,'token',['id_token'=>1]); ?>
			<div class="row">
			<div class='col-md-7'>		
		   <div class="card">
             <div class="card-header">	
		  <div> <span class="mr-3" id="token">Token : <?= $token['token'] ?></span> <button class="btn btn-primary btn-round btn-sm" onClick="refreshToken();">Refresh</button></div>
		</div>
	</div>
	</div>
	<div class="col-sm-5" >
	<div class="card">
             <div class="card-header">	
		<div class="edis">
		  <div style="font-size:20px"><i class="fas fa-graduation-cap"></i> Konfirmasi data Peserta</div>
		  <form id="formkonfir" action="" enctype="multipart/form-data">
				<div class="mt-1">
					<label><b>Kode Peserta</b></label> 
					<input type="text" class="form-control"  value="<?= $siswa['no_peserta'] ?>">
				</div>
				<div class="mt-1">
					<label><b>Nama Peserta</b></label> 
					<input type="text" class="form-control"  value="<?= $siswa['nama'] ?>" >
				</div>			
				<div class="mt-1">
					<label><b>Mata Ujian</b></label> 
					<?php if($menu['soal']==1){ ?>
					<input type="text" class="form-control" value="Literasi - Numerasi | <?= $setting['sekolah'] ?>" >
					<?php }else{ ?>
					<input type="text" class="form-control" value="C B T | <?= $setting['sekolah'] ?>" >
					<?php } ?>
				</div>
				<div class="mt-1">
					<label><b>Jenis Kelamin</b></label> 
					<select class="form-select" name="jenis_kelamin" required>
					        <option value=""></option>
							<option value="L">Laki-Laki</option>
							<option value="P">Perempuan</option>
						</select>
				</div>
				<div class="mt-1">
					<label><b>Token</b></label> 
					<input type="text" class="form-control" placeholder="Ketikkan token di sini"   name="token" required="true">
				</div>
			  <button type="submit" class="btn-konfir btn btn-outline-primary form-control mt-2"  name="btnsubmit">Submit</button>
			</form> 
			<br><br>
		</div>
    </div>
	 
  </div> 
</div>
         <script>
        $('#formkonfir').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'cek.php',
            data: $(this).serialize(),
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
                      iziToast.info(
            {
                title: 'Sukses!',
                message: 'Token berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
				  });
                    setTimeout(function() {
                        window.location.replace('jadwal');
                    }, 2000);
                } else {
                   iziToast.info(
            {
                title: 'Gagal!',
                message: 'Token Salah',
				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 ($pg == 'pengumuman') : ?>
				     <div class="row">
					   <div class='col-md-3'></div>
					 <div class='col-md-6'>					 
                            <div class="card">
                               <div class="card-header">	
                                    <h5 class='box-title'><i class="fas fa-bell"></i> Pengumuman</h5>
                                </div>
                                <div class='box-body'>
                                    <div id='pengumuman'>
                                   <?php $logC = 0;
                                        echo "<ul class='timeline'><br>";
                                        $logQ = mysqli_query($koneksi, "SELECT * FROM pengumuman where type='eksternal' ORDER BY date DESC");

                                        while ($log = mysqli_fetch_array($logQ)) {
                                            $logC++;
                                            $user = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM users WHERE id_pengawas='$log[user]'"));
                                            if ($log['type'] == 'internal') {
                                                $bg = 'bg-green';
                                                $color = 'text-green';
                                            } else {
                                                $bg = 'bg-blue';
                                                $color = 'text-blue';
                                            }
                                            echo "
                                                        
                                                        
                                                        <!-- timeline time label -->
                                                        
                                                        <li><i class='fa fa-envelope $bg'></i>
                                                        <div class='timeline-item'>
                                                        <span class='time'> <i class='fa fa-calendar'></i> " . buat_tanggal('d-m-Y', $log['date']) . " <i class='fa fa-clock-o'></i> " . buat_tanggal('h:i', $log['date']) . "</span>
                                                        <h3 class='timeline-header' style='background-color:#f9f0d5'><a class='$color' href='#'>$log[judul]</a> <small> $user[nama]</small>
                                                        
                                                        </h3>
                                                        <div class='timeline-body'>
                                                        " . ucfirst($log['text']) . "	
                                                        </div>
                                                        
                                                        </div>
                                                        </li>
                                            
                                                        
                                                    ";
                                        }
                                        if ($logC == 0) {
                                            echo "<p class='text-center'>Tidak ada aktifitas.</p>";
                                        }
                                        echo "</ul>";?>
										  </div>
                                </div>
                            </div>
                         </div>
			          </div>
				 <?php elseif ($pg == 'jadwal') : ?>
				
                    <div class='row'>
                        <div class='col-md-12'>
                            <div class="alert alert-custom" role="alert">
                                                    <div class="custom-alert-icon icon-dark"><i class="fa fa-check fa-2x"></i></div>
                                                    <div class="alert-content">
                                                        <span class="alert-title"><h5 style="font-size:18px;font-weight:bold;" id="jam"></h5></span>
                                                        <span class="alert-text"> Tombol ujian akan aktif bila waktu sudah sama dengan jadwal ujian, Refresh browser atau tekan F5 jika waktu ujian belum aktif</span>
                                                    </div>
                                                </div>
                                            </div>
                             <div id="boxtampil" class='col-md-12'>
                            <div id='formjadwalujian'>
                                <div class='card-header'>
                                    <h5 class='box-title'><i class="fas fa-calendar-alt"></i> Jadwal Ujian Hari ini</h5>
                              
                                </div>
                                
                                 <div class='row'>
                                    <?php

                                    $mapelQ = mysqli_query($koneksi, "SELECT * FROM ujian WHERE (level='$level' or level='semua') AND sesi='$idsesi' AND status='1'  ORDER BY tgl_ujian ");

                                    ?>
                                    <?php while ($mapelx = mysqli_fetch_array($mapelQ)) : ?>
                                        <?php if (date('Y-m-d', strtotime($mapelx['tgl_selesai'])) >= date('Y-m-d') and date('Y-m-d', strtotime($mapelx['tgl_ujian'])) <= date('Y-m-d')) : ?>
                                            <?php $datakelas = unserialize($mapelx['kelas']); ?>
                                            <?php $datapk = unserialize($mapelx['id_pk']); ?>
                                            <?php if (in_array($siswa['idpk'], $datapk) or in_array('semua', $datapk)) : ?>
                                                <?php if (in_array($siswa['id_kelas'], $datakelas) or in_array('semua', $datakelas)) : ?>
                                                    <?php
                                                    $no++;
                                                  
                                                    $where = array(
                                                      
                                                        'id_bank' => $mapelx['id_bank'],
                                                        'id_siswa' => $id_siswa
                                                       
                                                    );
                                                    $nilai = fetch($koneksi, 'nilai', $where);
                                                    $ceknilai = rowcount($koneksi, 'nilai', $where);
                                                    if ($ceknilai == '0') :
                                                        if (strtotime($mapelx['tgl_ujian']) <= time() and time() <= strtotime($mapelx['tgl_selesai'])) :
                                                            $status = '<label class="label label-success">Tersedia </label>';
                                                            $btntest = "<button data-id='$mapelx[id_ujian]' data-ids='$id_siswa' class='btnmulaitest btn btn-block btn-sm btn-outline-primary'><i class='fa fa-edit'></i> MULAI UJIAN</button>";
                                                        elseif (strtotime($mapelx['tgl_ujian']) >= time() and time() <= strtotime($mapelx['tgl_selesai'])) :
                                                            $status = '<label class="label label-danger">Belum Waktunya</label>';
                                                            $btntest = "<button' class='btn btn-block btn-sm btn-outline-danger disabled'> BELUM UJIAN</button>";
                                                        else :
                                                            $status = '<label class="label label-danger">Telat Ujian</label>';
                                                            $btntest = "<button' class='btn btn-block btn-sm btn-outline-danger disabled'> Telat Ujian</button>";
                                                        endif;
                                                    else :
                                                        if ($nilai['ujian_mulai'] <> '' and $nilai['ujian_berlangsung'] <> '' and $nilai['ujian_selesai'] == '') :
                                                            
                                                            if ($mapelx['reset'] == 1) {
                                                                if($nilai['online']==0){
                                                                $status = '<label class="label label-warning">Berlangsung</label>';
                                                                $btntest = "<button data-id='$mapelx[id_ujian]' data-ids='$id_siswa' class='btn-lanjut btn btn-block btn-sm btn-outline-warning'><i class='fas fa-edit'></i> LANJUTKAN</button>";
                                                                }else{
                                                                $status = '<label class="label label-warning">Siswa sedang aktif</label>';
                                                                $btntest = "<button  class=' btn btn-block btn-outline-danger'><i class='fas fa-edit'></i> Minta Reset</button>";
                                                                }
                                                            } else {
																
                                                                $status = '<label class="label label-warning">Berlangsung</label>';
                                                                $btntest = "<button data-id='$mapelx[id_ujian]' data-ids='$id_siswa' class='btn-lanjut btn btn-block btn-sm btn-outline-warning'><i class='fas fa-edit'></i> LANJUTKAN</button>";
																
                                                            } 
                                                         else :
                                                            if ($nilai['ujian_mulai'] <> '' and $nilai['ujian_berlangsung'] <> '' and $nilai['ujian_selesai'] <> '') {
                                                                if($mapelx['ulang_kkm']==0){
                                                                $status = '<label class="label label-primary">Selesai</label>';
                                                                $btntest = "<button class='btn btn-block btn-primary btn-sm disabled'> Sudah Ujian</button>";
                                                                }else{
                                                                    if($nilai['skor']>=$mapelx['kkm']){
                                                                        $btntest = "<button class='btn btn-primary btn-block btn-sm '>Kamu Lulus - Skor : ".$nilai['skor']."</button>";  
                                                                    } else{
                                                                        $btntest = "<button data-id='".$nilai['id_nilai']."' class='btn btn-ulang btn-outline-warning btn-block btn-sm '>Belum Lulus - Skor : ".$nilai['skor']."</button>";   
                                                                    }
                                                                }
                                                            } else {
                                                                $btntest = "<button class='btn btn-block btn-danger btn-sm disabled'> Eloy</button>";
                                                            }
                                                        endif;
                                                    endif;
                                                    ?>
 
                                                     <?php if ($mapelx['soal_agama'] <> null) : ?>
                                                        <?php if ($mapelx['soal_agama'] == $siswa['agama']) : ?>
                                                          
                                                           <div class="col-md-4">                                                         
                                                           <div class="card widget widget-list">
                                                                <div class="card-header">
                                                                    <div class="widget-list-item-icon">
                                                                        <img src="dist/img/tutwuri.png" width="60px" alt="">
                                                                    </div>
                                                                   
                                                                    <center><span class="widget-list-item-description">
																	<?php
                                                                                if (strlen($mapelx['nama']) > 25) {
                                                                                    echo substr($mapelx['nama'], 0, 25) . "...";
                                                                                } else {
                                                                                    echo $mapelx['nama'];
                                                                                }
                                                                             ?>
																			   <img style="z-index: 800;position:absolute;margin-top:-55px;margin-left:90px" src="<?=$setting['logo'] ?>" alt="" width="60px">
																			 </span></center> 
                                                                      
                                                                    
																		<center> 	
                                                                    <span class="widget-list-item-description">
                                                                        <i class="fa fa-tag"></i> <?= $mapelx['kode_ujian'] ?> &nbsp;
                                                                        <i class="fa fa-user"></i> <?= $mapelx['level'] ?> &nbsp;
                                                                        <i class="fa fa-wrench"></i> <?php
                                                                                                        $dataArray = unserialize($mapelx['id_pk']);
                                                                                                        foreach ($dataArray as $key => $value) :
                                                                                                            echo "<small class='label label-success'>$value </small>&nbsp;";
                                                                                                        endforeach;
															 
                                                                                                        ?>
                                                                    </span></center>                                                                    	
                                                                </div>
																<div class="card-body">
                                                               <ul class="list-group list-group-flush">
                                                                 <li class="list-group-item"><i class='fa fa-clock'></i> Ujian Dimulai<span class="widget-list-item-description right"><?= $mapelx['tgl_ujian'] ?></span></li>
                                                                 <li class="list-group-item"><i class='fa fa-clock'></i> Ujian Ditutup<span class="widget-list-item-description right"><?= $mapelx['tgl_selesai'] ?></span></li>
                                                                 <li class="list-group-item"><i class='fa fa-hourglass'></i> Durasi Ujian<span class="widget-list-item-description right"><?= $mapelx['tampil_pg'] + $mapelx['tampil_esai'] + $mapelx['tampil_multi'] + $mapelx['tampil_bs'] + $mapelx['tampil_urut'];  ?> Soal / <?= $mapelx['lama_ujian'] ?> menit</span></li>
                                                                 <li class="list-group-item"><i class='fa fa-rss'></i> Status Ujian<span class="widget-list-item-description right">
																  <?php
                                                                                    if ($mapelx['status'] == 1) {
                                                                                        echo "<i class='fa fa-spinner fa-spin'></i> <label>Sedang Aktif</label> <label class='badge badge-primary'>Sesi $mapelx[sesi]</label>";
                                                                                    } elseif ($mapelx['status'] == 0) {
                                                                                        echo "<label class='badge bg-red'>Tidak Aktif</label>";
                                                                                    }
                                                                                    ?>
																 </span></li>
                                                                    <li class="list-group-item"><i class='fa fa-laptop'></i> Status Ujian<span class="widget-list-item-description right"><?= $status ?></span></li>
                                                                     <li class="list-group-item"><i class='fa fa-edit'></i> Jenis Soal<span class="widget-list-item-description right">
																	 <?php if($menu['soal']==1){ ?>
                                                                                <span class="pull-right"><?= $mapelx['groupsoal'] ?></span>
                                                                                <?php }else{ ?>
																				<span class="pull-right">CBT</span>
																				<?php } ?>
																	 
                                                                    </ul>
                                                                    <center style="padding: 8px">
                                                                        <?= $btntest ?>
                                                                    </center>			
																	 </div>
                                                                </div>
                                                              </div>
                                                        <?php endif; ?>
                                                    <?php else : ?>
													
                                                        <div class="col-md-4">
                                                           <div class="card widget widget-list">
                                                                <div class="card-header">
                                                                    <div class="widget-list-item-icon">
                                                                        <img src="dist/img/tutwuri.png" width="60px" alt="">
                                                                    </div>
                                                                 
                                                                    <center><span class="widget-list-item-description">
																	<?php
                                                                                if (strlen($mapelx['nama']) > 25) {
                                                                                    echo substr($mapelx['nama'], 0, 25) . "...";
                                                                                } else {
                                                                                    echo $mapelx['nama'];
                                                                                }
                                                                             ?>
																			   <img style="z-index: 800;position:absolute;margin-top:-55px;margin-left:90px" src="<?=$setting['logo'] ?>" alt="" width="60px">
																			 </span></center> 
                                                                      
                                                                    
																		<center> 	
                                                                    <span class="widget-list-item-description">
                                                                        <i class="fa fa-tag"></i> <?= $mapelx['kode_ujian'] ?> &nbsp;
                                                                        <i class="fa fa-user"></i> <?= $mapelx['level'] ?> &nbsp;
                                                                        <i class="fa fa-wrench"></i> <?php
                                                                                                        $dataArray = unserialize($mapelx['id_pk']);
                                                                                                        foreach ($dataArray as $key => $value) :
                                                                                                            echo "<small class='label label-success'>$value </small>&nbsp;";
                                                                                                        endforeach;
															 
                                                                                                        ?>
                                                                    </span></center>                                                                    	
                                                                </div>
																<div class="card-body">
                                                               <ul class="list-group list-group-flush">
                                                                 <li class="list-group-item"><i class='fa fa-clock'></i> Ujian Dimulai<span class="widget-list-item-description right"><?= $mapelx['tgl_ujian'] ?></span></li>
                                                                 <li class="list-group-item"><i class='fa fa-clock'></i> Ujian Ditutup<span class="widget-list-item-description right"><?= $mapelx['tgl_selesai'] ?></span></li>
                                                                 <li class="list-group-item"><i class='fa fa-hourglass'></i> Durasi Ujian<span class="widget-list-item-description right"><?= $mapelx['tampil_pg'] + $mapelx['tampil_esai'] + $mapelx['tampil_multi'] + $mapelx['tampil_bs'] + $mapelx['tampil_urut'];  ?> Soal / <?= $mapelx['lama_ujian'] ?> menit</span></li>
                                                                 <li class="list-group-item"><i class='fa fa-rss'></i> Status Ujian<span class="widget-list-item-description right">
																  <?php
                                                                                    if ($mapelx['status'] == 1) {
                                                                                        echo "<i class='fa fa-spinner fa-spin'></i> <label>Sedang Aktif</label> <label class='badge badge-primary'>Sesi $mapelx[sesi]</label>";
                                                                                    } elseif ($mapelx['status'] == 0) {
                                                                                        echo "<label class='badge bg-red'>Tidak Aktif</label>";
                                                                                    }
                                                                                    ?>
																 </span></li>
                                                                    <li class="list-group-item"><i class='fa fa-laptop'></i> Status Ujian<span class="widget-list-item-description right"><?= $status ?></span></li>
                                                                     <li class="list-group-item"><i class='fa fa-edit'></i> Jenis Soal<span class="widget-list-item-description right">
																	 <?php if($menu['soal']==1){ ?>
                                                                                <span class="pull-right"><?= $mapelx['groupsoal'] ?></span>
                                                                                <?php }else{ ?>
																				<span class="pull-right">CBT</span>
																				<?php } ?>
																	 
                                                                    </ul>
                                                                    <center style="padding: 8px">
                                                                        <?= $btntest ?>
                                                                    </center>			
																	 </div>
                                                                </div>
                                                            </div>
                                                        
                                                    <?php endif; ?>

                                                <?php endif; ?>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    <?php endwhile; ?>
                                </div>
                            </div>
                        </div>
                    </div>
				 
				
                    <script>
                        $(document).on('click', '.btnmulaitest', function() {
                            var idm = $(this).data('id');
                            var ids = $(this).data('ids');
                            console.log(idm + '-' + ids);

                            $.ajax({
                                type: 'POST',
                                url: 'konfirmasi.php',
                                data: 'idm=' + idm + '&ids=' + ids,
                                success: function(response) {
                                    $('#formjadwalujian').hide();
                                    $('#boxtampil').html(response).slideDown();

                                }
                            });

                        });
						$(document).on('click', '.btn-lanjut', function() {
                            var idn = $(this).data('id');
                             var ids = $(this).data('ids');
                            console.log(idn);
                                swal({
                                    title: 'Lanjut Ujian ?',
                                    html: 'Setiap mengulang jawaban dihapus!',
                                    type: 'warning',
                                    showCancelButton: true,
                                    confirmButtonColor: '#3085d6',
                                    cancelButtonColor: '#d33',
                                    confirmButtonText: 'Iya'
                                }).then((result) => {
                                    if (result.value) {
                                        $.ajax({
                                            type: 'POST',
                                            url: 'gantistatus.php?pg=ulangujian',
                                            data: 'id=' + idn + '&ids=' + ids,
                                            success: function(response) {
                                               location.reload();
                                            }
                                        });
                                    }
                                })
                           

                        });
						
                    </script>
				  <?php elseif ($pg == 'materi') : ?>
                    <?php include "materi.php" ?>
					 <?php elseif ($pg == 'tugassiswa') : ?>
                    <?php include "tugas.php" ?>
                <?php elseif ($pg == 'lihattugas') : ?>
                    <?php include "lihattugas.php" ?>
					 <?php elseif ($pg == 'soalquiz') : ?>
                    <?php include "soalquiz.php" ?>
                    <?php elseif ($pg == 'lihatmateri') : ?>
                    <?php include "lihatmateri.php" ?>
					<?php elseif ($pg == 'profilku') : ?>
                    <?php include "profilku.php" ?>
					
                <?php elseif ($pg == 'lihathasil') : ?>
                    <?php
                    $ac = dekripsi($ac);
                    $nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$id_siswa' and id_ujian='$ac'"));
                    if ($nilai['hasil'] == 1) :
                        $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal WHERE id_bank='$nilai[id_bank]'"));
                    ?>
                        <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"></i> Data Hasil Ujian</h5>
                                    </div>
                                    <div class='box-body'>
                                        <table class='table'>
                                            <tr>
                                                <th width='150'>No Induk</th>
                                                <td width='10'>:</td>
                                                <td><?= $siswa['nis'] ?></td>
                                                <td style="text-align:center; width:150">Nilai</td>
                                            </tr>
                                            <tr>
                                                <th>Nama</th>
                                                <td width='10'>:</td>
                                                <td><?= $siswa['nama'] ?></td>
                                                <td rowspan='4' style='font-size:30px; text-align:center; width:150'><?= $nilai['total'] ?></td>
                                            </tr>
                                            <tr>
                                                <th>Kelas</th>
                                                <td width='10'>:</td>
                                                <td><?= $siswa['id_kelas'] ?></td>
                                            </tr>
                                            <tr>
                                                <th>Mata Pelajaran</th>
                                                <td width='10'>:</td>
                                                <td><?= $mapel['nama'] ?></td>
                                            </tr>
                                            <tr>
                                                <th>Nama Ujian</th>
                                                <td width='10'>:</td>
                                                <td><?= $nilai['kode_ujian'] ?></td>
                                            </tr>
                                        </table>
                                        <div class="card-body">
                                        <div class="example-content">
                                                <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
                                                    <li class="nav-item" role="presentation">
                                                        <button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Hasil Jawaban</button>
                                                    </li>
                                                    <li class="nav-item" role="presentation">
                                                        <button class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Peringkat</button>
                                                    </li>
                                                   
                                                </ul>
                                                <div class="tab-content" id="pills-tabContent">
                                                    <div class="tab-pane fade active show" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
                                                    <div class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5%'>#</th>
                                                                    <th>Soal PG</th>

                                                                    <th style='text-align:center' width='10%'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php $jawaban = unserialize($nilai['jawaban']); ?>
                                                                <?php foreach ($jawaban as $key => $value) : ?>
                                                                    <?php
                                                                    $no++;
                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key'"));
                                                                    if ($value == $soal['jawaban']) :
                                                                        $status = "<span class='text-green'><i class='fa fa-check'></i></span>";
                                                                    else :
                                                                        $status = "<span class='text-red'><i class='fa fa-times'></i></span>";
                                                                    endif;
                                                                    ?>
                                                                    <tr>
                                                                        <td><?= $no ?></td>
                                                                        <td>
																		<?= $soal['soal'] ?>
																		</td>

                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
													
                                                    <?php if($menu['soal']==1): ?>
                                                    <div class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5px'>#</th>
                                                                    <th>Soal PG Kompleks</th>

                                                                    <th style='text-align:center'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php $jawabm = unserialize($nilai['jawaban_multi']); ?>
                                                                <?php foreach ($jawabm as $key => $value) : ?>
                                                                    <?php
                                                                    $no++;
                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key'"));
                                                                    if ($value == $soal['jawaban']) :
                                                                        $status = "<span class='text-green'><i class='fa fa-check'></i></span>";
                                                                    else :
                                                                        $status = "<span class='text-red'><i class='fa fa-times'></i></span>";
                                                                    endif;
                                                                    ?>
                                                                    <tr>
                                                                        <td><?= $no ?></td>
                                                                        <td><?= $soal['soal'] ?></td>

                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                
													
												 <div class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5px'>#</th>
                                                                    <th>Soal Benar Salah</th>

                                                                    <th style='text-align:center'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php $jawabbs = unserialize($nilai['jawaban_bs']); ?>
                                                                <?php foreach ($jawabbs as $key => $value) : ?>
                                                                    <?php
                                                                    $no++;
                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key'"));
                                                                    if ($value == $soal['jawaban']) :
                                                                        $status = "<span class='text-green'><i class='fa fa-check'></i></span>";
                                                                    else :
                                                                        $status = "<span class='text-red'><i class='fa fa-times'></i></span>";
                                                                    endif;
                                                                    ?>
                                                                    <tr>
                                                                        <td><?= $no ?></td>
                                                                        <td><?= $soal['soal'] ?></td>

                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                
												
												<div class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5px'>#</th>
                                                                    <th>Soal Mengurutkan</th>

                                                                    <th style='text-align:center'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php $jawabu = unserialize($nilai['jawaban_urut']); ?>
                                                                <?php foreach ($jawabu as $key => $value) : ?>
                                                                    <?php
                                                                    $no++;
                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key'"));
                                                                    if ($value == $soal['jawaban']) :
                                                                        $status = "<span class='text-green'><i class='fa fa-check'></i></span>";
                                                                    else :
                                                                        $status = "<span class='text-red'><i class='fa fa-times'></i></span>";
                                                                    endif;
                                                                    ?>
                                                                    <tr>
                                                                        <td><?= $no ?></td>
                                                                        <td><?= $soal['soal'] ?></td>

                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
													
												<div class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5%'>#</th>
                                                                    <th>Soal Isian Singkat</th>

                                                                    <th style='text-align:center' width='10%'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php $jawabe = unserialize($nilai['jawaban_esai']); ?>
                                                                <?php foreach ($jawabe as $key => $value) : ?>
                                                                    <?php
                                                                    $no++;
                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key'"));
                                                                    if ($value == $soal['jawaban']) :
                                                                        $status = "<span class='text-green'><i class='fa fa-check'></i></span>";
                                                                    else :
                                                                        $status = "<span class='text-red'><i class='fa fa-times'></i></span>";
                                                                    endif;
                                                                    ?>
                                                                    <tr>
                                                                        <td><?= $no ?></td>
                                                                        <td><?= $soal['soal'] ?></td>

                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
													
                                                
												<?php else: ?>
													<div class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5%'>#</th>
                                                                    <th>Soal Isian Singkat</th>

                                                                    <th style='text-align:center' width='10%'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                               
                                                                    <tr>
                                                                        <td></td>
                                                                        <td><b style="color:red">Masih dalam Koreksi oleh Petugas Ujian</b></td>
                                                                        <td style='text-align:center'></td>
                                                                    </tr>
                                                               
                                                            </tbody>
                                                        </table>
                                                    </div>
													
												<?php endif; ?>
												      </div>
                                                <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
                                                    <table class='table-responsive'>
                                                        <table id='example1' class='table'>
                                                            <thead>
                                                                <tr>
                                                                    <th style='text-align:center' width='5px'>Peringkat</th>
                                                                    <th>Nama Siswa</th>
                                                                    <th style='text-align:center'>Hasil</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php $nilaix = mysqli_query($koneksi, "SELECT * FROM nilai WHERE  id_ujian='$ac' order by cast(skor as decimal) DESC "); ?>
                                                                <?php $no = 0; ?>
                                                                <?php while ($peringkat = mysqli_fetch_array($nilaix)) : ?>
                                                                    <?php
                                                                    $no++;
                                                                    $siswa = mysqli_fetch_array(mysqli_query($koneksi, "select * from siswa where id_siswa='$peringkat[id_siswa]'"));
                                                                    if ($peringkat['id_siswa'] == $id_siswa) {
                                                                        $style = "style='color:blue;font-weight:bold;font-size:16px;'";
                                                                    } else {
                                                                        $style = "";
                                                                    }
                                                                    ?>
                                                                    <tr <?= $style ?>>
                                                                        <td style='text-align:center'><?= $no ?></td>
                                                                        <td><?= $siswa['nama'] ?></td>
                                                                        <td style='text-align:center'><?= 
																		$peringkat['total']
																		?></td>
                                                                    </tr>
                                                                <?php endwhile; ?>
                                                            </tbody>
                                                        </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php else : ?>
                        <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"></i> Data Hasil Ujian</h5>
                                    </div>
                                    <div class='box-body'>
                                         <div class="alert alert-custom" role="alert">
                                                    <div class="custom-alert-icon icon-dark"><i class="fa fa-check fa-2x"></i></div>
                                                    <div class="alert-content">
                                                        <span class="alert-title"><h5 style="font-size:18px;font-weight:bold;" id="jam"></h5></span>
                                                        <span class="alert-text"> Maaf untuk hasil nilai belum dapat dilihat, akan diproses terlebih dahulu,,</span>
                                                    </div>
                                                </div>
                                            </div>
                            </div>
                        </div>
                    <?php endif; ?>

                <?php elseif ($pg == 'hasil') : ?>
                    <div class='row'>
                        <div class='col-md-12'>
                            <div class="card">
                               <div class="card-header">	
                                    <h5 class='box-title'><i class="fas fa-file-signature"></i> Data Nilai</h5>
                                </div>
                               <div class="box-body">
                                         <div class="example-container">
                                            <div class="example-content">
                                                <ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
                                                    <li class="nav-item" role="presentation">
                                                        <button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Nilai Ujian</button>
                                                    </li>
                                                    <li class="nav-item" role="presentation">
                                                        <button class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Nilai Tugas</button>
                                                    </li>
                                                    <li class="nav-item" role="presentation">
                                                        <button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Nilai Quiz</button>
                                                    </li>
                                                </ul>
                                                <div class="tab-content" id="pills-tabContent">
                                                    <div class="tab-pane fade active show" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
                                             
												<table id='example1' class='table'>
                                                    <thead>
                                                        <tr>
                                                            <th width='5px'>#</th>
                                                            <th>Kode Tes</th>
                                                            <th class='hidden-xs'>Ujian Selesai</th>
                                                           
                                                            <th>View</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $nilaix = mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$id_siswa' AND ujian_selesai <>'' ORDER BY ujian_selesai ASC "); ?>
                                                        <?php while ($nilai = mysqli_fetch_array($nilaix)) : ?>
                                                            <?php
                                                            $no++;
                                                            $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal WHERE id_bank='$nilai[id_bank]'"));
                                                            $namamapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE kode_mapel='$mapel[nama]'"));
                                                            ?>
                                                            <tr>
                                                                <td><?= $no ?></td>
                                                                <td><?= $mapel['nama'] ?></td>
                                                                <td class='hidden-xs'><?= $nilai['ujian_selesai'] ?></td>
                                                                
                                                                <td>
                                                                    <a href="<?= $homeurl . '/lihathasil/' . enkripsi($nilai['id_ujian']) ?>"><button class='btn btn-sm btn-outline-primary'>Lihat Nilai</button></a>
																	 
																</td>
                                                            </tr>
                                                        <?php endwhile; ?>
                                                    </tbody>
                                                </table>
                                            </div>
										
                                         <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">
                                                <table id='example1' class='table table-bordered table-striped'>
                                                    <thead>
                                                        <tr>
                                                            <th width='5px'>#</th>
                                                            <th>Nama Mapel</th>
                                                            
                                                            <th class='hidden-xs'>Update Dikerjakan</th>
                                                            <th>Nilai</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $tugasx = mysqli_query($koneksi, "SELECT * FROM jawaban_tugas WHERE id_siswa='$id_siswa' "); ?>
                                                        <?php while ($tugas = mysqli_fetch_array($tugasx)) : ?>
                                                            <?php
                                                            $nox++;
                                                            $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tugas WHERE id_tugas='$tugas[id_tugas]'"));
                                                            
                                                            ?>
                                                            <tr>
                                                                <td><?= $nox ?></td>
                                                                <td><?= $mapel['mapel'] ?></td>
                                                                <td class='hidden-xs'><?= $tugas['tgl_update'] ?></td>
                                                                <td ><label class='label label-primary'><?= $tugas['nilai']?></label></td>
                                                                
                                                            </tr>
                                                        <?php endwhile; ?>
                                                    </tbody>
                                                </table>
                                            </div>
											
											 <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">
                                                <table id='example1' class='table table-bordered table-striped'>
                                                    <thead>
                                                        <tr>
                                                            <th width='5px'>#</th>
                                                            <th>Nama Mapel</th>
                                                            
                                                            <th class='hidden-xs'>Update Dikerjakan</th>
                                                            <th>Nilai</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $tugasx = mysqli_query($koneksi, "SELECT * FROM nilaiquiz WHERE idsiswa='$id_siswa' "); ?>
                                                        <?php while ($nilai = mysqli_fetch_array($tugasx)) : ?>
                                                            <?php
                                                            $nox++;
                                                            $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM materi WHERE id_materi='$nilai[idmateri]'"));
                                                            
                                                            ?>
                                                            <tr>
                                                                <td><?= $nox ?></td>
                                                                <td><?= $mapel['mapel'] ?></td>
                                                                <td class='hidden-xs'><?= $nilai['tgl'] ?></td>
                                                                <td ><label class='label label-primary'><?= $nilai['nilai']?></label></td>
                                                                
                                                            </tr>
                                                        <?php endwhile; ?>
                                                    </tbody>
                                                </table>
                                            </div>
											 </div>
											
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
					
				  <?php elseif ($pg == 'testongoing') : ?>
				
                    <?php
                    $ac = dekripsi($ac);
                    $id = dekripsi($id);
                    $qcek = mysqli_query($koneksi, "select * from nilai where id_ujian='$ac' and id_siswa='$id'");
                    $cek = mysqli_num_rows($qcek);
                    if ($cek <> 0) :
                        $query = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM ujian WHERE id_ujian='$ac'"));
                        $idmapel = $query['id_bank'];
                        $no_soal = 0;
                        $no_prev = $no_soal - 1;
                        $no_next = $no_soal + 1;
                        $id_bank = $idmapel;
                        $id_siswa = $id;
                        $where = array(
                            'id_siswa' => $id_siswa,
                            'id_bank' => $id_bank
                        );
                        $where2 = array(
                            'id_siswa' => $id_siswa,
                            'id_bank' => $id_bank,
                            'id_ujian' => $ac
                        );

                        $mapel = fetch($koneksi, 'ujian', array('id_bank' => $id_bank, 'id_ujian' => $ac));
                        update($koneksi, 'nilai', array('ujian_berlangsung' => $datetime), $where2);
                        $nilai = fetch($koneksi, 'nilai', $where2);
                        $habis = strtotime($nilai['ujian_berlangsung']) - strtotime($nilai['ujian_mulai']);
                        $detik = ($mapel['lama_ujian'] * 60) - $habis;
                        $dtk = $detik % 60;
                        $mnt = floor(($detik % 3600) / 60);
                        $jam = floor(($detik % 86400) / 3600);
                        
                        $cekpg = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank' AND jenis='1'"));
                        $cekesai = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank' AND jenis='2'"));
                       $cekmulti = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank' AND jenis='3'"));
					  $cekbs = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank' AND jenis='4'"));
					  $cekurut = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank' AND jenis='5'"));
					  $quero = mysqli_fetch_array(mysqli_query($koneksi, "SELECT tampil_pg,tampil_esai,tampil_multi,tampil_bs,tampil_urut FROM banksoal WHERE id_bank='$id_bank'"));

                        if ($cekpg >= $quero['tampil_pg']) {
                            $soalpg = $quero['tampil_pg'];
                        } else {
                            $soalpg = $cekpg;
                        }
                        if ($cekesai >= $quero['tampil_esai']) {
                            $soalesai = $quero['tampil_esai'];
                        } else {
                            $soalpg = $cekesai;
                        }
						if ($cekmulti >= $quero['tampil_multi']) {
                             $soalmulti = $quero['tampil_multi'];
                      } else {
                     $soalpg = $cekmulti;
                       }
					   if ($cekbs >= $quero['tampil_bs']) {
                             $soalbs = $quero['tampil_bs'];
                      } else {
                     $soalpg = $cekbs;
                       }
					   if ($cekurut >= $quero['tampil_urut']) {
                             $soalurut = $quero['tampil_urut'];
                      } else {
                     $soalpg = $cekurut;
                       }
					   
                       $jumsoal = $soalpg + $soalesai + $soalmulti  + $soalbs + $soalurut;
                      
                    ?>
					
                        <div class='row'>
                            <div class="col-md-1"></div>
                            <div class='col-md-10' >
							
                                <div class='box box-solid' style="box-shadow: 0 1px 15px 5px rgba(0, 0, 0, 0.25);">
                                    <div class='box-header with-border' >

                                        <h3 class='box-title'><span class='hidden-xs'>SOAL NOMOR </span> <span class='btn bg-green' id='displaynum'><b><?= $no_next ?></b></span></h3>

                                        <div class='box-title pull-right'>

                                            <div class='btn btn-default'>
                                                <span style="font-size:12px">Sisa Waktu </span><span style="font-size:18px" id='countdown'> <span id='htmljam'><?= $jam ?></span>:<span id='htmlmnt'><?= $mnt ?></span>:<span id='htmldtk'><?= $dtk ?></span></span>
                                            </div>
                                            <div class='btn-group'>
                                                <form action='' method='post'>
                                                    <input type='submit' name='done' id='done-submit' style='display:none;' />
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="box-header with-border bg-gray">

                                        <div class='btn-group'>
                                            <button type='button' id='smaller_font' class='btn bg-purple'> - </button>
                                            <button type='button' id='reset_font' class='btn bg-purple'><i class='fa fa-sync-alt'></i></button>
                                            <button type='button' id='bigger_font' class='btn bg-purple'> + </button>
                                        </div>
                                        <div class='box-title pull-right'>

                                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modalnosoal">Daftar Soal <i class="fas fa-edit    "></i></button>
                                            <!-- Button trigger modal -->

                                            <!-- Modal -->
                                            <div class="modal fade" id="modalnosoal" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                                <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <h5 class="modal-title"><i class="fas fa-edit    "></i> Daftar Soal</h5>

                                                        </div>
                                                        <div class="modal-body">
                                                            <div id="loadnosoal">

                                                            </div>

                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fas fa-times    "></i></button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div id='loadsoal' >
                                         <div id='loading-image'>
                                            <center>
                                                <img src="<?=$homeurl ?>/dist/img/loader.gif" class="img-fluid" width="150">
                                                <br><b>Sedang memproses soal..</b>
                                                <br><b>jika terlalu lama silahkan logout dan login lagi</b>
                                                <br><b>cek koneksi internet buka menggunakan chrome</b>
                                            </center>
                                        </div>
                                    </div>

                                </div>
                            </div>
                  
                        </div>
					
                    <?php else : ?>
                        <?php jump($homeurl); ?>
                    <?php endif; ?>
                <?php else : ?>
                    <?php jump($homeurl); ?>
                <?php endif; ?>
            </section>
        </div>
       
    </div>
	 <?php if ($pg == 'testongoing'): ?>
	 	<?php else: ?>
<div class="footer hidden-lg">
<a href="<?= $homeurl ?>" class="btn btn-sm btn-outline-default"><i class="fa fa-home"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<?= $homeurl ?>/profilku" class="btn btn-sm btn-outline-default"><i class="fa fa-users-cog"></i></a>&nbsp;&nbsp;&nbsp;
<a href="<?= $homeurl ?>/pengumuman" class="btn btn-sm btn-outline-default"><i class="fa fa-bell"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="logout.php" class="btn btn-sm btn-outline-default"><i class="fa fa-sign-in-alt"></i>Logout</a>
</div>
<?php endif; ?>
    <?php if ($pg == 'testongoing'): ?>
  <?php include"bawahcbt.php"; ?>
	<?php else: ?>
   <?php include"bawah.php"; ?>
	<?php endif; ?>
	
	