<?php ob_start();

require("../../../config/koneksi.php");
require("../../../config/function.php");
require("../../../config/crud.php");
require("../../../config/dis.php");
	session_start();
if (!isset($_SESSION['id_user'])) {
    die('Anda tidak diijinkan mengakses langsung');
}

$id_bank = $_GET['m'];	
$level = $_GET['k'];


$mapel = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT banksoal.*, mata_pelajaran.nama_mapel FROM banksoal INNER JOIN mata_pelajaran ON banksoal.nama=mata_pelajaran.kode WHERE id_bank='$id_bank'"));
$jenis = mysqli_fetch_array(mysqli_query($koneksi, "select * from jenis where status='aktif'"));
	?>

<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>

    <title>NILAI <?= $mapel['kode'] ?></title>

<link rel='stylesheet' href='../../../vendor/css/cetak.min.css'>
<link rel='stylesheet' href='../../../vendor/css/bootstrap.min.css' />
<style>
@page { margin: 30px; }
body { margin: 30px; }
</style>
</head>

<body>	
<?php

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');
}
$tglsekarang = buat_tanggal('d M Y');
?>
 
				<table width='100%'>
					<tr>
						<td width='100'><img src='../../../images/kemdikbud.png' height='75'></td>
						<td>
							<CENTER>
								<strong class='f12'>
									REKAPITULASI NILAI <br>
									<?= strtoupper($jenis['nama']) ?> <br>TAHUN PELAJARAN <?= $ajaran ?>
								</strong>
							</CENTER></td>
							<td width='100'><img src="../../../images/<?= $setting['logo'] ?>" height='75'></td>
					</tr>
				</table>
				<hr>
				<table class='detail'>
					<tr>
						<td>SEKOLAH/MADRASAH</td><td>:</td><td><span style='width:450px;'>&nbsp;<?= $setting['sekolah'] ?></span></td>
					</tr>
					<tr>
						<td>UJIAN/KELAS</td><td>:</td><td><span style='width:450px;'>&nbsp;<?= $jenis['id_jenis'] ?> / <?= $level ?></span></td>
					</tr>
					<tr>
						<td>MATA PELAJARAN</td><td>:</td><td colspan='4'><span style='width:450px;'>&nbsp;<?= strtoupper($mapel['nama_mapel']) ?></span></td>
					</tr>
				</table>
				<table class='it-grid it-cetak' style="width:100%;font-size:12px">
				<tr>
					<th width='5%' height="30px" style='text-align:center'>NO</th>
					<th width="15%" style='text-align:center'>NO PESERTA</th>
					<th width="15%" style='text-align:center'>N I S</th>
					<th align='center'>NAMA PESERTA</th>
					<th width="5%" style='text-align:center'>JK</th>
					<th width="7%" style='text-align:center'>KELAS</th>
					<th width="7%" style='text-align:center'>NILAI</th>
					
				</tr>


		<?php $ckck = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$level' ");

		while ($siswa = mysqli_fetch_array($ckck)) {
			$no++;
			
			$nilai = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_bank='$id_bank' AND id_siswa='$siswa[id_siswa]'"));			
			$totalskor = number_format($nilai['total'], 2, '.', '');		
			?>
						<tr>
							<td align='center'><?= $no ?></td>
							<td align='center'><?= $siswa['no_peserta'] ?></td>
							<td align='center'><?= $siswa['nis'] ?></td>
							<td><?= ucwords(strtolower($siswa['nama'])) ?></td>
							<td align='center'><?= $siswa['jk'] ?></td>
							<td align='center'><?= $siswa['kelas'] ?></td>
							<td align='center'><?=$totalskor ?></td>
							
						</tr>
						<?php } ?>
		
				</table>
				<br>
				<table width='100%'>
					<tr>
						<td width='50%'>&nbsp;</td>
						<td width='30%'><?= $setting['kabupaten'] ?>, <?= $tglsekarang ?></td>
					</tr>
					<tr>
						<td width='50%'>&nbsp;</td>
						<td width='30%'>Kepala Sekolah,</td>
					</tr>
					<tr>
						<td width='50%'>&nbsp;</td>
						<td width='30%'><br><br><br><br><strong><?= $setting['kepsek'] ?></strong></td>
					</tr>
					<tr>
						<td width='50%'>&nbsp;</td>
						<td width='30%'>NIP. <?= $setting['nip'] ?></td>
					</tr>
				</table>
				
				
				</div>
			
			 
</body>

</html>
<?php

$html = ob_get_clean();
require_once '../../../vendor/vendors/autoload.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'Potrait');
$dompdf->render();
$dompdf->stream("Nilai ". $mapel['kode'].".pdf", array("Attachment" => false));
exit(0);
?>