Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/public-search.php

<?php
require_once 'config/config.php';

$pageTitle = "Search Membership - " . APP_NAME;

// Get settings for theme colors
$db = Database::getInstance()->getConnection();
$stmt = $db->query("SELECT * FROM general_settings ORDER BY id DESC LIMIT 1");
$settings = $stmt->fetch();

// Default settings if none exist
$settings = array_merge([
    'site_title' => 'Church Membership System',
    'theme_primary_color' => '#1E40AF',
    'theme_secondary_color' => '#F97316',
    'header_text' => '',
    'footer_text' => ''
], $settings ?: []);

// Initialize variables
$searchQuery = '';
$searchResults = [];
$totalResults = 0;
$error = '';

// Handle search request
if (isset($_GET['search']) && !empty($_GET['search'])) {
    $searchQuery = trim($_GET['search']);
    
    try {
        // Search members by name - include membershipcard_id (case-insensitive)
        $searchParam = '%' . strtolower($searchQuery) . '%';
        
        $sql = "SELECT m.id, m.title, m.first_name, m.middle_name, m.last_name, 
                       m.membershipcard_id, m.member_type,
                       a.area_name, d.district_name, asm.assembly_name
                FROM members m
                LEFT JOIN areas a ON m.area_id = a.id
                LEFT JOIN districts d ON m.district_id = d.id
                LEFT JOIN assemblies asm ON m.assembly_id = asm.id
                WHERE (LOWER(m.first_name) LIKE :search1 
                   OR LOWER(m.middle_name) LIKE :search2 
                   OR LOWER(m.last_name) LIKE :search3
                   OR LOWER(CONCAT(m.first_name, ' ', m.last_name)) LIKE :search4
                   OR LOWER(CONCAT(m.first_name, ' ', m.middle_name, ' ', m.last_name)) LIKE :search5
                   OR LOWER(m.membershipcard_id) LIKE :search6)
                AND m.is_active = 1
                ORDER BY m.first_name, m.last_name
                LIMIT 100";
        
        $stmt = $db->prepare($sql);
        $stmt->execute([
            'search1' => $searchParam,
            'search2' => $searchParam,
            'search3' => $searchParam,
            'search4' => $searchParam,
            'search5' => $searchParam,
            'search6' => $searchParam
        ]);
        $searchResults = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $totalResults = count($searchResults);
        
        // Debug: Log successful search
        error_log("Search for '{$searchQuery}' returned {$totalResults} results");
        
    } catch (PDOException $e) {
        $error = "Search error: " . $e->getMessage();
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $pageTitle; ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        .hero-gradient {
            background: linear-gradient(135deg, #1E40AF 0%, #9333EA 50%, #F97316 100%);
        }
        .search-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.15);
        }
        .search-card {
            transition: all 0.3s ease;
            border-left: 4px solid transparent;
        }
        .search-card:hover {
            border-left-color: #F97316;
        }
        .text-gradient {
            background: linear-gradient(135deg, #1E40AF 0%, #F97316 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeIn {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Header -->
    <header class="bg-white shadow-lg sticky top-0 z-50">
        <div class="container mx-auto px-4">
            <div class="flex items-center justify-between h-16">
                <!-- Logo and Title -->
                <div class="flex items-center space-x-3">
                    <div class="w-12 h-12 rounded-xl flex items-center justify-center" style="background: linear-gradient(135deg, #1E40AF 0%, #F97316 100%);">
                        <i class="fas fa-church text-white text-xl"></i>
                    </div>
                    <div>
                        <h1 class="text-xl font-bold text-gradient"><?php echo htmlspecialchars($settings['site_title']); ?></h1>
                        <p class="text-xs text-gray-500">Member Search</p>
                    </div>
                </div>
                
                <!-- Navigation -->
                <nav class="hidden md:flex items-center space-x-6">
                    <a href="index.php" class="text-gray-700 hover:text-blue-700 font-medium transition">
                        <i class="fas fa-home mr-1"></i>Home
                    </a>
                    <a href="conference.php" class="text-gray-700 hover:text-orange-600 font-medium transition">
                        <i class="fas fa-calendar mr-1"></i>Events
                    </a>
                    <?php if (isLoggedIn()): ?>
                        <a href="dashboard.php" class="text-gray-700 hover:text-purple-600 font-medium transition">
                            <i class="fas fa-tachometer-alt mr-1"></i>Dashboard
                        </a>
                    <?php else: ?>
                        <a href="login.php" class="px-6 py-2 rounded-full text-white font-semibold transition hover:shadow-lg" style="background: linear-gradient(135deg, #1E40AF 0%, #9333EA 100%);">
                            <i class="fas fa-sign-in-alt mr-1"></i>Login
                        </a>
                    <?php endif; ?>
                </nav>
                
                <!-- Mobile Menu Button -->
                <button class="md:hidden text-gray-600" onclick="toggleMobileMenu()">
                    <i class="fas fa-bars text-xl"></i>
                </button>
            </div>
            
            <!-- Mobile Menu -->
            <div id="mobileMenu" class="md:hidden hidden border-t border-gray-200 py-4">
                <div class="flex flex-col space-y-3">
                    <a href="index.php" class="text-gray-600 hover:text-primary transition">
                        <i class="fas fa-home mr-1"></i>Home
                    </a>
                    <a href="conference.php" class="text-gray-600 hover:text-primary transition">
                        <i class="fas fa-calendar mr-1"></i>Events
                    </a>
                    <?php if (isLoggedIn()): ?>
                        <a href="dashboard.php" class="text-primary font-medium">
                            <i class="fas fa-tachometer-alt mr-1"></i>Dashboard
                        </a>
                    <?php else: ?>
                        <a href="login.php" class="text-primary font-medium">
                            <i class="fas fa-sign-in-alt mr-1"></i>Login
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </header>

    <!-- Hero Section with Search -->
    <section class="hero-gradient text-white py-16">
        <div class="container mx-auto px-4">
            <div class="max-w-3xl mx-auto text-center">
                <div class="mb-6">
                    <i class="fas fa-search text-6xl mb-4 opacity-90"></i>
                </div>
                <h1 class="text-4xl md:text-5xl font-bold mb-4">
                    Search Our Membership
                </h1>
                <p class="text-xl mb-8 text-white/90">
                    Find members by searching their names
                </p>
                
                <!-- Search Form -->
                <form method="GET" action="" class="w-full">
                    <div class="flex flex-col sm:flex-row gap-3">
                        <div class="flex-1 relative">
                            <input 
                                type="text" 
                                name="search" 
                                id="searchInput"
                                value="<?php echo htmlspecialchars($searchQuery); ?>"
                                placeholder="Enter first name, last name, or full name..." 
                                class="w-full px-6 py-4 rounded-lg text-gray-800 text-lg focus:outline-none focus:ring-4 focus:ring-white/30"
                                required
                                autocomplete="off"
                            >
                            <i class="fas fa-search absolute right-6 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
                        </div>
                        <button 
                            type="submit" 
                            class="px-8 py-4 rounded-full text-white font-semibold transition hover:shadow-2xl"
                            style="background: linear-gradient(135deg, #F97316 0%, #FBBF24 100%);"
                        >
                            <i class="fas fa-search mr-2"></i>Search
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </section>

    <!-- Search Results Section -->
    <section class="py-12 min-h-screen">
        <div class="container mx-auto px-4">
            <?php if (!empty($error)): ?>
                <!-- Error Message -->
                <div class="max-w-4xl mx-auto mb-6">
                    <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded" role="alert">
                        <p class="font-bold"><i class="fas fa-exclamation-circle mr-2"></i>Error</p>
                        <p><?php echo htmlspecialchars($error); ?></p>
                    </div>
                </div>
            <?php endif; ?>
            
            <?php if (!empty($searchQuery)): ?>
                <div class="max-w-6xl mx-auto">
                    <!-- Results Header -->
                    <div class="mb-6 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
                        <div>
                            <h2 class="text-2xl font-bold text-gray-800">
                                Search Results
                            </h2>
                            <p class="text-gray-600 mt-1">
                                <?php if ($totalResults > 0): ?>
                                    Found <span class="font-semibold text-primary"><?php echo $totalResults; ?></span> 
                                    <?php echo $totalResults == 1 ? 'member' : 'members'; ?> 
                                    matching "<?php echo htmlspecialchars($searchQuery); ?>"
                                <?php else: ?>
                                    No members found matching "<?php echo htmlspecialchars($searchQuery); ?>"
                                <?php endif; ?>
                            </p>
                        </div>
                        <a href="public-search.php" class="bg-primary text-white px-6 py-2 rounded-lg hover:opacity-90 transition">
                            <i class="fas fa-redo mr-2"></i>New Search
                        </a>
                    </div>

                    <?php if ($totalResults > 0): ?>
                        <!-- Results List (Vertical) -->
                        <div class="space-y-4">
                            <?php foreach ($searchResults as $index => $member): ?>
                                <div class="search-card bg-white rounded-lg shadow-md border-l-4 border-primary hover:shadow-lg transition-shadow">
                                    <div class="p-6">
                                        <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
                                            <!-- Left: Member Info -->
                                            <div class="flex-1">
                                                <!-- Member Name & Card ID -->
                                                <div class="flex flex-col sm:flex-row sm:items-center gap-3 mb-3">
                                                    <h3 class="text-2xl font-bold text-gray-800">
                                                        <?php 
                                                        $fullName = trim(
                                                            ($member['title'] ? $member['title'] . ' ' : '') .
                                                            $member['first_name'] . ' ' . 
                                                            ($member['middle_name'] ? $member['middle_name'] . ' ' : '') . 
                                                            $member['last_name']
                                                        );
                                                        echo htmlspecialchars($fullName); 
                                                        ?>
                                                    </h3>
                                                    <span class="bg-primary text-white px-4 py-1.5 rounded-full text-sm font-semibold inline-flex items-center gap-2">
                                                        <i class="fas fa-id-card"></i>
                                                        <?php echo htmlspecialchars($member['membershipcard_id']); ?>
                                                    </span>
                                                </div>

                                                <!-- Location Information (Horizontal) -->
                                                <div class="flex flex-wrap gap-6">
                                                    <div class="flex items-center gap-2">
                                                        <i class="fas fa-location-dot text-secondary text-lg"></i>
                                                        <div>
                                                            <p class="text-xs text-gray-500 uppercase tracking-wide font-semibold">District</p>
                                                            <p class="text-base text-gray-800 font-medium"><?php echo htmlspecialchars($member['district_name'] ?: 'N/A'); ?></p>
                                                        </div>
                                                    </div>
                                                    <div class="flex items-center gap-2">
                                                        <i class="fas fa-church text-primary text-lg"></i>
                                                        <div>
                                                            <p class="text-xs text-gray-500 uppercase tracking-wide font-semibold">Assembly</p>
                                                            <p class="text-base text-gray-800 font-medium"><?php echo htmlspecialchars($member['assembly_name'] ?: 'N/A'); ?></p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>

                                            <!-- Right: Result Number & Actions -->
                                            <div class="flex-shrink-0 flex flex-col items-center gap-3">
                                                <div class="bg-gray-100 rounded-full w-12 h-12 flex items-center justify-center">
                                                    <span class="text-lg font-bold text-gray-600">#<?php echo $index + 1; ?></span>
                                                </div>
                                                <a href="membership-issue.php?type=incorrect&member_id=<?php echo $member['id']; ?>" 
                                                   class="bg-yellow-500 hover:bg-yellow-600 text-white px-4 py-2 rounded-lg text-sm font-medium transition inline-flex items-center gap-2"
                                                   title="Report incorrect details">
                                                    <i class="fas fa-exclamation-triangle"></i>
                                                    <span class="hidden sm:inline">Report Issue</span>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    <?php else: ?>
                        <!-- No Results Message -->
                        <div class="bg-white rounded-lg shadow-md p-12 text-center">
                            <i class="fas fa-search text-gray-300 text-6xl mb-4"></i>
                            <h3 class="text-2xl font-bold text-gray-800 mb-2">No Members Found</h3>
                            <p class="text-gray-600 mb-6">
                                We couldn't find any members matching "<?php echo htmlspecialchars($searchQuery); ?>". Please try:
                            </p>
                            <ul class="text-left max-w-md mx-auto text-gray-600 space-y-2 mb-8">
                                <li><i class="fas fa-check-circle text-primary mr-2"></i>Checking your spelling</li>
                                <li><i class="fas fa-check-circle text-primary mr-2"></i>Using different keywords</li>
                                <li><i class="fas fa-check-circle text-primary mr-2"></i>Trying just the first or last name</li>
                            </ul>
                            <div class="flex flex-col sm:flex-row gap-4 justify-center items-center">
                                <a href="public-search.php" class="inline-block bg-primary text-white px-8 py-3 rounded-lg hover:opacity-90 transition">
                                    <i class="fas fa-redo mr-2"></i>Try Another Search
                                </a>
                                <a href="membership-issue.php?type=not_found&search=<?php echo urlencode($searchQuery); ?>" 
                                   class="inline-block bg-red-600 text-white px-8 py-3 rounded-lg hover:bg-red-700 transition">
                                    <i class="fas fa-exclamation-circle mr-2"></i>Report Missing Member
                                </a>
                            </div>
                            <div class="mt-6 p-4 bg-blue-50 rounded-lg">
                                <p class="text-sm text-gray-700">
                                    <i class="fas fa-info-circle text-blue-500 mr-2"></i>
                                    <strong>Can't find your membership?</strong> Click "Report Missing Member" to notify our admin team.
                                </p>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            <?php else: ?>
                <!-- Initial State - No Search Yet -->
                <div class="max-w-4xl mx-auto">
                    <div class="bg-white rounded-lg shadow-md p-12 text-center">
                        <i class="fas fa-users text-primary text-6xl mb-6"></i>
                        <h3 class="text-2xl font-bold text-gray-800 mb-4">Welcome to Member Search</h3>
                        <p class="text-gray-600 text-lg mb-8">
                            Enter a member's name in the search box above to find their information including their area, district, and assembly.
                        </p>
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 max-w-2xl mx-auto">
                            <div class="text-center">
                                <div class="w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3">
                                    <i class="fas fa-search text-primary text-2xl"></i>
                                </div>
                                <h4 class="font-semibold text-gray-800 mb-1">Search</h4>
                                <p class="text-sm text-gray-600">Enter member name</p>
                            </div>
                            <div class="text-center">
                                <div class="w-16 h-16 bg-secondary/10 rounded-full flex items-center justify-center mx-auto mb-3">
                                    <i class="fas fa-list text-secondary text-2xl"></i>
                                </div>
                                <h4 class="font-semibold text-gray-800 mb-1">View Results</h4>
                                <p class="text-sm text-gray-600">Browse matches</p>
                            </div>
                            <div class="text-center">
                                <div class="w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-3">
                                    <i class="fas fa-info-circle text-primary text-2xl"></i>
                                </div>
                                <h4 class="font-semibold text-gray-800 mb-1">Get Info</h4>
                                <p class="text-sm text-gray-600">See location details</p>
                            </div>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-800 text-white py-8 mt-12">
        <div class="container mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="flex items-center space-x-3 mb-4 md:mb-0">
                    <div class="w-10 h-10 bg-primary rounded-lg flex items-center justify-center">
                        <i class="fas fa-church text-white text-lg"></i>
                    </div>
                    <div>
                        <h3 class="text-lg font-bold"><?php echo htmlspecialchars($settings['site_title']); ?></h3>
                        <p class="text-gray-400 text-sm">Member Search</p>
                    </div>
                </div>
                <div class="text-center md:text-right">
                    <p class="text-gray-400 text-sm mb-2">
                        © <?php echo date('Y'); ?> <?php echo htmlspecialchars($settings['site_title']); ?>
                    </p>
                    <div class="flex justify-center md:justify-end space-x-4">
                        <a href="index.php" class="text-gray-400 hover:text-white transition text-sm">Home</a>
                        <a href="conference.php" class="text-gray-400 hover:text-white transition text-sm">Events</a>
                        <a href="login.php" class="text-gray-400 hover:text-white transition text-sm">Login</a>
                    </div>
                </div>
            </div>
        </div>
    </footer>

    <script>
        function toggleMobileMenu() {
            const menu = document.getElementById('mobileMenu');
            menu.classList.toggle('hidden');
        }
        
        // Auto-focus search input on page load
        document.addEventListener('DOMContentLoaded', function() {
            const searchInput = document.getElementById('searchInput');
            if (searchInput && !searchInput.value) {
                searchInput.focus();
            }
        });
    </script>

    <?php 
    // Include Chat Hub Widget (Admin Chat + AI Chatbot)
    if (file_exists(__DIR__ . '/includes/chat-hub-widget.php')) {
        include 'includes/chat-hub-widget.php';
    }
    ?>
</body>
</html>

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