<?php
// Include database connection
require_once '../config/database.php';
// Start session if not already started
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || ($_SESSION['role'] !== 'admin' && $_SESSION['role'] !== 'director')) {
header('Location: login.php');
exit;
}
// Get theme settings
$settings_query = "SELECT * FROM theme_settings";
$settings_result = mysqli_query($conn, $settings_query);
$theme_settings = [];
if ($settings_result && mysqli_num_rows($settings_result) > 0) {
while ($row = mysqli_fetch_assoc($settings_result)) {
$theme_settings[$row['setting_key']] = $row['setting_value'];
}
}
// If no theme settings found, use defaults
if (empty($theme_settings)) {
$theme_settings = [
'theme_name' => 'default',
'header_bg_color' => '#ffffff',
'footer_bg_color' => '#f8f9fc',
'text_color' => '#333333',
'link_color' => '#4e73df',
'button_style' => 'rounded',
'font_family' => 'Roboto, sans-serif',
'custom_css' => ''
];
}
// Set filename with theme name and date
$theme_name = isset($theme_settings['theme_name']) ? $theme_settings['theme_name'] : 'default';
$filename = strtolower(str_replace(' ', '_', $theme_name)) . '_theme_' . date('Y-m-d_H-i-s') . '.json';
// Set headers for download
header('Content-Type: application/json');
header('Content-Disposition: attachment; filename="' . $filename . '"');
// Output theme settings as JSON
echo json_encode($theme_settings, JSON_PRETTY_PRINT);
exit;
?>