<?php
require("config/koneksi.php");
require("config/function.php");
require("config/crud.php");
require("config/apk.php");
(isset($_SESSION['id_siswa'])) ? $id_siswa = $_SESSION['id_siswa'] : $id_siswa = 0;
($id_siswa == 0) ?  header("Location:$homeurl/login.php") : null;

$siswa = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_siswa='$id_siswa'"));
$idsesi = $siswa['sesi'];
$idpk = $siswa['pk'];
$level = $siswa['level'];
$pk = fetch($koneksi, 'pk', array('id_pk' => $idpk));
$tglsekarang = time();
(isset($_GET['pg'])) ? $pg = $_GET['pg'] : $pg = '';

if ($pg == '') :
	$sidebar = 'sidebar-collapse';
elseif ($pg == 'jadwal') :
	$sidebar = 'sidebar-collapse';
elseif ($pg == 'testongoing') :
	$sidebar = 'sidebar-collapse';
elseif ($pg == 'skl') :
	$sidebar = 'sidebar-collapse';
else :
	$sidebar = '';
endif;
($pg == 'testongoing') ? $disa = '' : $disa = 'offcanvas';
$token = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM token"));
$nilsis = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$id_siswa' AND browser='0'"));
$skl = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM skl  WHERE id_skl='1'"));
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
   <meta name="description" content="CBT Server All in One">
    <meta name="keywords" content="CBT Server All in One">
    <meta name="author" content="cbtserver.com">
   
    <title><?= $setting['aplikasi'] ?></title>
    <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' />
    <link rel='shortcut icon' href='images/<?= $setting['logo'] ?>' />
    <link rel='stylesheet' href='vendor/css/bootstrap.min.css' />
    <link rel='stylesheet' href='vendor/fontawesome/css/all.css' />
    <link rel='stylesheet' href='vendor/css/AdminLTE.min.css' />
    <link rel='stylesheet' href='vendor/css/skins/skin-green-light.min.css' />
    <link rel='stylesheet' href='vendor/iCheck/square/green.css' />   
    <link rel="stylesheet" href="assets/css/sweetalert2.min.css">	
    <link rel='stylesheet' href='assets/toastr/toastr.min.css'>
   <link rel='stylesheet' href='assets/radio/css/style.css'>
    <link rel='stylesheet' href='assets/izitoast/css/iziToast.min.css'>
    <script src="assets/plugins/jquery/jquery-3.5.1.min.js"></script>
	<script type="text/javascript" src="assets/inc/TimeCircles.js"></script>
    <link rel="stylesheet" href="assets/inc/TimeCircles.css" />
    <link rel="stylesheet" type="text/css" href="assets/animate/animate.css">
    <link rel='stylesheet' href='vendor/css/costum.css' />
   <link rel='stylesheet' href='vendor/css/kostum.css'>
   <style>
   .edis {
  background-size: 260px;
  background-image: url('images/tutwuri2.png');
  background-repeat: no-repeat;
  background-position: top right; 
}
</style>
</head>

