<?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";}
}

?>
<!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>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="50%" style="background-color:#DCDCDC"><center>TAHUN PELAJAAN</center></th>
					   <th width="50%" style="background-color:#DCDCDC"><center><?= $setting['tp'] ?></center></th>
					   </tr>
                    <tr>
					 <th colspan="2" style="background-color:#DCDCDC"><center>ASPEK SIKAP</center></th>
					 </tr><tr>
                        <th width="30%"><center>Dimensi</center></th>
                        <th><center>Deskripsi</center></th>
                       
                    </tr>
                </thead>
                <tbody>
			              <?php							
                            $query = mysqli_query($koneksi, "select * from barusikap WHERE nis='$_GET[nis]' ORDER BY p_dimensi ASC");
                            $no = 0;
                            while ($sikap = mysqli_fetch_array($query)) {
							$dm=fetch($koneksi,'m_dimensi',['id_dimensi'=>$sikap['p_dimensi']]);
							$des=fetch($koneksi,'m_sub_elemen',['id_sub'=>$sikap['p_sub']]);
							$fase=$siswa['fase'];							
                                $no++;
                            ?>
							 <tr>
                                   
                                    <td><?= $dm['dimensi'] ?></td>
									<td style="text-align:justify">
									<?php if($fase=='A'){ ?>
									<?= $siswa['nama']?> <?= $des['A'] ?>
									<?php }elseif($fase=='B'){ ?>
									<?= $siswa['nama']?> <?= $des['B'] ?>
									<?php }elseif($fase=='C'){ ?>
									<?= $siswa['nama']?> <?= $des['C'] ?>
									<?php }elseif($fase=='D'){ ?>
									<?= $siswa['nama']?> <?= $des['D'] ?>
									<?php }elseif($fase=='E'){ ?>
									<?= $siswa['nama']?> <?= $des['E'] ?>
									<?php } ?>
								     </td>
								  </tr>
								   <?php } ?>
								</tbody>
							</table>
           
			
            <table style="margin-left: 30px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
					 <th colspan="4" style="background-color:#DCDCDC"><center>ASPEK PENGETAHUAN DAN KETERAMPILAN</center></th>
					 </tr><tr>
                       <th width="3%"><center>No</center></th>
                        <th width="32%"><center>Mata Pelajaran</center></th>
                     
					   <th width="5%"><center>Nilai Akhir</center></th>
					  
					   <th width="60%"><center>Capaian Kompetensi</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="4" style="background-color:#DCDCDC"> <b>Kelompok <?= $kelompok['kelompok'] ?></b></td>
                            </tr>
                           
							<?php
							while ($mapel = mysqli_fetch_array($query)) {
			
								
					$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'];

			
			$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']);	



$que = mysqli_query($koneksi, "select mapel,nis,MIN(nilai) as miniK,MAX(nilai) as makK
				 from nilai_rapor WHERE nis='$ids'   AND mapel= '$mapel[kode]' AND ki='KI4'");				
				while ($sandik = mysqli_fetch_array($que)) {			
  
$maxK   = $sandik['makK'];
$mINK   = $sandik['miniK'];		

	$posK = fetch($koneksi, 'nilai_rapor', ['nilai' => $maxK,'mapel' => $mapel['kode'],'nis' =>$ids,'smt'=>$setting['semester'],'ki'=>'KI4']);		
	$posKisi=substr($posK['ket'],2);
		$desmaxK = fetch($koneksi, 'deskripsi', ['urut' => $posKisi,'mapel' => $mapel['kode'],'kelas' =>$klas,'smt'=>$setting['semester'],'ki'=>'KI4']);		
		
		$posKe = fetch($koneksi, 'nilai_rapor', ['nilai' => $mINK,'mapel' => $mapel['kode'],'nis' =>$ids,'smt'=>$setting['semester'],'ki'=>'KI4']);	
	$posKisin=substr($posKe['ket'],2);
		$desminK = fetch($koneksi, 'deskripsi', ['urut' => $posKisin,'mapel' => $mapel['kode'],'kelas' =>$klas,'smt'=>$setting['semester'],'ki'=>'KI4']);		


		
 
							 $no++;
		?>
		
                                <tr>
                   <td style="text-align:center;" rowspan="2"> <?= $no ?></td>
                  <td  rowspan="2"><?= $mapel['mapel'] ?> </td>
				  
				  <td style="text-align:center;" rowspan="2">
				 <?php if($rerata<>0): ?>
				 <?= round($rerata) ?> 
				 <?php else: ?>
				 <?php endif; ?>
				  </td>
				  <td height="20px" style="text-align:justify">
				  <?php if($rerata<>0): ?>
				  Menunjukan kemampuan <?= $desmax['deskripsi'] ?> dan mampu <?= $desmaxK['deskripsi'] ?></td>
				   <?php else: ?>
				 <?php endif; ?>
				  </tr><tr>
				  <td height="20px" style="text-align:justify">
				  <?php if($rerata<>0): ?>
				 Perlu bimbingan <?= $desmin['deskripsi'] ?> dan <?= $desminK['deskripsi'] ?></td>
				  <?php else: ?>
				 <?php endif; ?>
				  </tr>
				
						<?php } } }}}?>	
                        
                   
                </tbody>
            </table>
           
            <table style="margin-left: 30px;margin-right:10px;" border ="1" width="100%">
                <thead>
                    <tr>
                       <th width="3%" style="background-color:#DCDCDC"><center>No</center></th>
                        <th width="37%" style="background-color:#DCDCDC"><center>Ekstrakurikuler</center></th>
					   <th width="60%" 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><?= $esk['ekstra'] ?> </td>
				<td><?= $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);
?>