Sindbad~EG File Manager
<?php
require_once '../config/config.php';
require_once '../classes/MemberAuth.php';
// Check if member is logged in
if (!MemberAuth::isMemberLoggedIn()) {
redirect('../login.php');
}
$pageTitle = "Messages - " . APP_NAME;
$db = Database::getInstance()->getConnection();
// Get current member data
$currentMember = MemberAuth::getCurrentMember();
if (!$currentMember) {
redirect('../login.php');
}
// Load member conversations
$memberConversations = [];
try {
$stmt = $db->prepare("SELECT c.id, c.created_at, c.type,
(SELECT message_text FROM chat_messages WHERE conversation_id = c.id ORDER BY id DESC LIMIT 1) AS last_message,
(SELECT created_at FROM chat_messages WHERE conversation_id = c.id ORDER BY id DESC LIMIT 1) AS last_message_time,
(SELECT COUNT(*) FROM chat_messages WHERE conversation_id = c.id AND is_read = 0 AND sender_type = 'admin') AS unread_count
FROM chat_conversations c
WHERE c.member_id = :member_id AND c.type IN ('public', 'member_admin')
ORDER BY (last_message_time IS NULL), last_message_time DESC, c.created_at DESC");
$stmt->execute(['member_id' => $currentMember['member_id']]);
$memberConversations = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
$memberConversations = [];
}
// Get settings for theme colors
$stmt = $db->query("SELECT * FROM general_settings ORDER BY id DESC LIMIT 1");
$settings = $stmt->fetch();
$settings = array_merge([
'site_title' => APP_NAME,
'theme_primary_color' => '#3B82F6',
'theme_secondary_color' => '#10B981'
], $settings ?: []);
?>
<!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>
.gradient-bg { background: linear-gradient(135deg, #1E40AF 0%, #9333EA 50%, #F97316 100%); }
.card-hover { transition: all 0.3s ease; }
.card-hover:hover { transform: translateY(-2px); box-shadow: 0 12px 20px -5px rgba(0,0,0,0.1); }
</style>
</head>
<body class="bg-gray-50">
<!-- Member Portal 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">
<div class="flex items-center space-x-3">
<div class="w-10 h-10 rounded-xl flex items-center justify-center gradient-bg">
<i class="fas fa-church text-white"></i>
</div>
<div>
<h1 class="text-lg font-bold text-gray-800"><?php echo htmlspecialchars($settings['site_title']); ?></h1>
<p class="text-xs text-gray-500">Member Portal</p>
</div>
</div>
<nav class="hidden md:flex items-center space-x-6">
<a href="dashboard.php" class="text-gray-700 hover:text-blue-600 transition">
<i class="fas fa-home mr-1"></i>Dashboard
</a>
<a href="profile.php" class="text-gray-700 hover:text-blue-600 transition">
<i class="fas fa-user mr-1"></i>Profile
</a>
<a href="messages.php" class="text-blue-600 font-medium border-b-2 border-blue-600 pb-1 relative">
<i class="fas fa-comments mr-1"></i>Messages
<?php
$totalUnread = array_sum(array_column($memberConversations, 'unread_count'));
if ($totalUnread > 0):
?>
<span class="absolute -top-2 -right-2 bg-red-500 text-white text-xs rounded-full w-5 h-5 flex items-center justify-center"><?php echo $totalUnread; ?></span>
<?php endif; ?>
</a>
<a href="event-checkin.php" class="text-gray-700 hover:text-green-600 transition">
<i class="fas fa-qrcode mr-1"></i>Event Check-in
</a>
<a href="transfer_request.php" class="text-gray-700 hover:text-blue-600 transition">
<i class="fas fa-exchange-alt mr-1"></i>Transfer
</a>
</nav>
<div class="flex items-center space-x-3">
<a href="../logout.php?member=1" class="text-gray-600 hover:text-red-600 transition">
<i class="fas fa-sign-out-alt mr-1"></i>Logout
</a>
</div>
</div>
</div>
</header>
<div class="container mx-auto px-4 py-8">
<div class="max-w-5xl mx-auto">
<!-- Page Header -->
<div class="mb-8">
<a href="dashboard.php" class="text-sm text-blue-600 hover:text-blue-800 mb-2 inline-block">
<i class="fas fa-arrow-left mr-1"></i>Back to Dashboard
</a>
<h1 class="text-3xl font-bold text-gray-800 mb-2">
<i class="fas fa-comments mr-2 text-blue-500"></i>Messages & Chats
</h1>
<p class="text-gray-600">View and manage your conversations with church admins</p>
</div>
<!-- Messages List -->
<?php if (empty($memberConversations)): ?>
<div class="bg-white rounded-xl shadow-lg p-12 text-center">
<div class="w-32 h-32 rounded-full flex items-center justify-center mx-auto mb-6" style="background: linear-gradient(135deg, #1E40AF 0%, #F97316 100%);">
<i class="fas fa-inbox text-white text-6xl"></i>
</div>
<h3 class="text-2xl font-bold text-gray-800 mb-2">No Messages Yet</h3>
<p class="text-gray-600 mb-6 max-w-md mx-auto">
You haven't started any conversations yet. Use the chat widget on the homepage to connect with church admins, or wait for broadcast messages from leadership.
</p>
<a href="../index.php" class="inline-flex items-center px-6 py-3 rounded-lg text-white font-semibold shadow-lg hover:shadow-xl transition" style="background: linear-gradient(135deg, #1E40AF 0%, #F97316 100%);">
<i class="fas fa-home mr-2"></i>Go to Homepage
</a>
</div>
<?php else: ?>
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<div class="border-b border-gray-200 px-6 py-4 bg-gray-50">
<div class="flex items-center justify-between">
<h2 class="text-lg font-semibold text-gray-800">
<i class="fas fa-list mr-2"></i>All Conversations
</h2>
<span class="text-sm text-gray-600"><?php echo count($memberConversations); ?> conversation(s)</span>
</div>
</div>
<div class="divide-y divide-gray-200">
<?php foreach ($memberConversations as $conv): ?>
<div class="px-6 py-5 hover:bg-gray-50 transition cursor-pointer card-hover" onclick="openChat(<?php echo $conv['id']; ?>)">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-4 flex-1">
<div class="w-14 h-14 rounded-full flex items-center justify-center text-white font-bold shadow-md" style="background: linear-gradient(135deg, #1E40AF 0%, #F97316 100%);">
<i class="fas fa-user-shield text-xl"></i>
</div>
<div class="flex-1 min-w-0">
<div class="flex items-center space-x-2 mb-1">
<p class="text-base font-bold text-gray-800">Church Admin</p>
<span class="px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
<?php echo $conv['type'] === 'public' ? 'Public Chat' : 'Direct Message'; ?>
</span>
<?php if (($conv['unread_count'] ?? 0) > 0): ?>
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-bold bg-red-500 text-white">
<?php echo $conv['unread_count']; ?> new
</span>
<?php endif; ?>
</div>
<p class="text-sm text-gray-600 truncate mb-1">
<?php echo htmlspecialchars(substr($conv['last_message'] ?? 'No messages yet', 0, 100)); ?>
</p>
<p class="text-xs text-gray-500 flex items-center">
<i class="fas fa-clock mr-1"></i>
<?php echo $conv['last_message_time'] ? date('M j, Y - g:i A', strtotime($conv['last_message_time'])) : 'Just now'; ?>
</p>
</div>
</div>
<div class="ml-4">
<i class="fas fa-chevron-right text-gray-400 text-xl"></i>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- Chat Widget Info -->
<div class="mt-6 bg-blue-50 border-l-4 border-blue-500 rounded-lg p-4">
<div class="flex items-start space-x-3">
<i class="fas fa-info-circle text-blue-500 text-xl mt-0.5"></i>
<div>
<p class="font-semibold text-blue-900">Start a New Conversation</p>
<p class="text-sm text-blue-800 mt-1">
Use the chat widget on the homepage to start a new conversation with our admin team. They'll respond as soon as they're available!
</p>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Footer -->
<footer class="bg-gray-800 text-white py-6 mt-12">
<div class="container mx-auto px-4 text-center">
<p class="text-sm text-gray-400">
© <?php echo date('Y'); ?> <?php echo htmlspecialchars($settings['site_title']); ?>. All rights reserved.
</p>
</div>
</footer>
<script>
function openChat(conversationId) {
// Redirect to homepage with chat widget open
window.location.href = '../index.php?open_chat=' + conversationId;
}
</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