<body class='hold-transition skin-green-light  fixed <?= $sidebar ?>'>
    <span id='livetime'></span>
  
    <div class='wrapper'>
        <header class='main-header'>
			 
            <nav class='navbar navbar-static-top' style='background-color:#2c94de;box-shadow: 0px 10px 10px 0px rgba(0,0,0,0.1)' role='navigation'>
                <a href='#' class='sidebar-baru' data-toggle='<?= $disa ?>' role='button'>
                    <i class="fa fa-bars fa-lg fa-fw"></i>
                </a>

                <div class='navbar-custom-menu'>
                    <ul class='nav navbar-nav'>
                        <li class="visible-xs"><a><?= $siswa['nama'] ?></a></li>
                        <li class='dropdown user user-menu'>
                            <a href='#' class='dropdown-toggle' data-toggle='dropdown'>
                                <?php
                                if ($siswa['foto'] <> '') :
                                    if (!file_exists("images/fotosiswa/$siswa[foto]")) :
                                        echo "<img src='images/user.png' class='user-image'   alt='+'>";
                                    else :
                                        echo "<img src='foto/fotosiswa/$siswa[foto]' class='user-image'   alt='+'>";
                                    endif;
                                else :
                                    echo "<img src='images/user.png' class='user-image'   alt='+'>";
                                endif;
                                ?>
                                <span class='hidden-xs' style="color:#fff;"><?= $siswa['nama'] ?> &nbsp; <i class='fa fa-caret-down'></i></span>
                            </a>
                            <ul class='dropdown-menu'>
                                <li class='user-header bg-blue'>
                                    <?php
                                    if ($siswa['foto'] <> '') :
                                        if (!file_exists("images/fotosiswa/$siswa[foto]")) :
                                            echo "<img src='images/user.png' class='img-circle' alt='User Image'>";
                                        else :
                                            echo "<img src='foto/fotosiswa/$siswa[foto]' class='img-circle' alt='User Image'>";
                                        endif;
                                    else :
                                        echo "<img src='images/user.png' class='img-circle' alt='User Image'>";
                                    endif;
                                    ?>
                                    <p style="color:#fff">
                                        <?= $siswa['nama'] ?>
                                    </p>
                                </li>
                                <li class='user-footer'>
                                    <div class='pull-right'>
									<?php if($pg !='testongoing'): ?>
                                        <a href='logout.php' class='btn btn-sm btn-default btn-flat'><i class='fa fa-sign-out'></i> Keluar</a>
										
                                   <?php endif; ?>
								   </div>
                                </li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </nav>
        </header>
        <aside class='main-sidebar'>
            <section class='sidebar'>
                <hr style="margin:0px">
                <div class='user-panel'>
                    <div class='pull-left image'>
                        <?php
                        if ($siswa['foto'] <> '') :
                            if (!file_exists("images/fotosiswa/$siswa[foto]")) :
                                echo "<img src='images/user.png' class='img'  style='max-width:60px' alt='+'>";
                            else :
                                echo "<img src='foto/fotosiswa/$siswa[foto]' class='img'  style='max-width:60px' alt='+'>";
                            endif;
                        else :
                            echo "<img src='images/user.png' class='img'  style='max-width:60px' alt='+'>";
                        endif;
                        ?>
                    </div>
                    <div class='pull-left info' style='left:65px'>
                        <?php
                        if (strlen($siswa['nama']) > 15) {
                            $nama = substr($siswa['nama'], 0, 15) . "...";
                        } else {
                            $nama = $siswa['nama'];
                        }
                        ?>
                        <p title="<?= $siswa['nama'] ?>"><?= $nama ?></p>
                        <p><a href='#'><i class='fa fa-circle text-green'></i> online</a>
                        <p><span class="badge bg-red"><?=$siswa['pk']?></span> <span class="badge bg-green"><?=$siswa['kelas']?></span></p>
                    </div>
                </div><br>
                <hr style="margin:0px">
                <ul class='sidebar-menu tree' data-widget='tree'>
				<br>
                    <li>&nbsp;&nbsp;<b>Menu Peserta Ujian</b></li>
					<br>
                    <li><a href='.'><i class='fas fa-tachometer-alt fa-fw'></i> <span> Dashboard</span></a></li>
					 <li><a href='?pg=hasil'><i class='fas fa-edit fa-fw'></i> <span> Hasil Ujian</span></a></li>
					 <li><a href='?pg=materi'><i class='fas fa-wifi fa-fw'></i> <span> Materi Belajar</span></a></li>
					  <li><a href='?pg=tugas'><i class='fas fa-rss fa-fw'></i> <span> Tugas Belajar</span></a></li>
			   </ul>
            </section>
        </aside>
        <div class='content-wrapper'>
            <section class='content-header' style="height:100px;z-index:0;background:#0979c7">
            </section>
            <section class='content' style="margin-top:-95px">

                <?php if ($pg == '') : ?>
         <
             <?php if($nilsis >=1){ ?>
				<script>
				$(function() {
				$("#myModal").modal();
				});
				</script>

			  <div class="modal fade" id="myModal" role="dialog">
				<div class="modal-dialog">

				  <!-- Modal content-->
				  <div class="modal-content">
					<div class="modal-header">
					  <button type="button" class="close" data-dismiss="modal">&times;</button>
					  <h4 class="modal-title">INFORMASI</h4>
					</div>
					<div class="modal-body">
					  <p>Anda terdeteksi keluar dari aplikasi, Untuk melanjutkan Ujian silahkan Hubungi Proktor / Admin</p>
					</div>
					<div class="modal-footer">
					  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					</div>
				  </div>

				</div>
			  </div>

				<?php } ?>


			<div class='col-md-7'>		
		<div class='box box-solid'>
            <div class='box-body'>
		  <div> 
		   TOKEN  <a href="#" class="btn btn-sm btn-warning"><?= $token['token'] ?></a>
		    <?php if($siswa['level']==$skl['tingkat']): ?>
		   <a href="?pg=skl" class="btn btn-sm btn-link">SKL</a>
		    <?php endif; ?>
			
		 <?php if($nilsis >= 1): ?>
		  <?php $reset = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$id_siswa' AND ujian_selesai<>'' AND browser='0' ORDER BY id_nilai DESC LIMIT 1"));?> 
		  <a href="?pg=mintareset&idn=<?= $reset['id_nilai'] ?>" class="btn btn-danger btn-round btn-sm pull-right">Minta Reset</a>
		  <?php endif; ?>
		  </div>
		</div>
	</div>
			
	                        <div class='box box-solid'>
                                <div class='box-header with-border'>
                                    <h3 class='box-title'><i class="fas fa-bell"></i> Informasi</h3>
                                </div>
                                <div class='box-body'>
                                    <div id='pengumuman'>
                                   <?php $logC = 0;
                                        echo "<ul class='timeline'><br>";
                                        $logQ = mysqli_query($koneksi, "SELECT * FROM informasi where untuk='0' ORDER BY id DESC LIMIT 1");

                                        while ($log = mysqli_fetch_array($logQ)) {
                                            $logC++;
                                           
                                            if ($log['untuk'] == '0') {
                                                $bg = 'bg-blue';
                                                $color = 'text-blue';
                                            } 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> " .$log['waktu'] . " <i class='fa fa-clock-o'></i> Admin</span>
                                                        <h3 class='timeline-header' style='background-color:#f9f0d5'><a class='$color' href='#'>$log[judul]</a> <small></small>
                                                        
                                                        </h3>
                                                        <div class='timeline-body'>
                                                        " . ucfirst($log['isi']) . "	
                                                        </div>
                                                        
                                                        </div>
                                                        </li>
                                            
                                                        
                                                    ";
                                        }
                                        if ($logC == 0) {
                                            echo "<p class='text-center'>Tidak ada informasi.</p>";
                                        }
                                        echo "</ul>";?>
                                    </div>
                                </div>
                            </div>
                        </div>

	<div class="col-sm-5" >
	<div class='box box-solid' >
          
			<div class='box-body' >
		<div class="edis">
		  <div style="font-size:20px"><i class="fas fa-graduation-cap"></i> Konfirmasi data Peserta</div>
		  <form method="post" action="" enctype="multipart/form-data">
				<div class="form-group-sm">
					<label><b>Kode Peserta</b></label> 
					<input type="text" class="form-control"   value="<?= $siswa['no_peserta'] ?>" required >
				</div>
				<div class="form-group-sm">
					<label><b>Nama Peserta</b></label> 
					<input type="text" class="form-control"  value="<?= $siswa['nama'] ?>" required >
				</div>			
				<div class="form-group-sm">
					<label><b>Mata Ujian</b></label> 
					<input type="text" class="form-control" value="Literasi - Numerasi | <?= $setting['sekolah'] ?>" readonly="true">
				</div>
				<div class="form-group-sm">
					<label><b>Token</b></label> 
					<input type="text" class="form-control" placeholder="Ketikkan token di sini"  value="<?= $token['token'] ?>" name="token" readonly="true">
				</div>
				<div class="form-group-sm">
					<label><b>Jenis Kelamin</b></label> 
					<select class="form-control" name="jenis_kelamin" required>
					        <option value=""></option>
							<option value="L">Laki-Laki</option>
							<option value="P">Perempuan</option>
						</select>
				</div>
				<br>
				
			  <button type="submit" class="btn btn-primary btn-round form-control mt-5"  name="btnsubmit">Submit</button>
			</form> 
			<br><br>
		</div>
    </div>
	 
  </div> 
</div>
 <?php            
 
 if (isset($_POST['btnsubmit'])) {
$jk = $_POST['jenis_kelamin'];
$tken = $_POST['token'];
$cekdata = "SELECT * FROM token WHERE  token='$tken' ";
$jikaada = mysqli_query($koneksi,$cekdata);
if(mysqli_num_rows($jikaada)>0){
	
	echo "
	  <script type='text/javascript'>
		setTimeout(function () { 	
			swal({
				title: 'Sukses !!!',
				text:  'Selamat melaksanakan Ujian',
				type: 'success',
				timer: 2000,
				showConfirmButton: true
			});		
		},10);	
		window.setTimeout(function(){ 
			window.location.replace('?pg=jadwal');
		} ,2000);	
	  </script>";
}else{
	echo"
	<script type='text/javascript'>
		setTimeout(function () { 	
			swal({
				title: 'Gagal !!!',
				text:  'Token Salah',
				type: 'error',
				timer: 2000,
				showConfirmButton: true
			});		
		},10);	
		window.setTimeout(function(){ 
			window.location.replace('.');
		} ,2000);	
	  </script>";
}
 }
