<?php ob_start();
error_reporting(0);
require("../../config/koneksi.php");
require("../../config/function.php");
require("../../config/crud.php");
session_start();


$kelas=$_GET['kelas'];
$jmpl = mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM jadwal_mapel WHERE kelas='$kelas' "));
$bl = date('m');
$bulane = fetch ($koneksi, 'bulan', ['bln' =>$bl]);
$user=fetch($koneksi,'users',['jabatan'=>$kelas]);

?>
<!DOCTYPE html>
<html>

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

    <title>DKN_kelas_<?= $kelas ?></title>
<link rel="stylesheet" href="../../plugins/bootstrap/dist/css/bootstrap.min.css">
</head>
<?php
  
	if($setting['semester']=='1'){
{$smt="(Satu)";}
}elseif($setting['semester']=='2'){
{$smt="(Dua)";}
}
  ?>
<body style="font-size: 12px;">
    
   
    <center>
        <h5>REKAP NILAI AKHIR SISWA</h5>
		
    </center>
    <br>
   
	
        <table style="margin-left: 80px;margin-right:60px"  width="100%" >
            <tr>
                <td width="15%">Satuan Pendidikan</td>
                <td width="1%">:</td>
				<td width="40%"><?= $setting['sekolah'] ?></td>
				<td></td>
				<td width="17%">Kelas</td>
                <td width="1%">:</td>
				<td width="20%"><?= $kelas ?></td>
            </tr>
            <tr>
                <td >Alamat</td>
                <td>:</td>
				<td><?= $ms['alamat'] ?> Kec. <?= $setting['kecamatan'] ?></td>
				<td></td>
				<td>Semester</td>
                <td>:</td>
				<td> <?= $setting['semester'] ?> <?= $smt ?></td>
            </tr>
			<tr>
                <td>Wali Kelas</td>
                <td>:</td>
				<td><?= $user['nama'] ?></td>
				<td></td>
				<td>Tahun Pelajaran</td>
                <td>:</td>
				<td><?= $setting['tp'] ?></td>
            </tr>
			
        </table>
       
          
        <br>
   <table style="margin-left: 50px;margin-right:30px"  width="100%" border="1">
            <tr style="text-align: center">
			<th width="3%" rowspan='2' >No</th>
			<th width="10%" rowspan='2' style="text-align: center">NIS</th>
			<th rowspan='2'>NAMA LENGKAP</th>
			
			<th colspan='<?= $jmpl ?>' style="text-align: center">MATA PELAJARAN</th>
			
			</tr>
			<tr style="text-align: center">
			<?php
             $queryx = mysqli_query($koneksi, "select * from jadwal_mapel WHERE kelas='$kelas' order by urut");
              while ($mapel = mysqli_fetch_array($queryx)) { ?>
                 <th width="4%" style="text-align: center"><?= $mapel['kode'] ?></th>
                                <?php } ?>
			
			</tr>
		
			 <?php
               $query = mysqli_query($koneksi, "select * from siswa where id_kelas='$kelas' ");
                            $no = 0;
                            while ($siswa = mysqli_fetch_array($query)) {
                                $no++;
                            ?>
							 
                                <tr>
                                    <td style="text-align: center"><?= $no; ?></td>
                                    <td style="text-align: center"><?= $siswa['nis'] ?></td>
                                    <td>&nbsp;<?= ucwords(strtolower($siswa['nama'])) ?></td>
			                       
								    <?php
								 
                                    $queryx = mysqli_query($koneksi, "select * from jadwal_mapel WHERE kelas='$kelas' order by urut");
                                    while ($mapel = mysqli_fetch_array($queryx)) {
                                   
									$su = mysqli_fetch_array(mysqli_query($koneksi, "SELECT AVG(nilai) AS rs FROM nilai_sumatif  WHERE mapel='$mapel[kode]' AND idsiswa='$siswa[id_siswa]' "));	
						           $rerata=$su['rs'];
								 
								   ?>
                                  <td style="text-align: center"><?= round($rerata) ?></td>
								  <?php } ?>
								   
									 
							</tr>
			<?php } ?>
			
		</table>	
		<br/>
	<table border='0' style="margin-left: 80px;width:850">
					<tr>
					
						<td>
							Mengetahui, <br/>
							Kepala Sekolah <br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $setting['kepsek'] ?></u><br/>
							NIP. <?= $setting['nip'] ?>
						</td>
						<td width='400px'></td>
						<td>
							<?= $setting['kecamatan'] ?>, <?php echo date('d'); ?> <?= $bulane['ket'] ?> <?= date('Y') ?><br/>
							Wali Kelas <?= $kelas ?><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', 'landscape');
$dompdf->render();
$dompdf->stream("Leger_K_Merdeka.pdf", array("Attachment" => false));
exit(0);
?>