<?php

$pdf->SetFont('Arial', '', 7);

$firstsent = html_entity_decode($firstsentpdf5);

$firstsent = iconv('UTF-8', 'windows-1252', $firstsent);

$secondsent = utf8_decode($secondsentpdf5);

//$thirdsent=utf8_decode('For the purposes of Article 6 of the REG 01 "Regulation for the assessment of the conformity of Personal Protective Equipment ');

//$foursent=utf8_decode('according to Regulation (EU) 2016/425" available on our website www.cimac.it');

$pdf->Cell(0, 0, $firstsent, 0, 1);

$pdf->Cell(0, 9, $secondsent, 0, 1);

//$pdf->Cell(0,0,$thirdsent,0,1);

//$pdf->Cell(0,9,$foursent,0,1);

// ***start with Audit address

//typecert 3 info

if ($idcertificate == 5) {

    include('pdfcreation/auditable.php');

} elseif ($idcertificate == 6) {

    include('pdfcreation/auditablem18b.php');

}

$pdf->Ln();

//include('pdfcreation/invoicecontacttable.php');

$pdf->Ln();

// auditdpi query

$auditdpilist = new WA_MySQLi_RS("auditdpilist", $cmctrfdb, 0);

$auditdpilist->setQuery("SELECT * FROM auditdpi LEFT JOIN auditsurveillancetype ON auditsurveillancetype.idauditsurveillancetype=auditdpi.moduleselection WHERE auditdpi.idtrfdetails='$idtrf'");

$auditdpilist->execute();

if ($idcertificate == 5) {

    $pdf->SetFont('', 'B', '10');

    $pdf->Cell(190, 6, $dpipdf, 1, 0, 'C');

    $pdf->SetFillColor(232, 242, 255);

    $pdf->Ln();

    $pdf->SetFont('', '', 9);

    $pdf->Cell(15, 6, $numberpdf, 1, 0, 'C');

    $pdf->Cell(80, 6, $certnumberpdf, 1, 0, 'C');

    $pdf->Cell(15, 6, $clientnamepdf, 1, 0, 'C');

    $pdf->Cell(60, 6, $surveillancepdf, 1, 0, 'C');

    $pdf->Cell(20, 6, $storagepdf, 1, 0, 'C');

    $pdf->Ln();

    $wa_startindex = 0;

    while (!$auditdpilist->atEnd()) {

        $yesreply = html_entity_decode('Sì');

        $yesreply = iconv('UTF-8', 'windows-1252', $yesreply);

        $wa_startindex = $auditdpilist->Index;

        $pdf->Cell(15, 6, $auditdpilist->getColumnVal("dpicode"), 1, 0, 'C', TRUE);

        // Decodifica i caratteri HTML

        $certificateNumber = html_entity_decode($auditdpilist->getColumnVal("certificatenumber"));



        // Stampa il valore decodificato

        $pdf->Cell(80, 6, $certificateNumber, 1, 0, 'C', TRUE);



        if ($auditdpilist->getColumnVal("issuebycimac") == 'yes') {

            $issuecmc = $yesreply;

        } else {

            $issuecmc = "No";

        }

        $pdf->Cell(15, 6, $issuecmc, 1, 0, 'C', TRUE);

        $pdf->Cell(60, 6, $auditdpilist->getColumnVal("survellaincetextit"), 1, 0, 'C', TRUE);

        if ($auditdpilist->getColumnVal("sampleinstore") == 'yes') {

            $smpstore = $yesreply;

        } else {

            $smpstore = 'No';

        }

        $pdf->Cell(20, 6, $smpstore, 1, 0, 'C', TRUE);

        $pdf->Ln();

        $auditdpilist->moveNext();

    }

    $auditdpilist->moveFirst(); //return RS to first record

    unset($wa_startindex);

    unset($wa_repeatcount);

    $pdf->Ln();

} elseif ($idcertificate == 6) {

    $pdf->SetFont('', 'B', '10');

    $pdf->Cell(190, 6, $dpipdf, 1, 0, 'C');

    $pdf->SetFillColor(232, 242, 255);

    $pdf->Ln();

    $pdf->SetFont('', '', 9);

    $pdf->Cell(20, 6, $numberpdf, 1, 0, 'C');

    $pdf->Cell(30, 6, $certnumberpdf, 1, 0, 'C');

    $pdf->Cell(30, 6, $clientnamepdf, 1, 0, 'C');

    $pdf->Cell(110, 6, $surveillancepdf, 1, 0, 'C');

    $pdf->Ln();

    $wa_startindex = 0;

    while (!$auditdpilist->atEnd()) {

        $wa_startindex = $auditdpilist->Index;

        $pdf->Cell(20, 6, '1', 1, 0, 'C', TRUE);

        $pdf->Cell(30, 6, $auditdpilist->getColumnVal("certificatenumber"), 1, 0, 'C', TRUE);

        if ($auditdpilist->getColumnVal("issuebycimac") == 'Y') {

            $issuecmc = $yesreply;

        } else {

            $issuecmc = "No";

        }

        $pdf->Cell(30, 6, $issuecmc, 1, 0, 'C', TRUE);

        $pdf->Cell(110, 6, $auditdpilist->getColumnVal("surveillancenameit"), 1, 0, 'C', TRUE);

        $pdf->Ln();

        $auditdpilist->moveNext();

    }

    $auditdpilist->moveFirst(); //return RS to first record

    unset($wa_startindex);

    unset($wa_repeatcount);

    $pdf->Ln();

}

