<?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="(Satu)";}
}elseif($setting['semester']=='2'){
{$smt="(Dua)";}
}
$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: 20px; }
body { margin: 20px; }
</style>
<body style="font-size: 11px;">
    
   
    <center>
        <h5>PENCAPAIAN KOMPETENSI PESERTA DIDIK</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. SIKAP</b><p></p>
    <b>1. Sikap Spiritual</b>
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                        <th width="20%"><center>Predikat</center></th>
                        <th><center>Deskripsi</center></th>
                       
                    </tr>
                </thead>
                <tbody>
				 <?php if ($ma['niss'] <> '') { ?>
                    <tr>
                        <td height="60px"><center> <?= $ma['pred'] ?> ( <?= $grades ?> )</center></td>
                  <td style="text-align:justify;">Selalu <?= $ma['keter'] ?> dan sikap <?= $ma['keter2'] ?> mulai berkembang</td>
				  </tr>
				   <?php } ?>
                </tbody>
            </table>
            <b>2. Sikap Sosial</b>
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                        <th width="20%"><center>Predikat</center></th>
                        <th><center>Deskripsi</center></th>
                       
                    </tr>
                </thead>
                <tbody>
				 <?php if ($mas['niss'] <> '') { ?>
                    <tr>
                     <td height="60px"><center> <?= $mas['pred'] ?> ( <?= $gra ?> )</center></td>
                  <td style="text-align:justify;">Selalu menunjukan <?= $mas['keter'] ?> sedangkan sikap <?= $mas['keter2'] ?> mengalami peningkatan</td>
				  </tr>
				    <?php } ?>
                </tbody>
            </table>
            <br>
			
			 <b>B. 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="32%"><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="60%"><center>Deskripsi</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"> <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(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='$siswa[nis]' AND nilai_rapor.nilai>'0' AND nilai_rapor.ki='KI3' 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";}
}	
		if($predikat=='A'){
{$edis="sangat Baik";}
}elseif($predikat=='B'){
{$edis="baik";}
}elseif($predikat=='C'){
{$edis="cukup";}
}elseif($predikat=='D'){
{$edis="kurang";}
}		
			
			$queryx = mysqli_query($koneksi, "select mapel,nis,MIN(nilai) as mini,MAX(nilai) as mak
				 from nilai_rapor WHERE nis='$ids'   AND ket<>'PTS' AND ket<>'PAS'  AND ket<>'PAT' AND mapel= '$mapel[kode]' AND ki='KI3' AND smt='$setting[semester]' AND tahun='$tahun'");				
				while ($ade = mysqli_fetch_array($queryx)) {			
  
$max   = $ade['mak'];
$min   = $ade['mini'];		

	$pos = fetch($koneksi, 'nilai_rapor', ['nilai' => $max,'mapel' => $mapel['kode'],'nis' =>$ids,'smt'=>$setting['semester'],'ki'=>'KI3']);	
	$posisi=substr($pos['ket'],2);
		$desmax = fetch($koneksi, 'deskripsi', ['urut' => $posisi,'mapel' => $mapel['kode'],'kelas' =>$klas,'smt'=>$setting['semester'],'ki'=>'KI3']);	
		
		$pose = fetch($koneksi, 'nilai_rapor', ['nilai' => $min,'mapel' => $mapel['kode'],'nis' =>$ids,'smt'=>$setting['semester'],'ki'=>'KI3']);		
	$posisin=substr($pose['ket'],2);
		$desmin = fetch($koneksi, 'deskripsi', ['urut' => $posisin,'mapel' => $mapel['kode'],'kelas' =>$klas,'smt'=>$setting['semester'],'ki'=>'KI3']);	
		 
 
							 $no++;
		?>
		
                                <tr>
                   <td style="text-align:center;"> <?= $no ?></td>
                  <td ><?= $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 height="55px" style="text-align:justify;font-size: 9px;">Memiliki kemampuan <?= $edis ?> dalam <?= $desmax['deskripsi'] ?>,perlu dimaksimalkan kemampuan dalam <?= $desmin['deskripsi'] ?></td>
				  </tr>
				
						<?php } } }}?>	
                        
                   
                </tbody>
            </table>
            <br>
      
      <b>C. KETERAMPILAN</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th width="2%"><center>No</center></th>
                        <th width="32%"><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="60%"><center>Deskripsi</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"> <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(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='$siswa[nis]' AND nilai_rapor.nilai>'0' AND nilai_rapor.ki='KI4' 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";}
}	
		if($predikat=='A'){
{$edis="sangat Baik";}
}elseif($predikat=='B'){
{$edis="baik";}
}elseif($predikat=='C'){
{$edis="cukup";}
}elseif($predikat=='D'){
{$edis="kurang";}
}		
			
			$queryx = mysqli_query($koneksi, "select mapel,nis,MIN(nilai) as mini,MAX(nilai) as mak
				 from nilai_rapor WHERE nis='$ids'   AND mapel= '$mapel[kode]' AND ki='KI4'");				
				while ($ade = mysqli_fetch_array($queryx)) {			
  
$max   = $ade['mak'];
$min   = $ade['mini'];		

	$pos = fetch($koneksi, 'nilai_rapor', ['nilai' => $max,'mapel' => $mapel['kode'],'nis' =>$ids,'smt'=>$setting['semester'],'ki'=>'KI4']);		
	$posisi=substr($pos['ket'],2);
		$desmax = fetch($koneksi, 'deskripsi', ['urut' => $posisi,'mapel' => $mapel['kode'],'kelas' =>$klas,'smt'=>$setting['semester'],'ki'=>'KI4']);		
		
		$pose = fetch($koneksi, 'nilai_rapor', ['nilai' => $min,'mapel' => $mapel['kode'],'nis' =>$ids,'smt'=>$setting['semester'],'ki'=>'KI4']);	
	$posisin=substr($pose['ket'],2);
		$desmin = fetch($koneksi, 'deskripsi', ['urut' => $posisin,'mapel' => $mapel['kode'],'kelas' =>$klas,'smt'=>$setting['semester'],'ki'=>'KI4']);		
		 
 
							 $no++;
							 
			  ?>
                                <tr>
                   <td style="text-align:center;"> <?= $no ?> </td>
                  <td><?= $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 height="55px" style="text-align:justify;font-size: 9px;">Memiliki keterampilan <?= $edis2 ?> dalam <?= $desmax['deskripsi'] ?>, perlu dimaksimalkan keterampilan dalam <?= $desmin['deskripsi'] ?></td>
				  </tr>
				
					<?php } }} }  ?>	
                </tbody>
            </table>
            <br> <br> <br> <br> <br> <br>
			<b>D. EKSTRAKURIKULER</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th width="2%"><center>No</center></th>
                        <th width="36%"><center>Kegiatan Ekstrakurikuler</center></th>
                       <th width="2%"><center>Nilai</center></th>
					   <th width="57%"><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><?= $esk['ekstra'] ?> </td>
				<td style="text-align:center;"><?= $eskuler['nilai'] ?></td>
				<td><?= $eskuler['ket'] ?>  </td>
				</tr>
				<?php } ?>
				</tr>
				
				
	</tbody>
            </table>
            <br>
			<b>E. PRESTASI</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th width="2%"><center>No</center></th>
                        <th width="42%"><center>Jenis Prestasi</center></th>
                       <th width="56%"><center>Keterangan</center></th>
					  
                    </tr>
                </thead>
                <tbody>
				<?php
							$no=0;
							 $queryx = mysqli_query($koneksi, "select * from siswa WHERE nis='$ids'");
                                 while ($pres = mysqli_fetch_array($queryx)) {
									 $no++;
									 ?>
				<tr>
				<td style="text-align:center;"><?= $no ?> </td>
				<td><?= $pres['prestasi'] ?> </td>
				<td> <?= $pres['ket_prestasi'] ?></td>
				
				</tr>
				<?php } ?>
				
	</tbody>
            </table>
            <br>
