Sindbad~EG File Manager
<?php
require_once '../config/config.php';
require_admin();
$database = new Database();
$conn = $database->getConnection();
$error = '';
$success = '';
// Handle settings update
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$settings = $_POST['settings'] ?? [];
foreach ($settings as $key => $value) {
$update_query = "UPDATE settings SET setting_value = ?, updated_by = ? WHERE setting_key = ?";
$stmt = $conn->prepare($update_query);
$stmt->execute([$value, $_SESSION['user_id'], $key]);
}
$success = 'Settings updated successfully!';
}
// Get current settings
$settings_query = "SELECT * FROM settings ORDER BY setting_key";
$stmt = $conn->prepare($settings_query);
$stmt->execute();
$current_settings = $stmt->fetchAll(PDO::FETCH_ASSOC);
$settings_by_key = [];
foreach ($current_settings as $setting) {
$settings_by_key[$setting['setting_key']] = $setting['setting_value'];
}
$flash = get_flash_message();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings - COP News Portal</title>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
<header class="header">
<nav class="navbar">
<a href="../dashboard.php" class="logo">
<i class="fas fa-church"></i>
COP News Portal
</a>
<ul class="nav-links">
<li><a href="../dashboard.php"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="../news/index.php"><i class="fas fa-newspaper"></i> News</a></li>
<li><a href="index.php"><i class="fas fa-cog"></i> Admin</a></li>
<li><a href="../profile.php"><i class="fas fa-user"></i> Profile</a></li>
<li><a href="../logout.php"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
</ul>
</nav>
</header>
<main class="container" style="margin-top: 2rem;">
<?php if ($flash): ?>
<div class="alert alert-<?php echo $flash['type']; ?>">
<i class="fas fa-info-circle"></i> <?php echo $flash['message']; ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-error">
<i class="fas fa-exclamation-circle"></i> <?php echo $error; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success">
<i class="fas fa-check-circle"></i> <?php echo $success; ?>
</div>
<?php endif; ?>
<div class="card">
<div class="card-header">
<h1><i class="fas fa-cog"></i> System Settings</h1>
</div>
<div class="card-body">
<form method="POST" action="">
<div class="grid grid-2">
<!-- Site Configuration -->
<div class="settings-section">
<h3><i class="fas fa-globe"></i> Site Configuration</h3>
<div class="form-group">
<label for="site_title" class="form-label">Site Title</label>
<input type="text" id="site_title" name="settings[site_title]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['site_title'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="footer_title" class="form-label">Footer Title</label>
<input type="text" id="footer_title" name="settings[footer_title]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['footer_title'] ?? ''); ?>">
</div>
<div class="form-group">
<label for="site_logo" class="form-label">Site Logo Path</label>
<input type="text" id="site_logo" name="settings[site_logo]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['site_logo'] ?? ''); ?>"
placeholder="assets/images/logo.png">
</div>
</div>
<!-- Theme Configuration -->
<div class="settings-section">
<h3><i class="fas fa-palette"></i> Theme Configuration</h3>
<div class="form-group">
<label for="theme_primary_color" class="form-label">Primary Color</label>
<input type="color" id="theme_primary_color" name="settings[theme_primary_color]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['theme_primary_color'] ?? '#3B82F6'); ?>">
</div>
<div class="form-group">
<label for="theme_secondary_color" class="form-label">Secondary Color</label>
<input type="color" id="theme_secondary_color" name="settings[theme_secondary_color]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['theme_secondary_color'] ?? '#6B7280'); ?>">
</div>
</div>
<!-- System Configuration -->
<div class="settings-section">
<h3><i class="fas fa-server"></i> System Configuration</h3>
<div class="form-group">
<label for="max_file_upload_size" class="form-label">Max File Upload Size (bytes)</label>
<input type="number" id="max_file_upload_size" name="settings[max_file_upload_size]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['max_file_upload_size'] ?? '5242880'); ?>">
<small style="color: var(--primary-grey);">Current: <?php echo number_format($settings_by_key['max_file_upload_size'] ?? 5242880); ?> bytes (<?php echo round(($settings_by_key['max_file_upload_size'] ?? 5242880) / 1024 / 1024, 2); ?> MB)</small>
</div>
<div class="form-group">
<label for="backup_frequency" class="form-label">Backup Frequency</label>
<select id="backup_frequency" name="settings[backup_frequency]" class="form-control form-select">
<option value="daily" <?php echo ($settings_by_key['backup_frequency'] ?? '') === 'daily' ? 'selected' : ''; ?>>Daily</option>
<option value="weekly" <?php echo ($settings_by_key['backup_frequency'] ?? '') === 'weekly' ? 'selected' : ''; ?>>Weekly</option>
<option value="monthly" <?php echo ($settings_by_key['backup_frequency'] ?? '') === 'monthly' ? 'selected' : ''; ?>>Monthly</option>
</select>
</div>
<div class="form-group">
<label class="form-label">
<input type="checkbox" name="settings[maintenance_mode]" value="true"
<?php echo ($settings_by_key['maintenance_mode'] ?? '') === 'true' ? 'checked' : ''; ?>>
Maintenance Mode
</label>
<small style="color: var(--primary-grey); display: block;">Enable to put the site in maintenance mode</small>
</div>
</div>
<!-- Editor Configuration -->
<div class="settings-section">
<h3><i class="fas fa-edit"></i> Editor Configuration</h3>
<div class="form-group">
<label for="tinymce_api_key" class="form-label">TinyMCE API Key</label>
<input type="text" id="tinymce_api_key" name="settings[tinymce_api_key]" class="form-control"
value="<?php echo htmlspecialchars($settings_by_key['tinymce_api_key'] ?? 'no-api-key'); ?>"
placeholder="Enter your TinyMCE API key">
<small style="color: var(--primary-grey);">
Get your free API key from <a href="https://www.tiny.cloud/" target="_blank">TinyMCE Cloud</a>.
Required for the rich text editor to work properly.
</small>
</div>
</div>
<!-- Backup & Restore -->
<div class="settings-section">
<h3><i class="fas fa-database"></i> Backup & Restore</h3>
<div class="backup-actions">
<button type="button" class="btn btn-success" onclick="createBackup()">
<i class="fas fa-download"></i> Create Backup
</button>
<div class="form-group mt-3">
<label for="restore_file" class="form-label">Restore from Backup</label>
<input type="file" id="restore_file" class="form-control" accept=".sql">
<button type="button" class="btn btn-warning mt-2" onclick="restoreBackup()">
<i class="fas fa-upload"></i> Restore Backup
</button>
</div>
</div>
</div>
</div>
<div class="mt-4">
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> Save Settings
</button>
<a href="index.php" class="btn btn-secondary">
<i class="fas fa-arrow-left"></i> Back to Admin
</a>
</div>
</form>
</div>
</div>
<!-- Admin Tools -->
<?php if ($_SESSION['account_type'] === 'superuser'): ?>
<div class="card mt-4">
<div class="card-header">
<h2><i class="fas fa-tools"></i> Admin Tools (Superuser Only)</h2>
</div>
<div class="card-body">
<div class="grid grid-3">
<button class="btn btn-warning" onclick="clearCache()">
<i class="fas fa-broom"></i> Clear Cache
</button>
<button class="btn btn-info" onclick="optimizeDatabase()">
<i class="fas fa-database"></i> Optimize Database
</button>
<button class="btn btn-danger" onclick="resetSystem()"
onclick="return confirm('This will reset all data. Are you sure?')">
<i class="fas fa-exclamation-triangle"></i> Reset System
</button>
</div>
</div>
</div>
<?php endif; ?>
</main>
<script>
function createBackup() {
if (confirm('Create a database backup? This may take a few moments.')) {
// In a real implementation, this would trigger a backup process
alert('Backup creation started. You will be notified when complete.');
}
}
function restoreBackup() {
const fileInput = document.getElementById('restore_file');
if (!fileInput.files.length) {
alert('Please select a backup file first.');
return;
}
if (confirm('Restore from backup? This will overwrite all current data. Are you sure?')) {
// In a real implementation, this would handle file upload and restoration
alert('Backup restoration started. The system will be temporarily unavailable.');
}
}
function clearCache() {
if (confirm('Clear system cache?')) {
// In a real implementation, this would clear cache files
alert('Cache cleared successfully.');
}
}
function optimizeDatabase() {
if (confirm('Optimize database? This may take a few moments.')) {
// In a real implementation, this would run database optimization
alert('Database optimization started.');
}
}
function resetSystem() {
const confirmation = prompt('Type "RESET" to confirm system reset:');
if (confirmation === 'RESET') {
alert('System reset initiated. Please contact support if you need assistance.');
}
}
// Live preview of color changes
document.getElementById('theme_primary_color').addEventListener('change', function() {
document.documentElement.style.setProperty('--primary-blue', this.value);
});
document.getElementById('theme_secondary_color').addEventListener('change', function() {
document.documentElement.style.setProperty('--primary-grey', this.value);
});
</script>
<style>
.settings-section {
background: var(--light-grey);
padding: 1.5rem;
border-radius: 8px;
margin-bottom: 1.5rem;
}
.settings-section h3 {
margin-bottom: 1rem;
color: var(--dark-grey);
border-bottom: 2px solid var(--primary-blue);
padding-bottom: 0.5rem;
}
.backup-actions {
display: flex;
flex-direction: column;
gap: 1rem;
}
input[type="color"] {
height: 40px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.mt-2 {
margin-top: 0.5rem;
}
.mt-3 {
margin-top: 1rem;
}
</style>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists