Sindbad~EG File Manager

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

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

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

$page_title = 'Assembly Dashboard';
$page_description = 'Assembly management and overview';

$assembly_id = $_SESSION['assembly_id'];

// Get assembly information
$assembly_query = "SELECT a.*, d.name as district_name, ar.name as area_name 
                   FROM assemblies a 
                   JOIN districts d ON a.district_id = d.id 
                   JOIN areas ar ON d.area_id = ar.id 
                   WHERE a.id = :assembly_id";
$assembly_stmt = $db->prepare($assembly_query);
$assembly_stmt->bindParam(':assembly_id', $assembly_id);
$assembly_stmt->execute();
$assembly_info = $assembly_stmt->fetch(PDO::FETCH_ASSOC);

// Get statistics for this assembly
$stats_query = "SELECT 
    (SELECT COUNT(*) FROM users WHERE assembly_id = :assembly_id AND is_active = 1) as assembly_users,
    (SELECT COUNT(*) FROM notifications WHERE user_id IN (SELECT id FROM users WHERE assembly_id = :assembly_id) AND created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)) as recent_notifications,
    (SELECT COUNT(*) FROM audit_logs WHERE user_id IN (SELECT id FROM users WHERE assembly_id = :assembly_id) AND created_at >= DATE_SUB(NOW(), INTERVAL 1 DAY)) as recent_activities";

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

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

// Get assembly users by role
$users_query = "SELECT user_role, COUNT(*) as count 
                FROM users 
                WHERE assembly_id = :assembly_id AND is_active = 1 
                GROUP BY user_role";
$users_stmt = $db->prepare($users_query);
$users_stmt->bindParam(':assembly_id', $assembly_id);
$users_stmt->execute();
$user_roles = $users_stmt->fetchAll(PDO::FETCH_ASSOC);

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

<!-- Assembly Header -->
<div class="bg-gradient-to-r from-purple-600 to-purple-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($assembly_info['name']); ?></h2>
            <p class="text-purple-100 mt-2">
                <?php echo htmlspecialchars($assembly_info['area_name']); ?> • 
                <?php echo htmlspecialchars($assembly_info['district_name']); ?>
            </p>
            <p class="text-purple-200 text-sm mt-1"><?php echo htmlspecialchars($assembly_info['description'] ?? 'Assembly Management Dashboard'); ?></p>
        </div>
        <div class="text-right">
            <p class="text-purple-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-3 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">Assembly Users</p>
                <p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['assembly_users']); ?></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 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-history text-3xl text-green-500"></i>
            </div>
            <div class="ml-4">
                <p class="text-sm font-medium text-gray-600">Recent Activities</p>
                <p class="text-2xl font-semibold text-gray-900"><?php echo number_format($stats['recent_activities']); ?></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-4 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="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">
    <!-- User Roles 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 Roles in Assembly</h3>
        </div>
        <div class="p-6">
            <?php if (empty($user_roles)): ?>
            <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 
                $role_colors = ['admin' => 'red', 'dataentry' => 'blue', 'viewer' => 'green'];
                $role_icons = ['admin' => 'user-shield', 'dataentry' => 'user-edit', 'viewer' => 'user'];
                foreach ($user_roles as $role): 
                    $color = $role_colors[$role['user_role']] ?? 'gray';
                    $icon = $role_icons[$role['user_role']] ?? 'user';
                ?>
                <div class="flex items-center justify-between p-4 bg-<?php echo $color; ?>-50 rounded-lg">
                    <div class="flex items-center">
                        <div class="w-10 h-10 bg-<?php echo $color; ?>-100 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-<?php echo $icon; ?> text-<?php echo $color; ?>-600"></i>
                        </div>
                        <div>
                            <h4 class="font-medium text-gray-800 capitalize"><?php echo htmlspecialchars($role['user_role']); ?></h4>
                            <p class="text-sm text-gray-600"><?php echo $role['count']; ?> user<?php echo $role['count'] != 1 ? 's' : ''; ?></p>
                        </div>
                    </div>
                    <?php if ($_SESSION['user_role'] == 'admin'): ?>
                    <a href="users.php?role=<?php echo $role['user_role']; ?>" class="text-<?php echo $color; ?>-600 hover:text-<?php echo $color; ?>-700">
                        <i class="fas fa-eye"></i>
                    </a>
                    <?php endif; ?>
                </div>
                <?php endforeach; ?>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- 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>
</div>

<!-- Assembly Information -->
<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">Assembly Information</h3>
    </div>
    <div class="p-6">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div>
                <h4 class="font-medium text-gray-800 mb-2">Hierarchy</h4>
                <div class="space-y-2">
                    <div class="flex items-center text-sm">
                        <i class="fas fa-map-marked-alt text-gray-400 mr-2"></i>
                        <span class="text-gray-600">Area:</span>
                        <span class="ml-2 font-medium"><?php echo htmlspecialchars($assembly_info['area_name']); ?></span>
                    </div>
                    <div class="flex items-center text-sm">
                        <i class="fas fa-building text-gray-400 mr-2"></i>
                        <span class="text-gray-600">District:</span>
                        <span class="ml-2 font-medium"><?php echo htmlspecialchars($assembly_info['district_name']); ?></span>
                    </div>
                    <div class="flex items-center text-sm">
                        <i class="fas fa-church text-gray-400 mr-2"></i>
                        <span class="text-gray-600">Assembly:</span>
                        <span class="ml-2 font-medium"><?php echo htmlspecialchars($assembly_info['name']); ?></span>
                    </div>
                </div>
            </div>
            
            <div>
                <h4 class="font-medium text-gray-800 mb-2">Details</h4>
                <div class="space-y-2">
                    <div class="flex items-center text-sm">
                        <i class="fas fa-calendar text-gray-400 mr-2"></i>
                        <span class="text-gray-600">Created:</span>
                        <span class="ml-2"><?php echo formatDateTime($assembly_info['created_at']); ?></span>
                    </div>
                    <div class="flex items-center text-sm">
                        <i class="fas fa-clock text-gray-400 mr-2"></i>
                        <span class="text-gray-600">Last Updated:</span>
                        <span class="ml-2"><?php echo formatDateTime($assembly_info['updated_at']); ?></span>
                    </div>
                    <div class="flex items-center text-sm">
                        <i class="fas fa-check-circle text-green-500 mr-2"></i>
                        <span class="text-gray-600">Status:</span>
                        <span class="ml-2 text-green-600 font-medium">Active</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

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

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