horariogrupo_select.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php
  2. /* AJAX
  3. * Selecciona los datos de la carrera
  4. * Recibe:
  5. * id - ID de grupo,
  6. * json
  7. * Return:
  8. * resultado o cadena de error
  9. */
  10. require_once("../../include/constantes.php");
  11. require_once("../../include/nocache.php");
  12. require_once("../../include/util.php");
  13. require_once("../../include/bd_pdo.php");
  14. require_once("../../classes/ValidaSesion.php");
  15. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  16. $objSesion = new ValidaSesion($pdo, array(51, 272), APSA);
  17. if(!$objSesion->tieneAcceso()){
  18. $return["error"] = "Error! No tienes permisos para realizar esta acción.";
  19. }else if(!isset($_POST["id"]) ){
  20. $return["error"] = "Error! No se recibió la información del grupo.";
  21. }else{
  22. $grupo = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  23. if(isset($_POST["puesto"]))
  24. $filtra_puesto = filter_input(INPUT_POST, "puesto", FILTER_VALIDATE_BOOLEAN);//limpia texto
  25. else $filtra_puesto = false;
  26. if(isset($_POST["editable"]))
  27. $editable = filter_input(INPUT_POST, "editable", FILTER_VALIDATE_BOOLEAN);//limpia texto
  28. else $editable = false;
  29. $error = false;
  30. if(!$filtra_puesto){
  31. if(!$editable){
  32. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, NULL, NULL)');//Obtiene todo el calendario
  33. $stmt->bindParam(":gpo", $grupo);
  34. if(!$stmt->execute()){
  35. $t = $stmt->errorInfo();
  36. $return["error"] = "Ocurrió un error al obtener los horarios del grupo ".$t[2];
  37. $error = true;
  38. }
  39. $horario_rs = $stmt->fetchAll();
  40. $stmt->closeCursor();
  41. }
  42. }else{
  43. if($editable){
  44. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, :usr, true)');//obtiene sólo del área del puesto
  45. }else{
  46. $stmt = $pdo->prepare('Select * from fs_horariogrupo(:gpo, :usr, false)');//obtiene lo que no está en el área del puesto
  47. }
  48. $stmt->bindParam(":usr", $_SESSION["usuario_id"]);
  49. $stmt->bindParam(":gpo", $grupo);
  50. if(!$stmt->execute()){
  51. $t = $stmt->errorInfo();
  52. $return["error"] = "Ocurrió un error al obtener los horarios del grupo ".$t[2];
  53. $error = true;
  54. }
  55. $horario_rs = $stmt->fetchAll();
  56. $stmt->closeCursor();
  57. }
  58. $json = array();
  59. if(isset($horario_rs) && is_array($horario_rs) && count($horario_rs)){
  60. //Obtiene fechas de periodo
  61. $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)');
  62. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  63. if(!$stmt->execute()){
  64. $return["error"] = "Ocurrió un error al obtener los datos del periodo ".$t[2];
  65. $error = true;
  66. }
  67. $periodo_rs = $stmt->fetch();
  68. $stmt->closeCursor();
  69. $periodo_inicial = (fechaGuion($periodo_rs["Periodo_fecha_inicial"]));
  70. $periodo_final = (fechaGuion($periodo_rs["Periodo_fecha_final"]));
  71. foreach($horario_rs as $horario){//crea objeto json
  72. $error = false;
  73. $clase_tmp =array();
  74. $clase_tmp["id"] = $horario["HorarioGrupo_id"];
  75. $clase_tmp["dia"] = $horario["Dia_id"];
  76. $clase_tmp["hora"] = substr($horario["Horario_hora"], 0, 5);//hh:mm
  77. $clase_tmp["duracion"] = $horario["Horario_duracion"];
  78. $clase_tmp["materia"] = $horario["Materia_id"];
  79. $clase_tmp["materia_nombre"] = $horario["Materia_desc"];
  80. if($horario["Salon_id"] == ""){
  81. $clase_tmp["salon"] = "";
  82. $clase_tmp["salon_nombre"] = "";
  83. $clase_tmp["salon_nombre_completo"] = "";
  84. }else{
  85. $clase_tmp["salon"] = $horario["Salon_id"];
  86. $clase_tmp["salon_nombre"] = $horario["Salon_desc"];
  87. if( strlen($horario["Salon_desc_larga"]) > 0){
  88. $clase_tmp["salon_nombre_completo"] = $horario["Salon_desc"]." [".$horario["Salon_desc_larga"]."]";
  89. }else
  90. $clase_tmp["salon_nombre_completo"] = $horario["Salon_desc"];
  91. }
  92. $clase_tmp["fecha_inicial"] = fechaSlash($horario["fecha_inicial"]);
  93. $clase_tmp["fecha_final"] = fechaSlash($horario["fecha_final"]);
  94. $clase_tmp["color"] = $horario["Area_color"];
  95. $clase_tmp["alerta"] = $horario["Area_hasAlerta"];
  96. if(isset($horario["TipoSubmateria_id"]) && $horario["TipoSubmateria_id"] != "")
  97. $clase_tmp["tipo"] = $horario["TipoSubmateria_id"];
  98. else
  99. $clase_tmp["tipo"] = 0;
  100. $completo = 0;
  101. $fecha_ini = (fechaGuion($horario["fecha_inicial"]));
  102. $fecha_fin = (fechaGuion($horario["fecha_final"]));
  103. //$return["comparacion"] = "[".$periodo_inicial."] == [".$fecha_ini."] && [".$periodo_final."] == [".$fecha_fin."]";//debug
  104. if( $periodo_inicial == $fecha_ini && $periodo_final == $fecha_fin){
  105. $completo = 1;
  106. }
  107. $clase_tmp["periodo_completo"] = $completo;
  108. $clase_tmp["profesores"] = array();
  109. //----- Carga profesores ----
  110. if($clase_tmp["tipo"] == 0){
  111. $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
  112. }else{
  113. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id, NULL)');
  114. }
  115. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  116. if(!$stmt->execute()){
  117. $t = $stmt->errorInfo();
  118. $return["error"] = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  119. $error = true;
  120. break;
  121. }
  122. $profesores_rs = $stmt->fetchAll();
  123. $stmt->closeCursor();
  124. if(count($profesores_rs) > 0){
  125. foreach($profesores_rs as $profesor){
  126. $profesor_tmp = array();
  127. $profesor_tmp["profesor"] = $profesor["Usuario_id"];
  128. $profesor_tmp["profesor_nombre"] = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  129. if($clase_tmp["tipo"] != 0){
  130. $profesor_tmp["submateria"] = $profesor["Submateria_id"];
  131. if($profesor["Salon_desc"] == ""){
  132. $profesor_tmp["salon"] = "";
  133. $profesor_tmp["salon_nombre"] = "";
  134. $profesor_tmp["salon_nombre_completo"] = "";
  135. }else{
  136. $profesor_tmp["salon"] = $profesor["Salon_id"];
  137. $profesor_tmp["salon_nombre"] = $profesor["Salon_desc"];
  138. if( strlen($profesor["Salon_desc_larga"]) > 0){
  139. $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"]." [".$profesor["Salon_desc_larga"]."]";
  140. }else
  141. $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"];
  142. }
  143. }
  144. if($profesor_tmp["profesor"] != "" && $profesor_tmp["profesor"] != 0)
  145. $clase_tmp["profesores"][] = $profesor_tmp;//agrega profesor
  146. }
  147. }
  148. //----- Carga submaterias ----
  149. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupo(:id)');
  150. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  151. if(!$stmt->execute()){
  152. $t = $stmt->errorInfo();
  153. $return["error"] = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  154. $error = true;
  155. break;
  156. }
  157. $clase_tmp["submaterias"] = array();
  158. $submaterias_rs = $stmt->fetchAll();
  159. $stmt->closeCursor();
  160. if(count($submaterias_rs) > 0){
  161. foreach($submaterias_rs as $submateria){
  162. if(isset($submateria["Submateria_id"]) && $submateria["Submateria_id"] != "" && $submateria["Submateria_id"] != 0){
  163. $sub_tmp = array();
  164. $sub_tmp["submateria"] = $submateria["Submateria_id"];
  165. $sub_tmp["submateria_nombre"] = $submateria["Submateria_desc"];
  166. $sub_tmp["fecha_inicial"] = fechaSlash($submateria["fecha_inicial"]);
  167. $sub_tmp["fecha_final"] = fechaSlash($submateria["fecha_final"]);
  168. $sub_tmp["activa"] = $submateria["Submateria_activa"];
  169. $clase_tmp["submaterias"][] = $sub_tmp;//agrega submateria
  170. }
  171. }
  172. }
  173. // ----- Carga vinculadas ---
  174. $stmt = $pdo->prepare('Select * from fs_horariogrupovinculado_all(:id)');//incluye id actual para validaciones
  175. $stmt->bindParam(":id", $horario["HorarioGrupo_id"]);
  176. if(!$stmt->execute()){
  177. $t = $stmt->errorInfo();
  178. $return["error"] = "Ocurrió un error al obtener los datos de las materias vinculadas ".$t[2];
  179. $error = true;
  180. break;
  181. }
  182. $vinculadas_rs = $stmt->fetchAll();
  183. $stmt->closeCursor();
  184. $stmt = null; // cierra conexion
  185. $clase_tmp["vinculada"] = array();
  186. foreach($vinculadas_rs as $vinculada){
  187. $vinculada_tmp = array();
  188. $vinculada_tmp["id_db"] = $vinculada["HorarioGrupo_id"];
  189. $vinculada_tmp["id_mat"] = $vinculada["Materia_id"];
  190. $vinculada_tmp["id_gpo"] = $vinculada["Grupo_id"];
  191. //if($_SESSION["nivel_id"] == 1)
  192. $vinculada_tmp["nombre"] = $vinculada["Grupo_desc"]." ".$vinculada["Carrera_prefijo"]." (".$vinculada["Materia_desc"].")";
  193. //else
  194. //$vinculada_tmp["nombre"] = $vinculada["Grupo_desc"]." (".$vinculada["Materia_desc"].")";
  195. $clase_tmp["vinculada"][] = $vinculada_tmp;//agrega materia
  196. //----- Carga profesores ----
  197. if($clase_tmp["tipo"] == 0){
  198. $stmt = $pdo->prepare('Select * from fs_profesorhorariogrupo(:id)');
  199. }else{
  200. $stmt = $pdo->prepare('Select * from fs_submateriahorariogrupoprofesor(:id, NULL)');
  201. }
  202. $stmt->bindParam(":id", $vinculada["HorarioGrupo_id"]);
  203. if(!$stmt->execute()){
  204. $t = $stmt->errorInfo();
  205. $return["error"] = "Ocurrió un error al obtener los datos de los profesores ".$t[2];
  206. $error = true;
  207. break;
  208. }
  209. $profesores_rs = $stmt->fetchAll();
  210. $stmt->closeCursor();
  211. if(count($profesores_rs) > 0){
  212. foreach($profesores_rs as $profesor){
  213. $profesor_tmp = array();
  214. $profesor_tmp["profesor"] = $profesor["Usuario_id"];
  215. $profesor_tmp["profesor_nombre"] = $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];
  216. if($clase_tmp["tipo"] != 0){
  217. $profesor_tmp["submateria"] = $profesor["Submateria_id"];
  218. if($profesor["Salon_desc"] == ""){
  219. $profesor_tmp["salon"] = "";
  220. $profesor_tmp["salon_nombre"] = "";
  221. $profesor_tmp["salon_nombre_completo"] = "";
  222. }else{
  223. $profesor_tmp["salon"] = $profesor["Salon_id"];
  224. $profesor_tmp["salon_nombre"] = $profesor["Salon_desc"];
  225. if( strlen($profesor["Salon_desc_larga"]) > 0){
  226. $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"]." [".$profesor["Salon_desc_larga"]."]";
  227. }else
  228. $profesor_tmp["salon_nombre_completo"] = $profesor["Salon_desc"];
  229. }
  230. }
  231. if($profesor_tmp["profesor"] != "" && $profesor_tmp["profesor"] != 0)
  232. $clase_tmp["profesores"][] = $profesor_tmp;//agrega profesor
  233. }
  234. }
  235. }
  236. if(!$error){
  237. $json[] = $clase_tmp;
  238. }
  239. }//fin foreach
  240. }//fin tiene datos
  241. $return["horario"] = $json;
  242. $return["ok"] = "El horario se cargó correctamente";
  243. }
  244. $return["json"] = json_encode($return);
  245. echo json_encode($return);
  246. ?>