<?php
include_once 'api/config.php';

// Check if the user is logged in
if (!isset($_SESSION['SESS_UID'])) {
    header('location:index.php');
    exit();
}

// Check if a delete request is made
if (isset($_GET['deleteId'])) {
    $deleteId = $_GET['deleteId'];

    // Perform delete operation
    $sql = "DELETE FROM customers WHERE cust_id = $deleteId";
    $result = mysqli_query($link, $sql);

    if ($result) {
        $_SESSION['MSG'] = "<div class='alert alert-success'>Customer deleted successfully.</div>";
    } else {
        $_SESSION['MSG'] = "<div class='alert alert-danger'>Failed to delete customer.</div>";
    }
}

// Redirect back to customers.php
header('location: customers.php');
exit();
?>
