<?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 PDFCredencialMantenimiento 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($nombre, $apellido, $foto, $des, $pla, $mat, $niv, $pi, $pf) {
        $this->SetAutoPageBreak(TRUE, 0);

        $rutaFoto = "fotosM/" . $foto;
        $nombre_fichero = $rutaFoto;
        $img = "";

        if (file_exists($nombre_fichero)) {
            $img = "fotosM/" . $foto;
        } else {
            $img = "images/usuario.png";
        }


        $this->Image($img, -12, 10, 50);
        $this->Image('images/cara1chico2.png', 0, 0, 54, 86);
        //$this->Image('images/CUAM.jpg', 0, 0, 23);
        $this->SetTextColor(255, 255, 255);
        $this->SetLeftMargin(2);
        $this->SetRightMargin(2);
        $this->SetFont('Arial', 'B', 12);
        $this->Ln(6);

        if ($pla == "CORPORATIVO" | $pla == "ALUMNO" | $pla == "FUTBOL" | $pla == "UTM") {
            
        } else {
            $this->Cell(0, 5, utf8_decode("PLANTEL"), 0, 0, 'R', false);
            $this->Cell(0, 5, utf8_decode(""), 0, 0, 'R', false);
        }


        if ($pla == "CORPORATIVO") {
            $this->SetFont('Arial', 'B', 8);
            $this->Cell(0, 5, utf8_decode("CORPORATIVO"), 0, 0, 'R', false);
            $this->Cell(0, 5, utf8_decode(""), 0, 0, 'R', false);
            $this->Ln();
        }

        if ($pla == "UTM") {
            $this->SetFont('Arial', 'B', 7.5);
            $this->Ln(2);
            $this->Cell(0, 5, utf8_decode("ADMINISTRATIVO"), 0, 0, 'R', false);
            $this->Cell(0, 5, utf8_decode(""), 0, 0, 'R', false);
            $this->Ln();
        }

        if ($pla == "ALUMNO") {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 10, utf8_decode("ALUMNO"), 0, 0, 'R', false);
            //$this->Cell(0, 5, utf8_decode(""), 0, 0, 'R', false);
            $this->Ln(5);
        }

        if ($pla == "TC") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 7.5);
            $this->Cell(0, 5, utf8_decode("TOLUCA CENTRO"), 0, 0, 'R', false);
        }

        if ($pla == "PS") {
            $this->Ln();
            $this->Cell(0, 5, utf8_decode("TOLUCA"), 0, 0, 'R', false);
        }

        if ($pla == "Z") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 8);
            $this->Cell(0, 5, utf8_decode("ZINACANTEPEC"), 0, 0, 'R', false);
        }

        if ($pla == "APAT") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 8);
            $this->Cell(0, 5, utf8_decode("APATZINGAN"), 0, 0, 'R', false);
        }
        if ($pla == "GUANA") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 8);
            $this->Cell(0, 5, utf8_decode("GUANAJUATO"), 0, 0, 'R', false);
        }
        if ($pla == "CELAYA") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 10);
            $this->Cell(0, 5, utf8_decode("CELAYA"), 0, 0, 'R', false);
        }

        if ($pla == "VB") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 7.4);
            $this->Cell(0, 5, utf8_decode("VALLE DE BRAVO"), 0, 0, 'R', false);
        }

        if ($pla == "VILLA") {
            $this->Ln();
            $this->SetFont('Arial', 'B', 7.4);
            $this->Cell(0, 5, utf8_decode("VILLA VICTORIA"), 0, 0, 'R', false);
        }

        if ($pla == "FUTBOL") {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 5, utf8_decode("CLUB DE "), 0, 0, 'R', false);
            $this->Ln();
            $this->Cell(0, 5, utf8_decode("FÚTBOL"), 0, 0, 'R', false);
        }

        $this->Ln(10);
        $this->SetFont('Arial', 'B', 12);
        $tamanioNombre = strlen($nombre);
        if ($tamanioNombre >= 9 & $tamanioNombre <= 10) {
            $this->SetFont('Arial', 'B', 9);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'R', false);
        } elseif ($tamanioNombre > 10 & $tamanioNombre <= 14) {
            $this->SetFont('Arial', 'B', 6.7);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'R', false);
        } elseif ($tamanioNombre > 14 & $tamanioNombre <= 16) {
            $this->SetFont('Arial', 'B', 6);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'R', false);
        } elseif ($tamanioNombre > 16) {
            $this->SetFont('Arial', 'B', 5);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'R', false);
        } elseif ($tamanioNombre == 8) {
            $this->SetFont('Arial', 'B', 11);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'R', false);
        } else {
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'R', false);
        }

        $this->Ln(5);
        $this->SetFont('Arial', '', 8);
        $tamanioApellido = strlen($apellido);
        if ($tamanioApellido == 13) {
            $this->SetFont('Arial', '', 7);
            $this->Cell(0, 5, utf8_decode($apellido), 0, 0, 'R', false);
        } elseif ($tamanioApellido > 13) {
            $this->SetFont('Arial', '', 5);
            $this->Cell(0, 5, utf8_decode($apellido), 0, 0, 'R', false);
        } else {
            $this->Cell(0, 5, utf8_decode($apellido), 0, 0, 'R', false);
        }
        $this->SetFont('Arial', '', 8);
        $this->Ln(8);


        if ($pla == "ALUMNO") {
            $this->SetXY(28, 44);
            if ($niv == "L") {
                $this->Cell(0, 5, utf8_decode("Licenciatura en:"), 0, 0, 'R', false);
            } elseif ($niv == "M") {
                $this->Cell(0, 5, utf8_decode("Maestría en:"), 0, 0, 'R', false);
            } elseif ($niv == "D") {
                $this->Cell(0, 5, utf8_decode("Doctorado en:"), 0, 0, 'R', false);
            }
            $this->SetXY(28, 55);
            $this->Cell(0, 5, utf8_decode("Matrícula:"), 0, 0, 'R', false);
            $this->Ln();
            $this->Cell(0, 5, utf8_decode($mat), 0, 0, 'R', false);
        }

        $this->SetXY(28, 49);



        //$this->MultiCell(0, 5, utf8_decode(ucwords(strtolower($a->getCveLic()->getNomLic())) ),0,'R');
        $this->SetFont('Arial', 'B', 9);
        //$this->MultiCell(0, 4, utf8_decode('PLANTEL TOLUCA'), 0, 'R');
        $this->Ln(0);
        if (strlen($des) >= 11 & strlen($des) <= 15) {
            $this->SetFont('Arial', 'B', 7);
        } elseif (strlen($des) <= 10) {
            $this->SetFont('Arial', 'B', 9);
        } elseif (strlen($des) <= 20) {
            $this->SetFont('Arial', 'B', 8);
        } else {
            $this->SetFont('Arial', 'B', 7);
        }
        $this->Cell(26);
        $this->MultiCell(0, 3, utf8_decode($des), 0, 'R');

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

        $this->AddPage();
        $this->Image('images/reversoChico2Corporativo.png', 0, 0, 54, 86);
        //$this->Image('images/reversoChico2OKGuanajuato.png', 0, 0, 54, 86);
        //$this->Image('images/reversoChico2OKapatzingan.png', 0, 0, 54, 86);
        $this->SetFont('Arial', 'B', 7);
        $this->Ln(68);
        $this->Cell(0, 5, "", 0, 0, "R", false);
        $this->Cell(0, 5, "Vigencia: " . $pi . " - " . $pf, 0, 0, "R", false);
        //$this->Image($cb, 10, 65);
    }

    function CredencialSep($nombre, $apellido, $foto, $des) {
        $this->SetAutoPageBreak(TRUE, 0);

        $rutaFoto = "fotosSep/" . $foto;
        $nombre_fichero = $rutaFoto;
        $img = "";

        if (file_exists($nombre_fichero)) {
            $img = "fotosSep/" . $foto;
        } else {
            $img = "images/usuario.png";
        }



        $this->Image('fotosSep/caraSep6.png', 0, 0, 54, 86);
        $this->Image($img, 14, 25, 25);
        //$this->Image('images/logoSep.png', 18, 52, 17);
        //$this->Image('images/CUAM.jpg', 0, 0, 23);
        $this->SetTextColor(0);
        $this->SetLeftMargin(2);
        $this->SetRightMargin(2);
        $this->Ln();
        $this->SetFont('Arial', 'B', 12);
        $this->Cell(0, 5, "", 0, 0, 'C', false);
        $this->Ln();
        $this->Cell(25, 5, "", 0, 0, 'C', false);
        $this->Cell(25, 5, "", 0, 0, 'C', false);
        $this->Ln(45);
        $this->SetFont('Arial', 'B', 12);
        $tamanioNombre = strlen($nombre);
        if ($tamanioNombre >= 9 & $tamanioNombre <= 10) {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'C', false);
        } elseif ($tamanioNombre > 10 & $tamanioNombre <= 14) {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'C', false);
        } elseif ($tamanioNombre > 14 & $tamanioNombre <= 16) {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'C', false);
        } elseif ($tamanioNombre > 16) {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'C', false);
        } elseif ($tamanioNombre == 8) {
            $this->SetFont('Arial', 'B', 12);
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'C', false);
        } else {
            $this->Cell(0, 6, utf8_decode($nombre), 0, 0, 'C', false);
        }

        $this->Ln(5);
        $this->SetFont('Arial', '', 10);
        $tamanioApellido = strlen($apellido);
        if ($tamanioApellido == 13) {
            $this->SetFont('Arial', '', 10);
            $this->Cell(0, 5, utf8_decode($apellido), 0, 0, 'C', false);
        } elseif ($tamanioApellido > 13) {
            $this->SetFont('Arial', '', 10);
            $this->Cell(0, 5, utf8_decode($apellido), 0, 0, 'C', false);
        } else {
            $this->Cell(0, 5, utf8_decode($apellido), 0, 0, 'C', false);
        }
        $this->SetFont('Arial', '', 8);

        $this->Ln(5);
        $this->SetFont('Arial', 'BI', 9);
        $this->Ln(0);
        if (strlen($des) >= 11 & strlen($des) <= 15) {
            $this->SetFont('Arial', '', 8);
        } elseif (strlen($des) <= 10) {
            $this->SetFont('Arial', 'BI', 10);
        } elseif (strlen($des) <= 20) {
            $this->SetFont('Arial', 'BI', 10);
        } else {
            $this->SetFont('Arial', 'BI', 7);
        }
        $this->SetFillColor(255, 100, 50);

        $this->MultiCell(0, 5, utf8_decode($des), 0, 'C', true);

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

        $this->AddPage();
        //$this->Image('images/reversoChicoMps.png', 0, 0, 54, 86);
        $this->SetFont('Arial', 'B', 7);
        $this->Ln(68);
        $this->Cell(0, 5, "", 0, 0, "R", false);
        //$this->Cell(0, 5, "Vigencia: Enero 2018 - Enero 2019", 0, 0, "R", false);
        //$this->Image($cb, 10, 65);
    }

}
