query("SELECT * FROM saved_timers ORDER BY created_at DESC"); $timers = $stmt->fetchAll(); echo json_encode(['success' => true, 'data' => $timers]); } elseif ($method === 'POST') { $data = json_decode(file_get_contents('php://input'), true); if (empty($data['name']) || empty($data['config'])) { throw new Exception("Missing name or config"); } $stmt = $pdo->prepare("INSERT INTO saved_timers (name, config) VALUES (:name, :config)"); $stmt->execute([ ':name' => $data['name'], ':config' => json_encode($data['config']) ]); echo json_encode(['success' => true, 'id' => $pdo->lastInsertId()]); } elseif ($method === 'DELETE') { $id = $_GET['id'] ?? null; if (!$id) { throw new Exception("Missing id"); } $stmt = $pdo->prepare("DELETE FROM saved_timers WHERE id = :id"); $stmt->execute([':id' => $id]); echo json_encode(['success' => true]); } } catch (Exception $e) { http_response_code(400); echo json_encode(['success' => false, 'error' => $e->getMessage()]); }