<?php
session_start();
include 'koneksi.php';
// Cek apakah admin sudah login
if (!isset($_SESSION['admin_id'])) {
    header("Location: index");
    exit();
}

if (!isset($_GET['table']) || !isset($_GET['id'])) {
    die("Invalid request");
}

$table = $_GET['table'];
$id = $_GET['id'];

$columns = $pdo->query("SHOW COLUMNS FROM `$table`")->fetchAll(PDO::FETCH_ASSOC);
$primaryKey = $columns[0]['Field'];

$query = $pdo->prepare("DELETE FROM `$table` WHERE `$primaryKey` = ?");
$query->execute([$id]);

header("Location: home?tab=$table");
exit();
