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 /*$fecha_inicial = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $fecha_final = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final", 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 } //---- $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(); if($nivel == 1){ $fecha_inicial_extras = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial_extras", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $fecha_final_extras = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final_extras", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto } //---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(); $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; //----- $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 = ""; //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(); $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; if($nivel == 1){ if($profesor == 0) //$stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, NULL, 0, NULL)'); $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_area(:periodo, NULL, 0, NULL)'); else{ //$stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, :prof, 0, NULL)'); $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 = $stmt->fetchAll(); $stmt->closeCursor(); $stmt = null; $cuenta = count($rs); $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); $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(); //----------- 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"); } //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/"); } $num = 1; foreach($rs as $profesor){ if(strtoupper($profesor["Usuario_nombre"]) != "VACANTE"){//no vacante $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); $nombre = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"]; $xtpl->assign("PROFESOR", $nombre); $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--; /*if($profesor["Usuario_id"] != $director_rs["Usuario_id"]){ $director = $titulo." ".$director_rs["Usuario_nombre"]." ".$director_rs["Usuario_apellidos"]; $xtpl->assign("NOMBRE_FIRMA", $director); $xtpl->assign("PUESTO_FIRMA", $director_rs["Puesto_desc"]); }else{//TODO cambiar por secretario académico $xtpl->assign("NOMBRE_FIRMA", "Mtro. Carlos Alfonso Herrera Anda"); $xtpl->assign("PUESTO_FIRMA", "Secretario Académico"); }*/ $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{//TODO cambiar por secretario académico $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($cuenta > 0) $xtpl->parse("main.pagebreak"); $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++; } }//fin vacante }//for profesor 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); 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; } /*echo $stylesheet; $xtpl->out("main");*/