<?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');
}
$tahun=date('Y');
$ids=$_GET['nis'];

$siswa = fetch($koneksi, 'siswa', ['nis' => $ids]);
$klas=$siswa['id_kelas'];
$idsiswa=$siswa['id_siswa'];
$walas = fetch($koneksi, 'users', ['jabatan' => $klas]);

	if($setting['semester']=='1'){
{$smt="GANJIL";}
}elseif($setting['semester']=='2'){
{$smt="GENAP";}
}
$ma = fetch($koneksi, 'spiritual', ['niss' => $ids]);	
$ceklis=$ma['pred'];
	if($ceklis=='A'){
{$grades="Sangat Baik";}
}elseif($ceklis=='B'){
{$grades="Baik";}
}elseif($ceklis=='C'){
{$grades="Cukup";}
}elseif($ceklis=='D'){
{$grades="Kurang";}
}
$mas = fetch($koneksi, 'sosial', ['niss' => $ids]);
$cek=$mas['pred'];
if($cek=='A'){
{$gra="Sangat Baik";}
}elseif($cek=='B'){
{$gra="Baik";}
}elseif($cek=='C'){
{$gra="Cukup";}
}elseif($cek=='D'){
{$gra="Kurang";}
}
?>
<!DOCTYPE html>
<html>

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

    <title>Raport_<?= $siswa['nama'] ?></title>
