Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/conference/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/conference/register.php

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

$eventId = $_GET['event'] ?? null;
$error = '';
$success = '';

if (!$eventId) {
    header('Location: ' . BASE_URL);
    exit();
}

$db = new CopMadinaDB();
$conn = $db->getConnection();

// Get event details
$stmt = $conn->prepare("SELECT e.*, 
                               a.name as area_name, 
                               d.name as district_name, 
                               ass.name as assembly_name
                        FROM events e
                        LEFT JOIN areas a ON e.area_id = a.id
                        LEFT JOIN districts d ON e.district_id = d.id
                        LEFT JOIN assemblies ass ON e.assembly_id = ass.id
                        WHERE e.id = ? AND e.status = 'published'");
$stmt->execute([$eventId]);
$event = $stmt->fetch();

// Get settings for site branding
$settings = getSettings();

if (!$event) {
    header('Location: ' . BASE_URL);
    exit();
}

// Check if registration is still open
$now = new DateTime();
$registrationDeadline = $event['registration_deadline'] ? new DateTime($event['registration_deadline']) : null;
$eventStart = new DateTime($event['start_date']);

if ($registrationDeadline && $now > $registrationDeadline) {
    $error = 'Registration deadline has passed.';
} elseif ($now > $eventStart) {
    $error = 'This event has already started.';
}

// Check capacity
$registrationCount = getEventRegistrationCount($eventId);
if ($event['capacity'] > 0 && $registrationCount >= $event['capacity']) {
    $error = 'This event is fully booked.';
}

// Get event form - check template first when set, then custom form as fallback
$formFields = [];

if (!empty($event['form_template_id'])) {
    // Use form template when assigned
    $stmt = $conn->prepare("SELECT form_fields FROM event_form_templates WHERE id = ? AND status = 'active'");
    $stmt->execute([$event['form_template_id']]);
    $template = $stmt->fetch();
    if ($template) {
        $formFields = json_decode($template['form_fields'], true) ?: [];
        
        // Generate name attributes for template fields that don't have them
        foreach ($formFields as &$field) {
            if (empty($field['name']) && !empty($field['label'])) {
                // Convert label to field name (lowercase, replace spaces with underscores, remove special chars)
                $field['name'] = strtolower(preg_replace('/[^a-zA-Z0-9\s]/', '', $field['label']));
                $field['name'] = preg_replace('/\s+/', '_', trim($field['name']));
            }
        }
        unset($field); // Break reference
        
    } else {
        error_log("No template found for form_template_id: " . $event['form_template_id']);
    }
}

// Fallback to custom event form if no template or template not found
if (empty($formFields)) {
    $stmt = $conn->prepare("SELECT form_fields FROM event_forms WHERE event_id = ?");
    $stmt->execute([$eventId]);
    $eventForm = $stmt->fetch();
    if ($eventForm) {
        $formFields = json_decode($eventForm['form_fields'], true) ?: [];
        error_log("Custom form fields loaded: " . json_encode($formFields));
    } else {
        error_log("No custom form found for event_id: " . $eventId);
    }
}

// Check if user is already registered
$alreadyRegistered = false;
if (isLoggedIn()) {
    $alreadyRegistered = isUserRegisteredForEvent($_SESSION['user_id'], $eventId);
}

// Get areas, districts, and assemblies for dropdowns
$areas = [];
$districts = [];
$assemblies = [];

try {
    // Get all active areas
    $stmt = $conn->prepare("SELECT id, name FROM areas WHERE status = 'active' ORDER BY name");
    $stmt->execute();
    $areas = $stmt->fetchAll();
    
    // Get all active districts
    $stmt = $conn->prepare("SELECT id, name, area_id FROM districts WHERE status = 'active' ORDER BY name");
    $stmt->execute();
    $districts = $stmt->fetchAll();
    
    // Get all active assemblies
    $stmt = $conn->prepare("SELECT id, name, district_id FROM assemblies WHERE status = 'active' ORDER BY name");
    $stmt->execute();
    $assemblies = $stmt->fetchAll();
} catch (Exception $e) {
    error_log("Error fetching organizational data: " . $e->getMessage());
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !$error && !$alreadyRegistered) {
    $firstName = sanitizeInput($_POST['first_name'] ?? '');
    $lastName = sanitizeInput($_POST['last_name'] ?? '');
    $email = sanitizeInput($_POST['email'] ?? '');
    $phone = sanitizeInput($_POST['phone'] ?? '');
    
    // Collect form data
    $formData = [];
    foreach ($formFields as $field) {
        $fieldName = $field['name'] ?? '';
        if (!empty($fieldName) && isset($_POST[$fieldName])) {
            $formData[$fieldName] = sanitizeInput($_POST[$fieldName]);
        }
    }
    
    // Collect area, district, and assembly data
    $areaId = sanitizeInput($_POST['area_id'] ?? '');
    $districtId = sanitizeInput($_POST['district_id'] ?? '');
    $assemblyId = sanitizeInput($_POST['assembly_id'] ?? '');
    
    if (empty($firstName) || empty($lastName) || empty($email) || empty($phone)) {
        $error = 'Please fill in all required fields.';
    } else {
        // Generate registration code
        $registrationCode = generateRandomCode(8);
        
        // Calculate registration fee
        $registrationFee = $event['registration_fee'];
        $earlyBirdDeadline = $event['early_bird_deadline'] ? new DateTime($event['early_bird_deadline']) : null;
        
        if ($earlyBirdDeadline && $now <= $earlyBirdDeadline && $event['early_bird_fee'] > 0) {
            $registrationFee = $event['early_bird_fee'];
        }
        
        try {
            $conn->beginTransaction();
            
            if (isLoggedIn()) {
                // Registered member registration
                $stmt = $conn->prepare("INSERT INTO event_registrations 
                                       (event_id, user_id, registration_code, form_data, amount_paid, payment_status, status) 
                                       VALUES (?, ?, ?, ?, ?, 'pending', 'confirmed')");
                $stmt->execute([
                    $eventId, 
                    $_SESSION['user_id'], 
                    $registrationCode, 
                    json_encode($formData), 
                    $registrationFee
                ]);
                
                $registrationId = $conn->lastInsertId();
                
                // Add notification
                addNotification($_SESSION['user_id'], 
                               'Event Registration Successful', 
                               "You have successfully registered for {$event['title']}. Registration code: {$registrationCode}",
                               'success');
            } else {
                // Non-member registration
                $stmt = $conn->prepare("INSERT INTO nonmember_registrations 
                                       (event_id, registration_code, first_name, last_name, email, phone, area_id, district_id, assembly_id, form_data, amount_paid, payment_status, status) 
                                       VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending', 'confirmed')");
                $stmt->execute([
                    $eventId, 
                    $registrationCode, 
                    $firstName, 
                    $lastName, 
                    $email, 
                    $phone,
                    !empty($areaId) ? $areaId : null,
                    !empty($districtId) ? $districtId : null,
                    !empty($assemblyId) ? $assemblyId : null,
                    json_encode($formData), 
                    $registrationFee
                ]);
                
                $registrationId = $conn->lastInsertId();
            }
            
            // ===== DYNAMIC TABLE POPULATION FEATURE - START =====
            // Populate custom event table if it exists
            if (!empty($event['custom_table_name'])) {
                try {
                    // Check if custom table exists
                    $table_check = $conn->prepare("SHOW TABLES LIKE ?");
                    $table_check->execute([$event['custom_table_name']]);
                    
                    if ($table_check->rowCount() > 0) {
                        // Prepare data for custom table insertion
                        $custom_data = [
                            'registration_id' => $registrationId,
                            'registration_code' => $registrationCode,
                            'registration_type' => isLoggedIn() ? 'member' : 'nonmember'
                        ];
                        
                        if (isLoggedIn()) {
                            $custom_data['user_id'] = $_SESSION['user_id'];
                        }
                        
                        // Add form field data to custom table data
                        foreach ($formFields as $field) {
                            $field_name = preg_replace('/[^a-zA-Z0-9_]/', '_', strtolower($field['label']));
                            $field_name = substr($field_name, 0, 64);
                            
                            if (isset($formData[$field['name']])) {
                                $custom_data[$field_name] = $formData[$field['name']];
                            }
                        }
                        
                        // Add area, district, and assembly data to custom table data
                        $custom_data['area_id'] = $areaId;
                        $custom_data['district_id'] = $districtId;
                        $custom_data['assembly_id'] = $assemblyId;
                        
                        // Build dynamic INSERT query
                        $columns = array_keys($custom_data);
                        $placeholders = str_repeat('?,', count($columns) - 1) . '?';
                        $insert_sql = "INSERT INTO `{$event['custom_table_name']}` (`" . implode('`, `', $columns) . "`) VALUES ($placeholders)";
                        
                        $custom_stmt = $conn->prepare($insert_sql);
                        $custom_stmt->execute(array_values($custom_data));
                        
                        logAudit('create', 'dynamic_table_data', $registrationId, "Populated table: {$event['custom_table_name']}");
                    }
                } catch (Exception $e) {
                    // Log error but don't fail registration
                    error_log("Dynamic table population failed for event {$eventId}: " . $e->getMessage());
                }
            }
            // ===== DYNAMIC TABLE POPULATION FEATURE - END =====
            
            // Log audit
            logAudit('event_registration', isLoggedIn() ? 'event_registrations' : 'nonmember_registrations', $registrationId);
            
            $conn->commit();
            
            $success = "Registration successful! Your registration code is: <strong>{$registrationCode}</strong>. Please save this code for your records.";
            
            if ($registrationFee > 0) {
                $success .= " Payment of " . formatCurrency($registrationFee) . " is required to complete your registration.";
            }
            
        } catch (Exception $e) {
            $conn->rollback();
            $error = 'Registration failed. Please try again.';
            error_log("Registration error: " . $e->getMessage());
            error_log("Registration error details - Event ID: $eventId, User logged in: " . (isLoggedIn() ? 'Yes' : 'No'));
            error_log("Registration error stack trace: " . $e->getTraceAsString());
        }
    }
}

$settings = getSettings();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register for <?php echo htmlspecialchars($event['title']); ?> - <?php echo htmlspecialchars($settings['site_name'] ?? 'COP Madina'); ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: {
                            50: '#eff6ff',
                            100: '#dbeafe',
                            500: '#3b82f6',
                            600: '#2563eb',
                            700: '#1d4ed8',
                            800: '#1e40af',
                            900: '#1e3a8a'
                        }
                    }
                }
            }
        }
    </script>
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
    </style>
