Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/show_module_data.php

<?php
require_once 'config/config.php';
checkLogin();
if (!isSuperuser()) die('Access denied');

$db = Database::getInstance()->getConnection();

// Get first module with access data
$query = "
    SELECT 
        m.*,
        GROUP_CONCAT(
            CONCAT(mal.access_level, ':', IF(mal.is_enabled, '1', '0'))
            ORDER BY FIELD(mal.access_level, 'assembly', 'district', 'area', 'superuser')
            SEPARATOR '|'
        ) as access_config
    FROM module_management m
    LEFT JOIN module_access_levels mal ON m.id = mal.module_id
    WHERE m.module_name = 'Events'
    GROUP BY m.id
";
$module = $db->query($query)->fetch();

// Parse it the same way
$module['access_levels'] = [];
if (!empty($module['access_config'])) {
    $configs = explode('|', $module['access_config']);
    foreach ($configs as $config) {
        if (strpos($config, ':') !== false) {
            list($level, $enabled) = explode(':', $config);
            $module['access_levels'][$level] = ($enabled === '1' || $enabled === 1 || $enabled === true);
        }
    }
}

// Ensure all levels exist
foreach (['assembly', 'district', 'area', 'superuser'] as $level) {
    if (!isset($module['access_levels'][$level])) {
        $module['access_levels'][$level] = true;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Module Data Debug</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 p-8">
    <div class="max-w-4xl mx-auto bg-white rounded-lg shadow p-6">
        <h1 class="text-2xl font-bold mb-6">Events Module Data Debug</h1>
        
        <div class="space-y-4">
            <div class="bg-gray-50 p-4 rounded">
                <strong class="text-lg">Raw access_config from DB:</strong>
                <pre class="mt-2 text-sm bg-white p-3 rounded border"><?php echo htmlspecialchars($module['access_config'] ?? 'NULL'); ?></pre>
            </div>
            
            <div class="bg-blue-50 p-4 rounded border border-blue-200">
                <strong class="text-lg">Parsed access_levels array:</strong>
                <pre class="mt-2 text-sm bg-white p-3 rounded border"><?php print_r($module['access_levels']); ?></pre>
            </div>
            
            <div class="bg-green-50 p-4 rounded border border-green-200">
                <strong class="text-lg">Individual Checks:</strong>
                <div class="mt-2 space-y-2">
                    <?php foreach (['assembly', 'district', 'area', 'superuser'] as $level): ?>
                        <div class="bg-white p-3 rounded border">
                            <strong><?php echo ucfirst($level); ?>:</strong>
                            <ul class="ml-4 mt-1 text-sm">
                                <li>isset: <?php echo isset($module['access_levels'][$level]) ? '✅ YES' : '❌ NO'; ?></li>
                                <li>Value: <?php echo var_export($module['access_levels'][$level] ?? 'undefined', true); ?></li>
                                <li>!empty: <?php echo !empty($module['access_levels'][$level]) ? '✅ TRUE' : '❌ FALSE'; ?></li>
                                <li class="font-bold mt-1">Will show: <?php echo !empty($module['access_levels'][$level]) ? '🟢 GREEN (checked)' : '⚪ GRAY (unchecked)'; ?></li>
                            </ul>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            
            <div class="bg-yellow-50 p-4 rounded border border-yellow-200">
                <strong class="text-lg">Expected Behavior:</strong>
                <ul class="mt-2 space-y-1 text-sm">
                    <li>✅ If database has is_enabled=1, access_config should have "assembly:1"</li>
                    <li>✅ After parsing, access_levels['assembly'] should be TRUE</li>
                    <li>✅ !empty(TRUE) = TRUE = toggle shows GREEN</li>
                    <li>❌ If any step fails, toggle shows GRAY</li>
                </ul>
            </div>
        </div>
        
        <div class="mt-6">
            <a href="modules/module-management/index.php" class="text-blue-600 hover:underline">← Back to Module Management</a>
        </div>
    </div>
</body>
</html>

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