<?php
session_start();
require_once(__DIR__ . '/../config/settings.php');

$masterAdmin = $db_settings['admin_user'] ?? 'Admin';
if (!isset($_SESSION['logged_in']) || $_SESSION['user_id'] !== $masterAdmin) {
    exit;
}

if (isset($_GET['id'])) {
    try {
        $dsn = "dblib:host={$db_settings['host']};dbname={$db_settings['name']};charset=UTF8";
        $pdo = new PDO($dsn, $db_settings['user'], $db_settings['pass']);

        $stmt = $pdo->prepare("DELETE FROM Web_Schedules WHERE id = ?");
        $stmt->execute([$_GET['id']]);
        echo "success";
    } catch (Exception $e) {
        echo "error";
    }
}