<?php
if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}

$myID = fetch_postget_val('id',$_POST, $_GET);
$id_program = fetch_postget_val('program',$_POST, $_GET);
$readonly = fetch_postget_val('readonly',$_POST, $_GET);
$dateTimeNow = dateTimeNow();

if($id_program == 5)
{
	$table_to_fetch = 'm_anakemas';
	$id_to_fetch = 'id_anakemas';
	$nosiri_to_fetch = 'no_sirianakemas';
	$uploadfolder_to_fetch = 'upload_anakemas';
}

$indicator_Query = "SELECT desk_program
				  FROM i_program 
				  WHERE id_program = ?";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
$PDO_stmt->execute();
$info_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT A.*, B.desk_bank
				  FROM {$table_to_fetch} A
				  LEFT JOIN i_bank B ON B.id_bank = A.id_bankanakemas
				  WHERE A.{$id_to_fetch} = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List[$table_to_fetch] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT A.*, C.alamat AS alamatpej
					FROM m_pemohon A					
					LEFT JOIN i_dun B ON B.id_dun = A.id_dun
					LEFT JOIN i_daerah C ON C.id_daerah = B.id_daerah
					WHERE A.id_pemohon = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $indicator_List[$table_to_fetch]['id_pemohon'], PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List['m_pemohon'] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT *
					FROM i_bank";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $indicator_List[$table_to_fetch]['id_bankanakemas'], PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List['i_bank'] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT *
					FROM i_jantina
					WHERE id_jantina = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $indicator_List[$table_to_fetch]['id_jantinaanakemas'], PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List['i_jantina'] = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

//get all borang info
$indicator_Query = "SELECT *
				  FROM u_borangdiv 
				  WHERE id_borangdiv NOT IN (1,2,9)
				  ORDER BY susunan";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->execute();
$borangDivList = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$borangDivList[$result['id_borangdiv']] = $result;
}

$indicator_Query = "SELECT B.*, A.is_check_input
				  FROM u_pautanborang A
				  LEFT JOIN u_borangitem B ON A.id_borangitem = B.id_borangitem
				  WHERE A.id_program = ?
				  AND B.linked_borangitem = 0
				  AND B.id_inputtype IN (1, 8, 20, 2, 3, 17, 11)
				  AND B.id_borangitem NOT IN (63)
				  AND B.aktif = 1
				  ORDER BY B.susunan";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
$PDO_stmt->execute();
$borangList = [];
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$borangList[$result['id_borangdiv']][] = $result;
}

$borangTabMenu = [];
foreach($borangDivList as $div_key => $div_item)
{
	if(count($borangList[$div_key]) > 0)
	{
		$borangTabMenu[$div_key] = $div_item;
	}
}


//var_dump($indicator_List);
//***********************************************************************************************************************
// PRINT PDF
//***********************************************************************************************************************
require_once('classes/tcpdf/config/tcpdf_config.php');
require_once('classes/tcpdf/tcpdf.php');
include_once ("classes/phpqrcode/qrlib.php");

$errorCorrectionLevel ='L';
$matrixPointSize = 1;
$url = $indicator_List['m_anakemas']['kpbaru_anakemas'];
$filename = 'qrcodes/'.$indicator_List['m_anakemas']['kpbaru_anakemas'].'.png';
QRcode::png($url, $filename, $errorCorrectionLevel, $matrixPointSize, 1);	

