'error', 'message' => 'Brak ścieżki pliku']); exit; } try { $stmt = $pdo->prepare("SELECT * FROM prototype_comments WHERE page_path = ? ORDER BY created_at DESC"); $stmt->execute([$pagePath]); $comments = $stmt->fetchAll(); echo json_encode(['status' => 'success', 'data' => $comments]); } catch (PDOException $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } exit; } // 2. DODAWANIE KOMENTARZA (POST) if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'add') { // Odczyt danych JSON z body requestu $input = json_decode(file_get_contents('php://input'), true); $pagePath = $input['page_path'] ?? ''; $selector = $input['selector'] ?? ''; $comment = $input['comment'] ?? ''; $author = $input['author'] ?? 'Anonim'; // Możesz tu potem wpiąć sesję użytkownika if (!$pagePath || !$selector || !$comment) { echo json_encode(['status' => 'error', 'message' => 'Brakuje danych']); exit; } try { $stmt = $pdo->prepare("INSERT INTO prototype_comments (page_path, dom_selector, author, comment) VALUES (?, ?, ?, ?)"); $stmt->execute([$pagePath, $selector, $author, $comment]); echo json_encode(['status' => 'success', 'id' => $pdo->lastInsertId()]); } catch (PDOException $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } exit; } ?>