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); } $pag = "../perfil.php"; //--- Objeto para validar usuario. El id de usuario lo lee desde sesión $objSesion = new ValidaSesion($pdo, 20, APSA); if(!$objSesion->tieneAcceso()){ header("Location: ".$pag."?error=3"); exit(); } unset($objValida); if(!isset($_POST["periodo"])){ header("Location: ".$pag."?error=0"); exit(); } $periodo_id = filter_input(INPUT_POST, "periodo", FILTER_SANITIZE_NUMBER_INT);//limpia texto $profesor = $_SESSION["usuario_id"]; //Obtiene fechas de periodo $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)'); $stmt->bindParam(":periodo", $periodo_id); if(!$stmt->execute()){ header("Location:".$pag."?error=4"); //print_r($stmt->errorInfo()); exit(); } $periodo_rs = $stmt->fetch(); $nivel = $periodo_rs["Nivel_id"]; $stmt->closeCursor(); //---Fecha de cartas $stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 4 )');//fechas profesores $stmt->bindParam(":periodo", $periodo_id); if(!$stmt->execute()){ //echo "4";print_r($stmt->errorInfo());exit(); header("Location:".$pag."?error=4"); exit(); } $rs = $stmt->fetch(); $stmt->closeCursor(); $fecha_carta = $rs["FechaImportante_inicial"]; //----- $stmt = $pdo->prepare('Select * from fs_fechaimportante(:periodo, 3 )');//fechas profesores $stmt->bindParam(":periodo", $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", $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"]; //Obtiene texto de carta y datos de firmas $stmt = $pdo->prepare('Select * from fs_cartanombramiento(:periodo)'); $stmt->bindParam(":periodo", $periodo_id); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location:".$pag."?error=4"); exit(); } $carta_rs = $stmt->fetch(); $texto = $carta_rs["CartaNombramiento_texto"]; $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']; $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' ]); $stylesheet = ""; //$hoy = strftime("%e de %B de %Y"); //Obtiene fechas de periodo $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)'); $stmt->bindParam(":periodo", $periodo_id); if(!$stmt->execute()){ header("Location:".$pag."?error=4"); //print_r($stmt->errorInfo()); exit(); } $periodo_rs = $stmt->fetch(); $nivel = $periodo_rs["Nivel_id"]; $stmt->closeCursor(); //Obtiene datos del profesor actual if($nivel == 1){ $stmt = $pdo->prepare('Select * from fs_profesoresperiodo(:periodo, :prof, 0, NULL)'); $stmt->bindParam(":prof", $profesor); }else{ $stmt = $pdo->prepare('Select * from fs_profesoresperiodo_carrera(:periodo, :prof)'); $stmt->bindParam(":prof", $profesor); } $stmt->bindParam(":periodo", $periodo_id); if(!$stmt->execute()){ header("Location:".$pag."?error=5"); //print_r($stmt->errorInfo()); exit(); } $rs = $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); $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); $xtpl->assign("TEXTO_CARTA", $texto); //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/"); } //---- $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 = $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(); unset($tmp_rs); foreach($rs as $profesor){ if(strtoupper($profesor["Usuario_nombre"]) != "VACANTE"){//no vacante $stmt = $pdo->prepare('Select * from fs_categoriaperiodo(:periodo, :prof )');//firmas $stmt->bindParam(":periodo", $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); $xtpl->assign("CATEGORIA", $cat_rs["Categoria_desc"]); 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", $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', $carta_rs["Director_firma"]); $director = $carta_rs["Director_grado"]." ".$carta_rs["Director_nombre"]." ".$carta_rs["Director_apellidos"]; $xtpl->assign("NOMBRE_FIRMA", $director); $xtpl->assign("PUESTO_FIRMA", $director_rs["Puesto_desc"]); }else{//TODO cambiar por secretario académico $xtpl->assign('FIRMA', $carta_rs["Secretario_imagen"]); $secretario = $carta_rs["Secretario_grado"]." ".$carta_rs["Secretario_nombre"]." ".$carta_rs["Secretario_apellidos"]; $xtpl->assign("NOMBRE_FIRMA", $secretario); $xtpl->assign("PUESTO_FIRMA", $secretario_rs["Puesto_desc"]); } if($cuenta > 0) $xtpl->parse("main.pagebreak"); $xtpl->parse("main"); }//fin vacante }//for profesor /*echo $stylesheet; $xtpl->out("main");exit();*/ $mpdf->WriteHTML($stylesheet); $mpdf->WriteHTML($xtpl->text("main")); $mpdf->Output("nombramientos.pdf", 'I');