//include_once ("inc/setup.inc.php");
error_reporting(0);

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	private $myHeaderTitle = array();
	public function setHeaderTable($headerArray)
	{
		$this->myHeaderTitle = array();
		for( $num = 0 ; $num < count($headerArray) ; $num++ )
		{
			$this->myHeaderTitle[] = $headerArray[$num];
		}
	}
	
	private $pageTitle = '';
	public function setHeaderTitle($title)
	{
		$this->pageTitle = $title;
	}
	//Page header
	public function Header() {
		
		$this->setJPEGQuality(90);
		$this->Image('images/banner.png', 0, 0, 210, 0, 'PNG', '');
				
		$this->Ln(30);
				
		$this->SetFont('helveticaB', '', 14); //CHANGE THIS FOR TITLE FONT
		$this->MultiCell(0, 0, $this->pageTitle, 0, 'C', 0, 1, '', '', true);
		/*
		$HTML = '<table border="1" style="text-align:center;padding: 6px;">';
		$HTML .= '<tr style="font-weight: bold;">';
		$counter = 1;
		for( $num = 0 ; $num < count($this->myHeaderTitle) ; $num++ )
		{
			if($this->myHeaderTitle[$num][1] > 0)
			{
				$HTML .= '<th style="width:'.$this->myHeaderTitle[$num][1].'%">'.$this->myHeaderTitle[$num][0].'</th>';
			}
		}
		$HTML .= '</tr>';
		$HTML .= '</table>';
		$this->SetFont('helvetica', '', 10); //CHANGE THIS FOR HEADER TITLE FONT
		$this->writeHTMLCell(0, 0, '', 19, $HTML, 0, 0, 0, true, '', false);
		*/
	}

	// Page footer
	public function Footer() {
		
		// Position at 15 mm from bottom
		$this->SetFont('helvetica', '', 8);
		$this->MultiCell(0, 0, 'Muka Surat '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, 'R', 0, 1, '', '', true);
	}
}

// -----------------------------------------------------------------------------
// create new PDF document
$pdf = new MYPDF("P", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); //P for portrait, L for landscape
$TITLE = 'BORANG PERMOHONAN ANAK EMAS';
$FILE_NAME = 'BORANG PERMOHONAN ANAK EMAS';
$output_filename = "borang_".$indicator_List['NoKPPemohon'].".pdf";
$pdf->setHeaderTitle($TITLE);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('PSUKPP');
$pdf->SetTitle($TITLE);
$pdf->SetSubject($TITLE);
$pdf->SetKeywords('TCPDF, PDF, $TITLE');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

if($manual_TOP <= 0)
{
	$manual_TOP = PDF_MARGIN_TOP + 15;
}
//set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetMargins(5, $manual_TOP, 5);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER - 10);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM - 10);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// -----------------------------------------------------------------------------
$pdf->setCellPaddings(0, 0, 0, 0);
$pdf->AddPage();
// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
$pdf->SetFont('helvetica', '', 10); //same font for the whole pdf

$HTML = '<table border="0" style="width:100%;padding:5px;">';
$HTML .= '<tr>';
$HTML .= '<td>';
$HTML .= '<img src="'.$filename.'" style="width:90px;height:90px">';	
$HTML .= '</td>';
$HTML .= '<td style="text-align: right;">No. Siri : <b>'.$indicator_List['m_anakemas']['no_sirianakemas'].'</b><br><b>'.$indicator_List['m_anakemas']['nama_anakemas'].'</b><br><b>'.$indicator_List['m_anakemas']['kpbaru_anakemas'].'</b>';
$HTML .= '</td>';
$HTML .= '</tr>';
$HTML .= '</table>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

