<?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');
}
$kelas = $_POST['kelas'];
$level =$_POST['level'];
 $kode = $_POST['edis']; 
?>
<!DOCTYPE html>
<html>

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

    <title>KARPEL</title>

</head>
<style>
@page { margin: 6px; }
body { margin: 6px; }
</style>
<body>
    <?php
	$jumlah= mysqli_num_rows(mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_kelas='$kelas'"));
      $ttb1=mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tartib WHERE nomor = '1'"));
	  $ttb2=mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tartib WHERE nomor = '2'"));
	  $ttb3=mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tartib WHERE nomor = '3'"));
	  $ttb4=mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM tartib WHERE nomor = '4'"));
        $img=mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM aplikasi WHERE id_aplikasi = '1'"));
          $g=mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM karpel WHERE level = '$level'"));
    ?>
	<?php $jml_data = count($kode);
for ($i=0; $i <= $jml_data; $i++){ ?>
	
	<?php $no=0; ?>
	 <?php $siswaQ = mysqli_query($koneksi, "SELECT * FROM siswa WHERE  id_siswa='".$kode[$i]."' "); ?>
        <?php while ($r = mysqli_fetch_array($siswaQ)) : ?>
		<?php   $no++; ?>
<div style="width: 750px;height: 243px;background-image: url('../../dist/img/karpel/<?php echo $g[gambar]; ?>');">

    <img style="position: absolute;padding-left: 12px;padding-top: 5px;" class="img-responsive img" alt="Responsive image" src="../../<?php echo "$img[logo]";?>" width="45px">
    <img style="position: absolute;margin-left: 312px;padding-top: 9px;" class="img-responsive img" alt="Responsive image" src="../../<?php echo "$img[logo_kanan]";?>" width="45px">
     <p style="position: absolute; font-family: arial; font-size: 10px; color: #000; padding-left: 85px;margin-top:5px;text-transform: uppercase; text-align: center;"><?php echo $img["header"];?><br>Kab / Kota <?php echo $img["kabupaten"];?><br><b style="font-size: 12px"><?php echo $img["sekolah"];?></b></p>
    <p style="padding-left: 123px;padding-top: 50px;color: #000; "><b>KARTU PELAJAR</b></p>
    <?php if($r['foto']==''){ ?>
   <img style="position: absolute;margin-left: 20px;margin-top: -20px;border: 1px solid #fff;" src="../../dist/img/avatar.png" width="80px">
   <?php }else{ ?>
 <img style="border: 1px solid #fff;position: absolute;margin-left: 20px;margin-top: -20px;" src="../../foto/fotosiswa/<?= $r['foto'] ?>" width="80px">
   <?php } ?>   
		<table style="margin-top: -10px;margin-left: 110px; position: relative;font-family: arial;font-size: 11px;">
            <tr>
                <td>Nama</td>
                <td>:</td>
                <td><?php echo "$r[nama]";?></td>
            </tr><tr>
                <td>NIS/NISN</td>
                <td>:</td>
               <td><?php echo "$r[nis]";?>/<?php echo "$r[nisn]";?></td>
            </tr>
            </tr><tr>
                <td>Tempat Lahir</td>
                <td>:</td>
                <td><?php echo "$r[tempat_lahir]";?></td>
            </tr>
            <tr>
                <td>Tanggal Lahir</td>
                <td>:</td>
                <td><?php echo "$r[tgl_lahir]";?></td>
            </tr>
            <tr>
                <td>Jenis Kelamin</td>
                <td>:</td>
                <td><?php echo "$r[jenis_kelamin]";?></td>
            </tr>
            <tr>
                <td>Alamat</td>
                <td>:</td>
                <td><?php echo "$r[alamat]";?> - <?php echo "$r[desa]";?></td>
            </tr>
            <tr>
                <td>Berlaku</td>
                <td>:</td>
                <td>Selama Menjadi Siswa/i</td>
            </tr>
        </table>
			
        <p style="padding-left: 20px;font-size: 8px;margin-top: 10px; font-family: arial;position: absolute;">Alamat: Jl. <?php echo "$i[alamat]";?>  Kec. <?php echo "$i[kecamatan]";?> - Kab <?php echo "$i[kota]";?><br> Email: <?php echo "$i[email]";?> | Telp. <?php echo "$i[telp]";?> | Website: <?php echo "$i[web]";?></p>
     	   <p style="margin-top: -200px;padding-left: 480px;padding-top: 1px;"><b>TATA TERTIB SEKOLAH</b></p><br>
	   <p style="margin-top: -200px;padding-left: 400px;padding-top: 1px;font-size:11px;text-alin:justify">1. <?php echo $ttb1['isi']; ?>
	   <br> 2. <?php echo $ttb2['isi']; ?>
		<br>3. <?php echo $ttb3['isi']; ?>
		<br>4. <?php echo $ttb4['isi']; ?>
		</p>
		 <br>
        <br>
		<p style="position: absolute;padding-left: 550px;margin-top: -140px;font-size: 10px; font-family: arial;">
           <?php echo $i['kabupaten'];?>, <?php
                $tanggal = date ("j");
                $bulan = array(1=>"Januari","Februari","Maret", "April", "Mei", "Juni","Juli","Agustus","September","Oktober", "November","Desember");
                $bulan = $bulan[date("n")];
                $tahun = date("Y");
                echo $tanggal ." ". $bulan ." ". $tahun;
            ?>
        </p>
		 <p style="padding-left: 550px;margin-top:-130px;padding-top: 1px;font-size:11px">Mengetahui,<br>Kepala Sekolah</p>
	   		 
		<img style="position: absolute;padding-left: 550px;margin-top: -95px;" class="img-responsive img" alt="Responsive image" src="../../dist/img/ttd.png" width="70px">
        <p style="position: absolute;padding-left: 550px;margin-top: -70px;font-size: 10px; font-family: arial;"><b><u><?php echo "$img[kepsek]";?></u></b><br>NIP. <?php echo "$img[nip]";?></p>
         <img style="position: absolute;padding-left: 530px;margin-top: -115px;" class="img-responsive img" alt="Responsive image" src="../../<?php echo $setting['stempel'] ?>" width="70px">
     
           </div>
		   
			<p>
		  
<?php endwhile; ?>
<?php } ?>
</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("KARPEL_" . $kelas . ".pdf", array("Attachment" => false));
exit(0);
?>