<?php
session_start();
include '../config/koneksi.php';

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

// Header export excel
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=Data_Pendaftar_SPMB.xls");

$data = mysqli_query($conn,"SELECT * FROM pendaftar ORDER BY id DESC");
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Export Excel SPMB</title>

<style>

table{
    border-collapse:collapse;
    width:100%;
}

table, th, td{
    border:1px solid black;
}

th{
    background:#0d6efd;
    color:white;
    padding:10px;
    text-align:center;
}

td{
    padding:8px;
}

.title{
    text-align:center;
    margin-bottom:20px;
}

</style>

</head>
<body>

<div class="title">

<h2>DATA PENDAFTAR SPMB</h2>
<h3>SMKN 1 CIKAUM</h3>
<p>Tahun Ajaran 2026 / 2027</p>

</div>

<table>

<tr>
<th>No</th>
<th>Nama</th>
<th>NISN</th>
<th>Asal Sekolah</th>
<th>Jurusan</th>
<th>No HP</th>
<th>Alamat</th>
<th>Foto KK</th>
<th>Foto KTP</th>
<th>Foto Akte</th>
<th>Tanggal Daftar</th>
</tr>

<?php
$no=1;

while($d=mysqli_fetch_array($data)){
?>

<tr>

<td><?= $no++ ?></td>

<td><?= $d['nama'] ?></td>

<td><?= $d['nisn'] ?></td>

<td><?= $d['asal_sekolah'] ?></td>

<td><?= $d['jurusan'] ?></td>

<td><?= $d['no_hp'] ?></td>

<td><?= $d['alamat'] ?></td>

<td>
<?= $d['foto_kk'] ?>
</td>

<td>
<?= $d['foto_ktp'] ?>
</td>

<td>
<?= $d['foto_akte'] ?>
</td>

<td>
<?= date('d-m-Y',strtotime($d['tanggal_daftar'])) ?>
</td>

</tr>

<?php } ?>

</table>

</body>
</html>