<?php ob_start();
error_reporting(0);
require("../../../config/koneksi.php");
require("../../../config/function.php");
require("../../../config/crud.php");
session_start();
if (!isset($_SESSION['id_user'])) {
    die('Anda tidak diijinkan mengakses langsung');
}
$idj=$_GET['idj'];
$mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM jadwal_mapel WHERE id_jadwal='$_GET[idj]'"));
$user = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM users WHERE id_user='$mapel[guru]'"));
$kelas = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM kelas WHERE id_kelas='$_GET[k]'"));
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');
}

?>
<!DOCTYPE html>
<html>

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

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

<link rel='stylesheet' href='<?= $homeurl ?>/dist/css/cetak.min.css'>

</head>
<style>
@page { margin: 50px; }
body { margin: 50px; }
</style>
<body>

            <table width='100%'>
                <tr>
                   
                    <td style="text-align:center">
                        <strong class='f12'>
                            REKAPITULASI NILAI HARIAN<br>
                            <?= strtoupper($mapel['mapel']) ?><BR>
                            TAHUN PELAJARAN <?= $ajaran ?>
                        </strong>
                    </td>
                  
                </tr>
            </table>
            <table class='detail'>
                <tr>
                    <td>SEKOLAH</td>
                    <td>:</td>
                    <td><span style='width:200px;'>&nbsp;<?= $setting['sekolah'] ?></span></td>
                   <td width="80px"><span></span></td>
				   <td>SEMESTER</td>
                    <td>:</td>
                    <td><span style='width:150px;'>&nbsp;<?= $setting['semester'] ?></span></td>
                </tr>
                <tr>
                    <td>KELAS</td>
                    <td>:</td>
                    <td><span style='width:200px;'>&nbsp;<?= $mapel['kelas'] ?></span></td>
					<td width="80px"></td>
                    <td>KURIKULUM</td>
                    <td>:</td>
                    <td><span style='width:150px;'>&nbsp;<?= strtoupper($kelas['kurikulum']); ?></span></td>
                </tr>
				 
            </table>
            <table class='it-grid it-cetak' width='100%'>
                <tr height="40px">
                    <th>No.</th>
                    <th>Nama</th>
					<?php
					$query = mysqli_query($koneksi, "select * from nilai_harian WHERE idjadwal='$idj' GROUP BY kd");                            
					 while ($n = mysqli_fetch_array($query)) {
					?>
                    <th width="8%"><?= $n['kd'] ?></th>
			        <?php } ?>	
                    <th width="8%">N Rata</th>
                </tr>
			
			     <?php
			      $no=0;
					$que = mysqli_query($koneksi, "select * from siswa WHERE id_kelas='$_GET[k]'");                            
					 while ($siswa = mysqli_fetch_array($que)) {
					 $rata = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai) AS rata,idsiswa,idjadwal FROM nilai_harian WHERE idjadwal='$idj' AND idsiswa='$siswa[id_siswa]'")); 	 
					$no++;
					?>
			              <tr>
                            <td style="text-align:center;width:15">&nbsp;<?= $no ?>.</td>
                            <td>&nbsp;<?= $siswa['nama'] ?></td>
                          
                       <?php
			      
					$quer = mysqli_query($koneksi, "select * from nilai_harian WHERE idjadwal='$idj' AND idsiswa='$siswa[id_siswa]' GROUP BY kd");                            
					 while ($nil = mysqli_fetch_array($quer)) {
					
					?>
					<td style="text-align:center;width:15"><?= $nil['nilai'] ?></td>
					 <?php } ?>	 
					 <td style="text-align:center;width:15"><?= round($rata['rata']) ?></td>
						</tr>

						     <?php } ?>	 							 
                    </table>
			
             <table style='background:#fff; width:97%; margin-left:50px'>
					<tr>
					<td width='50px'></td>
						<td>
							Mengetahui, <br/>
							Kepala Sekolah <br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $setting['kepsek'] ?></u><br/>
							NIP. <?= $setting['nip'] ?>
						</td>
						<td><span style='width:200px;'></span></td>
						<td>
							<?= $setting['kecamatan'] ?>, <?php echo date("t",time());; ?> <?= $bulane['ket'] ?> <?= date('Y') ?><br/>
							Guru Mata Pelajaran<br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $user['nama'] ?></u><br/>
							NIP. <?= $user['nip'] ?>
						</td>
					</tr>
				</table>

</body>

</html>
<?php

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

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("Raport_" . $siswa['nama'] . ".pdf", array("Attachment" => false));
exit(0);
?>