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

$id = (int)$_GET['id'];

$q = $mysqli->query("
  SELECT s.*, i.nama_lengkap
  FROM surat_penghasilan_ortu s
  JOIN infografis i ON s.warga_id=i.id
  WHERE s.id=$id
")->fetch_assoc();

if(!$q) die('Data surat tidak ditemukan');

}

if(!$q['surat_id']){
  die('Surat belum dibuat oleh admin');
}

switch($q['jenis_surat']){
  case 'penghasilan_ortu':
    header("Location: surat_penghasilan_ortu_print.php?id=".$q['surat_id']);
    break;

  case 'usaha':
    header("Location: surat_usaha_print.php?id=".$q['surat_id']);
    break;

  case 'domisili':
    header("Location: surat_domisili_print.php?id=".$q['surat_id']);
    break;

  default:
    die('Jenis surat belum tersedia');
}
exit;
