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 = ''; /********* HEADER Y FOOTER **********/ $this->header = ''; /********* 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; } }