<?php

App::import('Vendor','tcpdf/config/lang/eng');
App::import('Vendor','tcpdf/tcpdf');

class DspPDF  extends TCPDF {

	var $xEmployee = '';
	var $xheadertext  = 'PDF created using CakePHP and TCPDF'; 
	//var $xfootertext  = '4333, rue Ste-Catherine o., Bureau 410, Montr�al (Qu�bec) H3Z 1P9 T�l: (514) 938-1155  1-800-930-1232  Fax: (514) 938-5268'; 
	var $xClient = '';

	var $xDate = '';

	var $xDspId = '';

	############################# TR Quest #############################################


	    //Page header
	    function Header2() {
		$checkRef = 0;
	        // Logo
	        $image_file = K_PATH_IMAGES.'logo.png';
	        $this->Image($image_file, 12, 7, 95, 20, 'PNG', '', 'M', 2, 300, 'C', false, false, 0, false, false, false);
	        // Set font
	        $this->SetFont('dejavusans', 'B', 20);
	    }

	    // Page footer
	    // function Footer() {
	    //     // Position at 12 mm from bottom
	    //     $this->SetY(-7);
	    //     // Set font
	    //     $this->SetFont('helvetica', 'I', 6);
	    //     // Page number
	    //     $this->Cell(0, 7, '4333, rue Ste-Catherine o., Bureau 410, Montr�al (Qu�bec) H3Z 1P9 T�l: (514) 938-4166  Fax: (514) 938-5268', 'T', false, 'C', 0, '', 0, false, 'T', 'M');
	    //     // Position at 15 mm from bottom
	    //     $this->SetY(-15);
	    //     // Set font
	    //     $this->SetFont('helvetica', 'I', 8);
	    //     // Page number
	    //     $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
	    // }
		
	    function HeadingLetter() {
            // Set font
            $this->SetFont('dejavusans', '', 9);
//			$this->SetFontSize(11);
			$this->Ln(23);
			//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')
//			$this->Cell(0, 0, $this->xDateLetter, 1, false, 'R', 0, '', 1);
            $this->writeHTMLCell(184, '', '', '', $this->xDateLetter, 0, 1, 0, true, 'R', false);
			// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
			$this->writeHTMLCell(0, '', '', 55, $this->xAddressLetter, 0, 0, 0,true, 'L');		
	    }		
		
		function SubjectLetter() {	
			// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)	
			$this->writeHTMLCell(30, '', '', 85, $this->xSubjectTitle, 'B', 0, 0, true, 'L', true);
			// write the second column
			$this->writeHTMLCell(150, '', '', '', $this->xPatientSubject, 'B', 1, 0, true, 'L', true);	
			$this->Ln(2);	
		}	
		
