Sindbad~EG File Manager

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

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

$user = getCurrentUser();
if (!$user) {
    header('Location: ' . BASE_URL . 'login.php');
    exit();
}
$error = '';
$success = '';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['update_profile'])) {
        $firstName = sanitizeInput($_POST['first_name'] ?? '');
        $lastName = sanitizeInput($_POST['last_name'] ?? '');
        $phone = sanitizeInput($_POST['phone'] ?? '');
        
        if (empty($firstName) || empty($lastName)) {
            $error = 'First name and last name are required.';
        } else {
            $db = new CopMadinaDB();
            $conn = $db->getConnection();
            
            try {
                $stmt = $conn->prepare("UPDATE users SET first_name = ?, last_name = ?, phone = ? WHERE id = ?");
                $stmt->execute([$firstName, $lastName, $phone, $_SESSION['user_id']]);
                
                // Update session
                $_SESSION['user_name'] = $firstName . ' ' . $lastName;
                
                // Log audit
                logAudit('update', 'users', $_SESSION['user_id'], 
                        ['first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'phone' => $user['phone']], 
                        ['first_name' => $firstName, 'last_name' => $lastName, 'phone' => $phone]);
                
                $success = 'Profile updated successfully.';
                $user = getCurrentUser(); // Refresh user data
            } catch (Exception $e) {
                $error = 'Failed to update profile. Please try again.';
                error_log("Profile update error: " . $e->getMessage());
            }
        }
    } elseif (isset($_POST['change_password'])) {
        $currentPassword = $_POST['current_password'] ?? '';
        $newPassword = $_POST['new_password'] ?? '';
        $confirmPassword = $_POST['confirm_password'] ?? '';
        
        if (empty($currentPassword) || empty($newPassword) || empty($confirmPassword)) {
            $error = 'All password fields are required.';
        } elseif (strlen($newPassword) < PASSWORD_MIN_LENGTH) {
            $error = 'New password must be at least ' . PASSWORD_MIN_LENGTH . ' characters long.';
        } elseif ($newPassword !== $confirmPassword) {
            $error = 'New passwords do not match.';
        } elseif (!password_verify($currentPassword, $user['password'])) {
            $error = 'Current password is incorrect.';
        } else {
            $db = new CopMadinaDB();
            $conn = $db->getConnection();
            
            try {
                $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
                $stmt = $conn->prepare("UPDATE users SET password = ? WHERE id = ?");
                $stmt->execute([$hashedPassword, $_SESSION['user_id']]);
                
                // Log audit
                logAudit('password_change', 'users', $_SESSION['user_id']);
                
                $success = 'Password changed successfully.';
            } catch (Exception $e) {
                $error = 'Failed to change password. Please try again.';
                error_log("Password change error: " . $e->getMessage());
            }
        }
    }
}

// Get user's registrations
$db = new CopMadinaDB();
$conn = $db->getConnection();

$stmt = $conn->prepare("SELECT e.*, er.registration_code, er.payment_status, er.registration_date, er.status as reg_status
                       FROM events e
                       JOIN event_registrations er ON e.id = er.event_id
                       WHERE er.user_id = ?
                       ORDER BY er.registration_date DESC");
$stmt->execute([$_SESSION['user_id']]);
$registrations = $stmt->fetchAll();

$settings = getSettings();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Profile - COP Madina Conference Management</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-100">
    <div id="app" class="flex h-screen">
        <?php include 'includes/public_sidebar.php'; ?>
        
        <!-- Main Content -->
        <div class="flex-1 flex flex-col overflow-hidden">
            <div class="flex-1 overflow-y-auto">
                <!-- Header -->
                <header class="bg-white shadow-lg">
                    <nav class="container mx-auto px-4 py-3">
                        <div class="flex items-center justify-between">
                            <div class="flex items-center space-x-3">
                                <img src="<?php echo BASE_URL . ($settings['site_logo'] ?? 'assets/images/logo.png'); ?>" 
                                     alt="COP Madina" class="h-12 w-12 rounded-full">
                                <div>
                                    <h1 class="text-xl font-bold text-primary-600">COP Madina</h1>
                                    <p class="text-sm text-gray-600">Conference Management</p>
                <!-- Messages -->
                <?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 endif; ?>

                <?php if ($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 htmlspecialchars($success); ?>
                    </div>
                </div>
                <?php endif; ?>

                <div class="grid lg:grid-cols-3 gap-8">
                    <!-- Profile Information -->
                    <div class="lg:col-span-2 space-y-6">
                        <!-- Personal Information -->
                        <div class="bg-white rounded-lg shadow p-6">
                            <h2 class="text-xl font-semibold mb-6">Personal Information</h2>
                            
                            <form method="POST">
                                <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($user['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($user['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
                                        </label>
                                        <input type="email" id="email" readonly
                                               class="w-full px-3 py-2 border border-gray-300 rounded-lg bg-gray-50"
                                               value="<?php echo htmlspecialchars($user['email']); ?>">
                                        <p class="text-sm text-gray-500 mt-1">Email cannot be changed</p>
                                    </div>
                                    
                                    <div>
                                        <label for="phone" class="block text-sm font-medium text-gray-700 mb-2">
                                            Phone Number
                                        </label>
                                        <input type="tel" id="phone" name="phone"
                                               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($user['phone'] ?? ''); ?>">
                                    </div>
                                </div>
                                
                                <div class="flex justify-end">
                                    <button type="submit" name="update_profile"
                                            class="bg-primary-600 text-white px-6 py-2 rounded-lg hover:bg-primary-700 transition-colors font-medium">
                                        <i class="fas fa-save mr-2"></i>Update Profile
                                    </button>
                                </div>
                            </form>
                        </div>

                        <!-- Change Password -->
                        <div class="bg-white rounded-lg shadow p-6">
                            <h2 class="text-xl font-semibold mb-6">Change Password</h2>
                            
                            <form method="POST">
                                <div class="space-y-4 mb-6">
                                    <div>
                                        <label for="current_password" class="block text-sm font-medium text-gray-700 mb-2">
                                            Current Password <span class="text-red-500">*</span>
                                        </label>
                                        <input type="password" id="current_password" name="current_password" 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">
                                    </div>
                                    
                                    <div>
                                        <label for="new_password" class="block text-sm font-medium text-gray-700 mb-2">
                                            New Password <span class="text-red-500">*</span>
                                        </label>
                                        <input type="password" id="new_password" name="new_password" 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">
                                        <p class="text-sm text-gray-500 mt-1">Minimum <?php echo PASSWORD_MIN_LENGTH; ?> characters</p>
                                    </div>
                                    
                                    <div>
                                        <label for="confirm_password" class="block text-sm font-medium text-gray-700 mb-2">
                                            Confirm New Password <span class="text-red-500">*</span>
                                        </label>
                                        <input type="password" id="confirm_password" name="confirm_password" 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">
                                    </div>
                                </div>
                                
                                <div class="flex justify-end">
                                    <button type="submit" name="change_password"
                                            class="bg-yellow-600 text-white px-6 py-2 rounded-lg hover:bg-yellow-700 transition-colors font-medium">
                                        <i class="fas fa-key mr-2"></i>Change Password
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>

                    <!-- Sidebar -->
                    <div class="space-y-6">
                        <!-- Account Info -->
                        <div class="bg-white rounded-lg shadow p-6">
                            <h3 class="text-lg font-semibold mb-4">Account Information</h3>
                            
                            <div class="space-y-3 text-sm">
                                <div class="flex justify-between">
                                    <span class="text-gray-600">Role:</span>
                                    <span class="font-medium"><?php echo ucwords(str_replace('_', ' ', $user['role'] ?? 'Unknown')); ?></span>
                                </div>
                                
                                <div class="flex justify-between">
                                    <span class="text-gray-600">Member Since:</span>
                                    <span class="font-medium"><?php echo isset($user['created_at']) ? formatDate($user['created_at'], 'M Y') : 'Unknown'; ?></span>
                                </div>
                                
                                <div class="flex justify-between">
                                    <span class="text-gray-600">Last Login:</span>
                                    <span class="font-medium">
                                        <?php echo isset($user['last_login']) && $user['last_login'] ? formatDate($user['last_login'], 'M d, g:i A') : 'Never'; ?>
                                    </span>
                                </div>
                                
                                <div class="flex justify-between">
                                    <span class="text-gray-600">Status:</span>
                                    <span class="font-medium text-green-600"><?php echo ucfirst($user['status'] ?? 'Unknown'); ?></span>
                                </div>
                            </div>
                        </div>

                        <!-- Quick Stats -->
                        <div class="bg-white rounded-lg shadow p-6">
                            <h3 class="text-lg font-semibold mb-4">My Statistics</h3>
                            
                            <div class="space-y-4">
                                <div class="text-center p-4 bg-blue-50 rounded-lg">
                                    <div class="text-2xl font-bold text-blue-600"><?php echo count($registrations); ?></div>
                                    <div class="text-sm text-blue-800">Total Registrations</div>
                                </div>
                                
                                <div class="text-center p-4 bg-green-50 rounded-lg">
                                    <div class="text-2xl font-bold text-green-600">
                                        <?php echo count(array_filter($registrations, function($r) { return $r['reg_status'] === 'confirmed'; })); ?>
                                    </div>
                                    <div class="text-sm text-green-800">Active Registrations</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- My Registrations -->
                <div class="mt-8">
                    <div class="bg-white rounded-lg shadow">
                        <div class="px-6 py-4 border-b border-gray-200">
                            <h2 class="text-xl font-semibold">My Event Registrations</h2>
                        </div>
                        
                        <div class="p-6">
                            <?php if (!empty($registrations)): ?>
                                <div class="space-y-4">
                                    <?php foreach ($registrations as $registration): ?>
                                    <div class="border border-gray-200 rounded-lg p-4 hover:bg-gray-50 transition-colors">
                                        <div class="flex flex-col md:flex-row md:items-center justify-between">
                                            <div class="flex-1">
                                                <h3 class="font-semibold text-lg text-gray-800 mb-2">
                                                    <?php echo htmlspecialchars($registration['title']); ?>
                                                </h3>
                                                
                                                <div class="grid md:grid-cols-2 gap-4 text-sm text-gray-600 mb-3">
                                                    <div class="flex items-center">
                                                        <i class="fas fa-calendar-alt mr-2 text-primary-500"></i>
                                                        <span><?php echo formatDate($registration['start_date'], 'M d, Y g:i A'); ?></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center">
                                                        <i class="fas fa-map-marker-alt mr-2 text-primary-500"></i>
                                                        <span><?php echo htmlspecialchars($registration['venue'] ?? 'TBA'); ?></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center">
                                                        <i class="fas fa-ticket-alt mr-2 text-primary-500"></i>
                                                        <span>Code: <?php echo $registration['registration_code']; ?></span>
                                                    </div>
                                                    
                                                    <div class="flex items-center">
                                                        <i class="fas fa-clock mr-2 text-primary-500"></i>
                                                        <span>Registered: <?php echo formatDate($registration['registration_date'], 'M d, Y'); ?></span>
                                                    </div>
                                                </div>
                                                
                                                <div class="flex items-center space-x-4">
                                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium
                                                        <?php echo $registration['reg_status'] === 'confirmed' ? 'bg-green-100 text-green-800' : 
                                                                  ($registration['reg_status'] === 'cancelled' ? 'bg-red-100 text-red-800' : 'bg-yellow-100 text-yellow-800'); ?>">
                                                        <?php echo ucfirst($registration['reg_status']); ?>
                                                    </span>
                                                    
                                                    <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium
                                                        <?php echo $registration['payment_status'] === 'paid' ? 'bg-green-100 text-green-800' : 
                                                                  ($registration['payment_status'] === 'pending' ? 'bg-yellow-100 text-yellow-800' : 'bg-red-100 text-red-800'); ?>">
                                                        Payment: <?php echo ucfirst($registration['payment_status']); ?>
                                                    </span>
                                                </div>
                                            </div>
                                            
                                            <div class="mt-4 md:mt-0 md:ml-6 flex space-x-2">
                                                <a href="<?php echo BASE_URL; ?>event.php?id=<?php echo $registration['id']; ?>" 
                                                   class="bg-primary-600 text-white px-4 py-2 rounded-lg hover:bg-primary-700 transition-colors text-sm font-medium">
                                                    View Event
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                    <?php endforeach; ?>
                                </div>
                            <?php else: ?>
                                <div class="text-center py-8">
                                    <i class="fas fa-calendar-times text-4xl text-gray-300 mb-4"></i>
                                    <h3 class="text-lg font-semibold text-gray-600 mb-2">No Registrations Yet</h3>
                                    <p class="text-gray-500 mb-6">You haven't registered for any events yet.</p>
                                    <a href="<?php echo BASE_URL; ?>" 
                                       class="bg-primary-600 text-white px-6 py-3 rounded-lg hover:bg-primary-700 transition-colors font-medium inline-block">
                                        <i class="fas fa-calendar mr-2"></i>Browse Events
                                    </a>
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </main>
                </div>
            </div>
        </div>
    </div>

    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .sidebar-active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
    </style>

    <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