<?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');
}
$bl=date('m');
    $bulane = fetch ($koneksi, 'bulan', ['bln' =>$bl]);
?>
<!DOCTYPE html>
<html>

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

    <title>Data Buku</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>BUKU PERPUSTAKAAN<br><?= $setting['sekolah'] ?></h5>
    </center>
    <br>
       <table width="100%" border="1" style="font-size:10px">
          <tr>
         <th style="text-align:center;height:30px;width:5%">No</th>
		 <th style="text-align:center;">Judul Buku</th>
		 <th style="text-align:center;">Pengarang</th>
		 <th style="text-align:center;">Penerbit</th>
         <th style="text-align:center;">Lokasi Buku</th>
         <th style="text-align:center;width:5%">Jml</th>		 
		</tr>
		<?php
		$no = 0;
		$query = mysqli_query($koneksi, "select * from buku");
        while ($tjn = mysqli_fetch_array($query)) {
		$rak = fetch($koneksi,'buku_rak',['id_rak'=>$tjn['idrak']]);
                   $no++;
                   ?>
		 <tr>
          <td style="text-align:center;"><?= $no; ?></td>
		<td>&nbsp;<?= $tjn['judul'] ?></td>
		<td>&nbsp;<?= $tjn['pengarang'] ?></td>
		<td>&nbsp;<?= $tjn['penerbit'] ?></td>
		<td>&nbsp;<?= $rak['nama_rak'] ?> - BOX <?= $rak['nomor_box'] ?></td>
		<td style="text-align:center;"><?= $tjn['jumlah'] ?></td>
		</tr>
		<?php } ?>							
    </table>
		<br>
		<table width='100%'>
					<tr>
					<td></td>
					<td></td>
						<td>
							Mengetahui, <br/>
							Kepala Sekolah <br/>
							<br/>
							<br/>
							<br/>
							
							<u><?= $setting['kepsek'] ?></u><br/>
							NIP. <?= $setting['nip'] ?>
						</td>
						<td width='40%'></td>
						<td width="5%"></td>
						<td>
							<?= $setting['kecamatan'] ?>, <?php echo date("t",time());; ?> <?= $bulane['ket'] ?> <?= date('Y') ?><br/>
							Pengurus Perpustakaan<br/>
							<br/>
							<br/>
							<br/>
							
							<u>___________________________</u><br/>
							NIP. 
						</td>
					</tr>
				</table>

</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("Data Buku" . $bulane['ket'] . ".pdf", array("Attachment" => false));
exit(0);
?>