<?php
session_start();
include "koneksi.php";

if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
    die("Akses ditolak.");
}

if (!isset($_POST['id'])) {
    header("Location: kontak.php");
    exit;
}

$id = intval($_POST['id']);
$mitra = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT foto FROM kontak_mitra WHERE id=$id"));

if ($mitra && $mitra['foto'] && file_exists("foto_mitra/" . $mitra['foto'])) {
    @unlink("foto_mitra/" . $mitra['foto']);
}

mysqli_query($koneksi, "DELETE FROM kontak_mitra WHERE id=$id");
header("Location: kontak.php?msg=deleted");
exit;
