<?php
//============================================================+
// File name   : example_012.php
// Begin       : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 012 for TCPDF class
//               Graphic Functions
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Graphic Functions
 * @author Nicola Asuni
 * @since 2008-03-04
 */

header("Content-Type:text/html;charset=utf-8");
// Incluir librerias de datos
include_once('../php_conexion.php'); 
include_once('../Class/funciones.php');
$idinf=$_POST['idinf'];
$queryinfpac=mysqli_query($conexion,"SELECT * FROM pacientes_histologia WHERE id=$idinf");
$datainfpac=mysqli_fetch_array($queryinfpac);

// Include the main TCPDF library (search for installation path).
require_once('../tcpdf/tcpdf.php');

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

    //Page header
    public function Header() {
        // Logo
        $image_file = 'logosm.png';
        $this->Image($image_file, 12, 7, 25, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
        // Position at 15 mm from bottom
        //$this->SetY(25);
        // Set font
        //$this->SetFont('times', 'BI', 20);
        // Title
        //$this->Cell(0, 10, 'Informe Citológico', 0, false, 'C', 0, '', 0, false, 'M', 'M');
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-12);
        // Set font
        $this->SetFont('helvetica', 'I', 10);
        // set color for background
		$this->SetFillColor(193, 274, 255);
        // Page number
        //$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
        $this->Cell(0, 10, 'Av. de la Cultura Nº 1420 - Edificio Gonzáles Of. Nº 202 - Telf.:248494 - 984761002 - 273625', 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

//establecer margenes
$pdf->SetMargins(5,5,10);
$pdf->setHeaderMargin(10);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Jose HUiñapi');
$pdf->SetTitle('Informe Citologico');
$pdf->SetSubject('Citologico');
$pdf->SetKeywords('Informe, PDF, Citologico, Paciente');

if (!empty($_POST['membrete'])) {
// set default header data
    $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// disable header and footer
//$pdf->setPrintHeader(false);
//$pdf->setPrintFooter(false);

// CONJUNTO CABESERA Y PIE DE PAGINA

    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
}else{
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
}


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

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

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

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

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'BI', 20);
// add page
$pdf->AddPage();

//ESTILOS PARA GRAFICOS
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0));
$style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0));
$style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0));
$style4 = array('L' => 0,
                'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)),
                'R' => array('width' => 0.50, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)),
                'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10'));
$style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128));
$style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0));
$style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0));

//$txt = <<<EOD
//Informe Citológico
//EOD;

//$pdf->SetY(15);
//$pdf->Write(5, $txt, '', 0, 'C', true, 0, false, false, 0);

//set font
$pdf->SetFont('helvetica', 'BI', 10);

// set cell padding
$pdf->setCellPaddings(0, 0, 0, 0);

// set cell margins
$pdf->setCellMargins(0, 1, 0, 1);