foreach($borangTabMenu as $div_key => $div_item)
{
	$HTML = '<table border="0" style="width:100%;padding:5px;border:1px solid black;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h3>'.$div_item['title'].'</h3></td>';
	$HTML .= '</tr>';
	
	$isset_nosiri = 0;
	$isset_kategori = 0;
	foreach($borangList[$div_item['id_borangdiv']] as $key => $item)
	{
		if($isset_kategori == 0 && $div_key == 3)
		{
			$icno = $indicator_List['m_pemohon']['kpbaru_pemohon'];
			$kat_pemohon = 'BAPA';
			$jantina = processJantina($icno);
			if($jantina == 2)
			{
				$kat_pemohon = 'IBU';				
			}
			
			$currentValue = $indicator_List[$table_to_fetch][$nosiri_to_fetch];
			$HTML .= '<tr>';
				$HTML .= '<td style="width:30%">Kategori Pemohon</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%">'.$kat_pemohon.'</td>';
			$HTML .= '</tr>';
			$isset_kategori = 1;
		}
		
		if($isset_nosiri == 0 && $div_key == 5)
		{
			$currentValue = $indicator_List[$table_to_fetch][$nosiri_to_fetch];
			$HTML .= '<tr>';
				$HTML .= '<td style="width:30%">No. Siri</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%">'.(($currentValue=='')?'-':$currentValue).'</td>';
			$HTML .= '</tr>';
			$isset_nosiri = 1;
		}
		
		if($item['id_inputtype'] == 18) //checkbox
		{
			$HTML .= '<tr>';
			$HTML .= '<td colspan="3">';
			$HTML .= '<input type="checkbox" checked="checked"/>';
			$HTML .= $item['label'];
			$HTML .= '</td>';
			$HTML .= '</tr>';
		}
		else if($item['id_inputtype'] == 17) //dropzone
		{
			//get all dokumen from pemohon folder
			$path = 'upload_pemohon/'.$myID.'/*';
			$images = glob($path);
			for($num = 0; $num < count($images); $num++)
			{
				$HTML .= '<tr>';
				$HTML .= '<td>'.($num + 1).'.<td>';
				$HTML .= '<td></td>';
				$HTML .= '<td><a href="'.$images[$num].'" target="_blank">'.end(explode('/', $images[$num])).'</a></td>';
				$HTML .= '</tr>';
			}
		}
		else if($item['id_inputtype'] == 11) //datatable
		{
			$indicator_Query = "SELECT *
							  FROM u_datatableitem 
							  WHERE id_borangitem = ".$item['id_borangitem'].' 
							  AND (type = 3 OR type = 4)
							  AND id_datatableitem NOT IN (18,19,22)
							  ORDER BY datatable_index';
			$PDO_stmt = $PDO->prepare($indicator_Query);
			$PDO_stmt->execute();
			$datatableItemList = [];
			while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
			{
				if($result['table_name'] != '' && $result['column_label'] != '')
				{
					$currentValue = $indicator_List[$result['table_name']][$result['column_name']];
					$HTML .= '<tr>';
						$HTML .= '<td>'.$result['column_label'].'</td>';
						$HTML .= '<td>:</td>';
						$HTML .= '<td>'.$indicator_List[$result['table_name']][$result['column_name']].'</td>';
					$HTML .= '</tr>';
					
					if($currentValue != '' && $result['column_name'] == 'tkh_lahiranakemas')
					{
						$createDate = new DateTime($currentValue);
						$todayDate = new DateTime(date('Y-m-d'));
						$diff = $todayDate->diff($createDate)->format("%y Tahun %m Bulan");
						$HTML .= '<tr>';
							$HTML .= '<td>Umur</td>';
							$HTML .= '<td>:</td>';
							$HTML .= '<td>'.$diff.'</td>';
						$HTML .= '</tr>';
					}
				}
			}
		}
		else
		{
			$HTML .= '<tr>';
				$currentValue = '-';
				switch ($item['id_inputtype']) 
				{
					case '1': //textbox
					case '8': //textbox uncopyable
					case '20': //date textbox
						$currentValue = $indicator_List[$div_item['main_table']][$item['value']];
					break;
					
					case '2': //dropdown
						$tableName = $item['extra_param'];
						$name = 'desk_';
						$identifier = explode("_", $tableName);
						$indicator_Query = "SELECT id_{$identifier[1]} AS id, concat({$name}{$identifier[1]}) as name
											FROM {$tableName}
											WHERE aktif = 1 AND id_{$identifier[1]} = ?
											ORDER BY susunan";
						$PDO_stmt = $PDO->prepare($indicator_Query);
						$PDO_stmt->bindValue(1, $indicator_List[$div_item['main_table']][$item['value']], PDO::PARAM_INT);
						$PDO_stmt->execute();
						$ddResult = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
						$currentValue = $ddResult['name'];
					break;
					
					case '3': //dropdown_sql
						$PDO_stmt = $PDO->prepare($item['extra_param']);
						$PDO_stmt->execute();
						while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
						{
							if($result['id'] == $indicator_List[$div_item['main_table']][$item['value']])
							{
								$currentValue = $result['name'];
								break;
							}
						}
					break;
				}
				$HTML .= '<td style="width:30%">'.$item['label'].'</td>';
				$HTML .= '<td style="width:2%">:</td>';
				$HTML .= '<td style="width:68%"><b>'.(($currentValue=='')?'-':$currentValue).'</b></td>';
			$HTML .= '</tr>';
			
			/*if($currentValue != '' && $item['value'] == 'tkh_lahir')
			{
				$createDate = new DateTime($currentValue);
				$todayDate = new DateTime(date('Y-m-d'));
				$diff = $todayDate->diff($createDate)->format("%y");
				$HTML .= '<tr>';
					$HTML .= '<td>Umur</td>';
					$HTML .= '<td>:</td>';
					$HTML .= '<td><b>'.$diff.'</b></td>';
				$HTML .= '</tr>';
			}*/
		}
	}
	$HTML .= '</table>';
	$HTML .= '<br><br>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
}

