churchtube/api/toggle_theme.php

12 lines
382 B
PHP

<?php
require_once '../includes/db.php';
require_once '../includes/auth.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isLoggedIn()) {
$theme = $_POST['theme'] === 'light' ? 'light' : 'dark';
$stmt = $pdo->prepare("UPDATE users SET theme_preference = ? WHERE id = ?");
$stmt->execute([$theme, $_SESSION['user_id']]);
echo json_encode(['success' => true]);
}
?>