<?php
// File: admin/export_diterima.php
session_start();
if (!isset($_SESSION['admin'])) {
  header("Location: login.php");
  exit;
}

include '../config/koneksi.php';

header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=pendaftar_diterima_" . date("Ymd") . ".xls");

// Ambil data dari database
$data = mysqli_query($conn, "SELECT * FROM pendaftar WHERE status = 'diterima'");
?>

<table border="1">
  <thead>
    <tr>
      <th>No</th>
      <th>No. Pendaftaran</th>
      <th>Nama Lengkap</th>
      <th>Tempat Lahir</th>
      <th>Tanggal Lahir</th>
      <th>Usia</th>
      <th>Jenis Kelamin</th>
      <th>Alamat</th>
      <th>Sekolah Asal</th>
      <th>No HP</th>
      <th>NIK</th>
      <th>Nama Ayah</th>
      <th>Pekerjaan Ayah</th>
      <th>Status Ayah</th>
      <th>Nama Ibu</th>
      <th>Pekerjaan Ibu</th>
      <th>Status Ibu</th>
      <th>Tanggal Daftar</th>
    </tr>
  </thead>
  <tbody>
    <?php $no = 1; while ($row = mysqli_fetch_assoc($data)) : ?>
      <tr>
        <td><?= $no++ ?></td>
        <td><?= $row['nomor_pendaftaran'] ?></td>
        <td><?= $row['nama_lengkap'] ?></td>
        <td><?= $row['tempat_lahir'] ?></td>
        <td><?= $row['tanggal_lahir'] ?></td>
        <td><?= $row['usia'] ?></td>
        <td><?= $row['jenis_kelamin'] ?></td>
        <td><?= $row['alamat'] ?></td>
        <td><?= $row['sekolah_asal'] ?></td>
        <td><?= $row['no_hp'] ?></td>
        <td><?= $row['nik'] ?></td>
        <td><?= $row['nama_ayah'] ?></td>
        <td><?= $row['pekerjaan_ayah'] ?></td>
        <td><?= $row['status_ayah'] ?></td>
        <td><?= $row['nama_ibu'] ?></td>
        <td><?= $row['pekerjaan_ibu'] ?></td>
        <td><?= $row['status_ibu'] ?></td>
        <td><?= $row['created_at'] ?? '-' ?></td>
      </tr>
    <?php endwhile; ?>
  </tbody>
</table>