Sindbad~EG File Manager
<?php
require_once 'includes/functions.php';
requireLogin();
$user = getCurrentUser();
$userRole = $_SESSION['user_role'] ?? ($user ? $user['role'] : null);
// Ensure user_role is set in session
if ($userRole && !isset($_SESSION['user_role'])) {
$_SESSION['user_role'] = $userRole;
}
// Get dashboard statistics based on user role
$stats = [];
$recentEvents = [];
$notifications = getUnreadNotifications($_SESSION['user_id']);
$db = new CopMadinaDB();
$conn = $db->getConnection();
// Get settings for site branding
$settings = getSettings();
// Role-based statistics
switch ($userRole) {
case 'superuser':
// Superuser sees all statistics
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM users WHERE status = 'active'");
$stmt->execute();
$stats['total_users'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM events WHERE status = 'published'");
$stmt->execute();
$stats['total_events'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM event_registrations WHERE status = 'confirmed'");
$stmt->execute();
$registrations = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM nonmember_registrations WHERE status = 'confirmed'");
$stmt->execute();
$stats['total_registrations'] = $registrations + $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT SUM(amount_paid) as total FROM event_registrations WHERE payment_status = 'paid'
UNION ALL
SELECT SUM(amount_paid) as total FROM nonmember_registrations WHERE payment_status = 'paid'");
$stmt->execute();
$revenue = 0;
while ($row = $stmt->fetch()) {
$revenue += $row['total'] ?? 0;
}
$stats['total_revenue'] = $revenue;
// Recent events for superuser
$recentEvents = getUpcomingEvents(5);
break;
case 'area_admin':
// Area admin sees area-specific statistics
$areaId = $_SESSION['area_id'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM users WHERE area_id = ? AND status = 'active'");
$stmt->execute([$areaId]);
$stats['area_users'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM events WHERE area_id = ? AND status = 'published'");
$stmt->execute([$areaId]);
$stats['area_events'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM districts WHERE area_id = ? AND status = 'active'");
$stmt->execute([$areaId]);
$stats['total_districts'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM assemblies a
JOIN districts d ON a.district_id = d.id
WHERE d.area_id = ? AND a.status = 'active'");
$stmt->execute([$areaId]);
$stats['total_assemblies'] = $stmt->fetch()['total'];
// Recent area events
$stmt = $conn->prepare("SELECT e.*, COUNT(er.id) + COUNT(nr.id) as registration_count
FROM events e
LEFT JOIN event_registrations er ON e.id = er.event_id AND er.status = 'confirmed'
LEFT JOIN nonmember_registrations nr ON e.id = nr.event_id AND nr.status = 'confirmed'
WHERE e.area_id = ? AND e.status = 'published' AND e.start_date > NOW()
GROUP BY e.id
ORDER BY e.start_date ASC LIMIT 5");
$stmt->execute([$areaId]);
$recentEvents = $stmt->fetchAll();
break;
case 'district_admin':
// District admin sees district-specific statistics
$districtId = $_SESSION['district_id'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM users WHERE district_id = ? AND status = 'active'");
$stmt->execute([$districtId]);
$stats['district_users'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM events WHERE district_id = ? AND status = 'published'");
$stmt->execute([$districtId]);
$stats['district_events'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM assemblies WHERE district_id = ? AND status = 'active'");
$stmt->execute([$districtId]);
$stats['total_assemblies'] = $stmt->fetch()['total'];
// Recent district events
$stmt = $conn->prepare("SELECT e.*, COUNT(er.id) + COUNT(nr.id) as registration_count
FROM events e
LEFT JOIN event_registrations er ON e.id = er.event_id AND er.status = 'confirmed'
LEFT JOIN nonmember_registrations nr ON e.id = nr.event_id AND nr.status = 'confirmed'
WHERE e.district_id = ? AND e.status = 'published' AND e.start_date > NOW()
GROUP BY e.id
ORDER BY e.start_date ASC LIMIT 5");
$stmt->execute([$districtId]);
$recentEvents = $stmt->fetchAll();
break;
case 'assembly_admin':
// Assembly admin sees assembly-specific statistics
$assemblyId = $_SESSION['assembly_id'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM users WHERE assembly_id = ? AND status = 'active'");
$stmt->execute([$assemblyId]);
$stats['assembly_users'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM events WHERE assembly_id = ? AND status = 'published'");
$stmt->execute([$assemblyId]);
$stats['assembly_events'] = $stmt->fetch()['total'];
// Recent assembly events
$stmt = $conn->prepare("SELECT e.*, COUNT(er.id) + COUNT(nr.id) as registration_count
FROM events e
LEFT JOIN event_registrations er ON e.id = er.event_id AND er.status = 'confirmed'
LEFT JOIN nonmember_registrations nr ON e.id = nr.event_id AND nr.status = 'confirmed'
WHERE e.assembly_id = ? AND e.status = 'published' AND e.start_date > NOW()
GROUP BY e.id
ORDER BY e.start_date ASC LIMIT 5");
$stmt->execute([$assemblyId]);
$recentEvents = $stmt->fetchAll();
break;
case 'member':
// Member sees their own statistics
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM event_registrations WHERE user_id = ? AND status = 'confirmed'");
$stmt->execute([$_SESSION['user_id']]);
$stats['my_registrations'] = $stmt->fetch()['total'];
$stmt = $conn->prepare("SELECT COUNT(*) as total FROM event_registrations er
JOIN events e ON er.event_id = e.id
WHERE er.user_id = ? AND er.status = 'confirmed' AND e.start_date > NOW()");
$stmt->execute([$_SESSION['user_id']]);
$stats['upcoming_events'] = $stmt->fetch()['total'];
// Member's registered events
$stmt = $conn->prepare("SELECT e.*, er.registration_code, er.payment_status
FROM events e
JOIN event_registrations er ON e.id = er.event_id
WHERE er.user_id = ? AND er.status = 'confirmed' AND e.start_date > NOW()
ORDER BY e.start_date ASC LIMIT 5");
$stmt->execute([$_SESSION['user_id']]);
$recentEvents = $stmt->fetchAll();
break;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - <?php echo htmlspecialchars($settings['site_name'] ?? 'COP Madina Conference Management'); ?></title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.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%);
}
.sidebar-active {
background: linear-gradient(135deg, #3b82f6 0%, #6b7280 50%, #ef4444 100%);
color: white;
}
</style>
</head>
<body class="bg-gray-100">
<div id="app" class="flex h-screen">
<!-- Sidebar -->
<div class="bg-white shadow-lg w-64 min-h-screen">
<div class="p-6">
<div class="flex items-center space-x-3 mb-8">
<img src="<?php echo BASE_URL; ?>assets/images/logo.png" alt="COP Madina" class="h-10 w-10 rounded-full">
<div>
<h1 class="text-lg font-bold text-gray-800">COP Madina</h1>
<p class="text-xs text-gray-600">Conference Management</p>
</div>
</div>
<nav class="space-y-2">
<a href="<?php echo BASE_URL; ?>dashboard.php" class="sidebar-active flex items-center space-x-3 px-4 py-3 rounded-lg transition-colors">
<i class="fas fa-tachometer-alt"></i>
<span>Dashboard</span>
</a>
<?php if (hasRole('assembly_admin')): ?>
<a href="<?php echo BASE_URL; ?>events/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-calendar"></i>
<span>Events</span>
</a>
<?php endif; ?>
<?php if (hasRole('member')): ?>
<a href="<?php echo BASE_URL; ?>events/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-calendar-alt"></i>
<span>Browse Events</span>
</a>
<?php endif; ?>
<?php if (hasRole('district_admin')): ?>
<a href="<?php echo BASE_URL; ?>assemblies/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-church"></i>
<span>Assemblies</span>
</a>
<?php endif; ?>
<?php if (hasRole('area_admin')): ?>
<a href="<?php echo BASE_URL; ?>districts/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-building"></i>
<span>Districts</span>
</a>
<?php endif; ?>
<?php if (hasRole('superuser')): ?>
<a href="<?php echo BASE_URL; ?>areas/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-map"></i>
<span>Areas</span>
</a>
<a href="<?php echo BASE_URL; ?>users/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-users"></i>
<span>Users</span>
</a>
<?php endif; ?>
<a href="<?php echo BASE_URL; ?>registrations/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-user-plus"></i>
<span>Registrations</span>
</a>
<?php if (hasRole('assembly_admin')): ?>
<a href="<?php echo BASE_URL; ?>reports/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-chart-bar"></i>
<span>Reports</span>
</a>
<?php endif; ?>
<a href="<?php echo BASE_URL; ?>profile.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-user"></i>
<span>Profile</span>
</a>
<?php if (hasRole('superuser')): ?>
<a href="<?php echo BASE_URL; ?>settings/index.php" class="flex items-center space-x-3 px-4 py-3 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors">
<i class="fas fa-cog"></i>
<span>Settings</span>
</a>
<?php endif; ?>
</nav>
</div>
</div>
<!-- Main Content -->
<div class="flex-1 flex flex-col overflow-hidden">
<!-- Top Header -->
<header class="bg-white shadow-sm border-b border-gray-200">
<div class="flex items-center justify-between px-6 py-4">
<div>
<h1 class="text-2xl font-bold text-gray-800">Dashboard</h1>
<p class="text-gray-600">Welcome back, <?php echo htmlspecialchars($user && isset($user['first_name']) ? $user['first_name'] : 'User'); ?>!</p>
</div>
<div class="flex items-center space-x-4">
<!-- Notifications -->
<div class="relative" @click="showNotifications = !showNotifications">
<button class="relative p-2 text-gray-600 hover:text-gray-800 transition-colors">
<i class="fas fa-bell text-xl"></i>
<?php if (count($notifications) > 0): ?>
<span class="absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full h-5 w-5 flex items-center justify-center">
<?php echo count($notifications); ?>
</span>
<?php endif; ?>
</button>
<div v-show="showNotifications" class="absolute right-0 mt-2 w-80 bg-white rounded-lg shadow-lg border border-gray-200 z-50">
<div class="p-4 border-b border-gray-200">
<h3 class="text-lg font-semibold">Notifications</h3>
</div>
<div class="max-h-64 overflow-y-auto">
<?php if (!empty($notifications)): ?>
<?php foreach ($notifications as $notification): ?>
<div class="p-4 border-b border-gray-100 hover:bg-gray-50">
<div class="flex items-start space-x-3">
<div class="flex-shrink-0">
<i class="fas fa-info-circle text-blue-500"></i>
</div>
<div class="flex-1">
<p class="text-sm font-medium text-gray-800"><?php echo htmlspecialchars($notification['title']); ?></p>
<p class="text-sm text-gray-600"><?php echo htmlspecialchars($notification['message']); ?></p>
<p class="text-xs text-gray-500 mt-1"><?php echo formatDate($notification['created_at'], 'M d, g:i A'); ?></p>
</div>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="p-4 text-center text-gray-500">
<i class="fas fa-bell-slash text-2xl mb-2"></i>
<p>No new notifications</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- User Menu -->
<div class="relative" @click="showUserMenu = !showUserMenu">
<button class="flex items-center space-x-2 text-gray-700 hover:text-gray-900 transition-colors">
<img src="<?php echo BASE_URL; ?>assets/images/default-avatar.png" alt="User" class="h-8 w-8 rounded-full">
<span class="font-medium"><?php echo htmlspecialchars($user['first_name'] ?? 'User'); ?></span>
<i class="fas fa-chevron-down text-sm"></i>
</button>
<div v-show="showUserMenu" class="absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg border border-gray-200 z-50">
<div class="py-1">
<a href="<?php echo BASE_URL; ?>profile.php" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fas fa-user mr-2"></i>Profile
</a>
<a href="<?php echo BASE_URL; ?>" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fas fa-home mr-2"></i>Home
</a>
<div class="border-t border-gray-100"></div>
<a href="<?php echo BASE_URL; ?>logout.php" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<i class="fas fa-sign-out-alt mr-2"></i>Logout
</a>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- Dashboard Content -->
<main class="flex-1 overflow-y-auto p-6">
<!-- Statistics Cards -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<?php if ($userRole === 'superuser'): ?>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<i class="fas fa-users text-blue-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Total Users</p>
<p class="text-2xl font-bold text-gray-900"><?php echo number_format($stats['total_users']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
<i class="fas fa-calendar text-green-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Total Events</p>
<p class="text-2xl font-bold text-gray-900"><?php echo number_format($stats['total_events']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center">
<i class="fas fa-user-plus text-purple-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Registrations</p>
<p class="text-2xl font-bold text-gray-900"><?php echo number_format($stats['total_registrations']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-yellow-100 rounded-lg flex items-center justify-center">
<i class="fas fa-money-bill text-yellow-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Revenue</p>
<p class="text-2xl font-bold text-gray-900"><?php echo formatCurrency($stats['total_revenue']); ?></p>
</div>
</div>
</div>
<?php elseif ($userRole === 'member'): ?>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<i class="fas fa-calendar-check text-blue-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">My Registrations</p>
<p class="text-2xl font-bold text-gray-900"><?php echo number_format($stats['my_registrations']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
<i class="fas fa-clock text-green-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Upcoming Events</p>
<p class="text-2xl font-bold text-gray-900"><?php echo number_format($stats['upcoming_events']); ?></p>
</div>
</div>
</div>
<?php else: ?>
<!-- Admin role statistics -->
<?php foreach ($stats as $key => $value): ?>
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center">
<div class="flex-shrink-0">
<div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
<i class="fas fa-chart-bar text-blue-600 text-xl"></i>
</div>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600"><?php echo ucwords(str_replace('_', ' ', $key)); ?></p>
<p class="text-2xl font-bold text-gray-900"><?php echo number_format($value); ?></p>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Recent Events -->
<div class="bg-white rounded-lg shadow">
<div class="px-6 py-4 border-b border-gray-200">
<h2 class="text-lg font-semibold text-gray-800">
<?php echo $userRole === 'member' ? 'My Registered Events' : 'Recent Events'; ?>
</h2>
</div>
<div class="p-6">
<?php if (!empty($recentEvents)): ?>
<div class="space-y-4">
<?php foreach ($recentEvents as $event): ?>
<div class="flex items-center justify-between p-4 border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors">
<div class="flex-1">
<h3 class="font-semibold text-gray-800"><?php echo htmlspecialchars($event['title']); ?></h3>
<p class="text-sm text-gray-600"><?php echo formatDate($event['start_date'], 'M d, Y g:i A'); ?></p>
<?php if (isset($event['registration_code'])): ?>
<p class="text-xs text-blue-600">Registration Code: <?php echo $event['registration_code']; ?></p>
<?php endif; ?>
</div>
<div class="flex items-center space-x-4">
<?php if (isset($event['registration_count'])): ?>
<span class="text-sm text-gray-500"><?php echo $event['registration_count']; ?> registered</span>
<?php endif; ?>
<a href="<?php echo BASE_URL; ?>event.php?id=<?php echo $event['id']; ?>"
class="text-primary-600 hover:text-primary-800 font-medium">
View Details
</a>
</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>
<p class="text-gray-500">No events found</p>
</div>
<?php endif; ?>
</div>
</div>
</main>
</div>
</div>
<script>
const { createApp } = Vue;
createApp({
data() {
return {
showNotifications: false,
showUserMenu: false
}
},
mounted() {
// Close dropdowns when clicking outside
document.addEventListener('click', (e) => {
if (!e.target.closest('.relative')) {
this.showNotifications = false;
this.showUserMenu = false;
}
});
}
}).mount('#app');
</script>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists