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

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

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

<!DOCTYPE html>
<html lang="id">
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Pendaftar SPMB</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">

<style>

body{
    background:#f4f6f9;
    font-family:'Segoe UI',sans-serif;
}

/* Sidebar */
.sidebar{
    width:260px;
    min-height:100vh;
    background:#0d1b2a;
    position:fixed;
    left:0;
    top:0;
    color:white;
    padding-top:20px;
}

.sidebar .logo{
    text-align:center;
    margin-bottom:30px;
}

.sidebar .logo h4{
    font-weight:700;
}

.sidebar a{
    display:block;
    color:white;
    padding:15px 25px;
    text-decoration:none;
    transition:0.3s;
    font-size:15px;
}

.sidebar a:hover{
    background:#1b263b;
    padding-left:35px;
}

.sidebar a i{
    width:25px;
}

/* Main */
.main-content{
    margin-left:260px;
    padding:20px;
}

/* Navbar */
.navbar{
    background:linear-gradient(45deg,#0d6efd,#0b5ed7);
}

/* Card */
.main-card{
    border:none;
    border-radius:25px;
    overflow:hidden;
    box-shadow:0 10px 30px rgba(0,0,0,0.08);
}

.table thead{
    background:#0d6efd;
    color:white;
}

.table tbody tr:hover{
    background:#f1f5ff;
}

.badge-jurusan{
    padding:8px 15px;
    border-radius:20px;
    font-size:13px;
}

.btn-action{
    width:35px;
    height:35px;
    border-radius:10px;
    display:flex;
    align-items:center;
    justify-content:center;
}

.foto-preview{
    width:60px;
    height:60px;
    object-fit:cover;
    border-radius:10px;
    border:2px solid #ddd;
}

/* Responsive */
@media(max-width:992px){

    .sidebar{
        position:relative;
        width:100%;
        min-height:auto;
    }

    .main-content{
        margin-left:0;
    }

}

</style>

</head>
<body>

<!-- Sidebar -->
<div class="sidebar">

<div class="logo">
<h4>SPMB ADMIN</h4>
<p>SMKN 1 CIKAUM</p>
</div>

<a href="dashboard.php">
<i class="fa fa-home"></i> Dashboard
</a>

<a href="data_pendaftar.php">
<i class="fa fa-users"></i> Data Pendaftar
</a>


<a href="statistik.php">
<i class="fa fa-chart-bar"></i> Statistik
</a>



<a href="logout.php">
<i class="fa fa-sign-out-alt"></i> Logout
</a>

</div>

<!-- Main -->
<div class="main-content">

<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark rounded-4 shadow-sm px-4 mb-4">

<div class="container-fluid">

<span class="navbar-brand fw-bold">
Data Pendaftar SPMB
</span>

<div class="text-white">
<i class="fa fa-user-circle"></i>
Administrator
</div>

</div>

</nav>

<!-- Header Card -->
<div class="card main-card mb-4">

<div class="card-body p-4">

<div class="d-flex justify-content-between align-items-center flex-wrap gap-3">

<div>
<h3 class="fw-bold mb-1">
<i class="fa fa-users text-primary"></i>
Data Pendaftar
</h3>

<p class="text-muted mb-0">
Daftar peserta didik baru SMKN 1 CIKAUM
</p>
</div>

<div>

<a href="export_excel.php" class="btn btn-success rounded-pill px-4">
<i class="fa fa-file-excel"></i>
Export Excel
</a>



</div>

</div>

</div>

</div>

<!-- Table -->
<div class="card main-card">

<div class="card-body">

<div class="table-responsive">

<table class="table table-hover align-middle">

<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>NISN</th>
<th>Jurusan</th>
<th>No HP</th>
<th>KK</th>
<th>KTP</th>
<th>Akte</th>
<th>Tanggal</th>
<th>Aksi</th>
</tr>
</thead>

<tbody>

<?php
$no=1;

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

<tr>

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

<td>
<b><?= $d['nama'] ?></b><br>
<small class="text-muted">
<?= $d['asal_sekolah'] ?>
</small>
</td>

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

<td>

<?php
$warna = "primary";

if($d['jurusan']=="ATPH"){
    $warna="success";
}elseif($d['jurusan']=="ATU"){
    $warna="warning";
}elseif($d['jurusan']=="PPLG"){
    $warna="danger";
}elseif($d['jurusan']=="DKV"){
    $warna="dark";
}elseif($d['jurusan']=="TSM"){
    $warna="primary";
}elseif($d['jurusan']=="TPTUP"){
    $warna="info";
}
?>

<span class="badge bg-<?= $warna ?> badge-jurusan">
<?= $d['jurusan'] ?>
</span>

</td>

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

<!-- KK -->
<td>
<a href="../assets/img/kk/<?= $d['foto_kk'] ?>" target="_blank">
<img src="../assets/img/kk/<?= $d['foto_kk'] ?>"
class="foto-preview">
</a>
</td>

<!-- KTP -->
<td>
<a href="../assets/img/ktp/<?= $d['foto_ktp'] ?>" target="_blank">
<img src="../assets/img/ktp/<?= $d['foto_ktp'] ?>"
class="foto-preview">
</a>
</td>

<!-- Akte -->
<td>
<a href="../assets/img/akte/<?= $d['foto_akte'] ?>" target="_blank">
<img src="../assets/img/akte/<?= $d['foto_akte'] ?>"
class="foto-preview">
</a>
</td>

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

<td>

<div class="d-flex gap-2">

<a href="edit_pendaftar.php?id=<?= $d['id'] ?>"
class="btn btn-warning btn-action text-white">

<i class="fa fa-edit"></i>

</a>

<a href="hapus_pendaftar.php?id=<?= $d['id'] ?>"
class="btn btn-danger btn-action"
onclick="return confirm('Yakin ingin menghapus data ini?')">

<i class="fa fa-trash"></i>

</a>

</div>

</td>

</tr>

<?php } ?>

</tbody>

</table>

</div>

</div>

</div>

<!-- Footer -->
<div class="text-center mt-4 text-muted">
© 2026 SPMB SMKN 1 CIKAUM
</div>

</div>

</body>
</html>