Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/conference/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/conference/check-in.php

<?php
session_start();
require_once 'includes/functions.php';

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

$message = '';
$messageType = '';

// Handle check-in form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $registrationCode = trim($_POST['registration_code']);
    
    if (empty($registrationCode)) {
        $message = 'Please enter your registration code.';
        $messageType = 'error';
    } else {
        // Check in member registrations first
        $stmt = $conn->prepare("
            SELECT er.*, e.title as event_title, u.first_name, u.last_name, u.email
            FROM event_registrations er
            JOIN events e ON er.event_id = e.id
            JOIN users u ON er.user_id = u.id
            WHERE er.registration_code = ? AND e.status = 'published'
        ");
        $stmt->execute([$registrationCode]);
        $memberRegistration = $stmt->fetch();
        
        if ($memberRegistration) {
            if ($memberRegistration['status'] === 'attended') {
                $message = 'You have already checked in for this event.';
                $messageType = 'info';
            } else {
                // Update status to attended and set check-in time
                $updateStmt = $conn->prepare("UPDATE event_registrations SET status = 'attended', checked_in_at = NOW(), updated_at = NOW() WHERE registration_code = ?");
                $result = $updateStmt->execute([$registrationCode]);
                
                if ($result) {
                    // Log attendance
                    $logStmt = $conn->prepare("INSERT INTO attendance_logs (event_id, user_id, registration_code, registration_type, action, action_time, ip_address, user_agent) VALUES (?, ?, ?, 'member', 'check_in', NOW(), ?, ?)");
                    $logStmt->execute([
                        $memberRegistration['event_id'],
                        $memberRegistration['user_id'],
                        $registrationCode,
                        $_SERVER['REMOTE_ADDR'] ?? null,
                        $_SERVER['HTTP_USER_AGENT'] ?? null
                    ]);
                    
                    $message = "Welcome {$memberRegistration['first_name']}! You have been successfully checked in for '{$memberRegistration['event_title']}'.";
                    $messageType = 'success';
                    
                    // Log the check-in activity
                    logActivity($memberRegistration['user_id'], 'self_check_in', "Self checked in for event: {$memberRegistration['event_title']}");
                } else {
                    $message = 'Failed to check in. Please try again or contact support.';
                    $messageType = 'error';
                }
            }
        } else {
            // Check non-member registrations
            $stmt = $conn->prepare("
                SELECT nr.*, e.title as event_title
                FROM nonmember_registrations nr
                JOIN events e ON nr.event_id = e.id
                WHERE nr.registration_code = ? AND e.status = 'published'
            ");
            $stmt->execute([$registrationCode]);
            $nonMemberRegistration = $stmt->fetch();
            
            if ($nonMemberRegistration) {
                if ($nonMemberRegistration['status'] === 'attended') {
                    $message = 'You have already checked in for this event.';
                    $messageType = 'info';
                } else {
                    // Update status to attended and set check-in time
                    $updateStmt = $conn->prepare("UPDATE nonmember_registrations SET status = 'attended', checked_in_at = NOW(), updated_at = NOW() WHERE registration_code = ?");
                    $result = $updateStmt->execute([$registrationCode]);
                    
                    if ($result) {
                        // Log attendance
                        $logStmt = $conn->prepare("INSERT INTO attendance_logs (event_id, user_id, registration_code, registration_type, action, action_time, ip_address, user_agent) VALUES (?, NULL, ?, 'nonmember', 'check_in', NOW(), ?, ?)");
                        $logStmt->execute([
                            $nonMemberRegistration['event_id'],
                            $registrationCode,
                            $_SERVER['REMOTE_ADDR'] ?? null,
                            $_SERVER['HTTP_USER_AGENT'] ?? null
                        ]);
                        
                        $formData = json_decode($nonMemberRegistration['form_data'], true);
                        $guestName = ($formData['first_name'] ?? '') . ' ' . ($formData['last_name'] ?? '');
                        $guestName = trim($guestName) ?: 'Guest';
                        
                        $message = "Welcome {$guestName}! You have been successfully checked in for '{$nonMemberRegistration['event_title']}'.";
                        $messageType = 'success';
                    } else {
                        $message = 'Failed to check in. Please try again or contact support.';
                        $messageType = 'error';
                    }
                }
            } else {
                $message = 'Registration code not found. Please check your code and try again.';
                $messageType = 'error';
            }
        }
    }
}

// Get current active events for display
$activeEventsStmt = $conn->prepare("
    SELECT e.*, 
           COALESCE(
               (SELECT COUNT(*) FROM event_registrations er WHERE er.event_id = e.id AND er.status != 'cancelled') +
               (SELECT COUNT(*) FROM nonmember_registrations nr WHERE nr.event_id = e.id AND nr.status != 'cancelled'),
               0
           ) as total_registrations,
           COALESCE(
               (SELECT COUNT(*) FROM event_registrations er WHERE er.event_id = e.id AND er.status = 'attended') +
               (SELECT COUNT(*) FROM nonmember_registrations nr WHERE nr.event_id = e.id AND nr.status = 'attended'),
               0
           ) as total_attended
    FROM events e
    WHERE e.status = 'published' 
    AND e.start_date <= DATE_ADD(NOW(), INTERVAL 1 DAY)
    AND e.end_date >= NOW()
    ORDER BY e.start_date ASC
");
$activeEventsStmt->execute();
$activeEvents = $activeEventsStmt->fetchAll();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Event Check-In - COP Madina Conference</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    animation: {
                        'fade-in': 'fadeIn 0.5s ease-out',
                        'slide-up': 'slideUp 0.6s ease-out',
                        'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite'
                    },
                    keyframes: {
                        fadeIn: {
                            '0%': { opacity: '0' },
                            '100%': { opacity: '1' }
                        },
                        slideUp: {
                            '0%': { opacity: '0', transform: 'translateY(20px)' },
                            '100%': { opacity: '1', transform: 'translateY(0)' }
                        }
                    }
                }
            }
        }
    </script>
