Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/attendance/admin/debug_user_role.php

<?php
require_once '../config/config.php';

// Check if user is logged in
if (!isLoggedIn()) {
    redirect('login.php');
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>User Role Debug - Admin Panel</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
</head>
<body class="bg-gray-50">
    <div class="min-h-screen flex items-center justify-center">
        <div class="max-w-md mx-auto bg-white rounded-lg shadow-lg p-6">
            <h1 class="text-2xl font-bold text-gray-900 mb-6 text-center">
                <i class="fas fa-user-shield text-blue-600 mr-2"></i>User Role Debug
            </h1>
            
            <div class="space-y-4">
                <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
                    <h3 class="font-semibold text-blue-900 mb-2">Session Information:</h3>
                    <div class="text-sm space-y-1">
                        <p><strong>User ID:</strong> <?php echo $_SESSION['user_id'] ?? 'Not set'; ?></p>
                        <p><strong>Full Name:</strong> <?php echo $_SESSION['full_name'] ?? 'Not set'; ?></p>
                        <p><strong>Email:</strong> <?php echo $_SESSION['email'] ?? 'Not set'; ?></p>
                        <p><strong>User Role:</strong> <?php echo $_SESSION['user_role'] ?? 'Not set'; ?></p>
                        <p><strong>Location ID:</strong> <?php echo $_SESSION['location_id'] ?? 'Not set'; ?></p>
                    </div>
                </div>
                
                <div class="bg-green-50 border border-green-200 rounded-lg p-4">
                    <h3 class="font-semibold text-green-900 mb-2">Role Checks:</h3>
                    <div class="text-sm space-y-1">
                        <p><strong>isLoggedIn():</strong> <?php echo isLoggedIn() ? 'Yes' : 'No'; ?></p>
                        <p><strong>hasRole('superuser'):</strong> <?php echo hasRole('superuser') ? 'Yes' : 'No'; ?></p>
                        <p><strong>hasRole('admin'):</strong> <?php echo hasRole('admin') ? 'Yes' : 'No'; ?></p>
                        <p><strong>hasRole('user'):</strong> <?php echo hasRole('user') ? 'Yes' : 'No'; ?></p>
                    </div>
                </div>
                
                <div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4">
                    <h3 class="font-semibold text-yellow-900 mb-2">Database User Info:</h3>
                    <?php
                    $db = new Database();
                    $conn = $db->getConnection();
                    
                    if (isset($_SESSION['user_id'])) {
                        $query = "SELECT * FROM users WHERE id = ?";
                        $stmt = $conn->prepare($query);
                        $stmt->execute([$_SESSION['user_id']]);
                        $user = $stmt->fetch();
                        
                        if ($user) {
                            echo '<div class="text-sm space-y-1">';
                            echo '<p><strong>DB User ID:</strong> ' . $user['id'] . '</p>';
                            echo '<p><strong>DB Full Name:</strong> ' . htmlspecialchars($user['full_name']) . '</p>';
                            echo '<p><strong>DB Email:</strong> ' . htmlspecialchars($user['email']) . '</p>';
                            echo '<p><strong>DB Role:</strong> ' . htmlspecialchars($user['role']) . '</p>';
                            echo '<p><strong>DB Location ID:</strong> ' . ($user['location_id'] ?? 'NULL') . '</p>';
                            echo '<p><strong>DB Is Active:</strong> ' . ($user['is_active'] ? 'Yes' : 'No') . '</p>';
                            echo '</div>';
                        } else {
                            echo '<p class="text-sm text-red-600">User not found in database!</p>';
                        }
                    } else {
                        echo '<p class="text-sm text-red-600">No user ID in session!</p>';
                    }
                    ?>
                </div>
                
                <div class="bg-red-50 border border-red-200 rounded-lg p-4">
                    <h3 class="font-semibold text-red-900 mb-2">Sidebar Menu Access:</h3>
                    <div class="text-sm space-y-1">
                        <p><strong>Settings Page:</strong> <?php echo hasRole('superuser') ? 'Accessible' : 'Not Accessible'; ?></p>
                        <p><strong>Audit Page:</strong> <?php echo hasRole('superuser') ? 'Accessible' : 'Not Accessible'; ?></p>
                        <p><strong>Email Management:</strong> <?php echo hasRole('superuser') ? 'Accessible' : 'Not Accessible'; ?></p>
                        <p><strong>Email Diagnostics:</strong> <?php echo hasRole('superuser') ? 'Accessible' : 'Not Accessible'; ?></p>
                        <p><strong>User Management:</strong> <?php echo hasRole('superuser') ? 'Accessible' : 'Not Accessible'; ?></p>
                    </div>
                </div>
            </div>
            
            <div class="mt-6 text-center">
                <a href="dashboard.php" class="bg-blue-600 text-white px-6 py-2 rounded-lg hover:bg-blue-700 transition duration-300">
                    <i class="fas fa-arrow-left mr-2"></i>Back to Dashboard
                </a>
            </div>
        </div>
    </div>
</body>
</html>

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