Sindbad~EG File Manager

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

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

// Check if user is logged in
if (!isLoggedIn()) {
    header('Location: ' . BASE_URL . 'login.php');
    exit();
}

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

// Get users based on role permissions (public directory for member listings)
$whereClause = "WHERE u.status = 'active'";
$params = [];

if ($user['role'] === 'area_admin') {
    $whereClause .= " AND u.area_id = ?";
    $params[] = $user['area_id'];
} elseif ($user['role'] === 'district_admin') {
    $whereClause .= " AND u.district_id = ?";
    $params[] = $user['district_id'];
} elseif ($user['role'] === 'assembly_admin') {
    $whereClause .= " AND u.assembly_id = ?";
    $params[] = $user['assembly_id'];
} elseif ($user['role'] === 'member') {
    // Members can see other members in their organization
    $conditions = [];
    if ($user['area_id']) {
        $conditions[] = "u.area_id = ?";
        $params[] = $user['area_id'];
    }
    if ($user['district_id']) {
        $conditions[] = "u.district_id = ?";
        $params[] = $user['district_id'];
    }
    if ($user['assembly_id']) {
        $conditions[] = "u.assembly_id = ?";
        $params[] = $user['assembly_id'];
    }
    if (!empty($conditions)) {
        $whereClause .= " AND (" . implode(' OR ', $conditions) . ")";
    }
}

$sql = "SELECT u.first_name, u.last_name, u.email, u.phone, u.role,
               a.name as area_name,
               d.name as district_name,
               ass.name as assembly_name
        FROM users u
        LEFT JOIN areas a ON u.area_id = a.id
        LEFT JOIN districts d ON u.district_id = d.id
        LEFT JOIN assemblies ass ON u.assembly_id = ass.id
        $whereClause
        ORDER BY u.first_name, u.last_name";

$users = executeQuery($sql, $params)->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>Members Directory - COP Madina Conference Management</title>
    <script src="https://cdn.tailwindcss.com"></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%);
        }
        .sidebar-active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
    </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-sm border-b border-gray-200">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between items-center h-16">
                <div class="flex items-center">
                    <a href="<?php echo BASE_URL; ?>" class="flex items-center">
                        <img src="<?php echo BASE_URL; ?>assets/images/logo.png" alt="COP Madina" class="h-10 w-10 rounded-full mr-3">
                        <div>
                            <h1 class="text-xl font-bold text-gray-900">Members Directory</h1>
                            <p class="text-xs text-gray-500">Church Members & Leaders</p>
                        </div>
                    </a>
                </div>
                
                <nav class="flex items-center space-x-4">
                    <a href="<?php echo BASE_URL; ?>" class="text-gray-600 hover:text-gray-900 transition-colors">
                        <i class="fas fa-home mr-1"></i>Home
                    </a>
                    <a href="<?php echo BASE_URL; ?>dashboard.php" class="text-gray-600 hover:text-gray-900 transition-colors">
                        <i class="fas fa-tachometer-alt mr-1"></i>Dashboard
                    </a>
                    <div class="relative">
                        <span class="text-gray-700 font-medium">
                            <?php echo htmlspecialchars($user['first_name'] . ' ' . $user['last_name']); ?>
                        </span>
                    </div>
                    <a href="<?php echo BASE_URL; ?>logout.php" class="text-red-600 hover:text-red-800 transition-colors">
                        <i class="fas fa-sign-out-alt"></i>
                    </a>
                </nav>
            </div>
        </div>
    </header>

    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
        <!-- Page Header -->
        <div class="mb-8">
            <h1 class="text-3xl font-bold text-gray-900">Members Directory</h1>
            <p class="mt-2 text-gray-600">Connect with church members and leaders</p>
        </div>

        <!-- Members Grid -->
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            <?php foreach ($users as $member): ?>
            <div class="bg-white rounded-xl shadow-lg overflow-hidden hover:shadow-xl transition-shadow">
                <div class="p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-primary-100 rounded-full flex items-center justify-center mr-4">
                            <span class="text-primary-600 font-bold text-lg">
                                <?php echo strtoupper(substr($member['first_name'], 0, 1) . substr($member['last_name'], 0, 1)); ?>
                            </span>
                        </div>
                        <div>
                            <h3 class="text-lg font-bold text-gray-900">
                                <?php echo htmlspecialchars($member['first_name'] . ' ' . $member['last_name']); ?>
                            </h3>
                            <span class="inline-flex px-2 py-1 text-xs font-semibold rounded-full
                                <?php 
                                echo $member['role'] === 'superuser' ? 'bg-red-100 text-red-800' : 
                                    ($member['role'] === 'area_admin' ? 'bg-blue-100 text-blue-800' : 
                                    ($member['role'] === 'district_admin' ? 'bg-green-100 text-green-800' : 
                                    ($member['role'] === 'assembly_admin' ? 'bg-purple-100 text-purple-800' : 
                                    'bg-gray-100 text-gray-800')));
                                ?>">
                                <?php echo ucfirst(str_replace('_', ' ', $member['role'])); ?>
                            </span>
                        </div>
                    </div>
                    
                    <div class="space-y-2 mb-4">
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-envelope mr-2"></i>
                            <?php echo htmlspecialchars($member['email']); ?>
                        </div>
                        
                        <?php if ($member['phone']): ?>
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-phone mr-2"></i>
                            <?php echo htmlspecialchars($member['phone']); ?>
                        </div>
                        <?php endif; ?>
                        
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-sitemap mr-2"></i>
                            <?php 
                            $org_parts = [];
                            if ($member['area_name']) $org_parts[] = $member['area_name'];
                            if ($member['district_name']) $org_parts[] = $member['district_name'];
                            if ($member['assembly_name']) $org_parts[] = $member['assembly_name'];
                            echo htmlspecialchars(implode(' > ', $org_parts));
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        
        <?php if (empty($users)): ?>
        <div class="text-center py-12">
            <i class="fas fa-users text-gray-400 text-6xl mb-4"></i>
            <h3 class="text-xl font-semibold text-gray-900 mb-2">No Members Found</h3>
            <p class="text-gray-600">There are currently no members available to display.</p>
        </div>
        <?php endif; ?>
    </div>
</body>
</html>

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