Sindbad~EG File Manager
<?php
session_start();
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/functions.php';
// Check if user is area level
if (!isset($_SESSION['user_id']) || $_SESSION['user_level'] !== 'area') {
header('Location: ../login.php');
exit();
}
$page_title = 'Area Dashboard';
$page_description = 'Area-wide overview and management';
$area_id = $_SESSION['area_id'];
// Get area information
$area_query = "SELECT * FROM areas WHERE id = :area_id";
$area_stmt = $db->prepare($area_query);
$area_stmt->bindParam(':area_id', $area_id);
$area_stmt->execute();
$area_info = $area_stmt->fetch(PDO::FETCH_ASSOC);
// Get statistics for this area
$stats_query = "SELECT
(SELECT COUNT(*) FROM users WHERE area_id = :area_id AND is_active = 1) as area_users,
(SELECT COUNT(*) FROM districts WHERE area_id = :area_id AND is_active = 1) as total_districts,
(SELECT COUNT(*) FROM assemblies a JOIN districts d ON a.district_id = d.id WHERE d.area_id = :area_id AND a.is_active = 1) as total_assemblies,
(SELECT COUNT(*) FROM notifications WHERE user_id IN (SELECT id FROM users WHERE area_id = :area_id) AND created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)) as recent_notifications";
$stats_stmt = $db->prepare($stats_query);
$stats_stmt->bindParam(':area_id', $area_id);
$stats_stmt->execute();
$stats = $stats_stmt->fetch(PDO::FETCH_ASSOC);
// Get districts in this area
$districts_query = "SELECT * FROM districts WHERE area_id = :area_id AND is_active = 1 ORDER BY name";
$districts_stmt = $db->prepare($districts_query);
$districts_stmt->bindParam(':area_id', $area_id);
$districts_stmt->execute();
$districts = $districts_stmt->fetchAll(PDO::FETCH_ASSOC);
// Get assemblies in this area
$assemblies_query = "SELECT a.*, d.name as district_name
FROM assemblies a
JOIN districts d ON a.district_id = d.id
WHERE d.area_id = :area_id AND a.is_active = 1
ORDER BY d.name, a.name";
$assemblies_stmt = $db->prepare($assemblies_query);
$assemblies_stmt->bindParam(':area_id', $area_id);
$assemblies_stmt->execute();
$assemblies = $assemblies_stmt->fetchAll(PDO::FETCH_ASSOC);
include '../includes/header.php';
?>
<!-- Area Header -->
<div class="bg-gradient-to-r from-blue-600 to-blue-700 rounded-lg p-6 text-white mb-8">
<div class="flex items-center justify-between">
<div>
<h2 class="text-2xl font-bold"><?php echo htmlspecialchars($area_info['name']); ?></h2>
<p class="text-blue-100 mt-2"><?php echo htmlspecialchars($area_info['description'] ?? 'Area Management Dashboard'); ?></p>
</div>
<div class="text-right">
<p class="text-blue-100 text-sm">Your Role</p>
<p class="text-xl font-semibold capitalize"><?php echo htmlspecialchars($_SESSION['user_role']); ?></p>
</div>
</div>
</div>
<!-- Dashboard Stats -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-lg shadow-sm p-6 border-l-4 border-blue-500">
<div class="flex items-center">
<div class="flex-shrink-0">
<i class="fas fa-users text-3xl text-blue-500"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Area Users</p>
<p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['area_users']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm p-6 border-l-4 border-green-500">
<div class="flex items-center">
<div class="flex-shrink-0">
<i class="fas fa-building text-3xl text-green-500"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Districts</p>
<p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['total_districts']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm p-6 border-l-4 border-purple-500">
<div class="flex items-center">
<div class="flex-shrink-0">
<i class="fas fa-church text-3xl text-purple-500"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Assemblies</p>
<p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['total_assemblies']); ?></p>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-sm p-6 border-l-4 border-yellow-500">
<div class="flex items-center">
<div class="flex-shrink-0">
<i class="fas fa-bell text-3xl text-yellow-500"></i>
</div>
<div class="ml-4">
<p class="text-sm font-medium text-gray-600">Notifications</p>
<p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['recent_notifications']); ?></p>
</div>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="bg-white rounded-lg shadow-sm p-6 mb-8">
<h3 class="text-lg font-semibold text-gray-800 mb-4">Quick Actions</h3>
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-5 gap-4">
<a href="data-entry.php" class="flex flex-col items-center p-4 bg-blue-50 rounded-lg hover:bg-blue-100 transition duration-200">
<i class="fas fa-plus-circle text-2xl text-blue-600 mb-2"></i>
<span class="text-sm font-medium text-blue-800">Data Entry</span>
</a>
<a href="data-edit.php" class="flex flex-col items-center p-4 bg-green-50 rounded-lg hover:bg-green-100 transition duration-200">
<i class="fas fa-edit text-2xl text-green-600 mb-2"></i>
<span class="text-sm font-medium text-green-800">Edit Data</span>
</a>
<a href="reports.php" class="flex flex-col items-center p-4 bg-purple-50 rounded-lg hover:bg-purple-100 transition duration-200">
<i class="fas fa-chart-bar text-2xl text-purple-600 mb-2"></i>
<span class="text-sm font-medium text-purple-800">Reports</span>
</a>
<?php if ($_SESSION['user_role'] == 'admin'): ?>
<a href="user-management.php" class="flex flex-col items-center p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition duration-200">
<i class="fas fa-user-cog text-2xl text-gray-600 mb-2"></i>
<span class="text-sm font-medium text-gray-800">Manage Users</span>
</a>
<a href="settings.php" class="flex flex-col items-center p-4 bg-yellow-50 rounded-lg hover:bg-yellow-100 transition duration-200">
<i class="fas fa-cog text-2xl text-yellow-600 mb-2"></i>
<span class="text-sm font-medium text-yellow-800">Settings</span>
</a>
<?php endif; ?>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Districts Overview -->
<div class="bg-white rounded-lg shadow-sm">
<div class="p-6 border-b border-gray-200">
<h3 class="text-lg font-semibold text-gray-800">Districts in <?php echo htmlspecialchars($area_info['name']); ?></h3>
</div>
<div class="p-6">
<?php if (empty($districts)): ?>
<div class="text-center text-gray-500 py-8">
<i class="fas fa-building text-3xl mb-4"></i>
<p>No districts found</p>
<?php if ($_SESSION['user_role'] == 'admin'): ?>
<a href="district-management.php" class="mt-4 inline-block text-cop-blue hover:text-cop-light-blue">Add District</a>
<?php endif; ?>
</div>
<?php else: ?>
<div class="space-y-4">
<?php foreach ($districts as $district): ?>
<div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
<div>
<h4 class="font-medium text-gray-800"><?php echo htmlspecialchars($district['name']); ?></h4>
<p class="text-sm text-gray-600"><?php echo htmlspecialchars($district['description'] ?? 'No description'); ?></p>
</div>
<div class="text-right">
<a href="district-view.php?id=<?php echo $district['id']; ?>" class="text-cop-blue hover:text-cop-light-blue">
<i class="fas fa-eye"></i>
</a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<!-- Assemblies Overview -->
<div class="bg-white rounded-lg shadow-sm">
<div class="p-6 border-b border-gray-200">
<h3 class="text-lg font-semibold text-gray-800">Recent Assemblies</h3>
</div>
<div class="p-6">
<?php if (empty($assemblies)): ?>
<div class="text-center text-gray-500 py-8">
<i class="fas fa-church text-3xl mb-4"></i>
<p>No assemblies found</p>
</div>
<?php else: ?>
<div class="space-y-4">
<?php foreach (array_slice($assemblies, 0, 5) as $assembly): ?>
<div class="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
<div>
<h4 class="font-medium text-gray-800"><?php echo htmlspecialchars($assembly['name']); ?></h4>
<p class="text-sm text-gray-600"><?php echo htmlspecialchars($assembly['district_name']); ?></p>
</div>
<div class="text-right">
<a href="assembly-view.php?id=<?php echo $assembly['id']; ?>" class="text-cop-blue hover:text-cop-light-blue">
<i class="fas fa-eye"></i>
</a>
</div>
</div>
<?php endforeach; ?>
</div>
<?php if (count($assemblies) > 5): ?>
<div class="mt-6 text-center">
<a href="assemblies.php" class="text-sm text-cop-blue hover:text-cop-light-blue">View all assemblies</a>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
<?php include '../includes/footer.php'; ?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists