<?php
$pdf->SetFont('Arial', '', 9);
$pdf->SetFont('', 'B', '10');
//$pdf->Cell(190,6,$appformn,1,0,'C');
//$pdf->Ln();
$pdf->SetFont('', '', 8);
$pdf->Cell(50, 6, $pdfdescriptionpart, 1, 0, 'L');
$pdf->SetFillColor(232, 242, 255);
$pdf->Cell(140, 6, $trfData['sample_description'], 1, 0, 'L', TRUE);
$pdf->Ln();
$pdf->Cell(50, 7, $kindcertpdf, 1, 0, 'L');
$pdf->SetFillColor(232, 242, 255);
// Determina quale campo utilizzare in base alla lingua selezionata
$columnName = ($_SESSION['langselect'] == 'it') ? "description" : "description_en";

// Ottieni il valore dal campo appropriato
$certrev1 = $certificationrevision->getColumnVal($columnName);
$certrev1 = html_entity_decode($certrev1, ENT_QUOTES);
$certrev = iconv('UTF-8', 'windows-1252//IGNORE', $certrev1);

// Stampa la cella nel PDF
$pdf->Cell(70, 7, $certrev, 1, 0, 'L', TRUE);
//$pdf->Cell(70,50,'Terza',1,0,'C');
if (isset($trfData['photofilename'])) {
    // $pdf->Cell( 70, 42, $pdf->Image($image1, $pdf->GetX() + 10, $pdf->GetY(), 42), 1, 0, 'L');
    // $pdf->Cell( 70, 42, $pdf->Image($image1, $pdf->GetX(), $pdf->GetY(), -120, 42), 1, 0, 'L');
    $pdf->Cell(70, 42, $pdf->centreImage($image1, 70, 42, "S"), 1, 0, 'C');
} else {
    $image1 = "uploadimages/notav.jpg";
    // $pdf->Cell( 70, 42, $pdf->Image($image1, $pdf->GetX() + 10, $pdf->GetY(), 42), 1, 0, 'L');
    $pdf->Cell(70, 42, $pdf->Image($image1, $pdf->GetX(), $pdf->GetY(), 0, 42), 1, 0, 'L');
}
$pdf->Cell(1, 7, '', 0, 0, 'L');
$pdf->Ln();
$pdf->Cell(50, 7, $dateinsertpdf, 1, 0, 'L');
if ($sndrpt == 'Y') {
    $signed = $trfData['signedonsecondcert'];
} else {
    $signed = $trfData['signedon'];
}
if ($sndrpt == 'N') {
    $newDate = DateTime::createFromFormat('Y-m-d', $signed)->format('d-m-Y');
}
$pdf->Cell(70, 7, $newDate, 1, 0, 'L', TRUE);
$pdf->Ln();
$pdf->Cell(50, 7, $pdfarticlekind, 1, 0, 'L');
// Verifica la lingua scelta e imposta il nome appropriato dell'articolo
$articleName = ($_SESSION['langselect'] == 'it') ? $trfData['name_articletype'] : $trfData['name_articletypeeng'];

// Stampa la cella con il nome dell'articolo corretto
$pdf->Cell(70, 7, $articleName, 1, 0, 'L', TRUE);
$pdf->Ln();
$pdf->Cell(50, 7, $pdfmodeltitle, 1, 0, 'L');
// Verifica la lingua scelta e imposta il nome del modello appropriato
$modelName = ($_SESSION['langselect'] == 'it') ? $trfData['namemodelarticle'] : $trfData['namemodelarticle_eng'];

// Stampa la cella con il nome del modello corretto
$pdf->Cell(70, 7, $modelName, 1, 0, 'L', TRUE);
$pdf->Ln();
$measuretotal = $trfData['measurefrom'] . "-" . $trfData['measureto'];
$pdf->Cell(50, 6, $pdfrangemeasure, 1, 0, 'L');
$pdf->Cell(70, 6, $measuretotal, 1, 0, 'L', TRUE);
$pdf->Ln();
$pdf->Cell(50, 6, $pdfregisteredmark, 1, 0, 'L');
$pdf->Cell(70, 6, $trfData['registeredmark'], 1, 0, 'L', TRUE);
$pdf->Ln();
$idartchs = explode(",", $trfData['idarticle_characteristics']);
foreach ($idartchs as $idartch) {
    $artchname = new WA_MySQLi_RS("artchname", $cmctrfdb, 1);
    $artchname->setQuery("SELECT * FROM `article_characteristic` WHERE `article_characteristic`.idarticlecharacteristic='$idartch'");
    $artchname->execute();
    $pdf->Cell(50, 6, $kinddpipdf, 1, 0, 'L');
    // Determina quale campo utilizzare in base alla lingua selezionata
    $articleCharacteristic = ($_SESSION['langselect'] == 'it') ?
        $artchname->getColumnVal("name_articlecharacteristic") :
        $artchname->getColumnVal("name_articlecharacteristic_eng");

    // Stampa la cella con il valore caratteristico dell'articolo corretto
    $pdf->Cell(140, 6, $articleCharacteristic, 1, 0, 'L', TRUE);
    $pdf->Ln();
}

// Reference certificate number
if (isset($trfData['previousreportnumber']) && trim($trfData['previousreportnumber']) !== '') {

    $refCertLabel = ($_SESSION['langselect'] == 'it')
        ? 'Numero del certificato di riferimento'
        : 'Reference certificate number';

    $pdf->Cell(50, 6, $refCertLabel, 1, 0, 'L');
    $pdf->Cell(140, 6, $trfData['previousreportnumber'], 1, 0, 'L', true);
    $pdf->Ln();
}


$pdf->Ln();
