<?php
session_start();
if (!isset($_SESSION['admin_logged_in'])) {
    header("Location: admin_login.html");
    exit();
}
require_once 'connection.php';

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);

    // Optionally delete photo file from server
    $getPhoto = $conn->query("SELECT photo FROM employee_records WHERE id = $id");
    if ($getPhoto && $getPhoto->num_rows === 1) {
        $photoRow = $getPhoto->fetch_assoc();
        if (!empty($photoRow['photo']) && file_exists($photoRow['photo'])) {
            unlink($photoRow['photo']);
        }
    }

    $conn->query("DELETE FROM employee_records WHERE id = $id");
}

header("Location: admin_dashboard.php");
exit();
?>