// file attached details

$fileattachedlist = new WA_MySQLi_RS("fileattachedlist", $cmctrfdb, 0);

$fileattachedlist->setQuery("SELECT * FROM fileattached LEFT JOIN auditdpi ON fileattached.idauditdpi=auditdpi.idauditdpi WHERE fileattached.idtrfdetails='$idtrf'");

$fileattachedlist->execute();

if (!empty($fileattachedlist->getColumnVal("idfileattached"))) {

    $pdf->SetFont('', 'B', '10');

    $pdf->Cell(190, 6, $fileattachedtitle, 1, 0, 'C');

    $pdf->SetFillColor(232, 242, 255);

    $pdf->Ln();

    $pdf->SetFont('', '', 9);

    $pdf->Cell(20, 6, $dpicodetitle, 1, 0, 'C');

    $pdf->Cell(70, 6, $filenametitle, 1, 0, 'C');

    $pdf->Cell(100, 6, $descriptionfiletitle, 1, 0, 'C');

    $pdf->Ln();

    $wa_startindex = 0;

    while (!$fileattachedlist->atEnd()) {

        $wa_startindex = $fileattachedlist->Index;

        $pdf->Cell(20, 6, $fileattachedlist->getColumnVal("dpicode"), 1, 0, 'C', true);

        $pdf->SetTextColor(0, 0, 245);

        $linkspecific = 'public/uploaddocuments/' . $fileattachedlist->getColumnVal("filename_fileattached");

        $linkfile = $linkglobal . $linkspecific;

        $fileattachedlimited = substr($fileattachedlist->getColumnVal("filename_fileattached"), 0, 30);

        $pdf->Cell(70, 6, $fileattachedlimited, 1, 0, 'C', true, $linkfile);

        $pdf->SetTextColor(0, 0, 0);

        $descriptionlimited = substr($fileattachedlist->getColumnVal("description_fileattached"), 0, 30);

        $pdf->Cell(100, 6, $descriptionlimited, 1, 0, 'C', true);

        $pdf->Ln();

        $fileattachedlist->moveNext();

    }

    $fileattachedlist->moveFirst(); //return RS to first record

    unset($wa_startindex);

    unset($wa_repeatcount);

    //download zip

    $pdf->SetTextColor(0, 0, 245);

    $pdf->Cell(190, 6, $zipsentpdf, 1, 0, 'C', false, $namefilezippathpdf);

}

$pdf->Ln();

$pdf->Ln();

$pdf->SetTextColor(0, 0, 0);

include('pdfcreation/manufacturertable.php');

$pdf->Ln();

//invoice contact

include('pdfcreation/invoicecontacttable.php');

$pdf->Ln();

//trf option

include('pdfcreation/trfoption.php');

$pdf->Ln();

//Sign datatable

include('pdfcreation/signdatatable.php');

$pdf->Ln();

include('photobook.php');