$HTML = '<table border="0" style="width:100%;padding:5px;border:1px solid black;">';
$HTML .= '<tr>';
$HTML .= '<td style="text-align:left;border:1px solid black" colspan="3"><h3>Maklumat Akaun Bank</h3></td>';
$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Nama Bank</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%">'.$indicator_List['m_anakemas']['desk_bank'].'</td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">No. Akaun Bank</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%">'.$indicator_List['m_anakemas']['no_akaunanakemas'].'</td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="width:30%">Nama Pemilik Akaun</td>';
		$HTML .= '<td style="width:2%">:</td>';
		$HTML .= '<td style="width:68%">'.$indicator_List['m_anakemas']['nama_akaunanakemas'].'</td>';
	$HTML .= '</tr>';
$HTML .= '</table>';
$HTML .= '<br><br>';
$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
	
if($indicator_List['m_anakemas']['id_statusmohon'] <= 2)
{
	$pdf->AddPage();

	$HTML = '<table border="0" style="width:100%;padding:0px;border:none;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:none " colspan="2"><h3>Pengesahan Maklumat Akaun Bank Pemohon</h3><br></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;width:50%">
				Nama Bank : <b>'.$indicator_List['m_anakemas']['desk_bank'].'</b><br>
				Nama Pemilik Akaun : <b>'.$indicator_List['m_anakemas']['nama_akaunanakemas'].'</b><br>
				No. Akaun Bank : <b>'.$indicator_List['m_anakemas']['no_akaunanakemas'].'</b><br><br>
				Pemohon <b>DIWAJIBKAN</b> mendapatkan pengesahan bank bahawa maklumat akaun adalah betul dan aktif. Permohonan ini akan ditolak sekiranya akaun bank tidak disahkan.<br><br>
				URUSAN BANK<br>
				STATUS AKAUN : <b>*AKTIF/TIDAK AKTIF</b><br>
				(*potong mana yang tidak berkenaan)<br>
				</td>';
	$HTML .= '<td style="text-align:center;width:50%">Pengesahan Pegawai Bank: <br><br><br><br>
				................................................................<br>
				(NAMA & COP RASMI BANK)
			</td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
	$HTML .= '<td style="border-style: dashed;" colspan="2"></td>';
	$HTML .= '</tr>';
	$HTML .= '</table>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

	$HTML = '<table border="0" style="width:100%;padding:0px;border:none;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:none" colspan="2"><h3>Pengesahan Maklumat<br></h3></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="text-align:center;width:50%">Perakuan Permohon : Saya mengaku bahawa maklumat-maklumat diatas adalah benar<br><br><br>
					................................................................<br>
					(T.Tangan/Cap Jari Pemohon)<br>
				</td>';
		$HTML .= '<td style="text-align:center;width:50%">Disahkan Oleh : <br><br><br><br>
					................................................................<br>
					(ADUN/Ahli Parlimen/PD/KPPD/PPD/Penghulu/P.Penyelaras KADUN/Pengerusi MPKK)
				</td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="text-align:left;width:50%">
					Nama : '.$indicator_List['m_pemohon']['nama_pemohon'].'<br>
					Tarikh : '.formatdate($dateTimeNow,'d M Y').'<br>
				</td>';
		$HTML .= '<td style="text-align:left;width:50%">
					Nama : <br>
					Tarikh : <br>
					Cop Jawatan : <br>
				</td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:justify;border:none " colspan="2">* * * Pemohon dikehendaki mencetak dan menghantar borang permohonan <b>PROGRAM ANAK EMAS KERAJAAN NEGERI PULAU PINANG</b> ini berserta dengan lampiran salinan PENYATA BANK yang telah disahkan, dokumen Sijil Kelahiran Anak, Semakan Daftar Pemilih SPR dan Kad Pengenalan Ibu & Bapa ke <b>'.$indicator_List['m_pemohon']['alamatpej'].' dalam tempoh Tiga Puluh (30) hari </b>daripada tarikh <b>'.formatdate($indicator_List['m_anakemas']['tkh_daftar'],'d M Y').'</b> permohonan online dibuat. Kegagalan untuk menghantar dokumen yang diperlukan dalam tempoh masa yang ditetapkan akan menyebabkan permohonan tidak dapat diproses dan pembayaran juga tidak dapat dilakukan.<br>
			</td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
	$HTML .= '<td style="border-style: dashed;" colspan="2"></td>';
	$HTML .= '</tr>';
	$HTML .= '</table>';
	$HTML .= '<br>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

	$HTML = '<table style="width:100%;padding:0px;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align: right;">
				No. Siri : <b>'.$indicator_List['m_anakemas']['no_sirianakemas'].'</b><br><b>'.$indicator_List['m_anakemas']['nama_anakemas'].'</b><br><b>'.$indicator_List['m_anakemas']['kpbaru_anakemas'].'</b>';
	$HTML .= '</td>';
	$HTML .= '</tr>';
	$HTML .= '</table>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);

	$HTML = '<table border="0" style="width:100%;padding:0px;border:none;">';
	$HTML .= '<tr>';
	$HTML .= '<td style="text-align:left;border:none " colspan="2"><br><h3>Akuan Penerimaan : PROGRAM ANAK EMAS KERAJAAN NEGERI PULAU PINANG<br></h3></td>';
	$HTML .= '</tr>';
	$HTML .= '<tr>';
		$HTML .= '<td style="text-align:left;width:50%">
					Nama Anak : <b>'.$indicator_List['m_anakemas']['nama_anakemas'].'</b><br>
					No.MyKid : <b>'.$indicator_List['m_anakemas']['kpbaru_anakemas'].'</b><br>
					No.Sijil Kelahiran : <b>'.$indicator_List['m_anakemas']['no_sijillahir'].'</b><br>
					No. Telefon : <b>'.$indicator_List['m_pemohon']['tel_hp'].'</b><br>
				</td>';
		$HTML .= '<td style="text-align:left;width:50%">
					Diterima Oleh, <br><br>
					Nama : <br>
					Pejabat/Jabatan : <br>
					Tarikh : <br>Jawatan : <br>
					Cop Jabatan : <br> 
				</td>';
	$HTML .= '</tr>';
	$HTML .= '</table>';
	$HTML .= '<br><br>';
	$pdf->writeHTMLCell(0, 0, '', '', $HTML, 0, 1, 0, true, 'L', false);
}

//Close and output PDF document
ob_end_clean();
$pdf->Output($FILE_NAME.'.pdf', 'I');

//***********************************************************************************************************************
// END PRINT PDF
//***********************************************************************************************************************

?>