<?php 
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
require("../../config/dis.php");
(isset($_SESSION['id_user'])) ? $id_user = $_SESSION['id_user'] : $id_user = 0;
($id_user == 0) ? header('location:sig-in.php') : null;
echo "<style> .str{ mso-number-format:\@; } </style>";
$kelas = $_POST['kelas'];
$idb = $_POST['mapel'];
 $bank = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM banksoal WHERE id_bank='$idb'"));
              

$file = "JAWABAN MAPEL ".$bank['nama']." KELAS " . $kelas;
header("Content-type: application/octet-stream");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Disposition: attachment; filename=" . $file . ".xls");
?>
JAWABAN MAPEL <?= $bank['nama'] ?> KELAS <?= $kelas ?>
<br>
<?= $setting['sekolah'] ?>
<table border='1'>
	<thead>
		<tr>
		<th style="vertical-align:middle; width:5%">#</th>
			<th style='text-align:center;vertical-align:middle' >NIS</th>
			<th style='text-align:center;vertical-align:middle'>Nama Peserta</th>
			<?php
		    $no=0;
			$mapelQ = mysqli_query($koneksi, "SELECT * FROM soal WHERE id_bank='$idb' ");
			while ($mapel = mysqli_fetch_array($mapelQ)) :
			$no++;
				echo "<th style='text-align:center'>$no</th>";
			endwhile;
			?>
			<th style='text-align:center;vertical-align:middle'>Nilai</th>
			</tr>
			</thead>
	       <tbody>
		   <?php 
		   $no=0;
		   $siswaQ = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas' ORDER BY nama ASC"); 
		   ?>
		<?php while ($siswa = mysqli_fetch_array($siswaQ)) : ?>
			<?php
			$no++;
			 $nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_siswa='$siswa[id_siswa]' and id_bank='$idb'"));
                  
			?>
			<tr>
				<td><?= $no ?></td>
				<td style="text-align:center"><?= $siswa['no_peserta'] ?></td>
				<td><?= $siswa['nama'] ?></td>
				 <?php $jawaban = unserialize($nilai['jawaban']); ?>
              <?php foreach ($jawaban as $key => $value) : ?>
			  <?php $soal = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM soal WHERE id_soal='$key'")); ?>
			<?php if ($value == $soal['jawaban'] AND $soal['jenis']=='1') : ?>
			 <td style="background-color:green"><?= $value ?></td>
			 <?php else : ?>
			  <td style="background-color:red"><?= $value ?></td>
			 <?php endif; ?>
			    <?php endforeach; ?>
				 <?php $jawabane = unserialize($nilai['jawab_esai']); ?>
              <?php foreach ($jawabane as $key => $value) : ?>
				<?php if ($value == $soal['jawaban'] AND $soal['jenis']=='2') : ?>
			 <td><?= $value ?></td>
			
			 <?php endif; ?>
			    <?php endforeach; ?>
			  <td><?= $nilai['total'] ?></td>
				</tr>
		<?php endwhile; ?>
	</tbody>
</table>