</head>
<body class="bg-gradient-to-br from-blue-50 via-white to-slate-100 min-h-screen">
    <!-- Header -->
    <header class="bg-white/80 backdrop-blur-sm 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 py-4">
                <div class="flex items-center space-x-4">
                    <a href="index.php" class="flex items-center space-x-3">
                        <div class="w-10 h-10 bg-gradient-to-br from-blue-600 to-purple-600 rounded-xl flex items-center justify-center">
                            <i class="fas fa-church text-white text-lg"></i>
                        </div>
                        <div>
                            <h1 class="text-xl font-bold bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
                                COP Madina Conference
                            </h1>
                            <p class="text-sm text-slate-600">Event Check-In</p>
                        </div>
                    </a>
                </div>
                
                <nav class="hidden md:flex items-center space-x-6">
                    <a href="index.php" class="text-slate-600 hover:text-blue-600 transition-colors">
                        <i class="fas fa-home mr-2"></i>Home
                    </a>
                    <a href="register.php" class="text-slate-600 hover:text-blue-600 transition-colors">
                        <i class="fas fa-calendar-plus mr-2"></i>Register
                    </a>
                    <a href="login.php" class="bg-gradient-to-r from-blue-600 to-purple-600 text-white px-4 py-2 rounded-lg hover:from-blue-700 hover:to-purple-700 transition-all duration-200">
                        <i class="fas fa-sign-in-alt mr-2"></i>Login
                    </a>
                </nav>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Hero Section -->
        <div class="text-center mb-12 animate-fade-in">
            <div class="inline-flex items-center justify-center w-20 h-20 bg-gradient-to-br from-indigo-500 to-purple-600 rounded-2xl mb-6 shadow-lg">
                <i class="fas fa-sign-in-alt text-white text-3xl"></i>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold text-slate-800 mb-4">
                Event Check-In
            </h1>
            <p class="text-xl text-slate-600 max-w-2xl mx-auto">
                Enter your registration code to check in to your event. Available for both members and guests.
            </p>
        </div>

        <!-- Message Display -->
        <?php if ($message): ?>
        <div class="mb-8 animate-slide-up">
            <div class="p-6 rounded-2xl border-l-4 <?php echo $messageType === 'success' ? 'bg-emerald-50 border-emerald-500' : ($messageType === 'info' ? 'bg-blue-50 border-blue-500' : 'bg-red-50 border-red-500'); ?>">
                <div class="flex items-center">
                    <i class="fas <?php echo $messageType === 'success' ? 'fa-check-circle text-emerald-600' : ($messageType === 'info' ? 'fa-info-circle text-blue-600' : 'fa-exclamation-circle text-red-600'); ?> text-xl mr-4"></i>
                    <div>
                        <p class="font-semibold <?php echo $messageType === 'success' ? 'text-emerald-800' : ($messageType === 'info' ? 'text-blue-800' : 'text-red-800'); ?>">
                            <?php echo htmlspecialchars($message); ?>
                        </p>
                    </div>
                </div>
            </div>
        </div>
        <?php endif; ?>

        <!-- Check-In Form -->
        <div class="bg-white/70 backdrop-blur-sm rounded-2xl shadow-xl p-8 mb-12 border border-slate-200/50 animate-slide-up">
            <form method="POST" class="space-y-6">
                <div>
                    <label for="registration_code" class="block text-lg font-semibold text-slate-700 mb-3">
                        <i class="fas fa-ticket-alt mr-2 text-indigo-600"></i>
                        Registration Code
                    </label>
                    <input 
                        type="text" 
                        id="registration_code" 
                        name="registration_code" 
                        required 
                        class="w-full px-6 py-4 text-lg border-2 border-slate-300 rounded-xl focus:ring-4 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all duration-200 bg-white/50 backdrop-blur-sm"
                        placeholder="Enter your registration code (e.g., REG-12345)"
                        value="<?php echo htmlspecialchars($_POST['registration_code'] ?? ''); ?>"
                    >
                    <p class="mt-2 text-sm text-slate-600">
                        <i class="fas fa-info-circle mr-1"></i>
                        You can find your registration code in your confirmation email or registration receipt.
                    </p>
                </div>
                
                <button 
                    type="submit" 
                    class="w-full bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-700 hover:to-purple-700 text-white font-semibold py-4 px-8 rounded-xl transition-all duration-200 shadow-lg hover:shadow-xl transform hover:-translate-y-1 text-lg"
                >
                    <i class="fas fa-sign-in-alt mr-3"></i>
                    Check In to Event
                </button>
            </form>
        </div>

        <!-- Active Events Section -->
        <?php if (!empty($activeEvents)): ?>
        <div class="animate-slide-up">
            <h2 class="text-2xl font-bold text-slate-800 mb-6 text-center">
                <i class="fas fa-calendar-check mr-2 text-indigo-600"></i>
                Current Events
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <?php foreach ($activeEvents as $index => $event): ?>
                <?php 
                    $attendanceRate = $event['total_registrations'] > 0 ? ($event['total_attended'] / $event['total_registrations']) * 100 : 0;
                ?>
                <div class="bg-white/70 backdrop-blur-sm rounded-2xl shadow-lg hover:shadow-xl transition-all duration-300 p-6 border border-slate-200/50 hover:border-indigo-300/50" 
                     style="animation-delay: <?php echo $index * 0.1; ?>s">
                    <div class="mb-4">
                        <h3 class="text-xl font-bold text-slate-800 mb-2"><?php echo htmlspecialchars($event['title']); ?></h3>
                        <p class="text-sm text-slate-600 mb-2">
                            <i class="fas fa-calendar mr-2"></i>
                            <?php echo date('M j, Y g:i A', strtotime($event['start_date'])); ?>
                        </p>
                        <p class="text-sm text-slate-600">
                            <i class="fas fa-map-marker-alt mr-2"></i>
                            <?php echo htmlspecialchars($event['venue'] ?: 'TBA'); ?>
                        </p>
                    </div>
                    
                    <div class="space-y-3">
                        <div class="flex justify-between items-center">
                            <span class="text-sm text-slate-600">Total Registered:</span>
                            <span class="font-semibold text-slate-800"><?php echo $event['total_registrations']; ?></span>
                        </div>
                        
                        <div class="flex justify-between items-center">
                            <span class="text-sm text-slate-600">Checked In:</span>
                            <span class="font-semibold text-emerald-600"><?php echo $event['total_attended']; ?></span>
                        </div>
                        
                        <div class="flex justify-between items-center">
                            <span class="text-sm text-slate-600">Attendance Rate:</span>
                            <span class="font-semibold text-slate-800"><?php echo number_format($attendanceRate, 1); ?>%</span>
                        </div>
                        
                        <div class="w-full bg-slate-200 rounded-full h-2">
                            <div class="bg-gradient-to-r from-emerald-500 to-green-600 h-2 rounded-full transition-all duration-300" 
                                 style="width: <?php echo $attendanceRate; ?>%"></div>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
        <?php endif; ?>

        <!-- Help Section -->
        <div class="mt-12 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-2xl p-8 border border-blue-200/50 animate-slide-up">
            <h3 class="text-xl font-bold text-slate-800 mb-4">
                <i class="fas fa-question-circle mr-2 text-blue-600"></i>
                Need Help?
            </h3>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6 text-sm text-slate-600">
                <div>
                    <h4 class="font-semibold text-slate-800 mb-2">For Members:</h4>
                    <ul class="space-y-1">
                        <li><i class="fas fa-check text-green-600 mr-2"></i>Use the registration code from your email</li>
                        <li><i class="fas fa-check text-green-600 mr-2"></i>Check your member dashboard for codes</li>
                        <li><i class="fas fa-check text-green-600 mr-2"></i>Contact your area/district admin if needed</li>
                    </ul>
                </div>
                <div>
                    <h4 class="font-semibold text-slate-800 mb-2">For Guests:</h4>
                    <ul class="space-y-1">
                        <li><i class="fas fa-check text-green-600 mr-2"></i>Use the code from your registration confirmation</li>
                        <li><i class="fas fa-check text-green-600 mr-2"></i>Check your email for the registration receipt</li>
                        <li><i class="fas fa-check text-green-600 mr-2"></i>Contact event organizers for assistance</li>
                    </ul>
                </div>
            </div>
        </div>
    </main>

    <!-- Footer -->
    <footer class="bg-slate-800 text-white py-8 mt-16">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 text-center">
            <p class="text-slate-300">
                © <?php echo date('Y'); ?> The Church of Pentecost - Madina Area. All rights reserved.
            </p>
        </div>
    </footer>
</body>
</html>

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