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

<?php if ($ac == '') : ?>
 <?php

    if (empty($_GET['kelas'])) {
        $id_kelas = "";
        $sqlkelas = "";
    } else {
        $id_kelas = $_GET['kelas'];
        $sqlkelas = " and a.kelas ='" . $_GET['kelas'] . "'";
    }
    if (empty($_GET['id'])) {
        $id_bank = "";
    } else {
        $id_bank = $_GET['id'];
    }
    $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal where id_bank='$id_bank' "));
   $model = $mapel['model'];
    ?>
   
    <div class='row'>
      <div class="col-md-12">
                <div class="card">
				  <div class="card-header">
                   <h5 class="card-title">DATA NILAI</small></h5> 
                   
                </div>					 
                 <div class="card-body">   
				<div class="row">
                        <div class="col-md-3">
                           <select class="form-select ujian">
							<?php if($menu['soal']=='1'){ ?>
                                <?php $ujian = mysqli_query($koneksi, "select * FROM banksoal a join nilai b ON a.id_bank=b.id_bank group by a.id_bank"); ?>
							<?php }else{ ?>
							 <?php $ujian = mysqli_query($koneksi, "select * FROM banksoal a join nilai b ON a.id_bank=b.id_bank  group by a.id_bank"); ?>
							<?php } ?>
								<option> Pilih Mata Pelajaran</option>
                                <?php while ($uj = mysqli_fetch_array($ujian)) : ?>
                                    <option <?php if ($id_bank == $uj['id_bank']) {
                                                echo "selected";
                                            } else {
                                            } ?> value="<?= $uj['id_bank'] ?>"><?= $uj['kode'] ?> - <?= $uj['nama'] ?></option>
                                <?php endwhile; ?>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <select class="form-select kelas">
                                <?php $kelas = mysqli_query($koneksi, "select * from siswa a join nilai b on a.id_siswa=b.id_siswa group by a.kelas"); ?>
                                <option value=''> Pilih Kelas</option>
                                <?php while ($kls = mysqli_fetch_array($kelas)) : ?>
                                    <option <?php if ($id_kelas == $kls['kelas']) {
                                                echo "selected";
                                            } else {
                                            } ?> value="<?= $kls['kelas'] ?>"><?= $kls['kelas'] ?></option>
                                <?php endwhile; ?>
                            </select>
                        </div>
                        
						
                        <div class="col-md-3">

                            <button id="cari_nilai" class="btn btn-primary"><i class='material-icons'>search</i> Cari Nilai</button>
                            <script type="text/javascript">
                                $('#cari_nilai').click(function() {
                                    var kelas = $('.kelas').val();
                                    var ujian = $('.ujian').val();
                                    location.replace("?pg=nilai&kelas=" + kelas + "&id=" + ujian);
                                }); 
                            </script>

                        </div>
						 <div class="col-md-3">
						<?php if($id_kelas !=''): ?>
                        <a class='btn  btn-dark' href='asesmen/nilai/cetaknilai.php?m=<?= $id_bank ?>&k=<?= $id_kelas ?>' target="_blank" data-placement="top" data-toggle="tooltip" data-original-title="Cetak Nilai"><i class='material-icons'>print</i> Cetak</a>
                       <?php else: ?>
					   <a class="btn  btn-outline-secondary"><i class="material-icons">print</i> Cetak</a>
					   <?php endif; ?>
						
						</div>
							</div>
								</div>
									</div>
										</div>
											</div>
					   
					   <div class='row'>
					    <div class="col-md-12">
                            <div class="card">
							<div class="card-header">
							</div>
                   <div class="card-body"> 
                    <div id="tablenilai" class='table-responsive'>
                       <table id="datatable1" class='table table-hover' style="font-size:12px">
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                  
                                    <th>NAMA LENGKAP</th>
                                    <th>TINGKAT</th>
                                    <th>PG</th>
									<?php if($model==1){ ?>
									<th>MULTI</th>
									<th>BS</th>
									<th>JODOH</th>
									<?php } ?>
                                    <th>ESAI</th>
                                    <th>TOTAL</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $siswaQ = mysqli_query($koneksi, "SELECT * FROM siswa a join nilai b on a.id_siswa=b.id_siswa where b.id_bank='$id_bank'" . $sqlkelas); ?>
                                <?php while ($siswa = mysqli_fetch_array($siswaQ)) : ?>
                                    <?php
                                    $no++;
                                    $ket = '';
                                    
                                    $selisih = 0;
                                    //$kelas = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM kelas WHERE kelas='$kelas'"));
                                    $nilaiQ = mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_bank='$id_bank' AND id_siswa='$siswa[id_siswa]' ");
                                    $nilaiC = mysqli_num_rows($nilaiQ);
                                    $nilai = mysqli_fetch_array($nilaiQ);
                                    if ($nilaiC <> 0) :
                                        $selisih = '';
                                        if ($nilai['ujian_mulai'] <> '' and $nilai['ujian_selesai'] <> '') :
                                            $selisih = strtotime($nilai['ujian_selesai']) - strtotime($nilai['ujian_mulai']);

                                            $esai = number_format($nilai['skor_esai'], 2, '.', '');
                                             $bs = number_format($nilai['skor_bs'], 2, '.', '');
											 $multi = number_format($nilai['skor_multi'], 2, '.', '');
											 $urut = number_format($nilai['skor_urut'], 2, '.', '');
                                            $skor = number_format($nilai['skor'], 2, '.', '');
                                            $total = number_format($nilai['total'], 2, '.', '') ;
                                            $ket = "";
                                        elseif ($nilai['ujian_mulai'] <> '' and $nilai['ujian_selesai'] == '') :
                                            $selisih = strtotime($nilai['ujian_berlangsung']) - strtotime($nilai['ujian_mulai']);

                                            $ket = "<i class='fa fa-spin fa-spinner' title='Sedang ujian'></i>";
                                            $skor = $total = '--';
                                        endif;
                                    endif;
                                    ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                       
                                        <td><?= $siswa['nama'] ?></td>
                                        <td><?= $siswa['kelas'] ?></td>
                                       <?php if($model==1){ ?>
                                        <td><?= $skor ?></td>
										<td><?= $multi ?></td>
										<td><?= $bs ?></td>
										<td><?= $urut ?></td>
									   <?php } ?>
                                        <td><?= $esai ?></td>
                                        <td><?= $total ?></td>
                                        <td>
                                            <?php if ($total >= 0) : ?>
                                                <?php

                                                if ($nilai['jawaban'] <> "") :
                                                    $ket = '';
                                                    $link = "?pg=" . $pg . "&ac=esai&id=" . $_GET['id'] . "&ids=" . $siswa['id_siswa'];
                                                    $link2 = "?pg=" . $pg . "&ac=jawaban&id=" . $_GET['id'] .  "&ids=" . $siswa['id_siswa'];
                                                else :
                                                    $ket = 'style="display:none"';
                                                    $link = '#';
                                                    $link2 = '#';
                                                endif;
                                                ?>

                                                <a href='<?= $link2 ?>' class='btn btn-sm btn-success' <?= $ket ?>><i class='material-icons'>edit</i> </a>
                                               
                                                <a href="asesmen/nilai/prosesjawab.php?idnilai=<?= $nilai['id_nilai'] ?>&ids=<?= $siswa['id_siswa'] ?>" class='btn btn-sm btn-primary' <?= $ket ?>><i class='material-icons'>download</i></a>
                                               
                                                    <div class="modal fade" id="modelId<?= $nilai['id_nilai'] ?>" 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">JAWABAN ESAI</h5>

                                                                </div>
                                                                <div class="modal-body">
                                                                    <form id='formnesai<?= $nilai['id_nilai'] ?>'>
                                                                        <table class='table table-bordered table-hover'>

                                                                            <tbody>
                                                                                <?php $noX = 0;
                                                                                $jawabanesai = unserialize($nilai['jawaban_esai']);
                                                                                $nesai = unserialize($nilai['nilai_esai2']); ?>
                                                                                <?php foreach ($jawabanesai as $key2 => $value2) : ?>
                                                                                    <?php
                                                                                    $noX++;
                                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key2'"));

                                                                                    ?>
                                                                                    <tr>
                                                                                        <td><?= $noX ?></td>
                                                                                        <td><?= $soal['soal'] ?>
                                                                                            <p><b>JAWAB :</b> <?= $value2 ?></p>
                                                                                        </td>
                                                                                        <td>
                                                                                            <input type="hidden" class="form-control" name="id" value="<?= $nilai['id_nilai'] ?>">
                                                                                            <input style="width: 50px" type="text" class="form-control" name="nesai<?= $nilai['id_nilai'] ?>[<?= $key2 ?>]" value="<?= $nesai[$key2] ?>">
                                                                                        </td>
                                                                                    </tr>
                                                                                <?php endforeach; ?>
                                                                            </tbody>
                                                                        </table>


                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                    <button type="submit" id="simpanesai<?= $nilai['id_nilai'] ?>" class="btn btn-primary">Save</button>
                                                                </div>
                                                                </form>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <script>
                                                        $("#formnesai<?= $nilai['id_nilai'] ?>").submit(function(e) {
                                                            e.preventDefault();
                                                            var id = '<?= $nilai['id_nilai'] ?>';
                                                            $.ajax({
                                                                type: "POST",
                                                                url: "cbtserver_ujian/simpanesai.php",
                                                                data: $(this).serialize(),
                                                                success: function(result) {
                                                                    toastr.success(result);
                                                                    setTimeout(function() {
                                                                        location.reload();
                                                                    }, 2000);
                                                                }
                                                            });
                                                        });
                                                    </script>
                                               
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endwhile; ?>
                            </tbody>
                        </table>
 </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

