<?php
ob_start();

include_once '../includes/constants.php';
include_once '../includes/functions.php';
include_once '../includes/allstripslashes.php';

// Connect to DB using modern mysqli
$partners = new partners;
$partners->connection($host, $user, $pass, $db);

// Retrieve and sanitize input
$eventcompo = isset($_POST['eventcompo']) ? trim($_POST['eventcompo']) : '';

if ($eventcompo === '' || $eventcompo === 'ChooseEvent') {
    $msg = "Please select an event to Delete !!";
    header("Location: index.php?Act=event&msg=" . urlencode($msg));
    exit;
}

// Use prepared statements to prevent SQL injection
$stmt1 = $partners->conn->prepare("DELETE FROM partners_event WHERE event_name = ?");
$stmt2 = $partners->conn->prepare("DELETE FROM partners_adminmail WHERE adminmail_eventname = ?");

if ($stmt1 && $stmt2) {
    $stmt1->bind_param("s", $eventcompo);
    $stmt2->bind_param("s", $eventcompo);

    $stmt1->execute();
    $stmt2->execute();

    $stmt1->close();
    $stmt2->close();

    $msg = "Event " . htmlspecialchars($eventcompo) . " Deleted !!";
} else {
    $msg = "Database error: Unable to prepare delete statements.";
}

header("Location: index.php?Act=event&msg=" . urlencode($msg));
exit;
?>
