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 = "";
//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 = "Pendiente";
$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."
";
}
$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');
?>