<link rel="stylesheet" href="../../plugins/bootstrap/dist/css/bootstrap.min.css">
</head>
<style>
@page { margin: 30px; }
body { margin: 30px; }
</style>
<body style="font-size: 11px;">
    
   
    <center>
        <h5>DAFTAR NILAI</h5>
    </center>
    <br>
    
    <div class="col-md-14">
	
        <table style="margin-left: 30px;margin-right:10px"  width="100%">
            <tr>
                <td width="25%">NAMA PESERTA DIDIK</td>
                <td width="1%">:</td>
				<td width="40%"><?= $siswa['nama'] ?></td>
				<td>
				</tr>
              <tr>
				</td>
				<td width="17%">NIS / NISN</td>
                <td width="1%">:</td>
				<td width="20%"><?= $siswa['nis'] ?> / <?= $siswa['nisn'] ?></td>
            </tr>
            <tr>
                <td width="25%">KELAS</td>
                <td width="1%">:</td>
				<td width="40%"><?= $siswa['id_kelas'] ?></td>
				<td>
				</tr>
				 <tr>
                <td width="25%">SEMESTER</td>
                <td width="1%">:</td>
				<td width="40%"><?= $smt ?></td>
				<td>
				</tr>
        </table>
       
        <br>
 
            <table style="margin-left: 30px;margin-right:10px;" border ="1" width="100%">
                <thead>
                   
					<tr>
					   <th width="55%" style="background-color:#DCDCDC"><center>TAHUN PELAJAAN</center></th>
					   <th colspan="4" style="background-color:#DCDCDC"><center><?= $setting['tp'] ?></center></th>
					   </tr>
					   <tr>
					   <th width="50%" rowspan="3"><center>ASPEK SIKAP</center></th>
					   <th colspan="2"><center>SPIRITUAL</center></th>
					   <th colspan="2"><center>SOSIAL</center></th>
					   </tr>
					   <tr>
					    <th><center>KI-1</center></th>
						 <th><center>Deskripsi</center></th>
						 <th><center>KI-2</center></th>
						 <th><center>Deskripsi</center></th>
					   </tr>
                </thead>
                <tbody>
				<tr>
				
				<td class="text-center"><?= $ma['pred'] ?></td>
				<td>&nbsp;&nbsp;<?= $grades ?></td>
				<td class="text-center"><?= $mas['pred'] ?></td>
				<td>&nbsp;&nbsp;<?= $gra ?></td>
				</tr>
                </tbody>
            </table>
          
            <table style="margin-left: 30px;margin-right:10px;" border ="1" width="100%">
                <thead>
                   
					    <tr>
					   <th colspan="2" style="background-color:#DCDCDC"><center>ASPEK PENILAIAN</center></th>
					   <th colspan="3" style="background-color:#DCDCDC"><center>Pengetahuan</center></th>
					   <th colspan="3" style="background-color:#DCDCDC"><center>Keterampilan</center></th>
					   </tr>
					   <tr>
                       <th width="2%"><center>No</center></th>
                        <th width="32%"><center>Mata Pelajaran</center></th>
                       <th width="5%"><center>KKM</center></th>
					   <th width="5%"><center>KI-3</center></th>
					   <th width="5%"><center>Pred</center></th>
					   <th width="5%"><center>KKM</center></th>
					   <th width="5%"><center>KI-4</center></th>
					   <th width="5%"><center>Pred</center></th>
                    </tr>
                </thead>
                <tbody>
                    
                        <?php
                        $q1 = mysqli_query($koneksi, "SELECT * FROM jadwal_mapel WHERE kelas='$klas' group by kelompok order by kelompok");
                        $no = 0;
                        while ($kelompok = mysqli_fetch_array($q1)) {

                            $query = mysqli_query($koneksi, "SELECT * FROM jadwal_mapel where kelompok='$kelompok[kelompok]'  AND kelas='$klas' order by urut ");
                          
                        ?>
                            <tr>
                                <td colspan="8" style="background-color:#DCDCDC"> <b> Kelompok <?= $kelompok['kelompok'] ?></b></td>
                            </tr>
                           
							<?php
							while ($mapel = mysqli_fetch_array($query)) {
	$rentang=round(100-$mapel['kkm'])/3;		
    $predD=round($mapel['kkm']-1);
   $nilC1=round($mapel['kkm']);
	$nilC2=round($rentang)+($mapel['kkm']);				 
	$nilB1=round($nilC2+1);
	$nilB2=round($nilC2)+round($rentang);
	$nilA1=round($nilB2+1);
	$nilA2=round($nilB2)+round($rentang);			
								
					$n1 = mysqli_query($koneksi, "SELECT AVG (IF(ki='KI3',nilai,NULL)) AS rata,AVG (IF(ki='KI4',nilai,NULL)) AS ratak FROM nilai_rapor 
					JOIN jadwal_mapel ON jadwal_mapel.kode=nilai_rapor.mapel WHERE  jadwal_mapel.kelas='$klas' AND nilai_rapor.mapel= '$mapel[kode]' AND nilai_rapor.nis='$siswa[nis]'  AND nilai_rapor.smt='$setting[semester]' AND nilai_rapor.tahun='$tahun' ");
                        while ($kl = mysqli_fetch_array($n1)) {
						$rerata=$kl['rata'];
						if($rerata<=$predD){
						{$predikat="D";}
						}elseif($rerata>=$nilC1 && $rerata<=$nilC2){
						{$predikat="C";}
						}elseif($rerata>=$nilB1 && $rerata<=$nilB2){
						{$predikat="B";}
						}elseif($rerata>=$nilA1 && $rerata<=$nilA2){
						{$predikat="A";}
						}	
								
			
			           $rataK4=$kl['ratak'];
						if($rataK4<=$predD){
						{$predi="D";}
						}elseif($rataK4>=$nilC1 && $rataK4<=$nilC2){
						{$predi="C";}
						}elseif($rataK4>=$nilB1 && $rataK4<=$nilB2){
						{$predi="B";}
						}elseif($rataK4>=$nilA1 && $rataK4<=$nilA2){
						{$predi="A";}
						}	
							
 
							 $no++;
		?>
		
                                <tr>
                   <td style="text-align:center;"> <?= $no ?></td>
                  <td >&nbsp;<?= $mapel['mapel'] ?> </td>
				  <td style="text-align:center;"><?= $mapel['kkm'] ?></td>
				  <td style="text-align:center;"><?= round($rerata) ?> </td>
				  <td style="text-align:center;"><?= $predikat ?></td>
				  <td style="text-align:center;"><?= $mapel['kkm'] ?></td>
				  <td style="text-align:center;"><?= round($rataK4) ?> </td>
				  <td style="text-align:center;"><?= $predi ?></td>
				  </tr>
				
						<?php } } }?>	
                        
                   
                </tbody>
            </table>
			  <table style="margin-left: 30px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th width="5%" style="background-color:#DCDCDC"><center>No</center></th>
                        <th width="40%" style="background-color:#DCDCDC"><center>KEGIATAN EKSTRAKURIKULER</center></th>
					   <th width="55%" style="background-color:#DCDCDC"><center>KETERANGAN</center></th>
					
                    </tr>
                </thead>
                <tbody>
				<?php
							$no=0;
							 $queryx = mysqli_query($koneksi, "select * from m_eskul ");
                                 while ($esk = mysqli_fetch_array($queryx)) {
									 $eskuler=fetch($koneksi,'siswa_eskul',['eskul'=>$esk['ekstra']]);
									 $no++;
									 ?>
				<tr>
				<td style="text-align:center;"><?= $no ?> </td>
				<td>&nbsp;&nbsp;<?= $esk['ekstra'] ?> </td>
				<td>&nbsp;&nbsp;<?= $eskuler['ket'] ?>  </td>
				</tr>
				<?php } ?>
				</tr>
				
				
	</tbody>
            </table>
			<table style="margin-left: 30px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th colspan="2" width="65%" style="background-color:#DCDCDC"><center>KETIDAKHADIRAN</center></th>
                      <th rowspan="4" width="35%" style="text-align:justify">
					  <?php if($setting['semester']==2): ?>
					  Berdasarkan hasil yang dicapai pada semester 1 dan 2, peserta didik dinyatakan:
					  <h5>Naik ke kelas .......</h5>
					  <?php endif; ?>
					  </th>
                    </tr>
                </thead>
				<tr>
				<td width="50%">&nbsp;&nbsp;Sakit </td>
				<td> &nbsp;<?= $siswa['sakit'] ?> hari</td>
				</tr>
				<tr>
				<td>&nbsp;&nbsp;Izin </td>
				<td> &nbsp;<?= $siswa['izin'] ?> hari</td>
				</tr>
				<tr>
				<td>&nbsp;&nbsp;Tanpa Keterangan </td>
				<td> &nbsp;<?= $siswa['alpha'] ?> hari</td>
				</tr>
	
            </table>
            <br>
      
    
    </div>
</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);
?>