</head>
<body class="bg-gray-50">
    <div id="app">
        <!-- Navigation -->
        <nav class="bg-gradient-to-r from-blue-500 via-slate-600 to-violet-400 shadow-lg border-b border-slate-200/50 sticky top-0 z-50">
            <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
                <div class="flex justify-between items-center h-16">
                    <!-- Logo -->
                    <div class="flex items-center space-x-3">
                        <div class="p-2 rounded-xl bg-gradient-to-br from-blue-500 to-purple-600">
                            <i class="fas fa-church text-white text-xl"></i>
                        </div>
                        <div>
                            <h1 class="text-xl font-bold text-white drop-shadow-lg">
                                COP Madina
                            </h1>
                            <p class="text-xs text-white/80">Event Registration</p>
                        </div>
                    </div>
                    
                    <!-- Navigation Links -->
                    <div class="flex items-center space-x-6">
                        <a href="<?php echo BASE_URL; ?>" class="text-white/90 hover:text-white font-medium transition-colors">
                            <i class="fas fa-home mr-2"></i>Home
                        </a>
                        <a href="<?php echo BASE_URL; ?>event.php?id=<?php echo $eventId; ?>" class="text-white/90 hover:text-white font-medium transition-colors">
                            <i class="fas fa-info-circle mr-2"></i>Event Details
                        </a>
                        <?php if (isLoggedIn()): ?>
                            <a href="<?php echo BASE_URL; ?>" class="text-white/90 hover:text-white font-medium transition-colors">
                                <i class="fas fa-tachometer-alt mr-2"></i>Dashboard
                            </a>
                        <?php else: ?>
                            <a href="<?php echo BASE_URL; ?>login.php" class="text-white/90 hover:text-white font-medium transition-colors">
                                <i class="fas fa-sign-in-alt mr-2"></i>Login
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </nav>

        <!-- Main Content -->
        <main class="container mx-auto px-4 py-8">
            <div class="max-w-4xl mx-auto">
                <!-- Event Info -->
                <div class="bg-white rounded-lg shadow-lg mb-8 overflow-hidden">
                    <div class="gradient-bg text-white p-6">
                        <h1 class="text-3xl font-bold mb-2"><?php echo htmlspecialchars($event['title']); ?></h1>
                        <div class="grid md:grid-cols-3 gap-4 text-sm opacity-90">
                            <div class="flex items-center">
                                <i class="fas fa-calendar-alt mr-2"></i>
                                <span><?php echo formatDate($event['start_date'], 'M d, Y g:i A'); ?></span>
                            </div>
                            <div class="flex items-center">
                                <i class="fas fa-map-marker-alt mr-2"></i>
                                <span><?php echo htmlspecialchars($event['venue'] ?? 'Venue TBA'); ?></span>
                            </div>
                            <div class="flex items-center">
                                <i class="fas fa-money-bill mr-2"></i>
                                <span><?php echo $event['registration_fee'] > 0 ? formatCurrency($event['registration_fee']) : 'Free'; ?></span>
                            </div>
                        </div>
                    </div>
                    
                    <div class="p-6">
                        <p class="text-gray-600 mb-4"><?php echo htmlspecialchars($event['description']); ?></p>
                        
                        <?php if ($event['capacity'] > 0): ?>
                        <div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-4">
                            <div class="flex items-center justify-between">
                                <span class="text-blue-800 font-medium">
                                    <i class="fas fa-users mr-2"></i>Capacity: <?php echo $event['capacity']; ?>
                                </span>
                                <span class="text-blue-600">
                                    <?php echo $registrationCount; ?> registered
                                </span>
                            </div>
                            <div class="mt-2 bg-blue-200 rounded-full h-2">
                                <div class="bg-blue-600 h-2 rounded-full" 
                                     style="width: <?php echo ($registrationCount / $event['capacity']) * 100; ?>%"></div>
                            </div>
                        </div>
                        <?php endif; ?>
                        
                        <?php if ($event['registration_deadline']): ?>
                        <div class="text-sm text-gray-500">
                            <i class="fas fa-clock mr-2"></i>
                            Registration deadline: <?php echo formatDate($event['registration_deadline'], 'M d, Y g:i A'); ?>
                        </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Registration Form -->
                <?php if ($error): ?>
                <div class="bg-red-50 border border-red-200 text-red-700 px-6 py-4 rounded-lg mb-6">
                    <div class="flex items-center">
                        <i class="fas fa-exclamation-circle mr-2"></i>
                        <?php echo htmlspecialchars($error); ?>
                    </div>
                </div>
                <?php elseif ($success): ?>
                <div class="bg-green-50 border border-green-200 text-green-700 px-6 py-4 rounded-lg mb-6">
                    <div class="flex items-center">
                        <i class="fas fa-check-circle mr-2"></i>
                        <?php echo $success; ?>
                    </div>
                    <div class="mt-4 flex space-x-4">
                        <a href="<?php echo BASE_URL; ?>event.php?id=<?php echo $eventId; ?>" 
                           class="bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700 transition-colors">
                            View Event Details
                        </a>
                        <a href="<?php echo BASE_URL; ?>" 
                           class="bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700 transition-colors">
                            Back to Home
                        </a>
                    </div>
                </div>
                <?php elseif ($alreadyRegistered): ?>
                <div class="bg-yellow-50 border border-yellow-200 text-yellow-700 px-6 py-4 rounded-lg mb-6">
                    <div class="flex items-center">
                        <i class="fas fa-info-circle mr-2"></i>
                        You are already registered for this event.
                    </div>
                    <div class="mt-4">
                        <a href="<?php echo BASE_URL; ?>dashboard.php" 
                           class="bg-yellow-600 text-white px-4 py-2 rounded-lg hover:bg-yellow-700 transition-colors">
                            View My Registrations
                        </a>
                    </div>
                </div>
                <?php else: ?>
                <div class="bg-white rounded-lg shadow-lg">
                    <div class="px-6 py-4 border-b border-gray-200">
                        <h2 class="text-xl font-semibold text-gray-800">Event Registration</h2>
                        <p class="text-gray-600 text-sm mt-1">
                            <?php if (isLoggedIn()): ?>
                                Complete the form below to register for this event.
                            <?php else: ?>
                                Fill out the form below to register. You don't need an account to register for events.
                            <?php endif; ?>
                        </p>
                    </div>
                    
                    <form method="POST" class="p-6">
                        <div class="grid md:grid-cols-2 gap-6 mb-6">
                            <div>
                                <label for="first_name" class="block text-sm font-medium text-gray-700 mb-2">
                                    First Name <span class="text-red-500">*</span>
                                </label>
                                <input type="text" id="first_name" name="first_name" required
                                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
                                       value="<?php echo htmlspecialchars($_POST['first_name'] ?? (isLoggedIn() && getCurrentUser() ? getCurrentUser()['first_name'] : '')); ?>">
                            </div>
                            
                            <div>
                                <label for="last_name" class="block text-sm font-medium text-gray-700 mb-2">
                                    Last Name <span class="text-red-500">*</span>
                                </label>
                                <input type="text" id="last_name" name="last_name" required
                                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
                                       value="<?php echo htmlspecialchars($_POST['last_name'] ?? (isLoggedIn() && getCurrentUser() ? getCurrentUser()['last_name'] : '')); ?>">
                            </div>
                        </div>
                        
                        <div class="grid md:grid-cols-2 gap-6 mb-6">
                            <div>
                                <label for="email" class="block text-sm font-medium text-gray-700 mb-2">
                                    Email Address <span class="text-red-500">*</span>
                                </label>
                                <input type="email" id="email" name="email" required
                                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
                                       value="<?php echo htmlspecialchars($_POST['email'] ?? (isLoggedIn() && getCurrentUser() ? getCurrentUser()['email'] : '')); ?>">
                            </div>
                            
                            <div>
                                <label for="phone" class="block text-sm font-medium text-gray-700 mb-2">
                                    Phone Number <span class="text-red-500">*</span>
                                </label>
                                <input type="tel" id="phone" name="phone" required
                                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
                                       value="<?php echo htmlspecialchars($_POST['phone'] ?? (isLoggedIn() && getCurrentUser() ? getCurrentUser()['phone'] : '')); ?>">
                            </div>
                        </div>
                        
                        <!-- Area, District, and Assembly Fields -->
                        <div class="grid md:grid-cols-3 gap-6 mb-6">
                            <div>
                                <label for="area_id" class="block text-sm font-medium text-gray-700 mb-2">
                                    Area
                                </label>
                                <select id="area_id" name="area_id" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                                    <option value="">Select an area</option>
                                    <?php foreach ($areas as $area): ?>
                                    <option value="<?php echo htmlspecialchars($area['id']); ?>"
                                            <?php echo ($_POST['area_id'] ?? '') === $area['id'] ? 'selected' : ''; ?>>
                                        <?php echo htmlspecialchars($area['name']); ?>
                                    </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            
                            <div>
                                <label for="district_id" class="block text-sm font-medium text-gray-700 mb-2">
                                    District
                                </label>
                                <select id="district_id" name="district_id" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                                    <option value="">Select a district</option>
                                    <?php foreach ($districts as $district): ?>
                                    <option value="<?php echo htmlspecialchars($district['id']); ?>"
                                            <?php echo ($_POST['district_id'] ?? '') === $district['id'] ? 'selected' : ''; ?>>
                                        <?php echo htmlspecialchars($district['name']); ?>
                                    </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            
                            <div>
                                <label for="assembly_id" class="block text-sm font-medium text-gray-700 mb-2">
                                    Assembly
                                </label>
                                <select id="assembly_id" name="assembly_id" disabled class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500 bg-gray-100 cursor-not-allowed opacity-60">
                                    <option value="">Select an assembly (Disabled)</option>
                                    <?php foreach ($assemblies as $assembly): ?>
                                    <option value="<?php echo htmlspecialchars($assembly['id']); ?>"
                                            <?php echo ($_POST['assembly_id'] ?? '') === $assembly['id'] ? 'selected' : ''; ?>>
                                        <?php echo htmlspecialchars($assembly['name']); ?>
                                    </option>
                                    <?php endforeach; ?>
                                </select>
                                <p class="text-xs text-gray-500 mt-1">Assembly selection is currently disabled</p>
                            </div>
                        </div>
                        
                        <!-- Dynamic Form Fields -->
                        <?php if (!empty($formFields)): ?>
                        <div class="border-t border-gray-200 pt-6 mb-6">
                            <h3 class="text-lg font-medium text-gray-800 mb-4">Additional Information</h3>
                            <div class="space-y-4">
                                <?php foreach ($formFields as $field): ?>
                                <div>
                                    <label for="<?php echo htmlspecialchars($field['name'] ?? ''); ?>" 
                                           class="block text-sm font-medium text-gray-700 mb-2">
                                        <?php echo htmlspecialchars($field['label'] ?? ''); ?>
                                        <?php if ($field['required'] ?? false): ?>
                                        <span class="text-red-500">*</span>
                                        <?php endif; ?>
                                    </label>
                                    
                                    <?php if ($field['type'] === 'text'): ?>
                                    <input type="text" id="<?php echo htmlspecialchars($field['name'] ?? ''); ?>" 
                                           name="<?php echo htmlspecialchars($field['name'] ?? ''); ?>"
                                           <?php echo ($field['required'] ?? false) ? 'required' : ''; ?>
                                           class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500"
                                           value="<?php echo htmlspecialchars($_POST[$field['name'] ?? ''] ?? ''); ?>">
                                    
                                    <?php elseif ($field['type'] === 'textarea'): ?>
                                    <textarea id="<?php echo htmlspecialchars($field['name'] ?? ''); ?>" 
                                              name="<?php echo htmlspecialchars($field['name'] ?? ''); ?>"
                                              <?php echo ($field['required'] ?? false) ? 'required' : ''; ?>
                                              rows="3"
                                              class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500"><?php echo htmlspecialchars($_POST[$field['name'] ?? ''] ?? ''); ?></textarea>
                                    
                                    <?php elseif ($field['type'] === 'select'): ?>
                                    <select id="<?php echo htmlspecialchars($field['name'] ?? ''); ?>" 
                                            name="<?php echo htmlspecialchars($field['name'] ?? ''); ?>"
                                            <?php echo ($field['required'] ?? false) ? 'required' : ''; ?>
                                            class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-primary-500">
                                        <option value="">Select an option</option>
                                        <?php foreach ($field['options'] ?? [] as $option): ?>
                                        <option value="<?php echo htmlspecialchars($option); ?>"
                                                <?php echo ($_POST[$field['name'] ?? ''] ?? '') === $option ? 'selected' : ''; ?>>
                                            <?php echo htmlspecialchars($option); ?>
                                        </option>
                                        <?php endforeach; ?>
                                    </select>
                                    <?php endif; ?>
                                    
                                    <?php if (!empty($field['description'])): ?>
                                    <p class="text-sm text-gray-500 mt-1"><?php echo htmlspecialchars($field['description']); ?></p>
                                    <?php endif; ?>
                                </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                        <?php endif; ?>
                        
                        <!-- Registration Fee Info -->
                        <?php if ($event['registration_fee'] > 0): ?>
                        <div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mb-6">
                            <h4 class="font-medium text-yellow-800 mb-2">Registration Fee</h4>
                            <div class="text-sm text-yellow-700">
                                <?php
                                $currentFee = $event['registration_fee'];
                                $earlyBirdDeadline = $event['early_bird_deadline'] ? new DateTime($event['early_bird_deadline']) : null;
                                
                                if ($earlyBirdDeadline && $now <= $earlyBirdDeadline && $event['early_bird_fee'] > 0) {
                                    $currentFee = $event['early_bird_fee'];
                                    echo "<p><strong>Early Bird Fee:</strong> " . formatCurrency($event['early_bird_fee']) . " (until " . formatDate($event['early_bird_deadline'], 'M d, Y') . ")</p>";
                                    echo "<p>Regular Fee: " . formatCurrency($event['registration_fee']) . "</p>";
                                } else {
                                    echo "<p><strong>Registration Fee:</strong> " . formatCurrency($event['registration_fee']) . "</p>";
                                }
                                ?>
                                <p class="mt-2">Payment instructions will be provided after registration.</p>
                            </div>
                        </div>
                        <?php endif; ?>
                        
                        <!-- Terms and Conditions -->
                        <div class="mb-6">
                            <label class="flex items-start">
                                <input type="checkbox" required class="mt-1 mr-3">
                                <span class="text-sm text-gray-700">
                                    I agree to the <a href="#" class="text-primary-600 hover:text-primary-800">terms and conditions</a> 
                                    and understand that this registration is binding.
                                </span>
                            </label>
                        </div>
                        
                        <div class="flex space-x-4">
                            <button type="submit" 
                                    class="flex-1 gradient-bg text-white py-3 px-6 rounded-lg hover:opacity-90 transition-opacity font-medium">
                                <i class="fas fa-user-plus mr-2"></i>Submit Form
                            </button>
                            <a href="<?php echo BASE_URL; ?>event.php?id=<?php echo $eventId; ?>" 
                               class="bg-gray-500 text-white py-3 px-6 rounded-lg hover:bg-gray-600 transition-colors font-medium">
                                Cancel
                            </a>
                        </div>
                    </form>
                </div>
                <?php endif; ?>
            </div>
        </main>
    </div>

    <script>
        const { createApp } = Vue;
        
        createApp({
            data() {
                return {
                    // Vue data properties
                }
            }
        }).mount('#app');
    </script>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists