Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/reports/dashboard/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/reports/dashboard/superuser.php

<?php
session_start();
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../includes/functions.php';

// Check if user is superuser
if (!isset($_SESSION['user_id']) || $_SESSION['user_level'] !== 'superuser') {
    header('Location: ../login.php');
    exit();
}

$page_title = 'Superuser Dashboard';
$page_description = 'System-wide overview and administration';

// Get statistics
$stats_query = "SELECT 
    (SELECT COUNT(*) FROM users WHERE is_active = 1) as total_users,
    (SELECT COUNT(*) FROM areas WHERE is_active = 1) as total_areas,
    (SELECT COUNT(*) FROM districts WHERE is_active = 1) as total_districts,
    (SELECT COUNT(*) FROM assemblies WHERE is_active = 1) as total_assemblies,
    (SELECT COUNT(*) FROM notifications WHERE created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)) as recent_notifications,
    (SELECT COUNT(*) FROM audit_logs WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 DAY)) as recent_activities";

$stats_stmt = $db->prepare($stats_query);
$stats_stmt->execute();
$stats = $stats_stmt->fetch(PDO::FETCH_ASSOC);

// Get recent activities
$activities_query = "SELECT al.*, u.first_name, u.last_name, u.username 
                     FROM audit_logs al 
                     JOIN users u ON al.user_id = u.id 
                     ORDER BY al.created_at DESC 
                     LIMIT 10";
$activities_stmt = $db->prepare($activities_query);
$activities_stmt->execute();
$recent_activities = $activities_stmt->fetchAll(PDO::FETCH_ASSOC);

// Get user distribution by level
$user_dist_query = "SELECT user_level, COUNT(*) as count FROM users WHERE is_active = 1 GROUP BY user_level";
$user_dist_stmt = $db->prepare($user_dist_query);
$user_dist_stmt->execute();
$user_distribution = $user_dist_stmt->fetchAll(PDO::FETCH_ASSOC);

include '../includes/header.php';
?>

<!-- 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">Total Users</p>
                <p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['total_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-map-marked-alt text-3xl text-green-500"></i>
            </div>
            <div class="ml-4">
                <p class="text-sm font-medium text-gray-600">Areas</p>
                <p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['total_areas']); ?></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-building text-3xl text-yellow-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>

<!-- 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-6 gap-4">
        <a href="user-management.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-users-cog text-2xl text-blue-600 mb-2"></i>
            <span class="text-sm font-medium text-blue-800">User Management</span>
        </a>
        
        <a href="area-management.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-plus-circle text-2xl text-green-600 mb-2"></i>
            <span class="text-sm font-medium text-green-800">Add Area</span>
        </a>
        
        <a href="settings.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-cog text-2xl text-gray-600 mb-2"></i>
            <span class="text-sm font-medium text-gray-800">Settings</span>
        </a>
        
        <a href="backup.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-database text-2xl text-yellow-600 mb-2"></i>
            <span class="text-sm font-medium text-yellow-800">Backup</span>
        </a>
        
        <a href="audit.php" class="flex flex-col items-center p-4 bg-red-50 rounded-lg hover:bg-red-100 transition duration-200">
            <i class="fas fa-history text-2xl text-red-600 mb-2"></i>
            <span class="text-sm font-medium text-red-800">Audit Logs</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>
    </div>
</div>

<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
    <!-- Recent Activities -->
    <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 Activities</h3>
        </div>
        <div class="p-6">
            <?php if (empty($recent_activities)): ?>
            <div class="text-center text-gray-500 py-8">
                <i class="fas fa-history text-3xl mb-4"></i>
                <p>No recent activities</p>
            </div>
            <?php else: ?>
            <div class="space-y-4">
                <?php foreach ($recent_activities as $activity): ?>
                <div class="flex items-start space-x-3">
                    <div class="flex-shrink-0">
                        <div class="w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center">
                            <i class="fas fa-<?php echo $activity['action'] == 'LOGIN' ? 'sign-in-alt' : ($activity['action'] == 'CREATE' ? 'plus' : ($activity['action'] == 'UPDATE' ? 'edit' : ($activity['action'] == 'DELETE' ? 'trash' : 'history'))); ?> text-blue-600 text-xs"></i>
                        </div>
                    </div>
                    <div class="flex-1 min-w-0">
                        <p class="text-sm text-gray-900">
                            <span class="font-medium"><?php echo htmlspecialchars($activity['first_name'] . ' ' . $activity['last_name']); ?></span>
                            <?php echo strtolower($activity['action']); ?>d 
                            <?php if ($activity['table_name']): ?>
                            <span class="font-medium"><?php echo htmlspecialchars($activity['table_name']); ?></span>
                            <?php endif; ?>
                        </p>
                        <p class="text-xs text-gray-500"><?php echo getRelativeTime($activity['created_at']); ?></p>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
            <div class="mt-6 text-center">
                <a href="audit.php" class="text-sm text-cop-blue hover:text-cop-light-blue">View all activities</a>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- User Distribution -->
    <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">User Distribution</h3>
        </div>
        <div class="p-6">
            <?php if (empty($user_distribution)): ?>
            <div class="text-center text-gray-500 py-8">
                <i class="fas fa-users text-3xl mb-4"></i>
                <p>No users found</p>
            </div>
            <?php else: ?>
            <div class="space-y-4">
                <?php 
                $colors = ['superuser' => 'red', 'area' => 'blue', 'district' => 'green', 'assembly' => 'purple'];
                foreach ($user_distribution as $dist): 
                    $color = $colors[$dist['user_level']] ?? 'gray';
                    $percentage = ($dist['count'] / $stats['total_users']) * 100;
                ?>
                <div>
                    <div class="flex justify-between items-center mb-2">
                        <span class="text-sm font-medium text-gray-700 capitalize"><?php echo htmlspecialchars($dist['user_level']); ?></span>
                        <span class="text-sm text-gray-600"><?php echo $dist['count']; ?> users</span>
                    </div>
                    <div class="w-full bg-gray-200 rounded-full h-2">
                        <div class="bg-<?php echo $color; ?>-500 h-2 rounded-full" style="width: <?php echo $percentage; ?>%"></div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<!-- System Status -->
<div class="mt-8 bg-white rounded-lg shadow-sm">
    <div class="p-6 border-b border-gray-200">
        <h3 class="text-lg font-semibold text-gray-800">System Status</h3>
    </div>
    <div class="p-6">
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
            <div class="text-center">
                <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-server text-2xl text-green-600"></i>
                </div>
                <h4 class="font-medium text-gray-800">Database</h4>
                <p class="text-sm text-green-600">Connected</p>
            </div>
            
            <div class="text-center">
                <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-shield-alt text-2xl text-blue-600"></i>
                </div>
                <h4 class="font-medium text-gray-800">Security</h4>
                <p class="text-sm text-blue-600">Active</p>
            </div>
            
            <div class="text-center">
                <div class="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-clock text-2xl text-yellow-600"></i>
                </div>
                <h4 class="font-medium text-gray-800">Last Backup</h4>
                <p class="text-sm text-yellow-600">2 hours ago</p>
            </div>
        </div>
    </div>
</div>

<?php include '../includes/footer.php'; ?>

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