//DATOS DEL PACIENTE
$pdf->SetFillColor(255,255,255);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(49, 37);
//$pdf->MultiCell(36, 3, 'Nombre', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 11);
$pdf->MultiCell(140, 3, ': '.$datainfpac['apepaterno'].' '.$datainfpac['apematerno'].' '.$datainfpac['nombres'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(49, 42);
//$pdf->SetFont('helvetica', 'BI', 10);
//$pdf->MultiCell(36, 3, 'Edad', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 11);
$pdf->MultiCell(140, 3, ': '.$datainfpac['edad'].' años', 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(49, 47);
//$pdf->SetFont('helvetica', 'BI', 10);
//$pdf->MultiCell(36, 3, 'Muestra remitida', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 11);
$pdf->MultiCell(140, 3, ': '.$datainfpac['muestra'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(49, 52);
//$pdf->SetFont('helvetica', 'BI', 10);
//$pdf->MultiCell(36, 3, 'Fecha', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 11);
$pdf->MultiCell(140, 3, ': '.$datainfpac['fechareg'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetXY(49, 57);
//$pdf->SetFont('helvetica', 'BI', 10);
//$pdf->MultiCell(36, 3, 'Solicitado por', 0, 'J', 1, 0, '', '', true, 0, true, true, 40, 'T');
$pdf->SetFont('helvetica', 'I', 11);
$pdf->MultiCell(140, 3, ': '.$datainfpac['solicita'], 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
//$pdf->Line(13, 65, 195, 65, $style2);

//foto
if (!empty($_POST['foto'])) {
    $pdf->SetXY(160, 39);
    $pdf->Image('../'.$datainfpac['foto'], '', '', 30, 22.5, '', '', '', false, 300, '', false, false, 0, false, false, false);
}

//Numero de registro
$pdf->SetFont('helvetica', 'I', 12);
$pdf->SetXY(140, 30);
$pdf->MultiCell(22, 3, 'Codigo Nº:', 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->SetFont('helvetica', 'BI', 14);
$pdf->MultiCell(20, 3, prefempresa($conexion,$datainfpac['idempresa']).' '.str_pad($datainfpac['codpaciente'], 6, "0", STR_PAD_LEFT), 0, 'L', 1, 0, '', '', true, 0, false, true, 40, 'T');
//$pdf->MultiCell(20, 0, 'Codigo Nº:', 6, "0", STR_PAD_LEFT), 0, 1, 'L', 0, '', 1);

//$pdf->MultiCell(20, 0, prefempresa($conexion,$datainfpac['idempresa']).' '.str_pad($datainfpac['codpaciente']), 6, "0", STR_PAD_LEFT), 0, 1, 'L', 0, '', 1);

//DATOS DE EVALUACION
$obj=json_decode($datainfpac['imgs']);
// create some HTML content
$html = '
<style>
.wrapper {
    overflow:hidden;
    width:320px;
}
.wrapper div {
    /* cualquier altura mayor que el total de sumar la anchura de las img */
    width:330px;
 
    /* para evitar el margen superior de la primera fila */
    margin-top:-10px;
}
img {
    width:300px;
    height:262.5px;
    float:left;
    margin:10px 10px 0 10px;
}
.texto{
    text-align: justify;
}
</style>
<div class="wrapper">
<div><font face="helvetica"><i>';
if (count($obj)==3) {
    for ($i=0; $i < count($obj); $i++) {
        $html.='<img style="width:220px;height:165px;float:left;margin:10px 10px 0 10px;" src="../'.$obj[$i].'" />';
    }
}else{
    for ($i=0; $i < count($obj); $i++) {
        $html.='<img style="width:300px;height:262.5px;float:left;margin:10px 10px 0 10px;" src="../'.$obj[$i].'" />';
    }
}

$html.='</i></font></div></div>
<div class="texto"><font face="helvetica"><i>'.$datainfpac['text01'].'</i></font></div>
<div class="texto"><font face="helvetica"><i>'.$datainfpac['text02'].'</i></font></div>';


// output the HTML content
$borderStyle=array();
$borderStyle['cap']='butt';
$borderStyle['color']=array(0,0,0);
$borderStyle['dash']=0;
$borderStyle['join']='';    
$borderStyle['phase']=0;
$borderStyle['width']=0;

$divHeight=80;
$divWidth=100;

$divXPosition=15;
$divYPosition=70;

$pdf->SetFont('helvetica', 'I', 10);
//$pdf->writeHTML($html, true, false, true, false, '');
$pdf->writeHTMLCell(200, 'auto', $divXPosition,$divYPosition,$html, '');

mysqli_close($conexion);
// ---------------------------------------------------------
// move pointer to last page
$pdf->lastPage();

//Close and output PDF document
$pdf->Output($datainfpac['numdoc'].'-'.$datainfpac['apepaterno'].' '.$datainfpac['apematerno'].' '.$datainfpac['nombres'].'.pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+
?>
