123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- /* AJAX
- * Genera nombramientos en pdf
- * Recibe:
- * fecha_inicial
- * fecha_final
- * fecha_inicial_extras
- * fecha_final_extras
- * Return:
- * imprime pdf
- */
- setlocale(LC_TIME, 'es_MX.UTF-8');
- require_once("../../include/nocache.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../include/util.php");
- require_once("../../include/constantes.php");
- require_once("../../classes/ValidaSesion.php");
- include_once('../../include/xTemplate/xtemplate.class.php'); // including mpdf.php
- include_once('../../include/mpdf/autoload.php'); // including mpdf.php
- 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, $carpeta.'marca.png'); //Genera la imagen
- imagedestroy($imagen);
- }
- //$fechasArr[] ["busca"=>CODIGO, "reemplaza"=>fecha ]
- function cambiaFechas($texto, $fechasArr){
- $buscaArr = array();
- $reemplazaArr = array();
- foreach($fechasArr as $opt){
- $buscaArr[] = $opt["busca"];
- $reemplazaArr[] = $opt["reemplaza"];
- }
- return str_replace ($buscaArr, $reemplazaArr, $texto);
- }
- function directorioArea($texto){
- if($texto == "")
- return "";
- return "/".$texto;
- }
- $pag = "../nombramientos.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 54, APSA);
- if(!$objSesion->tieneAcceso()){
- header("Location: ".$pag."?error=3");
- exit();
- }
- unset($objValida);
- if(!isset($_POST["texto"]) || !isset($_POST["fecha_carta"]) /*|| !isset($_POST["fecha_inicial"]) || !isset($_POST["fecha_final"]) || !isset($_POST["fecha_inicial_extras"]) || !isset($_POST["fecha_final_extras"])*/){
- header("Location: ".$pag."?error=0");
- exit();
- }
- $texto = $_POST["texto"];
- $fecha_carta = fechaGuion(trim(filter_input(INPUT_POST, "fecha_carta", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- if(isset($_POST["profesor"]))
- $profesor = filter_input(INPUT_POST, "profesor", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- if(isset($_POST["categoria"]) && $_POST["categoria"]==1)
- $has_categoria = true;
- else
- $has_categoria = false;
- if(isset($_POST["pdf"]) && $_POST["pdf"] == 1){
- $pdf = true;
- }else{
- $pdf = false;
- }
- if(isset($_POST["split"]) && $_POST["split"] == 1){
- $split = true;
- }else{
- $split = false;
- }
- //----
- $stmt = $pdo->prepare('Select * from fs_director()');
- if(!$stmt->execute()){
- header("Location:".$pag."?error=1");
- //print_r($stmt->errorInfo());
- exit();
- }
- $director_rs = $stmt->fetch();
- $stmt->closeCursor();
- $stmt = null;
- $stmt = $pdo->prepare('Select * from fs_constanciafirma(NULL, NULL) where "Usuario_id" = :usr');
- $stmt->bindParam(":usr", $director_rs["Usuario_id"]);
- if(!$stmt->execute()){
- header("Location:".$pag."?error=1");
- //print_r($stmt->errorInfo());
- exit();
- }
- $firma_director = $stmt->fetch();
- $stmt->closeCursor();
- //-----
- $stmt = $pdo->prepare('Select * from fs_puesto(2)');//Secretario académico
- if(!$stmt->execute()){
- header("Location:".$pag."?error=1");
- //print_r($stmt->errorInfo());
- exit();
- }
- $secretario_rs = $stmt->fetch();
- $stmt->closeCursor();
- $stmt = null;
- $stmt = $pdo->prepare('Select * from fs_constanciafirma(NULL, NULL) where "Usuario_id" = :usr');
- $stmt->bindParam(":usr", $secretario_rs["Usuario_id"]);
- if(!$stmt->execute()){
- header("Location:".$pag."?error=1");
- //print_r($stmt->errorInfo());
- exit();
- }
- $firma_secretario = $stmt->fetch();
- $stmt->closeCursor();
- unset($tmp_rs);
- //Obtiene fechas de periodo
- $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)');
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- if(!$stmt->execute()){
- header("Location:".$pag."?error=1");
- //print_r($stmt->errorInfo());
- exit();
- }
- $periodo_rs = $stmt->fetch();
- $nivel = $periodo_rs["Nivel_id"];
- $stmt->closeCursor();
- //---Inserta/Actualiza fechas importantes nuevas
- $stmt = $pdo->prepare('Select * from fi_fechaimportante(:periodo, 4, :fechai, :fechaf )');//fecha de la carta
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- $stmt->bindParam(":fechai", $fecha_carta);
- $stmt->bindParam(":fechaf", $fecha_carta);
- if(!$stmt->execute()){
- //echo "4";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=4");
- exit();
- }
- $stmt->closeCursor();
- $stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 3 )');//fechas profesores
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- if(!$stmt->execute()){
- //echo "4";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=4");
- exit();
- }
- $rs = $stmt->fetch();
- $stmt->closeCursor();
- $fecha_inicial = $rs["FechaImportante_inicial"];
- $fecha_final = $rs["FechaImportante_final"];
- $stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 2 )');//fecha de extraordinarios
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- if(!$stmt->execute()){
- //echo "4";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=4");
- exit();
- }
- $rs = $stmt->fetch();
- $stmt->closeCursor();
- if(!empty($rs["FechaImportante_inicial"])){
- $fecha_inicial_extras = $rs["FechaImportante_inicial"];
- $fecha_final_extras = $rs["FechaImportante_final"];
- }
- //Guarda nuevo texto de carta
- $stmt = $pdo->prepare('Select * from fi_cartanombramiento(:periodo, :text, :firmaD, :firmaS)');
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- $stmt->bindParam(":text", $texto);
- $stmt->bindParam(":firmaD", $firma_director["ConstanciaFirma_id"]);
- $stmt->bindParam(":firmaS", $firma_secretario["ConstanciaFirma_id"]);
- if(!$stmt->execute()){
- //print_r($stmt->errorInfo());
- header("Location:".$pag."?error=5");
- exit();
- }
- $stmt->closeCursor();
- $stmt = null;
- //----
- $fechasArr = array();
- //Periodo tiene fechas de ciclo
- $fechasArr[] = array("busca"=>PR_INI, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_inicial"], false));
- $fechasArr[] = array("busca"=>PR_INI_Y, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_inicial"], true));
- $fechasArr[] = array("busca"=>PR_FIN, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_final"], false));
- $fechasArr[] = array("busca"=>PR_FIN_Y, "reemplaza"=>fechaTexto($periodo_rs["Periodo_fecha_final"], true));
- //forma tiene fechas periodo completo
- $fechasArr[] = array("busca"=>PE_INI, "reemplaza"=>fechaTexto($fecha_inicial, false));
- $fechasArr[] = array("busca"=>PE_INI_Y, "reemplaza"=>fechaTexto($fecha_inicial, true));
- $fechasArr[] = array("busca"=>PE_FIN, "reemplaza"=>fechaTexto($fecha_final, false));
- $fechasArr[] = array("busca"=>PE_FIN_Y, "reemplaza"=>fechaTexto($fecha_final, true));
- if($nivel == 1){
- //forma tiene fechas extraordinarios
- $fechasArr[] = array("busca"=>EX_INI, "reemplaza"=>fechaTexto($fecha_inicial_extras, false));
- $fechasArr[] = array("busca"=>EX_INI_Y, "reemplaza"=>fechaTexto($fecha_inicial_extras, true));
- $fechasArr[] = array("busca"=>EX_FIN, "reemplaza"=>fechaTexto($fecha_final_extras, false));
- $fechasArr[] = array("busca"=>EX_FIN_Y, "reemplaza"=>fechaTexto($fecha_final_extras, true));
- }
- $texto = cambiaFechas($texto, $fechasArr);
- if($nivel == 1){
- if($profesor == 0)
- if(!$split)
- $stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, NULL, 0, NULL)');
- else
- $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_area(:periodo, NULL, 0, NULL)');
- else{
- if(!$split)
- $stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, :prof, 0, NULL)');
- else
- $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_area(:periodo, :prof, 0, NULL)');
- $stmt->bindParam(":prof", $profesor);
- }
- }else{
- if($profesor == 0)
- $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_carrera(:periodo, NULL)');
- else{
- $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_carrera(:periodo, :prof)');
- $stmt->bindParam(":prof", $profesor);
- }
- }
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- if(!$stmt->execute()){
- header("Location:".$pag."?error=1");
- //print_r($stmt->errorInfo());
- exit();
- }
- $rs_usr = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- if($nivel == 1){
- $xtpl = new XTemplate('../tpl/nombramiento.tpl.html');
- }else{
- $xtpl = new XTemplate('../tpl/nombramiento_pos.tpl.html');
- }
- $xtpl->assign("FECHA_HOY", fechaTexto($fecha_carta, true));
- $xtpl->assign("FACULTAD", FACULTAD);
- if($has_categoria){
- $stmt = $pdo->prepare('Select * from fi_profesorperiodo_categoria(:periodo, :prof )');
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- foreach($rs_usr as $prof){
- if(strtoupper($prof["Usuario_nombre"]) != "VACANTE"){//no vacante
- $stmt->bindParam(":prof", $prof["Usuario_id"]);
- if(!$stmt->execute()){
- //echo "4";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=4");
- exit();
- }
- }
- }
- $stmt->closeCursor();
- }
- //-----
- if($pdf){
- $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
- $fontDirs = $defaultConfig['fontDir'];
- $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
- $fontData = $defaultFontConfig['fontdata'];
- $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
- $fontDirs = $defaultConfig['fontDir'];
- $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
- $fontData = $defaultFontConfig['fontdata'];
-
- $stylesheet = "<style>";
- $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
- $stylesheet .= file_get_contents('../css/carta.css'); // external css
- $stylesheet .= "</style>";
- if($split){
- //----------- Archivos y zip ---
- $fecha = date("Ymd_His");
- $tmp_folder = "./zip/pdf_".$fecha;
- if (!file_exists($tmp_folder)) {
- mkdir($tmp_folder, 0777, true);
- }
- $zip = new ZipArchive();
- $zip_filename = "zip/nombramientos_".$fecha.".zip";
- if ($zip->open($zip_filename, ZipArchive::CREATE)!==TRUE) {
- exit("cannot open <$zip_filename>\n");
- }
- }else{
- $mpdf = new \Mpdf\Mpdf([
- 'mode' => 'utf-8',
- 'format' => [215, 279],
- 'orientation' => 'P',
- 'margin_left' => 14,
- 'margin_right' => 14,
- 'margin_top' => 7,
- 'margin_bottom' => 7,
- 'fontDir' => array_merge($fontDirs, [
- __DIR__ . '/../../fonts/indivisaFont/ttf',
- ]),
- 'fontdata' => $fontData + [
- 'indivisa-display' => [
- 'R' => 'IndivisaDisplaySans-Regular.ttf',
- ],
- 'indivisa-title' => [
- 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
- ],
- 'indivisa-text' => [
- 'R' => 'IndivisaTextSans-Regular.ttf',
- ]
- ],
- 'default_font' => 'indivisa-text'
- ]);
- }
- //$hoy = strftime("%e de %B de %Y");
-
- $xtpl->assign("TEXTO_CARTA", $texto);
- $cuenta = count($rs_usr);//Cuenta total de usuarios para saber si hay salto de pagina o no
- //Marca de agua
- if (!file_exists($_SERVER['DOCUMENT_ROOT']. '/apsa/export/zip/marca.png')) {
- $marca = mb_strtoupper("Nombramiento",'UTF-8') . ' ' . fechaGuion($fecha_carta) . ' | '; //No acepta caracteres especiales
- generaMarcaDeAgua($marca, "./zip/");
- }
-
- foreach($rs_usr as $profesor){
- if(strtoupper($profesor["Usuario_nombre"]) != "VACANTE"){//no vacante
-
- if($split){
- $mpdf = new \Mpdf\Mpdf([
- 'mode' => 'utf-8',
- 'format' => [215, 279],
- 'orientation' => 'P',
- 'margin_left' => 14,
- 'margin_right' => 14,
- 'margin_top' => 7,
- 'margin_bottom' => 7,
-
- 'fontDir' => array_merge($fontDirs, [
- __DIR__ . '/../../fonts/indivisaFont/ttf',
- ]),
- 'fontdata' => $fontData + [
- 'indivisa-display' => [
- 'R' => 'IndivisaDisplaySans-Regular.ttf',
- ],
- 'indivisa-title' => [
- 'R' => 'IndivisaDisplaySerif-RegularItalic.ttf',
- ],
- 'indivisa-text' => [
- 'R' => 'IndivisaTextSans-Regular.ttf',
- ]
- ],
- 'default_font' => 'indivisa-text'
- ]);
-
- if($nivel == 1){
- $xtpl = new XTemplate('../tpl/nombramiento.tpl.html');
- }else{
- $xtpl = new XTemplate('../tpl/nombramiento_pos.tpl.html');
- }
- $xtpl->assign("FECHA_HOY", fechaTexto($fecha_carta, true));
- $xtpl->assign("FACULTAD", FACULTAD);
- //$titulo = "Ing."; //Título del director
- $xtpl->assign("TEXTO_CARTA", $texto);
- }
- $stmt = $pdo->prepare('Select * from fs_categoriaperiodo(:periodo, :prof )');//categoría correspondiente al periodo
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- $stmt->bindParam(":prof", $profesor["Usuario_id"]);
- if(!$stmt->execute()){
- $pdo->rollBack();
- header("Location:".$pag."?error=2");
- //print_r($stmt->errorInfo());
- exit();
- }
- $cat_rs = $stmt->fetch();
- $stmt->closeCursor();
-
- $nombre = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
- $xtpl->assign("PROFESOR", $nombre);
- if(!empty($cat_rs["Categoria_desc"]))
- $xtpl->assign("CATEGORIA", $cat_rs["Categoria_desc"]);
- else
- $xtpl->assign("CATEGORIA", "");
- //$xtpl->assign("CATEGORIA", $profesor["Profesor_categoria"]);
- if($nivel != 1){
- $xtpl->assign("PLAN", $profesor["Carrera_desc"]);
- $stmt = $pdo->prepare('Select * from fs_horariogrupoprofesor(:prof, :periodo, :carr)');
- $stmt->bindParam(":carr", $profesor["Carrera_id"]);
- }else
- $stmt = $pdo->prepare('Select * from fs_horariogrupoprofesor(:prof, :periodo, NULL)');
- $stmt->bindParam(":prof", $profesor["Usuario_id"]);
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- if(!$stmt->execute()){
- header("Location:".$pag."?error=2");
- //print_r($stmt->errorInfo());
- exit();
- }
- $asignatura_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $grupo_last = $asignatura_rs[0]["Grupo_id"].$asignatura_rs[0]["Materia_id"];
- foreach($asignatura_rs as $asignatura){
- if($grupo_last != $asignatura["Grupo_id"].$asignatura["Materia_id"]){
- $grupo_last = $asignatura["Grupo_id"].$asignatura["Materia_id"];
- $xtpl->parse("main.renglon");
- }
- $xtpl->assign("ASIGNATURA", $asignatura["Materia_desc"]);
- if($nivel == 1)
- $xtpl->assign("GRUPO", $asignatura["Grupo_desc"]." ".$asignatura["Carrera_prefijo"]);
- else
- $xtpl->assign("GRUPO", $asignatura["Materia_grupo_posgrado"]);
- if($asignatura["Salon_desc"] != "")
- $xtpl->assign("SALON", $asignatura["Salon_desc"]);
- else
- $xtpl->assign("SALON", " ");
- $xtpl->assign("DIA", diaNombre($asignatura["Dia_id"]));
- //$hora_fin = date('H:i', strtotime('+'.$asignatura["Horario_duracion"].' minutes', strtotime('2019-01-01 '.$asignatura["Horario_hora"])));
- $xtpl->assign("HORARIO", substr($asignatura["Horario_hora"], 0, 5)." - ".substr($asignatura["Horario_hora_final"],0, 5));
- $xtpl->parse("main.renglon.detalle");
- }
- $xtpl->parse("main.renglon");
- $cuenta--;
-
- $xtpl->assign('MARCA', './zip/marca.png');
- if($profesor["Usuario_id"] != $director_rs["Usuario_id"]){
- $xtpl->assign('FIRMA', $firma_director["ConstanciaFirma_imagen"]);
- $director = $firma_director["ConstanciaFirma_grado"]." ".$director_rs["Usuario_nombre"]." ".$director_rs["Usuario_apellidos"];
- $xtpl->assign("NOMBRE_FIRMA", $director);
- $xtpl->assign("PUESTO_FIRMA", $director_rs["Puesto_desc"]);
- }else{
- $xtpl->assign('FIRMA', $firma_secretario["ConstanciaFirma_imagen"]);
- $secretario = $firma_secretario["ConstanciaFirma_grado"]." ".$secretario_rs["Usuario_nombre"]." ".$secretario_rs["Usuario_apellidos"];
- $xtpl->assign("NOMBRE_FIRMA", $secretario);
- $xtpl->assign("PUESTO_FIRMA", $secretario_rs["Puesto_desc"]);
- }
- if($split){
- $xtpl->parse("main");
- $mpdf->WriteHTML($stylesheet);
- $mpdf->WriteHTML($xtpl->text("main"));
- $mpdf->SetProtection(array('print', 'print-highres'), '', md5(time()));
- $mpdf->Output($tmp_folder."/nombramiento_".sprintf("%03d", $num).".pdf", 'F');
- if(isset($profesor["Area_desc"])){
- $zip->addFile(
- $tmp_folder."/nombramiento_".sprintf("%03d", $num).".pdf",
- "nombramientos_".$fecha.directorioArea($profesor["Area_desc"])."/nombramiento_".sprintf("%06d", $profesor["Usuario_claveULSA"]).".pdf"
- );
- }else{
- $zip->addFile(
- $tmp_folder."/nombramiento_".sprintf("%03d", $num).".pdf",
- "nombramientos_".$fecha."/nombramiento_".sprintf("%06d", $profesor["Usuario_claveULSA"]).".pdf"
- );
- }
- if($cuenta > 0){
- $num++;
- }
- }else{
- if($cuenta > 0) $xtpl->parse("main.pagebreak");
- $xtpl->parse("main");
- }
-
- }//fin vacante
- }//for profesor
- /*echo $stylesheet;
- $xtpl->out("main");exit();*/
- if(!$split){
- $mpdf->WriteHTML($stylesheet);
- $mpdf->WriteHTML($xtpl->text("main"));
- $mpdf->Output("nombramientos.pdf", 'I');
- }else{
- if($zip->numFiles<=0){
- echo "Error al guardar en el zip";
- $zip->close();
- unlink($zip_filename);
- exit();
- }
- $zip->close();
-
- removeFolder($tmp_folder);
-
- header("Content-Type: application/zip");
- header("Content-Disposition: attachment; filename=".basename($zip_filename));
- header("Pragma: no-cache");
- header("Expires: 0");
- ob_end_clean();
- flush();
- readfile($zip_filename);
-
- unlink($zip_filename);
- }
- }else{
- header("Location: ../nombramientos.php?ok=0");
- }
- function removeFolder($folderName) {
- if (is_dir($folderName))
- $folderHandle = opendir($folderName);
- if (!$folderHandle)
- return false;
- while($file = readdir($folderHandle)) {
- if ($file != "." && $file != "..") {
- if (!is_dir($folderName."/".$file))
- unlink($folderName."/".$file);
- else
- removeFolder($folderName.'/'.$file);
- }
- }
- closedir($folderHandle);
- rmdir($folderName);
- return true;
- }
|