123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?php
- include_once '../../include/xTemplate.class.php';
- require_once '../../include/mpdf/autoload.php';
- require_once '../../include/util.php';
- class Constancia {
- private $config;
- private $stylesheet;
- private $header;
- private $footer;
- private $tipos;
- private $carpeta;
- private $usr;
- private $pdo;
- private $fecha;
- private $tiposConstancias = array('CONSTANCIA' => 1, 'RECONOCIMIENTO' => 2);
-
- function __construct($pdo, $fecha, $concurso, $idusuario){
- $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
- /********* FONTS **********/
- $fontDirs = $defaultConfig['fontDir'];
- $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
- $fontData = $defaultFontConfig['fontdata'] +
- [ 'tipo' => [
- 'R' => '../../fonts/indivisaFont/ttf/IndivisaDisplaySans-Thin.ttf',
- ]] +
- [ 'texto-a' => [
- 'R' => '../../fonts/indivisaFont/ttf/IndivisaTextSans-Light.ttf',
- ]] +
- ['indivisa-text' => [
- 'R' => '../../fonts/indivisaFont/ttf/IndivisaTextSans-Regular.ttf',
- 'B' => '../../fonts/indivisaFont/ttf/IndivisaTextSans-Bold.ttf',
- 'BI' => '../../fonts/indivisaFont/ttf/IndivisaTextSans-BoldItalic.ttf',
- ]];
-
- /********* CONFIGURACIÓN INICIAL **********/
- $this->config = [
- 'mode'=>'utf-8', 'format'=>'Letter',
- 'margin_header'=> 21, 'margin_top'=>52, 'margin_left'=> 35, 'margin_right'=> 30, 'margin_footer'=>10,
- 'fontDir' => array_merge($fontDirs, [__DIR__]), 'fontdata' => $fontData, 'default_font' => 'indivisa-text'
- ];
- /********* HOJA DE ESTILOS **********/
- $this->stylesheet = '<style>' . file_get_contents('../css/pdf/constancia.css') . '</style>';
-
- /********* HEADER Y FOOTER **********/
- $this->header = '<img id="logo" src="../img/pdf/lasalle_pdf.jpg">';
-
- /********* MARCA DE AGUA **********/
- $this->carpeta = 'const/export/';
-
- if (!file_exists($_SERVER['DOCUMENT_ROOT']. $this->carpeta . '/marca.png')) {
- //$marca = 'Facultad de Ingeniería - ';
- $marca = 'FI - ' . $concurso['nom'] . ' CIDIT ' . $concurso['anio'] . ' | '; //No acepta caracteres especiales
- $this->generaMarcaDeAgua($marca, $concurso['carpeta']);
- }
- $this->tipos = array('participante' => 'Constancia', 'ganador' =>'Reconocimiento', 'asesor' => 'Reconocimiento', 'evaluador' => 'Reconocimiento', 'organizador' => 'Constancia');
- $this->pdo = $pdo;
- $this->fecha = $fecha;
- $this->usr = $idusuario;
- }
-
- function getUser(){
- return $this->usr;
- }
- function fechaConstancia($fechaTxt){
- $fechaTxt = trim($fechaTxt);
- if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
- $fechaArr = explode("/", $fechaTxt);
- return mesNombre($fechaArr[1])." ".intval($fechaArr[0])." de ".$fechaArr[2];
- }
- if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
- $fechaArr = explode("-", $fechaTxt);
- return mesNombre($fechaArr[1])." ".intval($fechaArr[2])." de ".$fechaArr[0];
- }
- return "";
- }
-
- function generaFooter($concurso, $participante, $motivo, $tipo, $numFirmas){
- /********* ASIGNA FIRMAS **********/
- $xtpl = new XTemplate('../adds/tpl/constancia/footer.tpl.html');
- $fecha = $this->fechaConstancia($this->fecha);
- $xtpl->assign('FECHA_CARTA', $fecha);
- if($numFirmas >= 2)
- $numFirmas = 2; // 1 -> sólo una firma / 2 -> 2 o más firmas
- $firma = md5('12478');
- $xtpl->assign('NUM', $numFirmas);
- $xtpl->assign('MARCA', $this->carpeta . '/marca.png');
- $xtpl->assign('FIRMA', $firma . '.png');
- $xtpl->assign('NOMBRE', 'Mtro. Carlos Alfonso Herrera Anda');
- $xtpl->assign('PUESTO', 'Secretario Académico');
- $xtpl->parse('main.firma');
- $firma = md5('3557');
- $xtpl->assign('NUM', $numFirmas);
- $xtpl->assign('MARCA', $this->carpeta . '/marca.png');
- $xtpl->assign('FIRMA', $firma . '.png');
- $xtpl->assign('NOMBRE', 'Ing. Edmundo G. Barrera Monsiváis');
- $xtpl->assign('PUESTO', 'Director de la Facultad de Ingeniería');
- $xtpl->parse('main.firma');
-
- $xtpl->assign('NUM', $numFirmas);
- $folio = $this->creaFolio($concurso, $participante, $motivo, $tipo);
- if (!empty($folio)){
- $xtpl->assign('FOLIO', $folio);
- $xtpl->parse('main');
- $this->footer = $xtpl->text('main');
- return true;
- } else
- return false;
- }
-
- function generaParticipante($nombre, $proyecto, $clave, $concurso, $anio, $numFirmas){
- if ($this->generaFooter($concurso, $nombre, 'Participante', strtoupper($this->tipos['participante']), $numFirmas)) {
- $this->xtpl = new XTemplate('../adds/tpl/constancia/constancia.tpl.html');
- $this->xtpl->assign('TIPO', $this->tipos['participante']);
- $this->xtpl->assign('NOMBRE', $nombre);
- $this->xtpl->assign('PROYECTO', $proyecto);
- $this->xtpl->assign('CONCURSO', $concurso);
- $this->xtpl->assign('ANIO', $anio);
- $this->xtpl->parse('main.participante');
- $this->xtpl->parse('main');
- return $this->generaPDF($clave . ' - ' . $nombre,'temps/participantes',$this->tipos['participante']);
- } else
- return false;
- }
-
- function generaAsesor($nombre, $concurso, $anio){
- if ($this->generaFooter($concurso, $nombre, 'Asesor', strtoupper($this->tipos['asesor']))) {
- $this->xtpl = new XTemplate('../adds/tpl/constancia/constancia.tpl.html');
- $this->xtpl->assign('TIPO', $this->tipos['asesor']);
- $this->xtpl->assign('NOMBRE', $nombre);
- $this->xtpl->assign('CONCURSO', $concurso);
- $this->xtpl->assign('ANIO', $anio);
- $this->xtpl->parse('main.asesor');
- $this->xtpl->parse('main');
- return $this->generaPDF($nombre,'temps/asesores',$this->tipos['asesor']);
- } else
- return false;
- }
-
- function generaGanador($nombre, $lugar, $proyecto, $clave, $categoria, $concurso, $anio, $periodo){
- if ($this->generaFooter($concurso, $nombre, 'Ganador', strtoupper($this->tipos['ganador']))) {
- $this->xtpl = new XTemplate('../adds/tpl/constancia/constancia.tpl.html');
- $this->xtpl->assign('TIPO', $this->tipos['ganador']);
- $this->xtpl->assign('NOMBRE', $nombre);
- $this->xtpl->assign('LUGAR', $lugar);
- $this->xtpl->assign('PROYECTO', $proyecto);
- $this->xtpl->assign('CATEGORIA', $categoria);
- $this->xtpl->assign('CONCURSO', $concurso);
- $this->xtpl->assign('ANIO', $anio);
- $this->xtpl->assign('PERIODO', $periodo);
- $this->xtpl->parse('main.ganador');
- $this->xtpl->parse('main');
- return $this->generaPDF($clave . ' - ' . $nombre,'temps/ganadores',$this->tipos['ganador']);
- } else
- return false;
- }
-
- function generaEvaluador($nombre, $concurso, $anio){
- if ($this->generaFooter($concurso, $nombre, 'Comité Evaluador', strtoupper($this->tipos['evaluador']))) {
- $this->xtpl = new XTemplate('../adds/tpl/constancia/constancia.tpl.html');
- $this->xtpl->assign('TIPO', $this->tipos['evaluador']);
- $this->xtpl->assign('NOMBRE', $nombre);
- $this->xtpl->assign('CONCURSO', $concurso);
- $this->xtpl->assign('ANIO', $anio);
- $this->xtpl->parse('main.evaluador');
- $this->xtpl->parse('main');
- return $this->generaPDF($nombre,'temps/evaluadores',$this->tipos['evaluador']);
- } else
- return false;
- }
-
- function generaOrganizador($nombre, $puesto, $concurso, $anio){
- if ($this->generaFooter($concurso, $nombre, 'Comité Organizador', strtoupper($this->tipos['organizador']))) {
- $this->xtpl = new XTemplate('../adds/tpl/constancia/constancia.tpl.html');
- $this->xtpl->assign('TIPO', $this->tipos['organizador']);
- $this->xtpl->assign('NOMBRE', $nombre);
- $this->xtpl->assign('PUESTO', $puesto);
- $this->xtpl->assign('CONCURSO', $concurso);
- $this->xtpl->assign('ANIO', $anio);
- $this->xtpl->parse('main.organizador');
- $this->xtpl->parse('main');
- return $this->generaPDF($nombre,'temps/organizadores',$this->tipos['organizador']);
- } else
- return false;
- }
-
- private function generaPDF($nombre, $carpeta, $tipo){
- $error = false;
- try {
- $mpdf = new Mpdf\Mpdf($this->config);
- $mpdf->SetProtection(array('print','print-highres'),'',md5(time()));
- $mpdf->SHYlang = 'es';
- $mpdf->SetHTMLHeader($this->header);
- $mpdf -> SetTitle($tipo . '-' . $nombre);
- $mpdf -> SetAuthor('Facultad de Ingeniería. © Universidad La Salle A.C. 2021 Todos los derechos Reservados.');
- $mpdf -> WriteHTML($this->stylesheet);
- $mpdf -> WriteHTML($this->xtpl->text('main'));
- $mpdf->SetHTMLFooter($this->footer);
- $mpdf -> Output('../' . $carpeta . '/'. str_replace(' ', '', $nombre) . '.pdf','F');
- } catch (\Mpdf\MpdfException $e) {
- $error = true;
- }
- return $error;
- }
-
- private function generaMarcaDeAgua($marca, $carpeta) {
- $imagen = imagecreatetruecolor(344,143); // Crear la imagen de 591x379
- $textColor = imagecolorallocate($imagen, 224, 224, 224); //Colores del texto
- $transparente = imagecolorallocate ($imagen, 0, 0, 0); //Color que cambiará a transparene
- imagecolortransparent($imagen, $transparente); // Hacer el fondo transparente
- for ($cont = 0; $cont < 5; $cont++) { $marca .= $marca; }
- // Escribirlo
- for ($cont=1; $cont <= 50; $cont++){
- if ($cont%2 == 0)
- $val = -5;
- else
- $val = 5;
- imagestring($imagen,1, $val, 10*$cont, $marca, $textColor); //Escribe el texto
- }
- header('Content-Type: image/png');
- imagepng($imagen,'../concursos/' . $carpeta . '/constancias/marca.png'); //Genera la imagen
- imagedestroy($imagen);
- }
-
- private function creaFolio($concurso, $participante, $motivo, $tipo) {
- $evento = preg_replace('/[^0-9]+/', '', $concurso);
- $folio = $this->getFolio($evento, $participante, $motivo, $this->tiposConstancias[strtoupper($tipo)]);
- if (!empty($folio))
- $folio = 'FI - C' . $evento . ' - ' . sprintf("%04d", $folio);
- return $folio;
- }
-
- private function getFolio($evento,$participante,$motivo,$tipo){
- $folio = '';
- try {
- $stmt = $this->pdo->prepare('Select * from fi_constanciaLog(3,:evento,:participante,:motivo,:tipo,null,null,:usr)');
- $stmt->bindParam(':evento', $evento);
- $stmt->bindParam(':participante', $participante);
- $stmt->bindParam(':motivo', $motivo);
- $stmt->bindParam(':tipo', $tipo);
- $stmt->bindParam(':usr', $this->usr);
- $stmt->execute();
- $folio = $stmt->fetch();
- return $folio['ConstanciaLog_id'];
- } catch (\PDOException $ex){
- $folio = '';
- }
- $stmt->closeCursor();
- $stmt = null;
- return $folio;
- }
- }
|