Sindbad~EG File Manager
<?php
require_once '../../config/config.php';
checkLogin();
// Check access - users module requires 'area' level or higher
checkAccess('area');
$pageTitle = "User Management - " . APP_NAME;
$db = Database::getInstance()->getConnection();
// Get all users (except superuser for non-superusers)
$query = "SELECT u.*, a.area_name, d.district_name, asm.assembly_name
FROM users u
LEFT JOIN areas a ON u.area_id = a.id
LEFT JOIN districts d ON u.district_id = d.id
LEFT JOIN assemblies asm ON u.assembly_id = asm.id
WHERE 1=1";
if (!isSuperuser()) {
$query .= " AND u.is_superuser = 0";
}
$query .= " ORDER BY u.created_at DESC";
$users = $db->query($query)->fetchAll();
include '../../includes/header.php';
?>
<?php include '../../includes/sidebar.php'; ?>
<!-- Main Content -->
<main class="flex-1 md:ml-64 mt-16">
<div class="container mx-auto px-4 py-8">
<div class="flex justify-between items-center mb-6">
<div>
<h1 class="text-3xl font-bold text-gray-800">
<i class="fas fa-users-cog mr-2 text-blue-500"></i>User Management
</h1>
<p class="text-gray-600 mt-2">Manage system users and access levels</p>
</div>
<a href="add.php" class="bg-gradient-to-r from-blue-500 to-blue-600 text-white px-6 py-3 rounded-lg hover:from-blue-600 hover:to-blue-700 transition shadow-lg">
<i class="fas fa-user-plus mr-2"></i>Add New User
</a>
</div>
<!-- Stats -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-6 mb-6">
<div class="bg-white rounded-lg shadow p-4 border-l-4 border-blue-500">
<p class="text-gray-500 text-sm">Total Users</p>
<p class="text-2xl font-bold text-gray-800"><?php echo count($users); ?></p>
</div>
<div class="bg-white rounded-lg shadow p-4 border-l-4 border-green-500">
<p class="text-gray-500 text-sm">Active Users</p>
<p class="text-2xl font-bold text-gray-800">
<?php echo count(array_filter($users, fn($u) => $u['is_active'])); ?>
</p>
</div>
<div class="bg-white rounded-lg shadow p-4 border-l-4 border-yellow-500">
<p class="text-gray-500 text-sm">Area Admins</p>
<p class="text-2xl font-bold text-gray-800">
<?php echo count(array_filter($users, fn($u) => $u['access_level'] === 'area')); ?>
</p>
</div>
<div class="bg-white rounded-lg shadow p-4 border-l-4 border-purple-500">
<p class="text-gray-500 text-sm">District Admins</p>
<p class="text-2xl font-bold text-gray-800">
<?php echo count(array_filter($users, fn($u) => $u['access_level'] === 'district')); ?>
</p>
</div>
</div>
<!-- Users Table -->
<div class="bg-white rounded-lg shadow-lg overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gradient-to-r from-blue-500 to-blue-600">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-white uppercase">User</th>
<th class="px-6 py-3 text-left text-xs font-medium text-white uppercase">Access Level</th>
<th class="px-6 py-3 text-left text-xs font-medium text-white uppercase">Location</th>
<th class="px-6 py-3 text-left text-xs font-medium text-white uppercase">Last Login</th>
<th class="px-6 py-3 text-left text-xs font-medium text-white uppercase">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-white uppercase">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<?php foreach ($users as $user): ?>
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<img src="<?php echo !empty($user['profile_photo']) ? BASE_URL . 'uploads/profiles/' . $user['profile_photo'] : BASE_URL . 'assets/images/default-avatar.png'; ?>"
class="w-10 h-10 rounded-full mr-3">
<div>
<div class="font-semibold text-gray-800"><?php echo htmlspecialchars($user['full_name']); ?></div>
<div class="text-sm text-gray-500"><?php echo htmlspecialchars($user['email']); ?></div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-3 py-1 text-xs font-semibold rounded-full <?php
echo $user['is_superuser'] ? 'bg-red-100 text-red-800' :
($user['access_level'] === 'area' ? 'bg-blue-100 text-blue-800' :
($user['access_level'] === 'district' ? 'bg-yellow-100 text-yellow-800' :
'bg-green-100 text-green-800'));
?>">
<?php echo $user['is_superuser'] ? 'Superuser' : ucfirst($user['access_level']); ?>
</span>
</td>
<td class="px-6 py-4 text-sm text-gray-600">
<?php
if ($user['access_level'] === 'assembly') {
echo htmlspecialchars($user['assembly_name'] ?? 'N/A');
} elseif ($user['access_level'] === 'district') {
echo htmlspecialchars($user['district_name'] ?? 'N/A');
} elseif ($user['access_level'] === 'area') {
echo htmlspecialchars($user['area_name'] ?? 'N/A');
} else {
echo 'All Locations';
}
?>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-600">
<?php echo $user['last_login'] ? timeAgo($user['last_login']) : 'Never'; ?>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 py-1 text-xs font-semibold rounded-full <?php echo $user['is_active'] ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'; ?>">
<?php echo $user['is_active'] ? 'Active' : 'Inactive'; ?>
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<div class="flex space-x-2">
<a href="edit.php?id=<?php echo $user['id']; ?>" class="text-blue-600 hover:text-blue-800">
<i class="fas fa-edit"></i>
</a>
<?php if (!$user['is_superuser']): ?>
<button onclick="deleteUser(<?php echo $user['id']; ?>)" class="text-red-600 hover:text-red-800">
<i class="fas fa-trash"></i>
</button>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<script>
function deleteUser(id) {
confirmAction('Are you sure you want to delete this user?', function() {
window.location.href = 'delete.php?id=' + id;
});
}
</script>
</main>
<?php include '../../includes/footer.php'; ?>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists