<?php
session_start();
if (!isset($_SESSION['user_id']) || !isset($_GET['id'])) {
    header('Location: login.php');
    exit();
}

include 'db/config.php';

$id = $_GET['id'];

$pdo = db();
$stmt = $pdo->prepare("DELETE FROM functions WHERE id = :id");
$stmt->execute(['id' => $id]);

// Optional: Also delete user_functions associated with this function
$stmt = $pdo->prepare("DELETE FROM user_functions WHERE function_id = :function_id");
$stmt->execute(['function_id' => $id]);

header('Location: functions.php');
exit();
