<?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_proto WHERE kelas='$kelas' "));
$bl = date('m');
$bulane = fetch ($koneksi, 'bulan', ['bln' =>$bl]);
$user=fetch($koneksi,'pengawas',['jabatan'=>$kelas]);

?>
<!DOCTYPE html>
<html>

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

     <title>Leger Sumatif Akhir Materi_<?= $kelas ?></title>
<link rel="stylesheet" href="../../plugins/bootstrap/dist/css/bootstrap.min.css">

</head>
<?php
  
	$rapor=fetch($koneksi,'setting',['id_setting' => 1]);
	if($rapor['semester']=='1'){
{$smt="(Satu)";}
}elseif($rapor['semester']=='2'){
{$smt="(Dua)";}
}
  ?>
<body style="font-size: 12px;">
    
   
    <center>
        <h5>ASESMEN SUMATIF AKHIR LINGKUP MATERI</h5>
		
    </center>
    <br>
    
    <div class="col-md-14">
	
        <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> <?= $rapor['semester'] ?> <?= $smt ?></td>
            </tr>
			<tr>
                <td>Wali Kelas</td>
                <td>:</td>
				<td><?= $user['nama'] ?></td>
				<td></td>
				<td>Tahun Pelajaran</td>
                <td>:</td>
				<td><?= $rapor['tp'] ?></td>
            </tr>
			
        </table>
       
          
        <br>
 <table style="font-size: 12px" class="table table-bordered table-sm">
  <thead>
            <tr style="text-align: center">
			<th width="3%" rowspan='2' >No</th>
			<th width="8%" 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_proto WHERE kelas='$kelas' order by nourut");
              while ($mapel = mysqli_fetch_array($queryx)) { ?>
                 <th width="4%" style="text-align: center"><?= $mapel['kode'] ?></th>
                                <?php } ?>
			
			</tr>
			 </thead>
			 <?php
               $query = mysqli_query($koneksi, "select * from siswa where id_kelas='$kelas' ");
                            $no = 0;
                            while ($siswa = mysqli_fetch_array($query)) {
                                $no++;
                            ?>
							 <tbody>
                                <tr>
                                    <td style="text-align: center"><?= $no; ?></td>
                                    <td style="text-align: center"><?= $siswa['nis'] ?></td>
                                    <td>&nbsp;<?= ucwords(strtolower($siswa['nama'])) ?></td>
			                      
								    <?php
								  $tahun=date('Y');
                                    $queryx = mysqli_query($koneksi, "select * from jadwal_proto WHERE kelas='$kelas' order by nourut");
                                    while ($mapel = mysqli_fetch_array($queryx)) {
                                       $n1 = mysqli_query($koneksi, "SELECT AVG(nilai) AS rata FROM nilai_sumatif WHERE mapel='$mapel[kode]' AND idsiswa='$siswa[id_siswa]' AND khp='SAM' ");
                                    while ($kl = mysqli_fetch_array($n1)) {
						           $rerata=$kl['rata'];
								 
								   ?>
                                  <td style="text-align: center"><?= round($rerata) ?></td>
								   
									 <?php } }?>
							</tr>
			<?php } ?>
			 </tbody>
		</table>	
		<br/>
	<table border='0' style="margin-left: 80px;width:850">
					<tr>
					
						<td>
							Mengetahui, <br/>
							Kepala PKBM <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>
