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

$db = new Database();
$conn = $db->getConnection();
$id = $_GET['id'];

$stmt = $conn->prepare("SELECT j.*, g.nama_gereja FROM jemaat j JOIN gereja g ON j.gereja_id=g.id WHERE j.id=?");
$stmt->execute([$id]);
$d = $stmt->fetch(PDO::FETCH_ASSOC);

$pdf = new FPDF('P','mm',[85,54]); // Ukuran KTP
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Cell(0,5,'KARTU ANGGOTA JEMAAT',0,1,'C');
$pdf->SetFont('Arial','B',9);
$pdf->Cell(0,4,'GEREJA BETHEL INDONESIA',0,1,'C');
$pdf->SetFont('Arial','',8);
$pdf->Cell(0,4,$d['nama_gereja'],0,1,'C');
$pdf->Ln(2);

$pdf->Image('../assets/img/profil/'.$d['foto'],5,20,20,25);
$pdf->SetXY(28,20);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(0,4,'No. Anggota: '.$d['no_anggota'],0,1);
$pdf->SetX(28);
$pdf->Cell(0,4,'Nama: '.$d['nama_lengkap'],0,1);
$pdf->SetX(28);
$pdf->Cell(0,4,'TTL: '.$d['tempat_lahir'].', '.date('d-m-Y',strtotime($d['tgl_lahir'])),0,1);
$pdf->SetX(28);
$pdf->Cell(0,4,'Status: '.$d['status_baptis'].' Baptis',0,1);

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