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

session_start();
if (!isset($_SESSION['id_pengawas'])) {
    die('Anda tidak diijinkan mengakses langsung');
}

$nis=$_GET['nis'];

$seting = fetch($koneksi, 'setting', ['id_setting' => 1]);
$siswa = fetch($koneksi, 'siswa', ['nis' => $nis]);
$klas=$siswa['id_kelas'];

$user = mysqli_fetch_array(mysqli_query($koneksi, "select * from pengawas where jabatan='$klas' "));
$bl = date('m');
$bulane = fetch ($koneksi, 'bulan', ['bln' =>$bl]);
	if($setting['semester']=='1'){
{$smt="(Satu)";}
}elseif($setting['semester']=='2'){
{$smt="(Dua)";}
}
$ma = fetch($koneksi, 'spiritual', ['niss' => $nis]);	
$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' => $nis]);
$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>

<body style="font-size: 12px;">
    
   
    <center>
        <h5>LAPORAN  HASIL PENILAIAN ULANGAN TENGAH SEMESTER</h5>
    </center>
    <br>
    
    <div class="col-md-14">
	
        <table style="margin-left: 10px;margin-right:10px"  width="100%">
            <tr>
                <td width="15%">Nama Sekolah</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%"><?= $siswa['id_kelas'] ?></td>
            </tr>
            <tr>
                <td >Alamat</td>
                <td>:</td>
				<td><?= $setting['alamat'] ?> </td>
				<td></td>
				<td>Semester</td>
                <td>:</td>
				<td><?= $setting['semester'] ?> <?= $smt ?></td>
            </tr>
			<tr>
                <td>Nama</td>
                <td>:</td>
				<td><?= $siswa['nama'] ?></td>
				<td></td>
				<td>Tahun Pelajaran</td>
                <td>:</td>
				<td><?= $setting['tp'] ?></td>
            </tr>
			<tr>
                <td>N I S</td>
                <td>:</td>
				<td><?= $siswa['nis'] ?></td>
				<td></td>
				<td>N I S N</td>
                <td>:</td>
				<td><?= $siswa['nisn'] ?></td>
            </tr>
        </table>
       
        <br>

			
			 <b>A. PENGETAHUAN</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th width="2%"><center>No</center></th>
                        <th width="60%"><center>Mata Pelajaran</center></th>
                       <th width="2%"><center>KKM</center></th>
					   <th width="2%"><center>Nilai</center></th>
					   <th width="2%"><center>Pred</center></th>
					   <th width="30%"><center>Keterangan</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="6"><?= $kelompok['kelompok'] ?></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(nilai) AS rata 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='$nis' AND nilai_rapor.ki='KI3' AND nilai_rapor.ket<>'PAS' AND nilai_rapor.ket<>'PAT'");
                        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";}
}	
		if($predikat=='A'){
{$edis="sangat Baik";}
}elseif($predikat=='B'){
{$edis="Baik";}
}elseif($predikat=='C'){
{$edis="Cukup";}
}elseif($predikat=='D'){
{$edis="Kurang";}
}		
			
			
		 
 
							 $no++;
		?>
		
                                <tr>
                                     <td> <?= $no ?></td>
                  <td><?= $mapel['mapel'] ?> </td>
				  <td><center><?= $mapel['kkm'] ?></center> </td>
				  <td><center><?= round($rerata) ?></center> </td>
				  <td><center><?= $predikat ?></center></td>
				  <td><center><?= $edis ?></center></td>
				  </tr>
				
						<?php  } }}?>	
                        
                   
                </tbody>
            </table>
            <br>
      
      
			<b>B. SARAN - SARAN</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                
				<tr>
				<td height="40"><?= $siswa['catatan'] ?></td>
				
				</tr>
				
            </table>
            <br>
			
		
			
		
       <table width="100%">
		<tr>
               <td style="text-align: center" width="33%"></td>
                 <td style="text-align: center" width="33%"></td>
                <td style="text-align: center"><?= $setting['kecamatan'] ?>, <?= $setting['tanggal_rapor'] ?></td>
            </tr>
			</table>
			<table width="100%">
            <tr style="text-align: center">
                <td>Mengetahui  :</td>
			<td>Mengetahui  :</td>
				 <td>Wali Kelas <?= $siswa['kelas'] ?></td>
            </tr>
			
		<tr>
               <td style="text-align: center" width="33.3%">Orang Tua/Wali</td>
                 <td style="text-align: center" width="33.3%"> Kepala PKBM</td>
                <td style="text-align: center" width="33.3%"></td>
            </tr>
			</table>
			
			<br><br><br>
			
			<table width="100%">
		<tr>
               <td style="text-align: center" width="33.3%">______________________</td>
                 <td style="text-align: center" width="33.3%"> <?= $setting['kepsek'] ?></td>
                <td style="text-align: center" width="33.3%"><?= $user['nama'] ?></td>
            </tr>
			<tr>
               <td style="text-align: center" width="33.3%"></td>
                 <td style="text-align: center" width="33.3%"> NIP. <?= $setting['nip'] ?></td>
				 
                <td style="text-align: center" width="33.3%">NIP. <?= $user['nip'] ?></td>
				 
            </tr>
			
			</table>
    </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);
?>