Sindbad~EG File Manager

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

<?php
/**
 * Enable All Modules by Default
 * Sets all existing modules to enabled for all access levels
 */

require_once 'config/config.php';
checkLogin();

// Only superusers can run this
if (!isSuperuser()) {
    die('<div style="padding: 20px; background: #fee; border: 2px solid #c00; color: #c00; font-family: Arial;">
    <h2>Access Denied</h2>
    <p>Only superusers can run this script.</p>
    <a href="dashboard.php" style="color: #00f;">Return to Dashboard</a>
    </div>');
}

$db = Database::getInstance()->getConnection();
$success = [];
$errors = [];

try {
    // Get all modules
    $modules = $db->query("SELECT id, module_name FROM module_management")->fetchAll();
    
    if (empty($modules)) {
        $errors[] = "No modules found in database";
    } else {
        $db->beginTransaction();
        
        $updated = 0;
        $inserted = 0;
        
        foreach ($modules as $module) {
            foreach (['assembly', 'district', 'area', 'superuser'] as $level) {
                // Try to insert or update
                $stmt = $db->prepare("
                    INSERT INTO module_access_levels (module_id, access_level, is_enabled, enabled_by)
                    VALUES (?, ?, TRUE, ?)
                    ON DUPLICATE KEY UPDATE 
                        is_enabled = TRUE,
                        updated_at = CURRENT_TIMESTAMP
                ");
                
                $result = $stmt->execute([$module['id'], $level, $_SESSION['user_id']]);
                
                if ($stmt->rowCount() > 0) {
                    if ($db->query("SELECT LAST_INSERT_ID()")->fetchColumn() > 0) {
                        $inserted++;
                    } else {
                        $updated++;
                    }
                }
            }
        }
        
        $db->commit();
        
        $success[] = "✅ Processed " . count($modules) . " modules";
        $success[] = "✅ Inserted $inserted new access permissions";
        $success[] = "✅ Updated $updated existing access permissions";
        $success[] = "✅ All modules are now enabled for all access levels by default";
    }
    
} catch (Exception $e) {
    if ($db->inTransaction()) {
        $db->rollBack();
    }
    $errors[] = "❌ Error: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Enable All Modules</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body class="bg-gray-100">
    <div class="min-h-screen flex items-center justify-center p-4">
        <div class="max-w-3xl w-full bg-white rounded-2xl shadow-2xl p-8">
            
            <!-- Header -->
            <div class="text-center mb-8">
                <div class="inline-flex items-center justify-center w-20 h-20 rounded-full bg-gradient-to-br from-green-500 to-blue-600 mb-4">
                    <i class="fas fa-check-circle text-3xl text-white"></i>
                </div>
                <h1 class="text-4xl font-bold text-gray-800 mb-2">Enable All Modules</h1>
                <p class="text-gray-600">Setting all modules to enabled by default</p>
            </div>

            <!-- Success Messages -->
            <?php if (!empty($success)): ?>
                <div class="bg-green-50 border-l-4 border-green-500 p-6 rounded-lg mb-6">
                    <div class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 text-2xl mr-4 mt-1"></i>
                        <div class="flex-1">
                            <h3 class="text-lg font-bold text-green-800 mb-3">Success!</h3>
                            <ul class="space-y-2">
                                <?php foreach ($success as $msg): ?>
                                    <li class="text-green-700 flex items-center">
                                        <i class="fas fa-check mr-2 text-sm"></i>
                                        <?php echo htmlspecialchars($msg); ?>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                    </div>
                </div>
            <?php endif; ?>

            <!-- Error Messages -->
            <?php if (!empty($errors)): ?>
                <div class="bg-red-50 border-l-4 border-red-500 p-6 rounded-lg mb-6">
                    <div class="flex items-start">
                        <i class="fas fa-exclamation-circle text-red-500 text-2xl mr-4 mt-1"></i>
                        <div class="flex-1">
                            <h3 class="text-lg font-bold text-red-800 mb-3">Error</h3>
                            <ul class="space-y-2">
                                <?php foreach ($errors as $msg): ?>
                                    <li class="text-red-700 text-sm"><?php echo htmlspecialchars($msg); ?></li>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                    </div>
                </div>
            <?php endif; ?>

            <?php if (empty($errors)): ?>
                <!-- What was done -->
                <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-lg mb-6">
                    <h3 class="text-lg font-bold text-blue-800 mb-4">
                        <i class="fas fa-info-circle mr-2"></i>What Changed
                    </h3>
                    <ul class="space-y-2 text-blue-700">
                        <li>✅ All modules are now <strong>enabled</strong> for all access levels</li>
                        <li>✅ Assembly admins can see all modules</li>
                        <li>✅ District admins can see all modules</li>
                        <li>✅ Area admins can see all modules</li>
                        <li>✅ Superusers can see all modules</li>
                        <li>💡 You can now selectively <strong>disable</strong> specific modules for specific levels in Module Management</li>
                    </ul>
                </div>

                <!-- Next Steps -->
                <div class="bg-purple-50 border-l-4 border-purple-500 p-6 rounded-lg">
                    <h3 class="text-lg font-bold text-purple-800 mb-3">
                        <i class="fas fa-lightbulb mr-2"></i>Next Steps
                    </h3>
                    <p class="text-purple-700 mb-4">
                        Now that all modules are enabled by default, you can:
                    </p>
                    <ol class="space-y-2 text-purple-700">
                        <li><strong>1.</strong> Go to Module Management</li>
                        <li><strong>2.</strong> Selectively disable modules for specific access levels</li>
                        <li><strong>3.</strong> Test with different user accounts</li>
                        <li><strong>4.</strong> Adjust as needed based on your organizational structure</li>
                    </ol>
                </div>
            <?php endif; ?>

            <!-- Action Buttons -->
            <div class="mt-8 flex gap-4 justify-center">
                <a href="<?php echo BASE_URL; ?>modules/module-management/index.php" 
                   class="px-6 py-3 bg-gradient-to-r from-blue-500 to-purple-600 text-white rounded-lg hover:from-blue-600 hover:to-purple-700 transition shadow-lg flex items-center gap-2">
                    <i class="fas fa-sliders-h"></i>
                    Module Management
                </a>
                <a href="<?php echo BASE_URL; ?>dashboard.php" 
                   class="px-6 py-3 bg-gray-500 text-white rounded-lg hover:bg-gray-600 transition shadow-lg flex items-center gap-2">
                    <i class="fas fa-home"></i>
                    Dashboard
                </a>
            </div>

        </div>
    </div>
</body>
</html>

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