<b>F. KETIDAKHADIRAN</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="70%">
                
				<tr>
				<td width="50%">Sakit </td>
				<td> &nbsp;<?= $siswa['sakit'] ?> hari</td>
				</tr>
				<tr>
				<td>Izin </td>
				<td> &nbsp;<?= $siswa['izin'] ?> hari</td>
				</tr>
				<tr>
				<td>Tanpa Keterangan </td>
				<td> &nbsp;<?= $siswa['alpha'] ?> hari</td>
				</tr>
	
            </table>
            <br>
			 
			<b>G. CATATAN WALI KELAS</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                
				<tr>
				<td height="40"><?= $siswa['catatan'] ?></td>
				
				</tr>
				
            </table>
            <br>
			
			<b>H. TANGGAPAN ORANG TUA / WALI</b>
			
            <table style="margin-left: 10px;margin-right:10px;" border ="1" width="100%">
                
				<tr>
				<td height="40"></td>
				
				</tr>
				
            </table>
            <br>
			<?php if($setting['semester']==2){ ?>
       <table style="margin-left: 10px;margin-right:10px;" border ="1" width="50%">
                
				<tr>
				<td height="30">Berdasarkan pencapaian kompetensi pada semester ke-1<br>
				         dan ke-2, peserta didik ditetapkan *)<br>
						 <?php if($siswa['level']==6 OR $siswa['level']==9 OR $siswa['level']==12): ?>
						&nbsp;<b>Lulus</b>
						<?php else: ?>
						 <br>
						 naik ke kelas <b><?= $siswa['level'] + 1 ?></b>
						 <?php endif; ?>
						 <br><s><b>tinggal di kelas  <?= $siswa['level'] ?></b></s><br>*)Coret yang tidak perlu.					
                     </td>
				</tr>
            </table>
			
		<br>
		<?php } ?>
        <table style="margin-left: 80px;" width="90%">
		<tr>
               <td style="text-align: center" width="33.3%"></td>
                 <td style="text-align: center" width="33.3%"></td>
                <td width="33.3%"><?= $setting['kecamatan'] ?>, <?= $setting['tanggal_rapor'] ?></td>
            </tr>
			</table>
			<table style="margin-left: 80px;" width="90%">
            <tr>
                <td>Mengetahui  :</td>
			<td></td>
				 <td>Wali Kelas <?= $siswa['id_kelas'] ?></td>
            </tr>
			
		<tr>
               <td width="33.3%">Orang Tua/Wali</td>
                 <td  width="33.3%"> </td>
                <td  width="33.3%"></td>
            </tr>
			</table>
			
			<br><br><br>
			
			<table style="margin-left: 80px;" width="90%">
		<tr>
               <td width="33.3%">______________</td>
                 <td width="33.3%"> </td>
                <td  width="33.3%"><b><?= $walas['nama'] ?></b></td>
            </tr>
			<tr>
               <td style="text-align: center" width="33.3%"></td>
                 <td width="33.3%"> </td>
				 
                <td  width="33.3%">NIP. <?= $walas['nip'] ?></td>
				 
            </tr>
			
			</table>
			
			 
			</table>
			<table style="margin-left: 80px;" width="90%">
            <tr>
                <td></td>
			<td>Mengetahui  :</td>
				 <td></td>
            </tr>
			
		      <tr>
               <td width="33.3%"></td>
                 <td  width="33.3%">
				<?php if($setting['jenis']=='REGULER'): ?>
                    <p>Kepala Sekolah,</p>
					<?php else: ?>
					<p>Kepala PKBM,</p>
					<?php endif; ?>
				 </td>
                <td  width="33.3%"></td>
            </tr>
			</table>
			
			<br><br><br>
			
			<table style="margin-left: 80px;" width="90%">
		<tr>
               <td width="33.3%"></td>
                 <td width="33.3%"><?= $setting['kepsek'] ?> </td>
                <td  width="33.3%"><b></b></td>
            </tr>
			<tr>
               <td style="text-align: center" width="33.3%"></td>
                 <td width="33.3%">NIP. <?= $setting['nip'] ?> </td>
				 
                <td  width="33.3%"></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);
?>