<?php
session_start();
require('../fpdf/fpdf.php');
include '../config/database.php';

$id = $_GET['id'];
$db = new Database(); $conn = $db->getConnection();
$stmt = $conn->prepare("SELECT j.*, g.nama_gereja, g.alamat as alamat_gereja FROM jemaat j LEFT JOIN gereja g ON j.gereja_id=g.id WHERE j.id=?");
$stmt->execute([$id]);
$d = $stmt->fetch(PDO::FETCH_ASSOC);

if($d['status_baptis'] != 'Sudah'){
    die('Jemaat ini belum dibaptis');
}

class PDF extends FPDF {
    function Header(){
        $this->Image('../assets/img/logo_gbi.png',20,10,20);
        $this->SetFont('Arial','B',16);
        $this->Cell(0,7,'GEREJA BETHEL INDONESIA',0,1,'C');
        $this->SetFont('Arial','B',14);
        $this->Cell(0,7,strtoupper($GLOBALS['d']['nama_gereja']),0,1,'C');
        $this->SetFont('Arial','',10);
        $this->Cell(0,5,$GLOBALS['d']['alamat_gereja'],0,1,'C');
        $this->Line(10,35,200,35);
        $this->Ln(10);
    }
}

$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','BU',14);
$pdf->Cell(0,10,'SURAT KETERANGAN BAPTIS',0,1,'C');
$pdf->SetFont('Arial','',11);
$pdf->Cell(0,7,'No: '.date('Y').'/SB/'.sprintf('%03d',$id),0,1,'C');
$pdf->Ln(8);

$pdf->MultiCell(0,7,'Yang bertanda tangan di bawah ini, Gembala '. $d['nama_gereja'] .', menerangkan bahwa:',0,'J');
$pdf->Ln(3);

$pdf->Cell(40,7,'Nama',0,0); $pdf->Cell(3,7,':',0,0); $pdf->Cell(0,7,$d['nama_lengkap'],0,1);
$pdf->Cell(40,7,'Tempat/Tgl Lahir',0,0); $pdf->Cell(3,7,':',0,0); $pdf->Cell(0,7,$d['tempat_lahir'].', '.date('d F Y',strtotime($d['tgl_lahir'])),0,1);
$pdf->Cell(40,7,'Jenis Kelamin',0,0); $pdf->Cell(3,7,':',0,0); $pdf->Cell(0,7,$d['jenis_kelamin']=='L'?'Laki-laki':'Perempuan',0,1);
$pdf->Cell(40,7,'Alamat',0,0); $pdf->Cell(3,7,':',0,0); $pdf->MultiCell(0,7,$d['alamat'],0,1);
$pdf->Ln(5);

$pdf->MultiCell(0,7,'Telah menerima Baptisan Air sesuai dengan Firman Tuhan dalam Matius 28:19 di '. $d['nama_gereja'] .'.',0,'J');
$pdf->Ln(3);
$pdf->MultiCell(0,7,'Demikian surat keterangan ini dibuat untuk dapat dipergunakan sebagaimana mestinya.',0,'J');

$pdf->Ln(15);
$pdf->Cell(120);
$pdf->Cell(0,6,'Keerom, '.date('d F Y'),0,1,'C');
$pdf->Cell(120);
$pdf->Cell(0,6,'Gembala,',0,1,'C');
$pdf->Ln(20);
$pdf->Cell(120);
$pdf->SetFont('Arial','BU',11);
$pdf->Cell(0,6,$_SESSION['nama'],0,1,'C');

$pdf->Output('I','Surat_Baptis_'.$d['nama_lengkap'].'.pdf');
?>