123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- /* AJAX
- * Genera nombramientos en pdf
- * Recibe:
- * grupo
- * Return:
- * imprime pdf
- */
- setlocale(LC_TIME, 'es_MX.UTF-8');
- require_once("../../include/nocache.php");
- require_once("../../include/constantes.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../include/util.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
- $pag = "../reporte_horariogrupo.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 272, APSA);
- if(!$objSesion->tieneAcceso()){
- header("Location: ".$pag."?error=3");
- exit();
- }
- unset($objValida);
- if(!isset($_POST["grupo"])){
- header("Location: ".$pag."?error=0");
- exit();
- }
- $filter_grupo = filter_input(INPUT_POST, "grupo", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- if(isset($_POST["filter_fecha"]) && $_POST["filter_fecha"]!= "")
- $filter_fecha = fechaGuion(trim(filter_input(INPUT_POST, "filter_fecha", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $stmt = $pdo->prepare('Select * from fs_grupo(:grupo, :periodo)');
- $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
- $stmt->bindParam(":grupo", $filter_grupo);
- if(!$stmt->execute()){
- $errorDesc = "Ocurrió un error al cargar el grupo.";
- }
- $grupo_rs = $stmt->fetch();
- $stmt->closeCursor();
- //Obtiene horario del grupo
- $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, false)');
- $stmt->bindParam(":gpo", $filter_grupo);
- if(!$stmt->execute()){
- //header("Location: materias.php?error=2");
- $errorDesc = "Error al cargar el horario del grupo";
- print_r($stmt->errorInfo());
- exit();
- }
- $horario_rs = $stmt->fetchAll();
- $horaMin = horaMin($horario_rs);
- $horaMax = horaMax($horario_rs);
- $stmt->closeCursor();
- $stmt = $pdo->prepare('Select * from fs_dia(NULL)');
- if(!$stmt->execute()){
- echo "Error al obtener los días";
- print_r($stmt->errorInfo());
- }
- $dias_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- //-----
- $mpdf = new \Mpdf\Mpdf([
- 'mode' => 'utf-8',
- 'format' => [215, 279],
- 'orientation' => 'P'
- ]);
- //$mpdf->SetDisplayMode('fullpage');
- $stylesheet = "<style>";
- $stylesheet .= file_get_contents('../../css/indivisa.css'); // external css
- $stylesheet .= file_get_contents('../css/horario_reporte.css'); // external css
- $stylesheet .= "</style>";
- //echo $stylesheet;
- $xtpl = new XTemplate('../tpl/horario_reporte.tpl.html');
- if($_SESSION["nivel_id"] == 1)
- $xtpl->assign("LEFT", "Grupo: ".$grupo_rs["Grupo_desc"]." ".$grupo_rs["Carrera_prefijo"]);
- else
- $xtpl->assign("LEFT", "Grupo: ".$grupo_rs["Grupo_desc"]." ".$grupo_rs["Carrera_desc"]);
- if(intval($grupo_rs["Grupo_semestre"]) > 0){
- if($_SESSION["nivel_id"] == 1)
- $xtpl->assign("RIGHT", "Semestre: ".$grupo_rs["Grupo_semestre"]);
- else
- $xtpl->assign("RIGHT", "Cuatrimestre: ".$grupo_rs["Grupo_semestre"]);
- }else
- $xtpl->assign("RIGHT", "Propedéutico");
- $xtpl->parse("main.top");
- foreach($dias_rs as $dia){
- $xtpl->assign("DIA", $dia["Dia_desc"]);
- $xtpl->parse("main.header");
- }
- $rs_i = 0;
- $spacerArr = array(1=>0,0,0,0,0,0);
- $pendiente = "<em>Pendiente</em>";
- $horas_dif = intval(date('H', strtotime($horaMax))) - intval(date('H', strtotime($horaMin)));
- $sub_prof_num = 0;
- $sub_num = 0;
- $tiene_submaterias = false;
- for($h = date('H', strtotime($horaMin)); $h <= date('H', strtotime($horaMax)); $h++){
- $xtpl->assign("HORA", date('H', strtotime($h.":00")));
- $xtpl->assign("FRACCIONES", FRACCION_HORA);
- $xtpl->parse("main.hora_row.hora");
- for($f = 0; $f < FRACCION_HORA; $f++){
- foreach($dias_rs as $dia){
- if($rs_i < count($horario_rs) && date('H:i', strtotime($horario_rs[$rs_i]["Horario_hora"])) == date('H:i', strtotime($h.":".($f * (60/FRACCION_HORA)))) && $horario_rs[$rs_i]["Dia_id"] == $dia["Dia_id"]){
- if((isset($filter_fecha) && strtotime($filter_fecha) >= strtotime($horario_rs[$rs_i]["fecha_inicial"]) && strtotime($filter_fecha) <= strtotime($horario_rs[$rs_i]["fecha_final"]) ) || !isset($filter_fecha)){
- $size = $horario_rs[$rs_i]["Horario_duracion"]/(60/FRACCION_HORA);
- $spacerArr[$dia["Dia_id"]] = $size -1;
- $xtpl->assign("COLOR", '#e9e7e8');
- $xtpl->assign("DURACION_SIZE", $size);
- $xtpl->assign("MATERIA", $horario_rs[$rs_i]["Materia_desc"]);
-
- $xtpl->assign("HORA_I", substr($horario_rs[$rs_i]["Horario_hora"], 0, 5));
- $xtpl->assign("HORA_F", substr($horario_rs[$rs_i]["Horario_hora_final"], 0, 5));
-
- if($horario_rs[$rs_i]["Salon_desc"] != "")
- if($horario_rs[$rs_i]["Salon_desc_larga"] != "")
- $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]." [".$horario_rs[$rs_i]["Salon_desc_larga"]."]");
- else
- $xtpl->assign("SALON", $horario_rs[$rs_i]["Salon_desc"]);
- else{
- if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0)
- $xtpl->assign("SALON", $pendiente);
- else
- $xtpl->assign("SALON", "*");
- }
- //----- Carga profesores ----
- if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0){
- $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
- $stmt->bindParam(":id", $horario_rs[$rs_i]["HorarioGrupo_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
- break;
- }
- $profesores_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- }else{//Con submaterias
- //----- Carga submaterias ----
- $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupo(:id)');
- $stmt->bindParam(":id", $horario_rs[$rs_i]["HorarioGrupo_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
- break;
- }
- $submaterias_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $sub_prof_num = 0;
- $nombre_impreso = false;
- if(count($submaterias_rs) > 0){
- $tiene_submaterias = true;
- foreach($submaterias_rs as $submateria){
- $xtpl->assign("SUBMATERIA", $submateria["Submateria_desc"]);
- $xtpl->assign("DIA", diaNombre($submateria["Dia_id"]));
- //---
- $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id,:sub)');
- $stmt->bindParam(":id", $horario_rs[$rs_i]["HorarioGrupo_id"]);
- $stmt->bindParam(":sub", $submateria["Submateria_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $errorDesc = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
- break;
- }
- $profesores_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $sub_prof_num += count($profesores_rs);
- if(isset($profesores_rs) && count($profesores_rs) > 0){
- $profesores_all = "";
- foreach($profesores_rs as $profesor){
- $prof_nombre = "• ".$profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
- $profesores_all .= $prof_nombre."<br>";
- }
- $xtpl->assign("PROFESOR_SUB", $profesores_all);
- /*}else{
- $xtpl->assign("PROFESOR_SUB", $pendiente);
- }*/
- $xtpl->assign("SALON_SUB", $submateria["Salon_desc"]);
- $xtpl->parse("main.submaterias_block.row.submateria");
- if(!$nombre_impreso){
- $nombre_impreso = true;
- $xtpl->assign("MAT_ROWSPAN", count($submaterias_rs));
- $xtpl->parse("main.submaterias_block.row.materia");
- }
- $xtpl->parse("main.submaterias_block.row");
- }//solo si hay profesor
- }
- }
- unset($profesores_rs);
- }//fin con submaterias
- if(isset($profesores_rs) && count($profesores_rs) > 0){
- foreach($profesores_rs as $profesor){
- $prof_nombre = "• ".$profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
- $xtpl->assign("PROFESOR", $prof_nombre);
- $xtpl->parse("main.hora_row.td.td_horario.profesor");
- }
- }else{
- if($horario_rs[$rs_i]["TipoSubmateria_id"] == 0){//no pinta maestros electivas o secuenciales
- $prof_nombre = $pendiente;
- $xtpl->assign("PROFESOR", $prof_nombre);
- $xtpl->parse("main.hora_row.td.td_horario.profesor");
- }
- }
- $xtpl->parse("main.hora_row.td.td_horario.hora");
- $xtpl->parse("main.hora_row.td.td_horario.texto");
- $xtpl->parse("main.hora_row.td.td_horario.spacer");
- $xtpl->parse("main.hora_row.td.td_horario");
- }else
- $xtpl->parse("main.hora_row.td.td_vacio");
- $rs_i++;
- }else{
- if(!isset($spacerArr[$dia["Dia_id"]]) || $spacerArr[$dia["Dia_id"]] == 0)
- $xtpl->parse("main.hora_row.td.td_vacio");
- else
- $spacerArr[$dia["Dia_id"]]--;
- }
- $xtpl->parse("main.hora_row.td");
- }
- $xtpl->parse("main.hora_row");
- }
- }
- if($tiene_submaterias){
- $xtpl->parse("main.submaterias_block");
- }
- $xtpl->parse("main");
- //$xtpl->out("main");
- $mpdf->WriteHTML($stylesheet);
- if(!isset($errorDesc))
- $mpdf->WriteHTML($xtpl->text("main"));
- else
- $mpdf->WriteHTML($errorDesc);
- $mpdf->Output("horariogrupo.pdf", 'I');
- ?>
|