Sindbad~EG File Manager

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

<?php
/**
 * Quick Fix: Manually Register AI Chatbot Module
 */

require_once 'config/config.php';

// Check if user is logged in and is superuser
if (!isLoggedIn() || !isSuperuser()) {
    die('Access denied. This script requires superuser access.');
}

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

try {
    // Check if module already exists
    $stmt = $db->prepare("SELECT id FROM module_management WHERE module_name = 'AI Chatbot' LIMIT 1");
    $stmt->execute();
    $existing = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if ($existing) {
        echo "<h2>Module Already Registered</h2>";
        echo "<p>AI Chatbot module ID: " . $existing['id'] . "</p>";
        
        // Check access levels
        $stmt = $db->prepare("SELECT * FROM module_access_levels WHERE module_id = ?");
        $stmt->execute([$existing['id']]);
        $accessLevels = $stmt->fetchAll(PDO::FETCH_ASSOC);
        
        if (empty($accessLevels)) {
            // Add access level
            $stmt = $db->prepare("INSERT INTO module_access_levels (module_id, access_level, is_enabled) VALUES (?, 'superuser', 1)");
            $stmt->execute([$existing['id']]);
            echo "<p style='color: green;'>✅ Access level added for superuser</p>";
        } else {
            echo "<p>Access levels configured:</p>";
            echo "<ul>";
            foreach ($accessLevels as $al) {
                echo "<li>{$al['access_level']} - " . ($al['is_enabled'] ? 'Enabled' : 'Disabled') . "</li>";
            }
            echo "</ul>";
        }
        
        // Update to make sure it's active
        $stmt = $db->prepare("UPDATE module_management SET is_active = 1 WHERE id = ?");
        $stmt->execute([$existing['id']]);
        echo "<p style='color: green;'>✅ Module set to active</p>";
        
    } else {
        // Register the module
        $stmt = $db->prepare("
            INSERT INTO module_management (
                module_name, module_description, module_url, module_icon, 
                is_active, required_role, display_order, created_at
            ) VALUES (
                'AI Chatbot',
                'Manage AI chatbot, FAQs, and knowledge base',
                'modules/chatbot/index.php',
                'robot',
                1,
                'superuser',
                180,
                NOW()
            )
        ");
        $stmt->execute();
        $moduleId = $db->lastInsertId();
        
        echo "<h2 style='color: green;'>✅ Module Registered Successfully</h2>";
        echo "<p>Module ID: $moduleId</p>";
        
        // Add access level
        $stmt = $db->prepare("
            INSERT INTO module_access_levels (module_id, access_level, is_enabled)
            VALUES (?, 'superuser', 1)
        ");
        $stmt->execute([$moduleId]);
        
        echo "<p style='color: green;'>✅ Access level configured for superuser</p>";
    }
    
    echo "<hr>";
    echo "<h3>Module Details:</h3>";
    $stmt = $db->prepare("SELECT * FROM module_management WHERE module_name = 'AI Chatbot'");
    $stmt->execute();
    $module = $stmt->fetch(PDO::FETCH_ASSOC);
    
    echo "<table border='1' cellpadding='10' style='border-collapse: collapse;'>";
    foreach ($module as $key => $value) {
        echo "<tr><td><strong>$key</strong></td><td>$value</td></tr>";
    }
    echo "</table>";
    
    echo "<hr>";
    echo "<h2 style='color: green;'>✅ All Done!</h2>";
    echo "<p><strong>Next Steps:</strong></p>";
    echo "<ol>";
    echo "<li>Refresh your dashboard page</li>";
    echo "<li>Look for 'AI Chatbot' in the sidebar under Administration</li>";
    echo "<li>You should also see the AI Chatbot feature card on the dashboard</li>";
    echo "</ol>";
    
    echo "<p style='margin-top: 20px;'>";
    echo "<a href='dashboard.php' style='display: inline-block; background: linear-gradient(135deg, #1E40AF 0%, #9333EA 100%); color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: bold; margin-right: 10px;'>Go to Dashboard</a>";
    echo "<a href='modules/chatbot/index.php' style='display: inline-block; background: linear-gradient(135deg, #F97316 0%, #FBBF24 100%); color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: bold;'>Open AI Chatbot</a>";
    echo "</p>";
    
    echo "<p style='color: #666; margin-top: 30px; font-size: 14px;'><strong>Note:</strong> You can delete this file (register_chatbot_module.php) after use.</p>";
    
} catch (Exception $e) {
    echo "<h2 style='color: red;'>❌ Error</h2>";
    echo "<p style='color: red;'>" . htmlspecialchars($e->getMessage()) . "</p>";
    echo "<pre>" . htmlspecialchars($e->getTraceAsString()) . "</pre>";
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Register AI Chatbot Module</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 900px;
            margin: 50px auto;
            padding: 20px;
            background: #f5f5f5;
        }
        h2, h3 {
            color: #333;
        }
        table {
            background: white;
            margin: 20px 0;
        }
    </style>
</head>
<body>
</body>
</html>

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