		function DoctorInterpGSection($scoreGinterps) {	
			$this->Ln(2);	
	        foreach($scoreGinterps as $row) {
				if ($row['texte']  != '') {
                        // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
                    $this->MultiCell (179, 0, $row['texte'], 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
					if($row['id'] == 1 ||$row['id'] == 2 || $row['id'] == 3 || $row['id'] == 4 || $row['id'] == 5 || $row['id'] == 6) {
						$this->Ln(2);
					}				
				}
	        }
		}	

		function DoctorInterpPSection($scorePinterps, $nbr, $refCita, $ref138, $ref153) {	
		//$ref102, $ref111   $ref138, $ref153
			$this->Ln(6);
			$check139 = 0;
			$check144 = 0;
			$symbolRef = 1;
			$texte = '';
			
			$this->writeHTMLCell(0, '', '', '', $this->xTitleSection, 0, 0, 0,true, 'L');	
			$this->Ln();
			if (count($scorePinterps) > 9 && $nbr > 1) { $this->SetFontSize(10); }
	        foreach($scorePinterps as $row) {
				if ($row['texte']  != '') {								
					if($row['id'] == 139) {
						$this->MultiCell (0, 0, $row['texte'], 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
						$this->writeHTMLCell(15, '', '', '', '', 0, 0, 0, true, 'L', true);
						$this->writeHTMLCell(60, '', '', '', $this->xleftStoppedMeds, 0, 0, 0, true, 'L', true);
						# write the second column
						$this->writeHTMLCell(100, '', '', '', $this->xrightStoppedMeds, 0, 0, 0, true, 'L', true);	
						$this->writeHTMLCell(15, '', '', '', '', 0, 1, 0, true, 'L', true);	
						if ($nbr == 0) {
							$this->Ln(1);	
						} else {
							$check138 = $nbr * 3.5;
							$this->Ln($check138);	
						}					
					} else {
						if ($row['id'] == 144 && $check144 == 0) { $this->Ln(2); } 	
						if ((($row['id'] == 27 || $row['id'] == 30 || $row['id'] == 31 || $row['id'] == 38 || $row['id'] == 58 || $row['id'] == 61 || 
							$row['id'] == 64 || $row['id'] == 65 || $row['id'] == 66 || $row['id'] == 67  || $row['id'] == 70 || $row['id'] == 73  || 
							$row['id'] == 74 || $row['id'] == 100) && $refCita == 1) || ($row['id'] == 138 && $ref138 == 1) ||
							($row['id'] == 153 && $ref153 == 1)) { 
							if ($row['id'] == 138 || $row['id'] == 153) {
								$this->writeHTMLCell('', '', '', '', $row['texte'].'<sup>'.$symbolRef.'</sup>', 0, 1, 0, true, 'L', true);
							} else {
								$texte = str_replace('*', '<sup>'.$symbolRef.' </sup>', $row['texte']);
								$this->writeHTMLCell('', '', '', '', $texte, 0, 1, 0, true, 'L', true);													
							}						
							$symbolRef++;
						}else{ 
							//if ($row['id'] == 107 || $row['id'] == 81 || $row['id'] == 82 || $row['id'] == 83) { 
							if ($row['id'] == 144 || $row['id'] == 140 || $row['id'] == 141 || $row['id'] == 142) { 
								$check144 = 1; 
								$this->MultiCell (0, 0, $row['texte'], 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
								$this->Ln(2);
							} else {
								$this->MultiCell (0, 0, $row['texte'], 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
							}					
							
						}										
					}
				}
			$newx = '';
	        }
		}

		function EndLetter($endsal, $drTitle, $refs) {
            // Set font
            $this->SetFont('dejavusans', '', 7);
//			$this->SetFontSize(9);
			$this->Ln(50);
			$this->MultiCell (0, 0, $endsal, 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
			//$this->Ln(6);
	        //$image_file2 = K_PATH_IMAGES.'DrBrownSignature.png';
			//$this->Image($image_file2, '', '', 47, 11);			
				
			if(!empty($refs)){ $this->MultiCell (60, 0, '', 'B', 'L', false, 1, 10, 253, true, 0, false, true, 0, 'M', false ); }
			
			$this->writeHTMLCell('', '', 10, 260, $refs, 0, 1, 0, true, 'L', true);
		}

	################################### END TR Quest ################################################

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES.'logo.png';
//		$this->Cell(0, 0, $image_file, 1, 1, 'C', 0, '', 1);
        $this->Image($image_file, 15, 10, 95, 23, 'PNG', '', 'M', 2, 300, 'C', false, false, 0, false, false, false);
        // Set font
        $this->SetFont('dejavusans', 'B', 20);
    }

    //Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('dejavusans', 'I', 8);
        // Page number
        $this->Cell(0, 10, '                             Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }

    function EmployeeCover()
    {
        // Set font
        $this->SetFont('dejavusans', '', 10);
//		$this->SetFontSize(10);
			 
		$this->writeHTMLCell(0, '', '', 70, $this->xEmployee, 0, 0, 0,true, 'C');
		$this->Ln();
    }
	
	function DspPageHeader()
	{
		$this->SetFont('dejavusans', '', 12);
		$this->writeHTMLCell(0, 0, 0, 37, '<b>'.'  '.'</b>', 0, 0, 0, true, 'C');
		// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
        $this->SetFont('dejavusans', '', 10);
		$this->writeHTMLCell(80, '', '', 48, $this->xleftDspHeader, 0, 0, 0, true, 'L', true);
		// write the second column
		$this->writeHTMLCell(100, '', '', '', $this->xrightDspHeader, 0, 1, 0, true, 'R', false);
	
	}	

	function DspGraphSection($header,$imagepath)
	{
		//header spacing
		$this->Ln(19);
		$this->Cell(0, 0, $header, 1, 1, 'C', 0, '', 1);
		$this->Ln();
		
		//Image( $file,	$x = '',$y = '',$w = 0,	$h = 0,	$type = '',	$link = '',	$align = '',$resize = false,$dpi = 300,$palign = '',$ismask = false,	$imgmask = false,
		//		$border = 0,$fitbox = false,$hidden = false,$fitonpage = false,	$alt = false,$altimgs = array() ) 	
		$this->Image($imagepath,3,90,250,125);
		$this->SetFont('dejavusans', '', 10);
		$this->writeHTMLCell('', '', '', 210, $this->xnoteDspFooter, 0, 0, 0, true, 'L');		
	
	}	
	
	function ScoreInterpSection($header,$scoreinterps)
	{	
		//header spacing
		//echo pr($scoreinterps);
//		$this->Cell(0,55);
//		$w=array(40,85,30,35);
//		Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')
		$a = 70;
		$this->Ln(2);
		$this->Cell(0, 0, $header, 1, 1, 'C', 0, '', 1);
		$this->Ln(2);		
        foreach($scoreinterps as $row) 
		{
//		MultiCell ($w, $h, $txt, $border = 0, $align = 'J', $fill = false, $ln = 1, $x = '', $y = '', $reseth = true, $stretch = 0, $ishtml = false,
//		$autopadding = true, $maxh = 0, $valign = 'T', $fitcell = false )

//          $this->Cell(0, 0, $row['texte'], 1, 0, 'L', 0, '', 1);
//			$a = $a + 10;
			if ($row['texte']  != '')
			{			
			$this->MultiCell (0, 0, $row['texte'], 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
			$this->Ln(3);
			}
        }		
	
	}
	
	function CriticalQuestionsSection($header,$criticallists)
	{	
		//header spacing
		$this->Ln(2);
		$this->Cell(0, 0, $header, 1, 1, 'C', 0, '', 1);
		$this->Ln(2);
		
        foreach($criticallists as $row) 
		{
			$this->MultiCell (0, 0, $row, 0, 'L', false, 1, '', '', true, 0, false, true, 0, 'M', false );
        }		
	
	}	


} 

?>