Sindbad~EG File Manager

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

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

// Settings module should only be accessible by superusers
checkAccess('superuser');

$pageTitle = "Settings - " . APP_NAME;
$db = Database::getInstance()->getConnection();
$success = '';
$error = '';

// Get current settings
$stmt = $db->query("SELECT * FROM general_settings ORDER BY id DESC LIMIT 1");
$settings = $stmt->fetch();

// If no settings exist, create default settings
if (!$settings) {
    $db->exec("INSERT INTO general_settings (site_title) VALUES ('Church Membership System')");
    $settings = $db->query("SELECT * FROM general_settings ORDER BY id DESC LIMIT 1")->fetch();
}

// Ensure all keys have default values
$settings = array_merge([
    'id' => 1,
    'site_title' => 'Church Membership System',
    'theme_primary_color' => '#3B82F6',
    'theme_secondary_color' => '#FCD34D',
    'maintenance_mode' => 0,
    'timezone' => 'UTC',
    'enable_chat' => 1,
    'enable_email_notification' => 1,
    'enable_sms_notification' => 1,
    'header_text' => '',
    'footer_text' => '',
    'font_family' => 'Inter'
], $settings ?: []);

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['update_general'])) {
        try {
            $stmt = $db->prepare("
                UPDATE general_settings 
                SET site_title = :title,
                    theme_primary_color = :primary_color,
                    theme_secondary_color = :secondary_color,
                    maintenance_mode = :maintenance,
                    timezone = :timezone,
                    enable_chat = :enable_chat,
                    enable_email_notification = :enable_email,
                    enable_sms_notification = :enable_sms,
                    header_text = :header,
                    footer_text = :footer,
                    font_family = :font
                WHERE id = :id
            ");
            
            $stmt->execute([
                'title' => $_POST['site_title'] ?? '',
                'primary_color' => $_POST['primary_color'] ?? '#3B82F6',
                'secondary_color' => $_POST['secondary_color'] ?? '#10B981',
                'maintenance' => isset($_POST['maintenance_mode']) ? 1 : 0,
                'timezone' => $_POST['timezone'] ?? 'UTC',
                'enable_chat' => isset($_POST['enable_chat']) ? 1 : 0,
                'enable_email' => isset($_POST['enable_email']) ? 1 : 0,
                'enable_sms' => isset($_POST['enable_sms']) ? 1 : 0,
                'header' => $_POST['header_text'] ?? null,
                'footer' => $_POST['footer_text'] ?? null,
                'font' => $_POST['font_family'] ?? 'Inter',
                'id' => $settings['id']
            ]);
            
            $auditLog = new AuditLog();
            $auditLog->log($_SESSION['user_id'], 'update', 'settings', $settings['id']);
            
            $success = "Settings updated successfully!";
            
            // Refresh settings
            $stmt = $db->query("SELECT * FROM general_settings ORDER BY id DESC LIMIT 1");
            $settings = $stmt->fetch();
            
        } catch (PDOException $e) {
            $error = "Error updating settings: " . $e->getMessage();
        }
    }
}

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

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

