Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/chatbot/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/chatbot/settings.php

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

$pageTitle = "Chatbot Settings - " . APP_NAME;

// Check access
if (!isSuperuser()) {
    redirect('../../dashboard.php');
}

require_once '../../classes/ChatbotService.php';
$chatbot = new ChatbotService();

$success = '';
$error = '';

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save_settings'])) {
    $settings = [
        'enabled' => isset($_POST['enabled']) ? '1' : '0',
        'welcome_message' => trim($_POST['welcome_message'] ?? ''),
        'chat_welcome_message' => trim($_POST['chat_welcome_message'] ?? ''),
        'placeholder_text' => trim($_POST['placeholder_text'] ?? ''),
        'bot_name' => trim($_POST['bot_name'] ?? ''),
        'bot_avatar' => trim($_POST['bot_avatar'] ?? ''),
        'primary_color' => trim($_POST['primary_color'] ?? ''),
        'show_typing_indicator' => isset($_POST['show_typing_indicator']) ? '1' : '0',
        'response_delay' => (int)($_POST['response_delay'] ?? 500),
        'max_history' => (int)($_POST['max_history'] ?? 10),
        'allow_feedback' => isset($_POST['allow_feedback']) ? '1' : '0',
        'learn_from_interactions' => isset($_POST['learn_from_interactions']) ? '1' : '0'
    ];
    
    foreach ($settings as $key => $value) {
        $chatbot->updateSetting($key, $value, $_SESSION['user_id']);
    }
    
    $success = "Settings saved successfully!";
}

$settings = $chatbot->getAllSettings();

include '../../includes/header.php';
include '../../includes/sidebar.php';
?>

<main class="main-content md:ml-64 pt-16">
    <div class="container mx-auto px-4 py-8">
        <!-- Header -->
        <div class="mb-6 flex justify-between items-center">
            <div>
                <h1 class="text-3xl font-bold text-gray-800">
                    <i class="fas fa-cog mr-2 text-orange-500"></i>Chatbot Settings
                </h1>
                <p class="text-gray-600 mt-2">Configure chatbot appearance and behavior</p>
            </div>
            <a href="index.php" class="bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700 transition">
                <i class="fas fa-arrow-left mr-2"></i>Back
            </a>
        </div>

        <?php if ($success): ?>
            <div id="successMessage" class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded-lg mb-6 flex items-center justify-between">
                <div><i class="fas fa-check-circle mr-2"></i><?php echo $success; ?></div>
                <button onclick="dismissMessage('successMessage')" class="text-green-700 hover:text-green-900">
                    <i class="fas fa-times"></i>
                </button>
            </div>
        <?php endif; ?>

        <form method="POST" class="space-y-6">
            <!-- General Settings -->
            <div class="bg-white rounded-xl shadow-lg p-6">
                <h3 class="text-lg font-bold text-gray-800 mb-4">
                    <i class="fas fa-toggle-on mr-2"></i>General Settings
                </h3>
                <div class="space-y-4">
                    <div class="flex items-center">
                        <input type="checkbox" name="enabled" id="enabled" <?php echo $settings['enabled'] ? 'checked' : ''; ?>
                               class="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500">
                        <label for="enabled" class="ml-2 text-sm font-medium text-gray-700">Enable Chatbot</label>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Bot Name</label>
                        <input type="text" name="bot_name" value="<?php echo htmlspecialchars($settings['bot_name']); ?>"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Bot Avatar (Emoji)</label>
                        <input type="text" name="bot_avatar" value="<?php echo htmlspecialchars($settings['bot_avatar']); ?>"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500"
                               placeholder="🤖">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Primary Color</label>
                        <input type="color" name="primary_color" value="<?php echo htmlspecialchars($settings['primary_color']); ?>"
                               class="w-full h-12 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500">
                    </div>
                </div>
            </div>

            <!-- Messages -->
            <div class="bg-white rounded-xl shadow-lg p-6">
                <h3 class="text-lg font-bold text-gray-800 mb-4">
                    <i class="fas fa-comment-dots mr-2"></i>Messages
                </h3>
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Chatbot Welcome Message (inside chat)</label>
                        <textarea name="welcome_message" rows="2"
                                  class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500"><?php echo htmlspecialchars($settings['welcome_message']); ?></textarea>
                        <p class="text-xs text-gray-500 mt-1">First message users see when opening the chat window</p>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Popup Welcome Message (bubble)</label>
                        <input type="text" name="chat_welcome_message" value="<?php echo htmlspecialchars($settings['chat_welcome_message'] ?? 'Need help? Chat with us!'); ?>"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500"
                               placeholder="Need help? Chat with us!">
                        <p class="text-xs text-gray-500 mt-1">Short message shown in the welcome popup bubble (keep it brief!)</p>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Input Placeholder Text</label>
                        <input type="text" name="placeholder_text" value="<?php echo htmlspecialchars($settings['placeholder_text']); ?>"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500">
                    </div>
                </div>
            </div>

            <!-- Behavior -->
            <div class="bg-white rounded-xl shadow-lg p-6">
                <h3 class="text-lg font-bold text-gray-800 mb-4">
                    <i class="fas fa-sliders-h mr-2"></i>Behavior
                </h3>
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Response Delay (ms)</label>
                        <input type="number" name="response_delay" value="<?php echo htmlspecialchars($settings['response_delay']); ?>" min="0" max="5000"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500">
                        <p class="text-xs text-gray-500 mt-1">Delay before showing bot response (for natural feel)</p>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-2">Conversation History Limit</label>
                        <input type="number" name="max_history" value="<?php echo htmlspecialchars($settings['max_history']); ?>" min="5" max="50"
                               class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500">
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" name="show_typing_indicator" id="show_typing" <?php echo $settings['show_typing_indicator'] ? 'checked' : ''; ?>
                               class="w-4 h-4 text-orange-600 border-gray-300 rounded focus:ring-orange-500">
                        <label for="show_typing" class="ml-2 text-sm font-medium text-gray-700">Show Typing Indicator</label>
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" name="allow_feedback" id="allow_feedback" <?php echo $settings['allow_feedback'] ? 'checked' : ''; ?>
                               class="w-4 h-4 text-orange-600 border-gray-300 rounded focus:ring-orange-500">
                        <label for="allow_feedback" class="ml-2 text-sm font-medium text-gray-700">Allow User Feedback</label>
                    </div>
                    <div class="flex items-center">
                        <input type="checkbox" name="learn_from_interactions" id="learn_interactions" <?php echo $settings['learn_from_interactions'] ? 'checked' : ''; ?>
                               class="w-4 h-4 text-orange-600 border-gray-300 rounded focus:ring-orange-500">
                        <label for="learn_interactions" class="ml-2 text-sm font-medium text-gray-700">Learn from User Interactions</label>
                    </div>
                </div>
            </div>

            <!-- Save Button -->
            <div class="flex justify-end">
                <button type="submit" name="save_settings" class="bg-gradient-to-r from-orange-500 to-orange-600 text-white px-8 py-3 rounded-lg hover:shadow-lg transition">
                    <i class="fas fa-save mr-2"></i>Save Settings
                </button>
            </div>
        </form>
    </div>
</main>

<?php include '../../includes/footer.php'; ?>

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