?>				
		<?php elseif ($pg == 'materi') : ?>
		<?php include"materi.php"; ?>
		<?php elseif ($pg == 'lihatmateri') : ?>
		<?php include"lihatmateri.php"; ?>
		<?php elseif ($pg == 'tugas') : ?>
		<?php include"tugas.php"; ?>
		<?php elseif ($pg == 'lihattugas') : ?>
		<?php include"lihattugas.php"; ?>
                <?php elseif ($pg == 'jadwal') : ?>
					<div class='row'>
                        <div class='col-md-12'>
                            <div class='alert alert-info alert-dismissible'>
                                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
                                <i class='icon fa fa-info'></i>
                                Tombol ujian akan aktif bila waktu sudah sama dengan jadwal ujian,
                                Refresh browser atau tekan F5 jika waktu ujian belum aktif
                                </div>
                        </div>
                        <div id="boxtampil" class='col-md-12'>
                            <div id='formjadwalujian' class='box box-solid'>
                                <div class='box-header with-border'>
                                    <h3 class='box-title'><i class="fas fa-calendar-alt"></i> Jadwal Asesmen Hari ini</h3>
                               <div class='box-tools'>
                                        <button class='btn btn-flat btn-primary'><span id='waktu' style="font-family:'OCR A Extended'"><?= $waktu ?> </span></button>
                                    </div> 
                                </div>
                                <div class='box-body'>
                                    <?php

                                    $mapelQ = mysqli_query($koneksi, "SELECT * FROM ujian WHERE level='$level'  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 $datalevel = $mapelx['level']; ?>
                                            <?php $datakelas = unserialize($mapelx['kelas']); ?>
                                                <?php if ($siswa['level']==$datalevel) : ?>   
                                            <?php if (in_array($siswa['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-primary'><i class='fa fa-edit'></i> MULAI</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-danger disabled'> BELUM UJIAN</button>";
                                                        else :
                                                            $status = '<label class="label label-danger">Telat Ujian</label>';
                                                            $btntest = "<button' class='btn btn-block btn-sm btn-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-success'><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-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-success'><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-success btn-sm disabled'> Sudah Ujian</button>";
                                                                }else{
                                                                    if($nilai['skor']>=$mapelx['kkm']){
                                                                        $btntest = "<button class='btn btn-success btn-block btn-sm '>Kamu Lulus - Skor : ".$nilai['skor']."</button>";  
                                                                    } else{
                                                                        $btntest = "<button data-id='".$nilai['id_nilai']."' class='btn btn-ulang btn-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 animated tada" >
                                                                <div class="box box-widget widget-user-2">
                                                                   
                                                                    <div class="widget-user-header" style="padding: 6px">
                                                                        <div class="widget-user-image">
                                                                            <img src="images/pdf.png" alt="">
                                                                        </div>
                                                                       
                                                                        <h3 class="widget-user-username">
                                                                             <?php
                                                                                if (strlen($mapelx['nama']) > 10) {
                                                                                    echo substr($mapelx['nama'], 0, 10) . "...";
                                                                                } else {
                                                                                    echo $mapelx['nama'];
                                                                                }
                                                                             ?>
                                                                        </h3>
                                                                        <h5 class="widget-user-desc">
                                                                            <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['kelas']);
                                                                                                            foreach ($dataArray as $key => $value) :
                                                                                                                echo "<small class='label label-success'>$value </small>&nbsp;";
                                                                                                            endforeach;

                                                                                                            ?>
                                                                        </h5>
                                                                    </div>
                                                                    <div class="box-footer no-padding" style="background-color:white">
                                                                        <ul class="nav nav-stacked">
                                                                            <li>
                                                                                <a href="#">
                                                                                    <i class='fa fa-clock-o'></i> Ujian Dimulai
                                                                                    <span class="pull-right"><?= $mapelx['tgl_ujian'] ?></span>
                                                                                </a>
                                                                            </li>
                                                                            <li>
                                                                                <a href="#">
                                                                                    <i class='fa fa-clock-o'></i> Ujian Ditutup
                                                                                    <span class="pull-right"><?= $mapelx['tgl_selesai'] ?></span>
                                                                                </a>
                                                                            </li>
                                                                            <li>
                                                                                <a href="#">
                                                                                    <i class='fa  fa-hourglass-1'></i> Durasi Ujian
                                                                                    <span class="pull-right"><?= $mapelx['tampil_pg'] + $mapelx['tampil_esai'] + $mapelx['tampil_multi'] + $mapelx['tampil_bs'] + $mapelx['tampil_urut'];  ?> Soal / <?= $mapelx['lama_ujian'] ?> menit</span>
                                                                                </a>
                                                                            </li>
                                                                            <li><a href="#"><i class='fa fa-feed'></i> Status Ujian <span class="pull-right">
                                                                                        <?php
                                                                                        if ($mapelx['status'] == 1) {
                                                                                            echo "<i class='fa fa-spinner fa-spin'></i> <label>Sedang Aktif</label> <label class='badge bg-red'>Sesi $mapelx[sesi]</label>";
                                                                                        } elseif ($mapelx['status'] == 0) {
                                                                                            echo "<label class='badge bg-red'>Tidak Aktif</label>";
                                                                                        }
                                                                                        ?>
                                                                                    </span></a></li>
                                                                            <li>
                                                                                <a href="#">
                                                                                    <i class='fa  fa-hourglass-1'></i> Status Test
                                                                                    <span class="pull-right"><?= $status ?></span>
                                                                                </a>
                                                                            </li>
																			
                                                                        </ul>
                                                                        <center style="padding: 8px">
                                                                            <?= $btntest ?>
                                                                        </center>
                                                                    </div>
                                                                </div>
                                                                
                                                            </div>
                                                        <?php endif; ?>
                                                    <?php else : ?>
                                                        <div class="col-md-4 animated tada">

                                                            <div class="box box-widget widget-user-2">
                                                            
                                                                <div class="widget-user-header" style="padding: 6px">
                                                                    <div class="widget-user-image">
                                                                        <img src="images/pdf.png" alt="">
                                                                    </div>
                                                                   
                                                                    <center><h5 class="widget-user-usernam"><?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:-10px;margin-left:50px" src="<?=$setting['logo'] ?>" alt="" width="65">
																			 </h5> </center>
                                                                      
                                                                    
																			
                                                                    <h5 class="widget-user-desc">
                                                                        <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['kelas']);
                                                                                                        foreach ($dataArray as $key => $value) :
                                                                                                            echo "<small class='label label-success'>$value </small>&nbsp;";
                                                                                                        endforeach;
															 
                                                                                                        ?>
                                                                    </h5>
															  
                                                                      
                                                                   	
                                                                </div>
                                                                <div class="box-footer no-padding" style="background-color:white">
                                                                    <ul class="nav nav-stacked" style="background-color:white">
                                                                        <li>
                                                                            <a href="#">
                                                                                <i class='fa fa-clock-o'></i> Ujian Dimulai
                                                                                <span class="pull-right"><?= $mapelx['tgl_ujian'] ?></span>
                                                                            </a>
                                                                        </li>
                                                                        <li>
                                                                            <a href="#">
                                                                                <i class='fa fa-clock-o'></i> Ujian Ditutup
                                                                                <span class="pull-right"><?= $mapelx['tgl_selesai'] ?></span>
                                                                            </a>
                                                                        </li>
                                                                        <li>
                                                                            <a href="#">
                                                                                <i class='fa  fa-hourglass-1'></i> Durasi Ujian
                                                                                <span class="pull-right"><?= $mapelx['tampil_pg'] + $mapelx['tampil_esai'] + $mapelx['tampil_multi'] + $mapelx['tampil_bs'] + $mapelx['tampil_urut'];  ?> Soal / <?= $mapelx['lama_ujian'] ?> menit</span>
                                                                            </a>
                                                                        </li>
                                                                        <li><a href="#"><i class='fa fa-feed'></i> Status Ujian <span class="pull-right">
                                                                                    <?php
                                                                                    if ($mapelx['status'] == 1) {
                                                                                        echo "<i class='fa fa-spinner fa-spin'></i> <label>Sedang Aktif</label> <label class='badge bg-red'>Sesi $mapelx[sesi]</label>";
                                                                                    } elseif ($mapelx['status'] == 0) {
                                                                                        echo "<label class='badge bg-red'>Tidak Aktif</label>";
                                                                                    }
                                                                                    ?>
                                                                                </span></a></li>
                                                                        <li>
                                                                            <a href="#">
                                                                                <i class='fa  fa-hourglass-1'></i> Status Test
                                                                                <span class="pull-right"><?= $status ?></span>
                                                                            </a>
                                                                        </li>                                                                
														                 
                                                                    </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: 'Anda telah keluar dari Aplikasi Jawaban akan dihapus semua oleh sistem !',
                                    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 == 'mintareset') : ?>
 <div class="row">                   
<div class="col-md-3"></div>
<div class="col-md-6">
 <div class='box box-solid' style="box-shadow: 0 1px 15px 5px rgba(0, 0, 0, 0.25);">
   <div class='box-header with-border' >
   </div>
      <center>
	 	<div id='progressbox'></div>
	  <p>
	
<h4 style="color:red">PERMINTAAN RESET</h4>
 </center>
 
	<div class="box-body">
	<?php 
	$renilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_nilai='$_GET[idn]'")); 
	$rebank = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal WHERE id_bank='$renilai[id_bank]'"));
 $remap = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE kode='$rebank[nama]'")); 	
	?>
		  <form id="formreset">
                 <input type="hidden" class="form-control" name="idu"  value="<?= $renilai['id_ujian'] ?>" readonly>
				 <input type="hidden" class="form-control" name="idn"  value="<?= $_GET['idn'] ?>" readonly>
                      <div class="form-group-sm">
                            <label>Nama Siswa</label>
                            <input type="text" class="form-control" name="nama"  value="<?= $siswa['nama'] ?>" required >
                        </div> 
						 <div class="form-group-sm">
                            <label>Mapel Ujian</label>
                            <input type="text" class="form-control" name="mapel"  value="<?= $remap['nama_mapel'] ?>" required >
                        </div> 
                      
					
					<br>
					
		        <button type="submit" class="btn btn-primary btn-round form-control" id="submit" style="border-radius:20px" >KIRIM PERMINTAAN</button>
					
		
		</form> 
    </div>
	</div>
  </div> 
</div>
<script>
    $('#formreset').submit(function(e){
    e.preventDefault();
    var data = new FormData(this);
    $.ajax(
    {
        method: "POST",
        url: 'reset.php',
        enctype: 'multipart/form-data',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
       beforeSend: function() {
                $('#progressbox').html('<div><label class="kedip" style="color:blue;margin-left:10px;">Data sedang di proses</label>&nbsp;&nbsp;&nbsp;<img src="images/animasi1.gif" ></div>');
                $('.progress-bar').animate({
                    width: "30%"
                }, 1000);
            },
			success: function(data){ 
            setTimeout(function()
            {
                window.location.replace('?pg=cekreset&idn=<?= $_GET[idn] ?>');
            }, 2000);
		  
        }
    });
    return false;
});
</script>	
	         <?php elseif ($pg == 'cekreset') : ?>
						 <div class="row">                   
						<div class="col-md-3"></div>
						<div class="col-md-6">
						 <div class='box box-solid' style="box-shadow: 0 1px 15px 5px rgba(0, 0, 0, 0.25);">
						   <div class='box-header with-border' >
						   </div>
							  <center>
						<div id='progressbox'></div>
							<p>
							 
						<h4 style="color:red">CEK DATA RESET</h4>
						 </center>
						 <hr>
							<div class="box-body">
							<?php 
						$renilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_nilai='$_GET[idn]'")); 
						$rebank = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal WHERE id_bank='$renilai[id_bank]'"));
					    $remap = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM mata_pelajaran WHERE kode='$rebank[nama]'")); 	
						?>
								<form id="formcek">
               
				      <input type="hidden" class="form-control" name="idu"  value="<?= $renilai['id_ujian'] ?>" >
					  <input type="hidden" class="form-control" name="idn"  value="<?= $_GET['idn'] ?>" >
					   <input type="hidden" class="form-control" name="ids"  value="<?= $renilai['id_siswa'] ?>" >
                      <div class="form-group-sm">
                            <label>Nama Siswa</label>
                            <input type="text" class="form-control" name="nama"  value="<?= $siswa['nama'] ?>" required >
                        </div> 
						 <div class="form-group-sm">
                            <label>Mapel Ujian</label>
                            <input type="text" class="form-control" name="mapel"  value="<?= $remap['nama_mapel'] ?>" required >
                        </div> 
                      
					
					<br>
				
		        <button type="submit" class="btn btn-primary btn-round form-control" id="submit" style="border-radius:20px" >CEK DATA RESET</button>
					
		      </form> 	
									
									
								</div>
							</div>
						  </div> 
						</div>		
						           
						            <script>
										$('#formcek').submit(function(e){
										e.preventDefault();
										var data = new FormData(this);
										$.ajax(
										{
											method: 'POST',
											url: 'cek.php',
											enctype: 'multipart/form-data',
											data: data,
											cache: false,
											contentType: false,
											processData: false,
											success: function(data){   
											 if (data == 'OK') {		
												iziToast.info(
												{
													title: 'Sukses!',
													message: 'Data berhasil direset',
													titleColor: '#FFFF00',
													messageColor: '#fff',
													backgroundColor: 'rgba(0, 0, 0, 0.5)',
													 progressBarColor: '#FFFF00',
													  position: 'topRight'
												});
												setTimeout(function()
												{
													window.location.replace('.');
												}, 2000);
												 } else {
												 iziToast.warning(
												{
													title: 'Gagal!',
													message: 'Data Belum direset oleh Proktor',
													titleColor: '#FFFF00',
													messageColor: '#fff',
													backgroundColor: '#8b0000',
													 progressBarColor: '#FFFF00',
													  position: 'topRight'
												});
												setTimeout(function(){
													window.location.reload();
												}, 3000);	
											   }			
											}
										});
										return false;
									});
									</script>	
					<?php elseif ($pg == 'skl') : ?>
					
                 <div class="row">					
                       <div class='col-md-5'>		
						<div class='box box-solid'>
						 <div class='box-header with-border'>
                              <h3 class='box-title'><i class="fas fa-bell"></i> Informasi</h3>
                                </div>
								
							<div class='box-body'>
							<?php if($datetime <= $skl['ditutup']): ?>
							<center>
							  <h3 class='box-title' style="color:#000000;"><i class="fas fa-download"></i> DOWNLOAD DIBUKA</h3>
							  <h4 style="color:red"><?= date('d',strtotime($skl['dibuka'])) ?> <?= bulan_indo($skl['dibuka']) ?> <?= date('Y',strtotime($skl['dibuka'])) ?> s/d <?= date('d',strtotime($skl['ditutup'])) ?> <?= bulan_indo($skl['ditutup']) ?> <?= date('Y',strtotime($skl['ditutup'])) ?></h4>
								
								<div id="DateCountdown" data-date="<?= $skl['ditutup'] ?>" style="width: 400px; height: 125px; padding: 0px; box-sizing: border-box; background-color: #fff"></div>
								
								</center>
								<?php endif; ?>
                                   </div>
								    </div>
									 </div>
									 
						<div class='col-md-7'>		
						<div class='box box-solid'>
						 <div class='box-header with-border'>
                              <h3 class='box-title'><?= $siswa['nama'] ?></h3>
                                </div>
							<div class='box-body'>
							
							<div class="edis">
							<?php if($siswa['foto']==''): ?>
							<table class="table table-bordered" width="100%" style="font-size:13px;font-weight:bold;">
							<tr>
							<td rowspan="4" width="150px">
							<img src="images/user.png" style="max-width:150px" >
							</td>
							<td width="80px">N I S</td>
							<td><?= $siswa['nis'] ?></td>
							
							</tr>
							<tr>
							<td>N I S N</td>
							<td><?= $siswa['nisn'] ?></td>
							
							</tr>
							<tr>
							<td>ROMBEL</td>
							<td><?= $siswa['kelas'] ?></td>
							
							</tr>
							<tr>
							<td>JURUSAN</td>
							<td>
							<?php if($setting['jenjang']=='SMK' OR $setting['jenjang']=='SMA'): ?>
							<?php $kls = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM kelas  WHERE kelas='$siswa[kelas]'"));?>
							<?= $kls['program'] ?>
							<?php endif; ?>
							</td>
							
							</tr>
							
							</table>
							
						
							<center>
							<?php if( $datetime >= $skl['dibuka'] AND $datetime <= $skl['ditutup']): ?>
							<a id="amplop" href="#">
							<h4 style="color:blue">Buka Amplop</h4>
								<img src="images/amplop.png" alt=".." style="width:100%;max-width:150px;" />
							</a>
							<?php else: ?>
							<a href="#">
							<h4 style="color:red">Belum Waktunya Buka Amplop</h4>
								<img src="images/amplop.png" alt=".." style="width:100%;max-width:150px;" />
							</a>
							<marquee bgcolor="#D2691E" style="font-size:24px; color:#fff;"><?= $skl['tulisan'] ?></marquee>
							<?php endif; ?>
							</center>
							
							<br>
							<div class='animated tada keterangan' style="font-weight:bold;margin-top:-30px;">
							<center>
							<img src="images/buka.png" alt=".." style="width:100%;max-width:250px;" />
						<h3 style="font-weight:bold;margin-top:-100px;">
						<?php if ($siswa['lulus'] == 1) {
							echo "LULUS";
						} elseif ($siswa['lulus'] == 2) {
							echo "PANGGILAN";
						} else {
							echo "TIDAK LULUS";
						}
						?>
					</h3>
					</center>
							</div>
							<br><br><br><br>
									<div class="download">
									<table class="table table-hover">
									<tr>
									<th>Surat Keterangan Lulus</th>
									<td><a href="skl/print_skl.php?nis=<?= $siswa['nis'] ?>" target="_blank" class="btn btn-sm btn-success"><i class="fa fa-download"></i> </a></td>
									</tr>
									<tr>
									<th>Surat keterangan Kelakuan Baik</th>
									<td><a href="skl/cetakskkb.php?nis=<?= $siswa['nis'] ?>" target="_blank" class="btn btn-sm btn-primary"><i class="fa fa-download"></i> </a></td>
									</tr>
									<tr>
									<th>Transkip Nilai</th>
									<td><a href="skl/cetaktranskip.php?nis=<?= $siswa['nis'] ?>" target="_blank" class="btn btn-sm btn-danger"><i class="fa fa-download"></i> </a></td>
									</tr>
									</table>
									</div>
					
								  
									 </div>
										</div>
										<?php endif; ?>
										</div>
										</div>
									<script>
            $("#DateCountdown").TimeCircles();
            $("#CountDownTimer").TimeCircles({ time: { Days: { show: false }, Hours: { show: false } }});
            $("#PageOpenTimer").TimeCircles();
            
            var updateTime = function(){
                var date = $("#date").val();
                var time = $("#time").val();
                var datetime = date + ' ' + time + ':00';
                $("#DateCountdown").data('date', datetime).TimeCircles().start();
            }
            $("#date").change(updateTime).keyup(updateTime);
            $("#time").change(updateTime).keyup(updateTime);
            
            $(".startTimer").click(function() {
                $("#CountDownTimer").TimeCircles().start();
            });
            $(".stopTimer").click(function() {
                $("#CountDownTimer").TimeCircles().stop();
            });
            $(".fadeIn").click(function() {
                $("#PageOpenTimer").fadeIn();
            });
            $(".fadeOut").click(function() {
                $("#PageOpenTimer").fadeOut();
            });
			 $('.keterangan').hide();
			  $('.download').hide();
			$("#amplop").click(function(e) {
				e.preventDefault();
				$(this).hide();
				var id = '<?= $_SESSION['id_siswa'] ?>';
				$.ajax({
					type: 'POST',
					url: 'cekskl.php',
					data: 'id=' + id,
					success: function(data) {
						setTimeout(function() {
						
							 $('.keterangan').show();
							  $('.download').show();
						}, 1000);
							
					}
				});
			});
			
			
			
			
        </script> 	
					<?php elseif ($pg == 'hasil') : ?>
                    <div class='row'>
                        <div class='col-md-12'>
                            <div class='box box-solid'>
                                <div class='box-header with-border'>
                                    <h3 class='box-title'>Data Nilai Ujian</h3>
                                </div>
                                <div class='box-body'>
                                    <div class="nav-tabs-custom">
                                        <ul class="nav nav-tabs">
                                            <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Hasil Ujian</a></li>
                                            
									   </ul>
                                        <div class="tab-content">
                                            <div class="tab-pane active" id="tab_1">
                                                <div class="alert alert-default" role="alert">
                                                    <strong>Daftar Ujian yang sudah dikerjakan</strong>
                                                </div>
                                                <table id='example1' class='table table-bordered'>
                                                    <thead>
                                                        <tr>
                                                            <th width='5px'>#</th>
                                                            <th>Kode Tes</th>
                                                            <th class='hidden-xs'>Ujian Selesai</th>
                                                            <th class='hidden-xs'>Status</th>
															<th>Jenis Soal</th>
                                                            <th></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[nama]'"));
                                                            ?>
                                                            <tr>
                                                                <td><?= $no ?></td>
                                                                <td><?= $mapel['nama'] . '-' . $namamapel['nama_mapel'] ?></td>
                                                                <td class='hidden-xs'><?= $nilai['ujian_selesai'] ?></td>
                                                                <td class='hidden-xs'><label class='label label-primary'>Selesai</label></td>
																<td><?= $mapel['groupsoal'] ?></td>
                                                                <td>
                                                                    <a href="?pg=lihathasil&idu=<?= $nilai['id_ujian'] ?>"><button class='btn btn-sm btn-success'><i class='fa fa-search'></i> Lihat Hasil</button></a>
																	 
																</td>
                                                            </tr>
                                                        <?php endwhile; ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                           
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
						<?php elseif ($pg == 'lihathasil') : ?>
                    <?php
                    $ac = $_GET['idu'];
                    $nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$id_siswa' and id_ujian='$ac'"));
                  
                        $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='box box-solid'>
                                    <div class='box-header with-border'>
                                        <h3 class='box-title'>Data Hasil Ujian</h3>
                                    </div>
                                    <div class='box-body'>
                                        <table id='example1' class='table table-bordered'>
                                            <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['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>
                                        <br>
                                        <div class="nav-tabs-custom">
                                            <ul class="nav nav-tabs">
                                                <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Detail Jawaban</a></li>
                                                
                                            </ul>
                                            <div class="tab-content">
                                                <div class="tab-pane active" id="tab_1">
												
                                                    <div class='table-responsive'>
                                                        <table id='example1' class='table table-bordered'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5px'>#</th>
                                                                    <th>Soal PG</th>

                                                                    <th style='text-align:center'>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><?= substr($soal['soal'],0,20)."...." ?></td>

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

                                                                    <th style='text-align:center'>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><?= substr($soal['soal'],0,20)."...." ?></td>

                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
													
                                               
												 <?php if($mapel['model']==1){ ?>
                                                    <div class='table-responsive'>
                                                        <table id='example1' class='table table-bordered'>
                                                            <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><?= substr($soal['soal'],0,20)."...." ?></td>


                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                
													
												 <div class='table-responsive'>
                                                        <table id='example1' class='table table-bordered'>
                                                            <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><?= substr($soal['soal'],0,20)."...." ?></td>


                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                
												
												<div class='table-responsive'>
                                                        <table id='example1' class='table table-bordered'>
                                                            <thead>
                                                                <tr>
                                                                    <th width='5px'>#</th>
                                                                    <th>Soal Menjodohkan</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><?= substr($soal['soal'],0,20)."...." ?></td>


                                                                        <td style='text-align:center'><?= $status ?></td>
                                                                    </tr>
                                                                <?php endforeach; ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
												 <?php } ?>
												
											 </div>
											</div>
										</div>
									</div>	
								 </div>	
							</div>						 
                <?php elseif ($pg == 'testongoing') : ?>
                   <?php
                    $ac = dekripsi($_GET['idu']);
                    $id = dekripsi($_GET['ids']);
                    $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);
                       $jumsoal = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$id_bank' "));
                    ?>
					
                        <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:20px">Sisa Waktu </span><span style="font-size:20px" 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='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>
                                          
                                            <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>

                                </div>
                            </div>
                  
                        </div>
						<?php else : ?>
                        <?php jump($homeurl); ?>
                    <?php endif; ?>
                    <?php else : ?>
                        <?php jump($homeurl); ?>
                    <?php endif; ?>
                
            </section>
        </div>
       
    </div>
    
    <script src='assets/zoom-master/jquery.zoom.js'></script>
    <script src='vendor/js/bootstrap.min.js'></script>
    <script src='vendor/iCheck/icheck.min.js'></script>
    <script src='vendor/js/app.min.js'></script>	
   <script src="assets/js/sweetalert2.min.js"></script>
	 <script src='assets/toastr/toastr.min.js'></script>	 
   <script src='assets/mousetrap/mousetrap.min.js'></script>
   <script src='assets/izitoast/js/iziToast.min.js'></script>
   
   
   <script>
        $('.loader').fadeOut('fast');
        var url = window.location;
        $('ul.sidebar-menu a').filter(function() {
            return this.href == url;
        }).parent().addClass('active');
      
        $('ul.treeview-menu a').filter(function() {
            return this.href == url;
        }).closest('.treeview').addClass('active');
       
    </script>
   
        <script>
            var homeurl;
            homeurl = '.';
           $(window).keydown(function(event) 
            {
                if(event.keyCode == 91)
                    {
                  
                    console.log("Win Key was clicked");
                    }
            });
            jQuery('body').on('contextmenu', function(e){ 
                return false; 
            });
            jQuery(document).bind('selectstart dragstart', function(e) {
                e.preventDefault();
                return false;
            });
            $(document).keydown(function(e) {
                if (e.keyCode == 27) return false;
            });
                function selesai() {
                    var idmapel = '<?= $id_bank  ?>';
                    var idsiswa = '<?= $id_siswa  ?>';
                    $.ajax({
                        type: 'POST',
                        url: homeurl + '/selesai.php',
                        data: {
                            
                            id_bank: idmapel,
                            id_siswa: idsiswa,
                            id_ujian: <?= $ac ?>
                        },
                        beforeSend: function() {
                            $('.loader').css('display', 'block');
                        },
                        success: function(response) {
                           
                            $('.loader').css('display', 'none');
                            location.href=homeurl;
                           
                           
                        }
                    });
                }    
        var elem = document.documentElement;

        function openFullscreen() {
            if (elem.requestFullscreen) {
                elem.requestFullscreen();
            } else if (elem.mozRequestFullScreen) {
               
                elem.mozRequestFullScreen();
            } else if (elem.webkitRequestFullscreen) {
              
                elem.webkitRequestFullscreen();
            } else if (elem.msRequestFullscreen) {
            
                elem = window.top.document.body; 
                elem.msRequestFullscreen();
            }
        }
        swal({
            title: 'Info Ujian',
            html: 'Selamat Mengerjakan',
           
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Iya',
            allowOutsideClick: false
        }).then((result) => {
            if (result.value) {
                openFullscreen();
            }
        })
        
        if (document.addEventListener) {
            document.addEventListener('fullscreenchange', exitHandler, false);
            document.addEventListener('mozfullscreenchange', exitHandler, false);
            document.addEventListener('MSFullscreenChange', exitHandler, false);
            document.addEventListener('webkitfullscreenchange', exitHandler, false);
        }

        function exitHandler() {
            if (document.webkitIsFullScreen === false) {
                <?php if($mapel['pelanggaran']<>0){ ?>
                var
                    closeInSeconds = <?= $mapel['pelanggaran'] ?>,
                    displayText = "Ujian terpaksa selesai dalam #1 detik lagi",
                    timer;


                timer = setInterval(function() {
                    closeInSeconds--;
                    if (closeInSeconds < 0) {
                        clearInterval(timer);
                        selesai();
                    }
                    $('.swal2-content').text(displayText.replace(/#1/, closeInSeconds));
                }, 1000);
                swal({
                    title: "Pelanggaran!",
                    text: displayText.replace(/#1/, closeInSeconds),
                    timer: closeInSeconds * 1000,
                    confirmButtonText: 'Lanjut Ujian',
                    allowOutsideClick: false
                }).then((result) => {
                    if (result.value) {
                        clearInterval(timer);
                        openFullscreen();
                    }
                })
                <?php }else{?>
                    swal({
                        title: 'Ujian',
                        html: '',
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Iya',
                        allowOutsideClick: false
                    }).then((result) => {
                        if (result.value) {
                            openFullscreen();
                        }
                    })
                <?php } ?>
            } else if (document.mozFullScreen === false) {
                console.log('bbbbbb')
            } else if (document.msFullscreenElement === false) {
                console.log('cccccc')
            }
        }
            window.history.pushState(null, "", window.location.href);
            window.onpopstate = function() {
                window.history.pushState(null, "", window.location.href);
            };
            
            var homeurl;
            homeurl = '<?= $homeurl ?>';
            $(document).ready(function() {
                $("#modalnosoal").on('shown.bs.modal', function() {
                    var idmapel = '<?= $id_bank  ?>';
                    var idsiswa = '<?= $id_siswa  ?>';
                    var pengacak = JSON.parse(localStorage.getItem('pengacakpg'));
                    var pengacakpil = JSON.parse(localStorage.getItem('pengacakpil'));
                    $.ajax({
                        type: 'POST',
                        url: homeurl + '/nosoal.php',
                        data: {
                            id_bank: idmapel,
                            id_siswa: idsiswa,
                            pengacak: pengacak,
                            pengacakpil: pengacakpil,
                            idu: <?= $ac ?>
                        },
                        success: function(response) {
                            
                            $('#loadnosoal').html(response);

                        }
                    });
                });
            });


            function soalpertama() {
                var idmapel = '<?= $id_bank  ?>';
                var idsiswa = '<?= $id_siswa  ?>';
                var soalsoal = JSON.parse(localStorage.getItem('soallokal'));
                var ujianya = JSON.parse(localStorage.getItem('ujianya'));
                var pengacak = JSON.parse(localStorage.getItem('pengacakpg'));
                var pengacakpil = JSON.parse(localStorage.getItem('pengacakpil'));
                $.ajax({
                    type: 'POST',
                    url: homeurl + '/soal.php',
                    data: {
                        pg: 'soal',
                        id_bank: idmapel,
                        id_siswa: idsiswa,
                        no_soal: 0,
                        ujian: ujianya,
                        soal: soalsoal,
                        pengacak: pengacak,
                        pengacakpil: pengacakpil,
                        idu: <?= $ac ?>
                    },
                    beforeSend: function() {
						$('#loading-image').show();
					},
                    success: function(response) {
                        num = 1;
                        $('#loading-image').hide();
                        $('#displaynum').html(num);
                        $('#loadsoal').html(response);
                        $('.fa-spin').hide();
                        
                        soalFont(fontSize);
                        
                    }
                });
            }
            soalpertama();
            /* Font Adjusments */
            let defaultFontSize = 10;
            let fontSize = 0;
            fontSize = localStorage.getItem('fontSize');
            if (!fontSize) {
                fontSize = defaultFontSize;
                localStorage.setItem('fontSize', fontSize);
            }
            soalFont(fontSize);

            function soalFont(fontSize) {
                $('div.soal > p > span').css({
                    fontSize: fontSize + 'pt'
                });
                $('span.soal > p > span').css({
                    fontSize: fontSize + 'pt'
                });
                $('.soal').css({
                    fontSize: fontSize + 'pt'
                })
                $('.callout soal').css({
                    fontSize: fontSize + 'pt'
                })
            }

            $(document).ready(function() {
                $('#smaller_font').on('click', function() {
                    fontSize = localStorage.getItem('fontSize')
                    fontSize--;
                    localStorage.setItem('fontSize', fontSize)
                    soalFont(fontSize)
                });

                $('#bigger_font').on('click', function() {
                    fontSize = localStorage.getItem('fontSize')
                    fontSize++;
                    localStorage.setItem('fontSize', fontSize)
                    soalFont(fontSize)
                });

                $('#reset_font').on('click', function() {
                    fontSize = defaultFontSize
                    localStorage.setItem('fontSize', fontSize)
                    soalFont(fontSize)
                });
                function selesai() {
                    var idmapel = '<?= $id_bank  ?>';
                    var idsiswa = '<?= $id_siswa  ?>';
                    $.ajax({
                        type: 'POST',
                        url: homeurl + '/selesai.php',
                        data: {
                            
                            id_bank: idmapel,
                            id_siswa: idsiswa,
                            id_ujian: <?= $ac ?>
                        },
                        beforeSend: function() {
                            $('.loader').css('display', 'block');
                        },
                        success: function(response) {
                           
                            $('.loader').css('display', 'none');
                            location.href=homeurl;
                           
                           
                        }
                    });
                }
                $(document).on('click', '.done-btn', function() {
                    var idmapel = '<?= $id_bank  ?>';
                    var idsiswa = '<?= $id_siswa  ?>';
                    $.ajax({
                        type: 'POST',
                        url: homeurl + '/cekselesai.php',
                        data: {
                            id_bank: idmapel,
                            id_siswa: idsiswa,
                            id_ujian: <?= $ac ?>
                        },
                        success: function(response) {
                            if (response == 'ok') {
                                swal({
                                    title: 'Apa kamu yakin telah selesai?',
                                    html: 'Pastikan telah menyelesaikan semua dengan benar!',
                                    type: 'warning',
                                    showCancelButton: true,
                                    confirmButtonColor: '#3085d6',
                                    cancelButtonColor: '#d33',
                                    confirmButtonText: 'Iya'
                                }).then((result) => {
                                    if (result.value) {
                                        
                                       selesai();
                                    }
                                })
                            } else if (response == 'ragu') {
                                swal({
                                    type: 'warning',
                                    title: 'Peringatan',
                                    html: 'Masih ada soal yang masih ragu!!',
                                })
                            } else {
                                swal({
                                    type: 'warning',
                                    title: 'Peringatan',
                                    html: 'Masih ada soal yang belum dikerjakan!!',
                                })
                            }

                        }
                    });

                });
                
                var result = '';
                $('.jawabesai').change(function() {
                    result = $(this).val();
                    $('#result').html(result);
                });

                var jam = $('#htmljam').html();
                var menit = $('#htmlmnt').html();
                var detik = $('#htmldtk').html();

                function hitung() {
                    setTimeout(hitung, 1000);
                    $('#countdown').html(jam + ':' + menit + ':' + detik);
                    detik--;
                    if (detik < 0) {
                        detik = 59;
                        menit--;
                        if (menit < 0) {
                            menit = 59;
                            jam--;
                            if (jam < 0) {
                                jam = 0;
                                menit = 0;
                                detik = 0;
                                selesai();
                            }
                        }
                    }
                }
                hitung();

            });

            function waktuhabis() {
                swal({
                    title: 'Peringatan!',
                    text: 'Waktu Ujian Telah Habis',
                    timer: 1000,
                    onOpen: () => {
                        swal.showLoading()
                    }
                }).then((result) => {
                    selesai();
                });
            }

            function loadsoal(idmapel, idsiswa, nosoal) {

                if (nosoal >= 0 && nosoal<<?= $jumsoal ?>) {
                    curnum = $('#displaynum').html();
                    if (nosoal == curnum) {
                        $('#spin-next').show();
                    }
                    if (nosoal > curnum) {
                        $('#spin-next').show();
                    }
                    if (nosoal < curnum) {
                        $('#spin-prev').show();
                    }
                    var ujianya = JSON.parse(localStorage.getItem('ujianya'));
                    var soalsoal = JSON.parse(localStorage.getItem('soallokal'));
                    var pengacak = JSON.parse(localStorage.getItem('pengacakpg'));
                    var pengacakpil = JSON.parse(localStorage.getItem('pengacakpil'));
                    $.ajax({
                        type: 'POST',
                        url: homeurl + '/soal.php',
                        data: {
                            pg: 'soal',
                            id_bank: idmapel,
                            id_siswa: idsiswa,
                            no_soal: nosoal,
                            soal: soalsoal,
                            pengacak: pengacak,
                            pengacakpil: pengacakpil,
                            ujian: ujianya

                        },
                        success: function(response) {
                            num = nosoal + 1;
                            $('#displaynum').html(num);
                            $('#loadsoal').html(response);
                            $('.fa-spin').hide();
                            $("#modalnosoal").modal('hide');
                            soalFont(fontSize);
                            
                        }
                    });
                }
            }

            function jawabsoal(idmapel, idsiswa, idsoal, jawab, jawabQ, jenis, idu) {

                
                $.ajax({
                    type: 'POST',
                    url: homeurl + '/soal.php',
                    data: {
                        pg: 'jawab',
                        id_bank: idmapel,
                        id_siswa: idsiswa,
                        id_soal: idsoal,
                        jawaban: jawab,
                        jenis: jenis,
                        idu: idu,
                        jawabx: jawabQ
                    },
                    success: function(response) {
                      
                        if (response == 'OK') {
                            $('#nomorsoal #badge' + idsoal).removeClass('bg-gray');
                            $('#nomorsoal #badge' + idsoal).removeClass('bg-yellow');
                            $('#nomorsoal #badge' + idsoal).addClass('bg-green');
                            $('#nomorsoal #jawabtemp' + idsoal).html(jawabQ);
                            $('#ketjawab').load(window.location.href + ' #ketjawab');
                        }
                    }
                });
            }

			
			  function jawabbs(idmapel, idsiswa, idsoal, jawabbs, jawabbs2, jawabQ, jenis, idu) {

                
                $.ajax({
                    type: 'POST',
                    url: homeurl + '/soal.php',
                    data: {
                        pg: 'jawabbs',
                        id_bank: idmapel,
                        id_siswa: idsiswa,
                        id_soal: idsoal,
                        jawabbs: jawabbs,
						jawabbs2: jawabbs2,
                        jenis: jenis,
                        idu: idu,
                        jawabx: jawabQ
                    },
                    success: function(response) {
                        
                        if (response == 'OK') {
                            $('#nomorsoal #badge' + idsoal).removeClass('bg-gray');
                            $('#nomorsoal #badge' + idsoal).removeClass('bg-yellow');
                            $('#nomorsoal #badge' + idsoal).addClass('bg-green');
                            $('#nomorsoal #jawabtemp' + idsoal).html(jawabQ);
                            $('#ketjawab').load(window.location.href + ' #ketjawab');
                        }
                    }
                });
            }

			
            function jawabesai(idmapel, idsiswa, idsoal, jenis) {
                var jawab = $('#jawabesai').val();
                $.ajax({
                    type: 'POST',
                    url: homeurl + '/soal.php',
                    data: {
                        pg: 'jawab',
                        id_bank: idmapel,
                        id_siswa: idsiswa,
                        id_soal: idsoal,
                        jawaban: jawab,
                        jenis: jenis,
                        idu: <?= $ac ?>
                    },
                    success: function(response) {
                        if (response == 'OK') {
                            toastr.success("jawaban berhasil disimpan");
                            $('#badge' + idsoal).removeClass('bg-gray');
                            $('#badge' + idsoal).removeClass('bg-yellow');
                            $('#badge' + idsoal).addClass('bg-green');
                            $('#ketjawab').load(window.location.href + ' #ketjawab');
                        }

                    }
                });
            }

            function radaragu(idmapel, idsiswa, idsoal, idu) {
                cekclass = $('#nomorsoal #badge' + idsoal).attr('class');
                if (cekclass != 'btn btn-app bg-gray') {
                    $.ajax({
                        type: 'POST',
                        url: homeurl + '/soal.php',
                        data: {
                            pg: 'ragu',
                            id_bank: idmapel,
                            id_siswa: idsiswa,
                            id_soal: idsoal,
                            id_ujian: idu
                        },
                        success: function(response) {
                            console.log(response);
                            if (response == 'OK') {
                                if (cekclass == 'btn btn-app bg-green') {
                                    $('#nomorsoal #badge' + idsoal).removeClass('bg-gray');
                                    $('#nomorsoal #badge' + idsoal).removeClass('bg-green');
                                    $('#nomorsoal #badge' + idsoal).addClass('bg-yellow');
                                    console.log('kuning');
                                }
                                if (cekclass == 'btn btn-app bg-yellow') {
                                    $('#nomorsoal #badge' + idsoal).removeClass('bg-gray');
                                    $('#nomorsoal #badge' + idsoal).removeClass('bg-yellow');
                                    $('#nomorsoal #badge' + idsoal).addClass('bg-green');
                                    console.log('hijau');
                                }
                            }
                        }
                    });
                } else {
                    $('#load-ragu input').removeAttr('checked');
                }
            }
        </script>
	<script>
	function kelapKelip() {
			$('.kedip').fadeOut(); 
			$('.kedip').fadeIn(); 
			}
			setInterval(kelapKelip, 500);
	</script>
	
    
	
</body>

</html>
 