<!-- Main Content -->
<main class="flex-1 md:ml-64 mt-16">
<div class="container mx-auto px-4 py-8">
    <div class="max-w-6xl mx-auto">
        <div class="mb-6">
            <h1 class="text-3xl font-bold text-gray-800">
                <i class="fas fa-cog mr-2 text-blue-500"></i>System Settings
            </h1>
            <p class="text-gray-600 mt-2">Configure your church management system</p>
        </div>
        
        <?php if ($success): ?>
            <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded-lg mb-6">
                <i class="fas fa-check-circle mr-2"></i><?php echo $success; ?>
            </div>
        <?php endif; ?>
        
        <?php if ($error): ?>
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded-lg mb-6">
                <i class="fas fa-exclamation-circle mr-2"></i><?php echo $error; ?>
            </div>
        <?php endif; ?>
        
        <!-- Settings Tabs -->
        <div class="bg-white rounded-xl shadow-lg">
            <div class="border-b border-gray-200">
                <nav class="flex flex-wrap">
                    <button onclick="switchSettingsTab('general')" class="settings-tab px-6 py-4 font-medium border-b-2 border-blue-500 text-blue-600">
                        <i class="fas fa-sliders-h mr-2"></i>General
                    </button>
                    <button onclick="switchSettingsTab('theme')" class="settings-tab px-6 py-4 font-medium text-gray-600 hover:text-blue-600 border-b-2 border-transparent">
                        <i class="fas fa-palette mr-2"></i>Theme
                    </button>
                    <button onclick="switchSettingsTab('email')" class="settings-tab px-6 py-4 font-medium text-gray-600 hover:text-blue-600 border-b-2 border-transparent">
                        <i class="fas fa-envelope mr-2"></i>Email
                    </button>
                    <button onclick="switchSettingsTab('sms')" class="settings-tab px-6 py-4 font-medium text-gray-600 hover:text-blue-600 border-b-2 border-transparent">
                        <i class="fas fa-sms mr-2"></i>SMS
                    </button>
                    <button onclick="switchSettingsTab('backup')" class="settings-tab px-6 py-4 font-medium text-gray-600 hover:text-blue-600 border-b-2 border-transparent">
                        <i class="fas fa-database mr-2"></i>Backup
                    </button>
                </nav>
            </div>
            
            <!-- General Settings Tab -->
            <div id="generalTab" class="p-6">
                <form method="POST">
                    <h3 class="text-xl font-bold text-gray-800 mb-4">General Settings</h3>
                    
                    <div class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Site Title</label>
                            <input type="text" name="site_title" value="<?php echo htmlspecialchars($settings['site_title'] ?? ''); ?>" 
                                   class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Timezone</label>
                            <select name="timezone" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                                <option value="UTC" <?php echo ($settings['timezone'] ?? '') === 'UTC' ? 'selected' : ''; ?>>UTC</option>
                                <option value="Africa/Accra" <?php echo ($settings['timezone'] ?? '') === 'Africa/Accra' ? 'selected' : ''; ?>>Africa/Accra (GMT)</option>
                                <option value="America/New_York" <?php echo ($settings['timezone'] ?? '') === 'America/New_York' ? 'selected' : ''; ?>>America/New York (EST)</option>
                            </select>
                        </div>
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <label class="flex items-center space-x-3">
                                <input type="checkbox" name="enable_chat" <?php echo !empty($settings['enable_chat']) ? 'checked' : ''; ?> 
                                       class="rounded border-gray-300">
                                <span class="text-sm font-medium text-gray-700">Enable Chat System</span>
                            </label>
                            
                            <label class="flex items-center space-x-3">
                                <input type="checkbox" name="enable_email" <?php echo !empty($settings['enable_email_notification']) ? 'checked' : ''; ?> 
                                       class="rounded border-gray-300">
                                <span class="text-sm font-medium text-gray-700">Enable Email Notifications</span>
                            </label>
                            
                            <label class="flex items-center space-x-3">
                                <input type="checkbox" name="enable_sms" <?php echo !empty($settings['enable_sms_notification']) ? 'checked' : ''; ?> 
                                       class="rounded border-gray-300">
                                <span class="text-sm font-medium text-gray-700">Enable SMS Notifications</span>
                            </label>
                            
                            <label class="flex items-center space-x-3">
                                <input type="checkbox" name="maintenance_mode" <?php echo !empty($settings['maintenance_mode']) ? 'checked' : ''; ?> 
                                       class="rounded border-gray-300">
                                <span class="text-sm font-medium text-gray-700">Maintenance Mode</span>
                            </label>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Header Text</label>
                            <textarea name="header_text" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"><?php echo htmlspecialchars($settings['header_text'] ?? ''); ?></textarea>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Footer Text</label>
                            <textarea name="footer_text" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500"><?php echo htmlspecialchars($settings['footer_text'] ?? ''); ?></textarea>
                        </div>
                    </div>
                    
                    <div class="mt-6 flex justify-end">
                        <button type="submit" name="update_general" 
                                class="bg-gradient-to-r from-blue-500 to-blue-600 text-white px-6 py-2 rounded-lg hover:from-blue-600 hover:to-blue-700 transition">
                            <i class="fas fa-save mr-2"></i>Save Changes
                        </button>
                    </div>
                </form>
            </div>
            
            <!-- Theme Settings Tab -->
            <div id="themeTab" class="p-6 hidden">
                <form method="POST">
                    <h3 class="text-xl font-bold text-gray-800 mb-4">Theme Settings</h3>
                    
                    <div class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Primary Color</label>
                                <div class="flex items-center space-x-2">
                                    <input type="color" name="primary_color" value="<?php echo htmlspecialchars($settings['theme_primary_color'] ?? '#3B82F6'); ?>" 
                                           class="h-10 w-20 border border-gray-300 rounded">
                                    <input type="text" value="<?php echo htmlspecialchars($settings['theme_primary_color'] ?? '#3B82F6'); ?>" 
                                           class="flex-1 px-4 py-2 border border-gray-300 rounded-lg" readonly>
                                </div>
                            </div>
                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">Secondary Color</label>
                                <div class="flex items-center space-x-2">
                                    <input type="color" name="secondary_color" value="<?php echo htmlspecialchars($settings['theme_secondary_color'] ?? '#FCD34D'); ?>" 
                                           class="h-10 w-20 border border-gray-300 rounded">
                                    <input type="text" value="<?php echo htmlspecialchars($settings['theme_secondary_color'] ?? '#FCD34D'); ?>" 
                                           class="flex-1 px-4 py-2 border border-gray-300 rounded-lg" readonly>
                                </div>
                            </div>
                        </div>
                        
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-2">Font Family</label>
                            <select name="font_family" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                                <option value="Inter" <?php echo ($settings['font_family'] ?? '') === 'Inter' ? 'selected' : ''; ?>>Inter</option>
                                <option value="Roboto" <?php echo ($settings['font_family'] ?? '') === 'Roboto' ? 'selected' : ''; ?>>Roboto</option>
                                <option value="Open Sans" <?php echo ($settings['font_family'] ?? '') === 'Open Sans' ? 'selected' : ''; ?>>Open Sans</option>
                                <option value="Poppins" <?php echo ($settings['font_family'] ?? '') === 'Poppins' ? 'selected' : ''; ?>>Poppins</option>
                            </select>
                        </div>
                        
                        <div class="bg-gray-50 rounded-lg p-4">
                            <h4 class="font-semibold text-gray-800 mb-2">Preview</h4>
                            <div class="space-y-2">
                                <div class="h-12 rounded" style="background: linear-gradient(135deg, <?php echo htmlspecialchars($settings['theme_primary_color'] ?? '#3B82F6'); ?> 0%, <?php echo htmlspecialchars($settings['theme_secondary_color'] ?? '#FCD34D'); ?> 100%);"></div>
                                <p class="text-gray-600">This is how your theme colors will look</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mt-6 flex justify-end">
                        <button type="submit" name="update_general" 
                                class="bg-gradient-to-r from-blue-500 to-blue-600 text-white px-6 py-2 rounded-lg hover:from-blue-600 hover:to-blue-700 transition">
                            <i class="fas fa-save mr-2"></i>Save Changes
                        </button>
                    </div>
                </form>
            </div>
            
            <!-- Email Settings Tab -->
            <div id="emailTab" class="p-6 hidden">
                <h3 class="text-xl font-bold text-gray-800 mb-4">Email Settings</h3>
                <p class="text-gray-600 mb-4">Configure SMTP settings for email notifications</p>
                
                <div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mb-4">
                    <i class="fas fa-info-circle text-yellow-600 mr-2"></i>
                    <span class="text-sm text-gray-700">Email functionality requires valid SMTP credentials</span>
                </div>
                
                <div class="text-center py-8">
                    <i class="fas fa-envelope text-5xl text-gray-300 mb-4"></i>
                    <p class="text-gray-500">Email settings configuration coming soon</p>
                </div>
            </div>
            
            <!-- SMS Settings Tab -->
            <div id="smsTab" class="p-6 hidden">
                <h3 class="text-xl font-bold text-gray-800 mb-4">SMS Settings</h3>
                <p class="text-gray-600 mb-4">Configure SMS gateway for notifications</p>
                
                <div class="text-center py-8">
                    <i class="fas fa-sms text-5xl text-gray-300 mb-4"></i>
                    <p class="text-gray-500">SMS settings configuration coming soon</p>
                </div>
            </div>
            
            <!-- Backup Settings Tab -->
            <div id="backupTab" class="p-6 hidden">
                <h3 class="text-xl font-bold text-gray-800 mb-4">Backup & Restore</h3>
                
                <div class="space-y-6">
                    <div class="bg-blue-50 rounded-lg p-6">
                        <h4 class="font-semibold text-gray-800 mb-2">Create Backup</h4>
                        <p class="text-sm text-gray-600 mb-4">Download a complete backup of your database</p>
                        <button onclick="createBackup()" class="bg-blue-500 text-white px-6 py-2 rounded-lg hover:bg-blue-600 transition">
                            <i class="fas fa-download mr-2"></i>Download Backup
                        </button>
                    </div>
                    
                    <div class="bg-green-50 rounded-lg p-6">
                        <h4 class="font-semibold text-gray-800 mb-2">Restore Backup</h4>
                        <p class="text-sm text-gray-600 mb-4">Upload and restore a previous backup</p>
                        <input type="file" accept=".sql" class="mb-2">
                        <button class="bg-green-500 text-white px-6 py-2 rounded-lg hover:bg-green-600 transition">
                            <i class="fas fa-upload mr-2"></i>Restore Backup
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function switchSettingsTab(tab) {
        // Hide all tabs
        ['generalTab', 'themeTab', 'emailTab', 'smsTab', 'backupTab'].forEach(id => {
            document.getElementById(id).classList.add('hidden');
        });
        
        // Remove active state from all buttons
        document.querySelectorAll('.settings-tab').forEach(btn => {
            btn.classList.remove('border-blue-500', 'text-blue-600');
            btn.classList.add('border-transparent', 'text-gray-600');
        });
        
        // Show selected tab
        const tabMap = {
            'general': 'generalTab',
            'theme': 'themeTab',
            'email': 'emailTab',
            'sms': 'smsTab',
            'backup': 'backupTab'
        };
        
        document.getElementById(tabMap[tab]).classList.remove('hidden');
        event.target.closest('.settings-tab').classList.add('border-blue-500', 'text-blue-600');
        event.target.closest('.settings-tab').classList.remove('border-transparent', 'text-gray-600');
    }
    
    function createBackup() {
        showLoader();
        showToast('Creating backup...', 'info');
        
        setTimeout(() => {
            hideLoader();
            showToast('Backup created successfully!', 'success');
        }, 2000);
    }
</script>

</main>

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

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