<?php
require_once __DIR__.'/../includes/db.php';

$id = (int)($_GET['id'] ?? 0);
$r = $mysqli->query("SELECT * FROM surat_undangan WHERE id=$id")->fetch_assoc();
if(!$r) die('Data tidak ditemukan');

function tgl($d){
  return date('d F Y', strtotime($d));
}

$tujuan = explode("\n", trim($r['tujuan']));
$linkQR = urlencode(
  "https://adminmambu.sidea.id/modules/verifikasi_surat_undangan.php?kode=".$r['qr_kode']
);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Surat Undangan</title>

<style>
@page{size:A4;margin:1cm 3cm 0cm 3cm}
body{font-family:"Times New Roman";font-size:12pt;line-height:1.2}

/* KOP */
.kop{margin-bottom:10px}
.logo{width:70px}
.kop-text{text-align:center}
.kop-text .baris1{font-size:14pt;font-weight:bold}
.kop-text .baris2,
.kop-text .baris3{font-size:13pt;font-weight:bold}
.kop-text .alamat{font-size:10pt;font-style:italic}
.garis-kop{border-top:2px solid #000;border-bottom:1px solid #000;height:4px;margin:8px 0 18px}

.paragraf{text-align:justify}
table.meta td{padding:2px 6px;vertical-align:top}
.ttd{margin-top:10px;text-align:center}
</style>
</head>

<body onload="window.print()">

<!-- KOP -->
<div class="kop">
<table width="100%">
<tr>
<td width="15%"><img src="assets/img/logo.png" class="logo"></td>
<td width="85%" align="center">
  <div class="kop-text">
    <div class="baris1">PEMERINTAH KABUPATEN POLEWALI MANDAR</div>
    <div class="baris2">KECAMATAN LUYO</div>
    <div class="baris3">DESA MAMBU</div>
    <div class="alamat">
      Alamat : Jl. Poros Tutar Dusun Kottar Desa Mambu Kec. Luyo
      &nbsp; Kode Pos : 91353
    </div>
  </div>
</td>
</tr>
</table>
</div>

<div class="garis-kop"></div>

<p style="text-align:right">Mambu, <?= tgl($r['tanggal_surat']) ?></p>

<table class="meta">
<tr><td width="15%">Nomor</td><td>: <?= $r['nomor_surat'] ?></td></tr>
<tr><td>Sifat</td><td>: <?= $r['sifat'] ?></td></tr>
<tr><td>Lampiran</td><td>: <?= $r['lampiran'] ?></td></tr>
<tr><td>Perihal</td><td>: <b><?= $r['perihal'] ?></b></td></tr>
</table>

<br>

<p>
Kepada<br>
Yth.
<?php foreach($tujuan as $t): ?>
<br><?= esc($t) ?>
<?php endforeach; ?>
<br><br>
Di -<br>
&nbsp;&nbsp;&nbsp;&nbsp;Tempat
</p>

<p><i>Assalamualaikum Warahmatullahi Wabarakatuh</i></p>

<p class="paragraf">Dengan Hormat,</p>

<p class="paragraf">
<?= nl2br(esc($r['isi'])) ?>
</p>

<table>
<tr><td width="30%">Hari / Tanggal</td><td>: <?= $r['hari_tanggal'] ?></td></tr>
<tr><td>Pukul</td><td>: <?= $r['pukul'] ?></td></tr>
<tr><td>Tempat</td><td>: <?= $r['tempat'] ?></td></tr>
</table>

<p class="paragraf">
Demikian undangan ini kami sampaikan, atas kehadiran dan kerjasamanya
kami ucapkan terima kasih.
</p>

<div class="ttd">
Mambu, <?= tgl($r['tanggal_surat']) ?><br>
Kepala Desa Mambu<br>

<img
  src="https://api.qrserver.com/v1/create-qr-code/?size=120x120&data=<?= $linkQR ?>"
  alt="QR Verifikasi"
>

<br>
<b><u>HAYAMUDDIN</u></b>
</div>

</body>
</html>
