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

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

$id = $_GET['id'];

$data = mysqli_query($conn,
"SELECT * FROM pendaftar WHERE id='$id'");

$d = mysqli_fetch_array($data);

// Hapus file gambar
if(file_exists("../assets/img/kk/".$d['foto_kk'])){
    unlink("../assets/img/kk/".$d['foto_kk']);
}

if(file_exists("../assets/img/ktp/".$d['foto_ktp'])){
    unlink("../assets/img/ktp/".$d['foto_ktp']);
}

if(file_exists("../assets/img/akte/".$d['foto_akte'])){
    unlink("../assets/img/akte/".$d['foto_akte']);
}

// Hapus data database
mysqli_query($conn,
"DELETE FROM pendaftar WHERE id='$id'");

echo "
<script>
alert('Data berhasil dihapus');
window.location='data_pendaftar.php';
</script>
";
?>