true, 'theme' => $currentTheme, ]); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $raw = file_get_contents('php://input'); $data = json_decode($raw, true); $theme = $data['theme'] ?? ($_POST['theme'] ?? 'dark'); if (!in_array($theme, ['dark', 'light', 'system'])) { http_response_code(400); echo json_encode(['success' => false, 'error' => 'Ongeldig thema. Kies dark, light of system.']); exit; } $ok = update_user_theme($userId, $theme); if ($ok) { echo json_encode([ 'success' => true, 'theme' => $theme, 'message' => 'Themavoorkeur succesvol opgeslagen.', ]); } else { http_response_code(500); echo json_encode(['success' => false, 'error' => 'Kon thema niet opslaan in database.']); } exit; } http_response_code(405); echo json_encode(['success' => false, 'error' => 'Method not allowed']);