38458-vm/api/update_theme.php
Flatlogic Bot 5ac812ef05 Final3
2026-02-16 03:29:05 +00:00

22 lines
602 B
PHP

<?php
require_once '../auth_helper.php';
require_login();
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$theme = $input['theme'] ?? 'light';
if (!in_array($theme, ['light', 'dark'])) {
echo json_encode(['success' => false, 'error' => 'Invalid theme']);
exit;
}
try {
$stmt = db()->prepare("UPDATE users SET theme = ? WHERE id = ?");
$stmt->execute([$theme, $_SESSION['user_id']]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}