<?php
require_once('../Connections/cmctrfdb.php'); // Database connection

if (isset($_GET['idtrf']) && is_numeric($_GET['idtrf'])) {
    $idtrf = intval($_GET['idtrf']);
    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("Connessione al database fallita: " . $conn->connect_error);
    }

    // Esegui l'aggiornamento per impostare phototwo a NULL
    $query = "UPDATE `trf-details` SET phototwo = NULL WHERE idtrfdetails = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $idtrf);
    $stmt->execute();

    if ($stmt->affected_rows > 0) {
        error_log("Successfully updated phototwo to NULL for idtrfdetails = $idtrf");
    } else {
        error_log("Failed to update phototwo for idtrfdetails = $idtrf");
    }

    $stmt->close();
    $conn->close();

    // Reindirizza alla pagina principale
    header("Location: adddocument.php?idtrf=$idtrf&t=" . time());
    exit;
} else {
    // Se idtrf non è valido, reindirizza
    header("Location: index.php");
    exit;
}