<?php elseif ($ac == 'jawaban') : ?>
    <?php
    $idmapel = $_GET['id'];

    $id_siswa = $_GET['ids'];
    $nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$id_siswa' and id_bank='$idmapel'"));
    $mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal where id_bank='$idmapel'"));
    $siswa = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_siswa='$id_siswa'"));
    ?>
     <div class='row'>
      <div class="col-md-12">
                <div class="card">
				  <div class="card-header">
                   <h5 class="card-title">DATA NILAI</small></h5>  
                    <div class='pull-right'>
					<a class='btn btn-secondary' href='?pg=nilai'><i class="material-icons">arrow_back</i> Back</a>
                       
                     </div>
                  </div>
              
				 <div class="card-body">
                    <table class='table' style="width:100%;">
                        <tr>
                            <th width='150'>No Induk</th>
                            <td width='10'>:</td>
                            <td><?= $siswa['nis'] ?></td>
                            <td style="text-align:center; width:150">Nilai PG</td>
							<td style="text-align:center; width:150">Nilai PG Kompleks</td>
							<td style="text-align:center; width:150">Nilai Benar Salah</td>
							<td style="text-align:center; width:150">Nilai Menjodohkan</td>
                            <td style="text-align:center; width:150">Nilai Esai</td>
                            <td style="text-align:center; width:150">Total Nilai</td>
                        </tr>
                        <tr>
                            <th>Nama</th>
                            <td width='10'>:</td>
                            <td><?= $siswa['nama'] ?></td>
                            <td rowspan='3' style='font-size:30px; text-align:center; width:150'><?= $nilai['skor'] ?></td>
							<td rowspan='3' style='font-size:30px; text-align:center; width:150'><?= $nilai['skor_multi'] ?></td>
							<td rowspan='3' style='font-size:30px; text-align:center; width:150'><?= $nilai['skor_bs'] ?></td>
							<td rowspan='3' style='font-size:30px; text-align:center; width:150'><?= $nilai['skor_urut'] ?></td>
                            <td rowspan='3' style='font-size:30px; text-align:center; width:150'><?= $nilai['skor_esai'] ?></td>
                            <td rowspan='3' style='font-size:30px; color:blue; 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['kode'] ?></td>
                        </tr>
						 <tr>
                            <th>Jenis Soal</th>
                            <td width='10'>:</td>
                            <td><b><?= $mapel['groupsoal'] ?></b></td>
                        </tr>
                    </table>
					<br>
                 
                    <div class='table-responsive'>
                        <table  class='table' style="width:100%;">
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    <th>Soal PG</th>
                                    <th style='text-align:center' width="35%">Jawab</th>
                                    <th style='text-align:center' width="5%">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 style='color:green'><i class='material-icons'>check</i></span>";
                                       else :
                                     $status = "<span style='color:red'><i class='material-icons'>close</i></span>";
                                      endif;
                                    ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                        <td><?= substr($soal['soal'],0,50)."......."; ?></td>
                                        <td style='text-align:center'><?= $value ?></td>
                                        <td style='text-align:center'><?= $status ?></td>
										
										<input type="hidden" name="jwb[]" value="<?= $value ?>">
										<input type="hidden" name="nomer[]" value="<?= $soal['nomor'] ?>">
										<input type="hidden" name="ids[]" value="<?= $id_siswa ?>">
										<input type="hidden" name="idmap[]" value="<?= $idmapel ?>">
										<input type="hidden" name="kelas[]" value="<?= $siswa['kelas'] ?>">
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
						
                    <div class='table-responsive'>
                        <table class='table' style="width:100%;">
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    <th>Soal PG Kompleks</th>
                                    <th style='text-align:center' width="35%">Jawab</th>
                                    <th style='text-align:center' width="5%">Hasil</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $jawaban = unserialize($nilai['jawaban_multi']); ?>
                                <?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 style='color:green'><i class='material-icons'>check</i></span>";
                                       else :
                                     $status = "<span style='color:red'><i class='material-icons'>close</i></span>";
                                      endif;
                                    ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                          <td><?= substr($soal['soal'],0,50)."......."; ?></td>
                                        <td style='text-align:center'><?= $value ?></td>
                                        <td style='text-align:center'><?= $status ?></td>
										
										<input type="hidden" name="jwb[]" value="<?= $value ?>">
										<input type="hidden" name="nomer[]" value="<?= $soal['nomor'] ?>">
										<input type="hidden" name="ids[]" value="<?= $id_siswa ?>">
										<input type="hidden" name="idmap[]" value="<?= $idmapel ?>">
										<input type="hidden" name="kelas[]" value="<?= $siswa['kelas'] ?>">
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
						
						 <br>
                    <div class='table-responsive'>
                        <table class='table' style="width:100%;">
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    <th>Soal Benar Salah</th>
                                    <th style='text-align:center' width="35%">Jawab</th>
                                    <th style='text-align:center' width="5%">Hasil</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $jawaban = unserialize($nilai['jawaban_bs']); ?>
                                <?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 style='color:green'><i class='material-icons'>check</i></span>";
                                       else :
                                     $status = "<span style='color:red'><i class='material-icons'>close</i></span>";
                                      endif;
                                    ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                          <td><?= substr($soal['soal'],0,50)."......."; ?></td>
                                        <td style='text-align:center'><?= $value ?></td>
                                        <td style='text-align:center'><?= $status ?></td>
										
										<input type="hidden" name="jwb[]" value="<?= $value ?>">
										<input type="hidden" name="nomer[]" value="<?= $soal['nomor'] ?>">
										<input type="hidden" name="ids[]" value="<?= $id_siswa ?>">
										<input type="hidden" name="idmap[]" value="<?= $idmapel ?>">
										<input type="hidden" name="kelas[]" value="<?= $siswa['kelas'] ?>">
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
						
						 <br>
                    <div class='table-responsive'>
                        <table class='table' style="width:100%;">
                            <thead>
                                <tr>
                                    <th width='5px'>#</th>
                                    <th>Soal Menjodohkan</th>
                                    <th style='text-align:center' width="35%">Jawab</th>
                                    <th style='text-align:center' width="5%">Hasil</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $jawaban = unserialize($nilai['jawaban_urut']); ?>
                                <?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 style='color:green'><i class='material-icons'>check</i></span>";
                                       else :
                                     $status = "<span style='color:red'><i class='material-icons'>close</i></span>";
                                      endif;
                                    ?>
                                    <tr>
                                        <td><?= $no ?></td>
                                         <td><?= substr($soal['soal'],0,50)."......."; ?></td>
                                        <td style='text-align:center'><?= $value ?></td>
                                        <td style='text-align:center'><?= $status ?></td>
										
										<input type="hidden" name="jwb[]" value="<?= $value ?>">
										<input type="hidden" name="nomer[]" value="<?= $soal['nomor'] ?>">
										<input type="hidden" name="ids[]" value="<?= $id_siswa ?>">
										<input type="hidden" name="idmap[]" value="<?= $idmapel ?>">
										<input type="hidden" name="kelas[]" value="<?= $siswa['kelas'] ?>">
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
						
                        <?php if ($nilai['jawaban_esai'] <> null) { ?>
                            <table class='table' style="width:100%;">
                                <thead>
                                    <tr>
                                        <th width='5px'>#</th>
                                        <th><b>Soal Esai</b></th>
                                        <th style='text-align:center' width="35%">Jawab</th>
										 <th style='text-align:center' width="5%">Hasil</th>
										  <th style='text-align:center' width="15%">
										  <button type="button" class="btn  btn-secondary" data-bs-toggle="modal" data-bs-target="#modelId<?= $nilai['id_nilai'] ?>">
                                                            <i class="material-icons">edit</i> Nilai
                                                        </button>
										  </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $jawaban = unserialize($nilai['jawaban_esai']); ?>
                                      <?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 style='color:green'><i class='material-icons'>check</i></span>";
                                                     else :
                                                $status = "<span style='color:red'><i class='material-icons'>close</i></span>";
                                                     endif;
                                                                    ?>
                                       
                                        <tr>
                                            <td><?= $no ?></td>
                                              <td><?= substr($soal['soal'],0,50)."......."; ?></td>
                                            <td><?= $value3 ?></td>
											<td style='text-align:center'><?= $status ?></td>
											 <td>
												
																	 </td>
																</tr>
															<?php endforeach; ?>
														</tbody>
													</table>
												<?php } ?>
												<br>
						
						
														<div class="modal fade" id="modelId<?= $nilai['id_nilai'] ?>" tabindex="-1" aria-labelledby="modelId<?= $nilai['id_nilai'] ?>" aria-hidden="true">
                                                          <div class="modal-dialog modal-lg">
														   <div class="modal-content">
															  <div class="modal-header">
																<h5 class="modal-title">Nilai Esai</h5>
																   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
																		</div>
																		  <div class="modal-body">
                                                                    <form id='formnesai<?= $nilai['id_nilai'] ?>'>
                                                                        <table class='table table-bordered table-hover'>

                                                                            <tbody>
                                                                                <?php $noX = 0;
                                                                                $jawabanesai = unserialize($nilai['jawaban_esai']);
                                                                                $nesai = unserialize($nilai['nilai_esai2']); ?>
                                                                                <?php foreach ($jawabanesai as $key2 => $value2) : ?>
                                                                                    <?php
                                                                                    $noX++;
                                                                                    $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key2'"));

                                                                                    ?>
                                                                                    <tr>
                                                                                        <td width="5%"><?= $noX ?></td>
                                                                                        <td  style='text-align:justify'><?= $soal['soal'] ?>
                                                                                            <p><b>JAWAB :</b> <?= $value2 ?></p>
                                                                                        </td>
                                                                                        <td width="15%">
                                                                                            <input type="hidden" class="form-control" name="id" value="<?= $nilai['id_nilai'] ?>">
                                                                                          <input type="hidden" class="form-control" name="makskor" value="<?= $soal['max_skor'] ?>">
																						 <small style="color:red"> Skor tidak boleh lebih dari </small><b> <?= $soal['max_skor'] ?></b>
																							
																							<input style="width: 100px" type="text" class="form-control" name="nesai<?= $nilai['id_nilai'] ?>[<?= $key2 ?>]" value="<?= $nesai[$key2] ?>">
                                                                                        </td>
                                                                                    </tr>
                                                                                <?php endforeach; ?>
                                                                            </tbody>
                                                                        </table>


                                                                </div>
                                                                <div class="modal-footer">
                                 
                                                                    <button type="submit" id="simpanesai<?= $nilai['id_nilai'] ?>" class="btn btn-sm btn-primary">Simpan</button>
                                                                </div>
                                                                </form>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <script>
                                                        $("#formnesai<?= $nilai['id_nilai'] ?>").submit(function(e) {
                                                            e.preventDefault();
                                                            var id = '<?= $nilai['id_nilai'] ?>';
                                                            $.ajax({
                                                                type: "POST",
                                                                url: "asesmen/nilai/simpanesai.php",
                                                                data: $(this).serialize(),
                                                                success: function(data){   
														 if (data == 'OK') {		
															iziToast.info(
															{
																title: 'Sukses!',
																message: 'Data berhasil disimpan',
																titleColor: '#FFFF00',
																messageColor: '#fff',
																backgroundColor: 'rgba(0, 0, 0, 0.5)',
																 progressBarColor: '#FFFF00',
																  position: 'topRight'
															});
															setTimeout(function()
															{
																window.location.reload();
															}, 2000);
															 } else {
															 iziToast.warning(
															{
																title: 'Gagal!',
																message: 'Pengisian skor tidak boleh melebihi yg ditentukan',
																titleColor: '#FFFF00',
																messageColor: '#fff',
																backgroundColor: '#8b0000',
																 progressBarColor: '#FFFF00',
																  position: 'topRight'
															});
															setTimeout(function(){
																window.location.reload();
															}, 2000);	
														   }			
														}
													});
													return false;
												});
											</script>
                                           </div>     
                                      </div>
							   </div>        
						 </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php endif; ?>
<script>
    
    $(document).on('click', '.ulangnilai', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Apa anda yakin?',
            text: " Akan Mengulang Ujian Ini ??",
            showCancelButton: true,
			type:'warning',
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes!'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'cbtserver_ujian/ulangujian.php',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                        iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
                    });
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
</script>