<?php

require_once('config/lang/eng.php');
require_once('tcpdf.php');

// extend TCPF with custom functions
class CDPDF extends TCPDF {

    public $tipo;
    public $titulo;
    public $documento;
    public $fecha;
    public $version;
    public function setTipo($tipo) {


        $this->tipo = $tipo;
    }

    public function setDocumento($documento) {


        $this->documento = $documento;
    }

    public function setFecha($fecha) {


        $this->fecha = $fecha;
    }

    public function setTitulo($titulo) {


        $this->titulo = $titulo;
    }
    
    public function setVersion($version) {


        $this->version = $version;
    }

    public function Header() {

        
        $this->SetLineStyle( array( 'color' => array(0,0,0)));

        $this->Line(10,10,$this->getPageWidth()-10,10); 
        $this->Line($this->getPageWidth()-10,10,$this->getPageWidth()-10,$this->getPageHeight()-20);
        $this->Line(10,$this->getPageHeight()-20,$this->getPageWidth()-10,$this->getPageHeight()-20);
        $this->Line(10,10,10,$this->getPageHeight()-20);
        

        if ($this->tipo == '1') {
            
            if ($this->getPage() > 1) {
                
                $this->SetTopMargin(10);
                $this->SetRightMargin(70);
                $this->SetLeftMargin(70);
                
                $this->SetFont('Times', '', 10);
                
                $html = '<table border="0" cellpadding="2" width="100%">';
                $html.='<tr><td width="33%" style="text-align:center"><b>'.$this->documento.'</b></td>
                    <td  width="33%" style="text-align:center"><b>DEL '.$this->fecha.'</b></td>
                    <td width="33%" style="text-align:center"><b>HOJA '.$this->getAliasNumPage().' de '.$this->getAliasNbPages().'</b></td>    
                ';
                $html.='</tr></table>';
                
                   
                $this->writeHTML($html);
                
                $this->SetTopMargin(30);
                $this->SetRightMargin(70);
                $this->SetLeftMargin(70);
                //$this->setFooterMargin(150);
                
            } else {
                $this->SetTopMargin(20);
                $this->SetRightMargin(70);
                $this->SetLeftMargin(70);
                
                $this->SetFont('Times', '', 10);
                
                $html = '<table border="0" cellpadding="2" width="100%"><tr><td width="100%" style="text-align:center"><img width="50px" height="50px" src="images/escudo.jpg" /></td></tr>';
                $html.='<tr><td  width="100%" style="text-align:center"><b>AGENCIA NACIONAL DE MINERÍA<br/><br/>OFICINA ASESORA JURIDICA<br/>GRUPO DE COBRO COACTIVO<br/><br/>'.$this->documento.'<br/><br/>(  '.$this->fecha.'   )</b></td>';
                $html.='</tr>';
                
                
                
                $this->writeHTML($html);
                
                $this->SetTopMargin(80);
                $this->SetRightMargin(70);
                $this->SetLeftMargin(70);
                //$this->setFooterMargin(150);
            }

//            $this->SetMargins(20, 15, 20);
        }
    }

    public function Footer() {
        $html = "";


        $date = date('d-M-y  h:m');
        $time = time();
        $html = "";
        $this->SetRightMargin(15);
        $this->SetLeftMargin(15);
        $this->SetFont('helvetica', '', 7);
        $this->SetY(-20);

         $html= '<table border="0" cellpadding="2" width="100%">
          <tr>
          <td style="text-align:right">'.$this->version.'</td></tr>         

          </table>'; 

        $this->writeHTML($html);
    }

    function fechaEspanol($fecha) {


        $transf = strtotime($fecha);
        $dia = date("d", $transf);
        $mes = date("F", $transf);

        if ($mes == "January")
            $mes = "Enero";
        if ($mes == "February")
            $mes = "Febrero";
        if ($mes == "March")
            $mes = "Marzo";
        if ($mes == "April")
            $mes = "Abril";
        if ($mes == "May")
            $mes = "Mayo";
        if ($mes == "June")
            $mes = "Junio";
        if ($mes == "July")
            $mes = "Julio";
        if ($mes == "August")
            $mes = "Agosto";
        if ($mes == "September")
            $mes = "Septiembre";
        if ($mes == "October")
            $mes = "Octubre";
        if ($mes == "November")
            $mes = "Noviembre";
        if ($mes == "December")
            $mes = "Diciembre";
        $ano = date("Y", $transf);
        $fecha_resol = $dia . " " . $mes . " " . $ano;
        return $fecha_resol;
    }

}
