<?php
session_start();
require_once '../koneksi.php';
require_once '../auth.php';
cekAdminAtauGuru(); // Sesuaikan dengan fungsi otentikasi Anda

if (isset($_GET['id'])) {
    $id = mysqli_real_escape_string($koneksi, $_GET['id']);

    // Opsional: Hapus file foto jika ada agar tidak memenuhi folder
    $query_foto = mysqli_query($koneksi, "SELECT foto FROM master_siswa WHERE id_siswa = '$id'");
    $d = mysqli_fetch_assoc($query_foto);
    if (!empty($d['foto']) && file_exists('../assets/img/siswa/'.$d['foto'])) {
        unlink('../assets/img/siswa/'.$d['foto']);
    }

    // Jalankan query hapus
    $hapus = mysqli_query($koneksi, "DELETE FROM master_siswa WHERE id_siswa = '$id'");

    if ($hapus) {
        echo "<script>alert('Data berhasil dihapus!'); window.location='siswa.php';</script>";
    } else {
        echo "<script>alert('Gagal menghapus data!'); window.location='siswa.php';</script>";
    }
} else {
    header("Location: siswa.php");
}
?>