<?php
/**
 * Registration Handler for Charity Boat Race
 */

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
    $type = filter_input(INPUT_POST, 'registration_type', FILTER_SANITIZE_SPECIAL_CHARS);
    
    // Common sanitation
    $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $name = filter_input(INPUT_POST, 'full_name', FILTER_SANITIZE_SPECIAL_CHARS) 
            ?: filter_input(INPUT_POST, 'contact_name', FILTER_SANITIZE_SPECIAL_CHARS) 
            ?: filter_input(INPUT_POST, 'captain_name', FILTER_SANITIZE_SPECIAL_CHARS)
            ?: "Valued Participant";
    
    // Simulate processing
    // In a real app, save to database here
    
    echo "<!DOCTYPE html>
    <html lang='en'>
    <head>
        <meta charset='UTF-8'>
        <meta name='viewport' content='width=device-width, initial-scale=1.0'>
        <title>Registration Received | Charity Boat Race</title>
        <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
        <link rel='stylesheet' href='../css/style.css'>
    </head>
    <body class='bg-background d-flex align-items-center justify-content-center' style='min-height: 100vh;'>
        <div class='card p-5 shadow-lg text-center' style='max-width: 600px;'>
            <div class='bg-secondary-subtle p-4 rounded-circle mx-auto mb-4' style='width: 80px; height: 80px;'>
                <svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='text-secondary'><path d='M22 11.08V12a10 10 0 1 1-5.93-9.14'/><polyline points='22 4 12 14.01 9 11.01'/></svg>
            </div>
            <h2 class='fw-bold mb-3'>Registration Received!</h2>
            <p class='text-muted mb-4'>Thank you, $name. We've received your registration for the <strong>" . ucfirst($type) . "</strong>. A confirmation email has been sent to <strong>$email</strong> with further instructions.</p>
            <div class='bg-light p-3 rounded-3 mb-4'>
                <p class='small mb-0 text-muted'>Reference ID: CBR-" . strtoupper(substr(md5(time()), 0, 8)) . "</p>
            </div>
            <a href='../index.php' class='btn btn-primary px-4'>Back to Home</a>
        </div>
    </body>
    </html>";
    
} else {
    header("Location: ../index.php");
    exit();
}
?>
