<?php
require_once '../includes/config.php';

$registrationId = $_GET['id'] ?? 0;
$eventId = $_GET['event_id'] ?? 0;

if ($registrationId) {
    // Get member info for the registration
    $stmt = $pdo->prepare("SELECT member_id FROM event_registrations WHERE id = ?");
    $stmt->execute([$registrationId]);
    $registration = $stmt->fetch();
    
    if ($registration) {
        // Delete registration
        $stmt = $pdo->prepare("DELETE FROM event_registrations WHERE id = ?");
        $stmt->execute([$registrationId]);
        
        // Update event attendee count
        $stmt = $pdo->prepare("UPDATE events SET current_attendees = current_attendees - 1 WHERE id = ?");
        $stmt->execute([$eventId]);
    }
}

header('Location: event_manage.php?id=' . $eventId);
exit;
?>