<?php
include('../include/headscript.php');
include("../class/company.php");
$conn = new mysqli($servername, $username, $password, $database);

// Recupera sia l'ID dell'analisi che l'ID del composto dalla richiesta POST
$analysisId = $_POST['analysis_id'] ?? null;
$compoundId = $_POST['compound_id'] ?? null;

if ($analysisId && $compoundId) {
    // Elimina l'associazione specifica tra l'analisi e il composto
    $sql = "DELETE FROM analysis_compounds WHERE idanalysisvocabulary = ? AND idcompoundsvocabulary = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ii", $analysisId, $compoundId);

    if ($stmt->execute()) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'error' => 'Error deleting compound association.']);
    }

    $stmt->close();
} else {
    echo json_encode(['success' => false, 'error' => 'Invalid analysis or compound ID.']);
}

$conn->close();
