disponibilidad_select.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, 51, APSA);
  17. if(!$objSesion->tieneAcceso()){
  18. $return["error"] = "No tienes permisos para realizar esta acción.";
  19. }else if(!isset($_SESSION["periodo_id"]) || $_SESSION["periodo_id"] ==""){
  20. $return["error"] = "Necesitas seleccionar un periodo.";
  21. }else{
  22. $usr = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  23. $stmt = $pdo->prepare('Select * from fs_disponibilidad(:usr)');//Obtiene todo el calendario
  24. $stmt->bindParam(":usr", $usr);
  25. if(!$stmt->execute()){
  26. $t = $stmt->errorInfo();
  27. $return["error"] = "Ocurrió un error al obtener los horarios ".$t[2];
  28. $error = true;
  29. }else{
  30. $horario_rs = $stmt->fetchAll();
  31. $stmt->closeCursor();
  32. $json = array();
  33. foreach($horario_rs as $horario){//crea objeto json
  34. $horario_tmp =array();
  35. $horario_tmp["id"] = $horario["Horario_id"];
  36. $horario_tmp["dia"] = $horario["Dia_id"];
  37. $horario_tmp["hora"] = substr($horario["Hora_inicio"], 0, 5);//hh:mm
  38. $horario_tmp["duracion"] = $horario["Duracion"];
  39. $horario_tmp["color"] = "#f0b6c0";
  40. $json[] = $horario_tmp;
  41. }//fin foreach
  42. }//fin tiene datos
  43. $return["horario"] = $json;
  44. $return["ok"] = "El horario se cargó correctamente";
  45. }
  46. $return["json"] = json_encode($return);
  47. echo json_encode($return);
  48. ?>