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

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

$id = intval($_GET['id']);
$produk = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM produk WHERE id='$id'"));
if($produk){
    if(file_exists('../assets/img/'.$produk['gambar'])) unlink('../assets/img/'.$produk['gambar']);
    mysqli_query($conn, "DELETE FROM produk WHERE id='$id'");
}

header("Location: index_admin.php");
exit;
