<?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'];
$user = fetch($koneksi, 'users', array('id_user' => $id_user));

if (date('m') >= 7 and date('m') <= 12) :
	$ajaran = date('Y') . "/" . (date('Y') + 1);
elseif (date('m') >= 1 and date('m') <= 6) :
	$ajaran = (date('Y') - 1) . "/" . date('Y');
endif;

$file = "REKAP NILAI KELAS " . $kelas;
$file = str_replace(" ", "_", $file);
$file = str_replace(":", "", $file);
header("Content-type: application/octet-stream");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Disposition: attachment; filename=" . $file . ".xls");
?>
REKAP NILAI HASIL UJIAN
<br>
<?= $setting['sekolah'] ?>
<table border='1'>
	<thead>
		<tr>
			<th rowspan='3' style="vertical-align:middle; width:5px">#</th>
			<th style='text-align:center;vertical-align:middle' rowspan='3'>No Peserta</th>
			<th style='text-align:center;vertical-align:middle' rowspan='3'>Nama Peserta</th>
			<th style='text-align:center;vertical-align:middle' rowspan='3'>Kelas</th>
			<?php
			$kodeujian = mysqli_fetch_array(mysqli_query($koneksi, "select * from jenis where status='aktif'"));
			$mapelQ = mysqli_query($koneksi, "SELECT * FROM banksoal a JOIN nilai b ON a.id_bank=b.id_bank where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_bank ");
			while ($mapel = mysqli_fetch_array($mapelQ)) :
				echo "<th style='text-align:center' colspan='3'>$mapel[nama]</th>";
			endwhile;
			?>
		</tr>
		<tr>
			<?php
			$kode = mysqli_query($koneksi, "SELECT * FROM banksoal a JOIN nilai b ON a.id_bank=b.id_bank where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_bank");
			while ($mapel = mysqli_fetch_array($kode)) :
				echo "<th style='text-align:center' colspan='3'>$mapel[kode_ujian]</th>";
			endwhile;
			?>
		</tr>
		<tr>
			<?php $mapelQ = mysqli_query($koneksi, "SELECT * FROM banksoal a JOIN nilai b ON a.id_bank=b.id_bank where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_bank "); ?>
			<?php while ($mapel = mysqli_fetch_array($mapelQ)) : ?>
				<th style='text-align:center'colspan="3">SKOR</th>
			
			<?php endwhile; ?>
		</tr>
	</thead>
	<tbody>
		<?php $siswaQ = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas' ORDER BY nama ASC"); ?>
		<?php while ($siswa = mysqli_fetch_array($siswaQ)) : ?>
			<?php
			$no++;
			$ket = '';
			$esai = $lama = $jawaban = $skor = $total = '--';
			?>
			<tr>
				<td><?= $no ?></td>
				<td style="text-align:center"><?= $siswa['no_peserta'] ?></td>
				<td><?= $siswa['nama'] ?></td>
				<td style="text-align:center"><?= $siswa['kelas'] ?></td>
				<?php $mapelQ = mysqli_query($koneksi, "SELECT * FROM banksoal a JOIN nilai b ON a.id_bank=b.id_bank where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_bank "); ?>
				<?php while ($mapel = mysqli_fetch_array($mapelQ)) : ?>
					<?php
					$nilaiQ = mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_bank='$mapel[id_bank]' AND id_siswa='$siswa[id_siswa]' ");
					$nilaiC = mysqli_num_rows($nilaiQ);
					$nilai = mysqli_fetch_array($nilaiQ);
					?>
					
					
					<td style="text-align:center" class='str' colspan="3"><?= $nilai['total'] ?></td>
		        	
				<?php endwhile; ?>
			</tr>
		<?php endwhile; ?>
	</tbody>
</table>