<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace CmBundle\Controller;

use CmBundle\Controller\PDF_Rotate;

date_default_timezone_set('America/Mexico_City');

/**
 * Description of PDFCredencial
 *
 * @author Omar
 */
class PDFCredencial extends PDF_Rotate {

    //put your code here
    function RotatedImage($file, $x, $y, $w, $h, $angle) {
        //Image rotated around its upper-left corner
        $this->Rotate($angle, $x, $y);
        $this->Image($file, $x, $y, $w, $h);
        $this->Rotate(0);
    }

    function Credencial($a, $cb) {
        $this->SetAutoPageBreak(TRUE, 0);

        $rutaFoto = "fotos/" . $a->getCveCtl() . ".jpg";
        $nombre_fichero = $rutaFoto;
        $img = "";

        if (file_exists($nombre_fichero)) {
            $img = "fotos/" . $a->getCveCtl() . ".jpg";
        } else {
            $img = "images/usuario.png";
        }


        $this->Image($img, -12, 10, 50);
        if ($a->getCvePla()->getCvePla() == '45') { // TEOTIHUACAN
            $this->Image('images/cara1TeotihuacanOK.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '05') {
            $this->Image('images/cara1VILLAok.png', 0, 0, 54, 86);
        } else {
            $this->Image('images/cara1chico2.png', 0, 0, 54, 86);
        }

        $this->SetTextColor(255, 255, 255);
        $this->SetLeftMargin(2);
        $this->SetRightMargin(2);
        $this->SetFont('Arial', 'B', 12);
        $this->Ln(6);
        $this->Cell(0, 10, "ALUMNO", 0, 0, 'R', false);
        $this->Ln(15);
        $tamanioNombre = strlen($a->getNomAlu());
        if ($tamanioNombre >= 9 & $tamanioNombre <= 10) {
            $this->SetFont('Arial', 'B', 10);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'R', false);
        } elseif ($tamanioNombre > 10 & $tamanioNombre <= 14) {
            $this->SetFont('Arial', 'B', 6.8);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'R', false);
        } elseif ($tamanioNombre > 14 & $tamanioNombre <= 16) {
            $this->SetFont('Arial', 'B', 6);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'R', false);
        } elseif ($tamanioNombre > 16) {
            $this->SetFont('Arial', 'B', 5);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'R', false);
        } elseif ($tamanioNombre == 8) {
            $this->SetFont('Arial', 'B', 11);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'R', false);
        } else {
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'R', false);
        }

        $this->Ln(5);
        $this->SetFont('Arial', '', 8);
        $tamanioApellido = strlen($a->getApePat() . " " . $a->getApeMat());
        if ($tamanioApellido == 13) {
            $this->SetFont('Arial', '', 7);
            $this->Cell(0, 5, utf8_decode($a->getApePat() . " " . $a->getApeMat()), 0, 0, 'R', false);
        } elseif ($tamanioApellido > 13) {
            $this->SetFont('Arial', '', 5);
            $this->Cell(0, 5, utf8_decode($a->getApePat() . " " . $a->getApeMat()), 0, 0, 'R', false);
        } else {
            $this->Cell(0, 5, utf8_decode($a->getApePat() . " " . $a->getApeMat()), 0, 0, 'R', false);
        }
        $this->SetFont('Arial', '', 8);
        $this->Ln(8);
        if ($a->getTipoAlumno() == 1) {
            $this->Cell(0, 5, utf8_decode(""), 0, 0, 'R', false);
        } elseif ($a->getTipoAlumno() == 2) {
            $this->Cell(0, 5, utf8_decode("Bachillerato:"), 0, 0, 'R', false);
        } elseif ($a->getTipoAlumno() == 3) {
            $this->Cell(0, 5, utf8_decode("Licenciatura en:"), 0, 0, 'R', false);
        } elseif ($a->getTipoAlumno() == 4) {
            $this->Cell(0, 5, utf8_decode("Maestría en:"), 0, 0, 'R', false);
        } elseif ($a->getTipoAlumno() == 5) {
            $this->Cell(0, 5, utf8_decode("Doctorado en:"), 0, 0, 'R', false);
        }

        $this->Ln();
        $this->Cell(0, 5, utf8_decode(""), 0, 0, 'R', false);
        $this->Ln();
        $this->Cell(26, 5, utf8_decode(""), 0, 0, 'R', false);
        $this->Cell(24, 5, utf8_decode(""), 0, 0, 'R', false);
        $this->Ln();
        $this->SetFont('Arial', '', 8);
        $this->Cell(0, 5, utf8_decode("Matrícula:"), 0, 0, 'R', false);
        $this->Ln(4);
        $this->Cell(0, 5, utf8_decode($a->getCveCtl()), 0, 0, 'R', false);
        $this->SetXY(28, 49);

        if (strlen($a->getCveLic()->getNomLic()) >= 11 & strlen($a->getCveLic()->getNomLic()) <= 15) {
            $this->SetFont('Arial', 'B', 6.5);
        } elseif (strlen($a->getCveLic()->getNomLic()) <= 10) {
            $this->SetFont('Arial', 'B', 8);
        } else {
            $this->SetFont('Arial', 'B', 6);
        }

        //$this->MultiCell(0, 5, utf8_decode(ucwords(strtolower($a->getCveLic()->getNomLic())) ),0,'R');
        $this->MultiCell(0, 3.5, utf8_decode($a->getCveLic()->getNomLic()), 0, 'R');

        $this->AddPage();
        if ($a->getCvePla()->getCvePla() == '01') { // ZINACANTEPEC
            $this->Image('images/reversoChico2OKZina.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '02') { // PINO SUAREZ
            $this->Image('images/reversoChico2OKToluca.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '03') { // VALLE DE BRAVO
            $this->Image('images/reversoChico2OKValle.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '04') { // CENTRO
            $this->Image('images/reversoChico2OKCentro.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '44') { // APATZINGAN
            $this->Image('images/reversoChico2OKapatzingan.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '45') { // TEOTIHUACAN
            $this->Image('images/reversoChico2OKTeotihuacan.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '05') { // TEOTIHUACAN
            $this->Image('images/reversoChico2OKVILLA.png', 0, 0, 54, 86);
        }

        $this->SetFont('Arial', 'B', 6.9);
        $this->Ln(68);
        $this->Cell(0, 5, "Vigencia: Enero 2020 - Enero 2021", 0, 0, "R", false);
        $this->SetFillColor(245,244,0);
        $this->Rect(0, 76, 10, 10, 'F');
        //$this->Image($cb, 10, 65);
    }

    function Credencial2019($a, $cb) {
        $this->SetAutoPageBreak(TRUE, 0);

        $rutaFoto = "fotos/" . $a->getCveCtl() . ".jpg";
        $nombre_fichero = $rutaFoto;
        $img = "";

        if (file_exists($nombre_fichero)) {
            $img = "fotos/" . $a->getCveCtl() . ".jpg";
        } else {
            $img = "images/usuario.png";
        }


        $this->Image($img, -12, 10, 50);
        $this->Image('images/cara1chico2NuevoDiseñoOK.png', 0, 0, 54, 86);
        $this->SetTextColor(2, 162, 6);
        $this->SetLeftMargin(2);
        $this->SetRightMargin(2);
        $this->SetFont('Arial', 'B', 8);
        $this->SetLeftMargin(27);
        $this->SetRightMargin(0);
        $this->Ln(15);
        $this->Cell(0, 10, "ALUMNO", 0, 0, 'C', false);
        $this->Ln(15);
        $this->SetFont('Arial', 'B', 12);
        $tamanioNombre = strlen($a->getNomAlu());
        if ($tamanioNombre >= 9 & $tamanioNombre <= 10) {
            $this->SetFont('Arial', 'B', 10);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'C', false);
        } elseif ($tamanioNombre > 10 & $tamanioNombre <= 14) {
            $this->SetFont('Arial', 'B', 6.8);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'C', false);
        } elseif ($tamanioNombre > 14 & $tamanioNombre <= 16) {
            $this->SetFont('Arial', 'B', 6);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'C', false);
        } elseif ($tamanioNombre > 16) {
            $this->SetFont('Arial', 'B', 5);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'C', false);
        } elseif ($tamanioNombre == 8) {
            $this->SetFont('Arial', 'B', 11);
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'C', false);
        } else {
            $this->Cell(0, 6, utf8_decode($a->getNomAlu()), 0, 0, 'C', false);
        }

        $this->Ln(5);
        $this->SetFont('Arial', '', 8);
        $tamanioApellido = strlen($a->getApePat() . " " . $a->getApeMat());
        if ($tamanioApellido == 13) {
            $this->SetFont('Arial', '', 7);
            $this->Cell(0, 5, utf8_decode($a->getApePat() . " " . $a->getApeMat()), 0, 0, 'C', false);
        } elseif ($tamanioApellido > 13) {
            $this->SetFont('Arial', '', 5);
            $this->Cell(0, 5, utf8_decode($a->getApePat() . " " . $a->getApeMat()), 0, 0, 'C', false);
        } else {
            $this->Cell(0, 5, utf8_decode($a->getApePat() . " " . $a->getApeMat()), 0, 0, 'C', false);
        }
        $this->SetFont('Arial', '', 8);
        $this->SetTextColor(255, 255, 255);
        $this->Ln(12);
        $this->SetLeftMargin(1);
        $this->SetRightMargin(1);
        $this->SetFont('Arial', '', 5.5);

        $this->Ln(0);
        $this->Text(9, 67.5, utf8_decode("ESPECIALIDAD"));
        $this->Text(37, 67.5, utf8_decode("MATRICULA"));

        if (strlen(utf8_decode($a->getCveLic()->getNomLic())) >= 11 & strlen(utf8_decode($a->getCveLic()->getNomLic())) <= 15) {
            $this->SetFont('Arial', 'B', 10);
        } elseif (strlen(utf8_decode($a->getCveLic()->getNomLic())) <= 10) {
            $this->SetFont('Arial', 'B', 8);
        } elseif (strlen(utf8_decode($a->getCveLic()->getNomLic())) <= 30) {
            $this->SetFont('Arial', 'B', 8);
        } else {
            $this->SetFont('Arial', 'B', 6);
        }
        $this->Ln(12.5);
        $this->MultiCell(30, 3, utf8_decode($a->getCveLic()->getNomLic()), 0, 'C', false);
        $this->SetXY(32, 69.5);
        $this->SetFont('Arial', 'B', 11);
        $this->Cell(20, 5, utf8_decode($a->getCveCtl()), 0, 0, 'C', false);




        $this->AddPage();
        if ($a->getCvePla()->getCvePla() == '01') { // ZINACANTEPEC
            $this->Image('images/reversoChico2OKZina.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '02') { // PINO SUAREZ
            $this->Image('images/reversoChico2OKToluca.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '03') { // VALLE DE BRAVO
            $this->Image('images/reversoChico2OKValle.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '04') { // CENTRO
            $this->Image('images/reversoChico2OKCentro.png', 0, 0, 54, 86);
        } elseif ($a->getCvePla()->getCvePla() == '44') { // APATZINGAN
            $this->Image('images/reversoChico2OKapatzingan.png', 0, 0, 54, 86);
        }

        $this->SetFont('Arial', 'B', 6.9);
        $this->Ln(68);
        $this->Cell(0, 5, "Vigencia: Junio 2019 - Junio 2020", 0, 0, "R", false);
        $this->SetFillColor(255, 0, 128);
        $this->Rect(0, 76, 10, 10, 'F');
        //$this->Image($cb, 10, 65);
    }

}
