123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <?php
- /* AJAX
- * Selecciona los datos de la carrera
- * Recibe:
- * id - ID de grupo,
- * json
- * Return:
- * resultado o cadena de error
- */
- require_once("../../include/constantes.php");
- require_once("../../include/nocache.php");
- require_once("../../include/util.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../classes/ValidaSesion.php");
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, array(51, 272), APSA);
- if(!$objSesion->tieneAcceso()){
- $return["error"] = "Error! No tienes permisos para realizar esta acción.";
- }else if(!isset($_POST["id"]) ){
- $return["error"] = "Error! No se recibió la información del grupo.";
- }else{
- $grupo = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- if(isset($_POST["puesto"]))
- $filtra_puesto = filter_input(INPUT_POST, "puesto", FILTER_VALIDATE_BOOLEAN);//limpia texto
- else $filtra_puesto = false;
- if(isset($_POST["editable"]))
- $editable = filter_input(INPUT_POST, "editable", FILTER_VALIDATE_BOOLEAN);//limpia texto
- else $editable = false;
- $error = false;
-
- if(!$filtra_puesto){
- if(!$editable){
- $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, NULL)');//Obtiene todo el calendario
- $stmt->bindParam(":gpo", $grupo);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] = "Ocurrió un error al obtener los horarios del grupo ".$t[2];
- $error = true;
- }
- $horario_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- }
- }else{
- if($editable){
- $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, :usr, true)');//obtiene sólo del área del puesto
- }else{
- $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, :usr, false)');//obtiene lo que no está en el área del puesto
- }
- $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
- $stmt->bindParam(":gpo", $grupo);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] = "Ocurrió un error al obtener los horarios del grupo ".$t[2];
- $error = true;
- }
- $horario_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- }
-
- $json = array();
- if(isset($horario_rs) && is_array($horario_rs) && count($horario_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()){
- $return["error"] = "Ocurrió un error al obtener los datos del periodo ".$t[2];
- $error = true;
- }
- $periodo_rs = $stmt->fetch();
- $stmt->closeCursor();
- $periodo_inicial = (fechaGuion($periodo_rs["Periodo_fecha_inicial"]));
- $periodo_final = (fechaGuion($periodo_rs["Periodo_fecha_final"]));
- foreach($horario_rs as $horario){//crea objeto json
- $error = false;
- $clase_tmp =array();
- $clase_tmp["id"] = $horario["HorarioGrupo_id"];
- $clase_tmp["dia"] = $horario["Dia_id"];
- $clase_tmp["hora"] = substr($horario["Horario_hora"], 0, 5);//hh:mm
- $clase_tmp["duracion"] = $horario["Horario_duracion"];
- $clase_tmp["materia"] = $horario["Materia_id"];
- $clase_tmp["materia_nombre"] = $horario["Materia_desc"];
- if($horario["Salon_id"] == ""){
- $clase_tmp["salon"] = "";
- $clase_tmp["salon_nombre"] = "";
- $clase_tmp["salon_nombre_completo"] = "";
- }else{
- $clase_tmp["salon"] = $horario["Salon_id"];
- $clase_tmp["salon_nombre"] = $horario["Salon_desc"];
- if( strlen($horario["Salon_desc_larga"]) > 0){
- $clase_tmp["salon_nombre_completo"] = $horario["Salon_desc"]." [".$horario["Salon_desc_larga"]."]";
- }else
- $clase_tmp["salon_nombre_completo"] = $horario["Salon_desc"];
- }
- $clase_tmp["fecha_inicial"] = fechaSlash($horario["fecha_inicial"]);
- $clase_tmp["fecha_final"] = fechaSlash($horario["fecha_final"]);
- $clase_tmp["color"] = $horario["Area_color"];
- $clase_tmp["alerta"] = $horario["Area_hasAlerta"];
- if(isset($horario["TipoSubmateria_id"]) && $horario["TipoSubmateria_id"] != "")
- $clase_tmp["tipo"] = $horario["TipoSubmateria_id"];
- else
- $clase_tmp["tipo"] = 0;
- $completo = 0;
- $fecha_ini = (fechaGuion($horario["fecha_inicial"]));
- $fecha_fin = (fechaGuion($horario["fecha_final"]));
- //$return["comparacion"] = "[".$periodo_inicial."] == [".$fecha_ini."] && [".$periodo_final."] == [".$fecha_fin."]";//debug
- if( $periodo_inicial == $fecha_ini && $periodo_final == $fecha_fin){
- $completo = 1;
- }
- $clase_tmp["periodo_completo"] = $completo;
- $clase_tmp["profesores"] = array();
- //----- Carga profesores ----
- if($clase_tmp["tipo"] == 0){
- $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
- }else{
- $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id, NULL)');
- }
- $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
- $error = true;
- break;
- }
- $profesores_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- if(count($profesores_rs) > 0){
- foreach($profesores_rs as $profesor){
- $profesor_tmp = array();
- $profesor_tmp["profesor"] = $profesor["Usuario_id"];
- $profesor_tmp["profesor_nombre"] = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
- if($clase_tmp["tipo"] != 0){
- $profesor_tmp["submateria"] = $profesor["Submateria_id"];
-
- if($profesor["Salon_desc"] == ""){
- $profesor_tmp["salon"] = "";
- $profesor_tmp["salon_nombre"] = "";
- $profesor_tmp["salon_nombre_completo"] = "";
- }else{
- $profesor_tmp["salon"] = $profesor["Salon_id"];
- $profesor_tmp["salon_nombre"] = $profesor["Salon_desc"];
- if( strlen($profesor["Salon_desc_larga"]) > 0){
- $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"]." [".$profesor["Salon_desc_larga"]."]";
- }else
- $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"];
- }
- }
-
- if($profesor_tmp["profesor"] != "" && $profesor_tmp["profesor"] != 0)
- $clase_tmp["profesores"][] = $profesor_tmp;//agrega profesor
-
- }
- }
- //----- Carga submaterias ----
- $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupo(:id)');
- $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
- $error = true;
- break;
- }
- $clase_tmp["submaterias"] = array();
- $submaterias_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- if(count($submaterias_rs) > 0){
- foreach($submaterias_rs as $submateria){
- if(isset($submateria["Submateria_id"]) && $submateria["Submateria_id"] != "" && $submateria["Submateria_id"] != 0){
- $sub_tmp = array();
- $sub_tmp["submateria"] = $submateria["Submateria_id"];
- $sub_tmp["submateria_nombre"] = $submateria["Submateria_desc"];
- $sub_tmp["fecha_inicial"] = fechaSlash($submateria["fecha_inicial"]);
- $sub_tmp["fecha_final"] = fechaSlash($submateria["fecha_final"]);
- $sub_tmp["activa"] = $submateria["Submateria_activa"];
-
- $clase_tmp["submaterias"][] = $sub_tmp;//agrega submateria
- }
- }
- }
- // ----- Carga vinculadas ---
- $stmt = $pdo->prepare('Select * from fs_horariogrupovinculado_all(:id)');//incluye id actual para validaciones
- $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] = "Ocurrió un error al obtener los datos de las materias vinculadas ".$t[2];
- $error = true;
- break;
- }
- $vinculadas_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null; // cierra conexion
- $clase_tmp["vinculada"] = array();
- foreach($vinculadas_rs as $vinculada){
- $vinculada_tmp = array();
- $vinculada_tmp["id_db"] = $vinculada["HorarioGrupo_id"];
- $vinculada_tmp["id_mat"] = $vinculada["Materia_id"];
- $vinculada_tmp["id_gpo"] = $vinculada["Grupo_id"];
- //if($_SESSION["nivel_id"] == 1)
- $vinculada_tmp["nombre"] = $vinculada["Grupo_desc"]." ".$vinculada["Carrera_prefijo"]." (".$vinculada["Materia_desc"].")";
- //else
- //$vinculada_tmp["nombre"] = $vinculada["Grupo_desc"]." (".$vinculada["Materia_desc"].")";
- $clase_tmp["vinculada"][] = $vinculada_tmp;//agrega materia
- //----- Carga profesores ----
- if($clase_tmp["tipo"] == 0){
- $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
- }else{
- $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id, NULL)');
- }
- $stmt->bindParam(":id", $vinculada["HorarioGrupo_id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
- $error = true;
- break;
- }
- $profesores_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- if(count($profesores_rs) > 0){
- foreach($profesores_rs as $profesor){
- $profesor_tmp = array();
- $profesor_tmp["profesor"] = $profesor["Usuario_id"];
- $profesor_tmp["profesor_nombre"] = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
- if($clase_tmp["tipo"] != 0){
- $profesor_tmp["submateria"] = $profesor["Submateria_id"];
-
- if($profesor["Salon_desc"] == ""){
- $profesor_tmp["salon"] = "";
- $profesor_tmp["salon_nombre"] = "";
- $profesor_tmp["salon_nombre_completo"] = "";
- }else{
- $profesor_tmp["salon"] = $profesor["Salon_id"];
- $profesor_tmp["salon_nombre"] = $profesor["Salon_desc"];
- if( strlen($profesor["Salon_desc_larga"]) > 0){
- $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"]." [".$profesor["Salon_desc_larga"]."]";
- }else
- $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"];
- }
- }
-
- if($profesor_tmp["profesor"] != "" && $profesor_tmp["profesor"] != 0)
- $clase_tmp["profesores"][] = $profesor_tmp;//agrega profesor
-
- }
- }
- }
- if(!$error){
- $json[] = $clase_tmp;
- }
-
- }//fin foreach
- }//fin tiene datos
- $return["horario"] = $json;
- $return["ok"] = "El horario se cargó correctamente";
- }
- $return["json"] = json_encode($return);
- echo json_encode($return);
- ?>
|