action_auditoria.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?
  2. #input $_GET['id_espacio_sgu']
  3. #output rutas: [ ...ruta, salones: [{...salon}] ]
  4. header('Content-Type: application/json charset=utf-8');
  5. ini_set('display_errors', 1);
  6. ini_set('display_startup_errors', 1);
  7. error_reporting(E_ALL);
  8. $ruta = "../";
  9. require_once $ruta . "class/c_login.php";
  10. if (!isset($_SESSION['user'])) {
  11. http_response_code(401);
  12. die(json_encode(['error' => 'unauthorized']));
  13. }
  14. $user = unserialize($_SESSION['user']);
  15. // check method
  16. try {
  17. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  18. $data = $db->query(
  19. "WITH horarios AS (
  20. SELECT *,
  21. materia_nombre as materia,
  22. carrera_nombre as carrera,
  23. facultad_nombre as facultad,
  24. nivel_nombre as nivel,
  25. horario_hora + duracion_interval as horario_fin
  26. FROM horario
  27. left JOIN materia USING (materia_id)
  28. JOIN carrera USING (carrera_id)
  29. JOIN nivel USING (nivel_id)
  30. JOIN facultad ON facultad.facultad_id = carrera.facultad_id
  31. JOIN PERIODO_CARRERA USING (carrera_id)
  32. JOIN PERIODO USING (periodo_id)
  33. JOIN SALON USING (salon_id)
  34. JOIN duracion USING (duracion_id)
  35. WHERE (periodo_id, facultad.facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad.facultad_id))
  36. ),
  37. fechas AS (
  38. SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
  39. FROM horarios h
  40. ),
  41. sin_registro AS (
  42. SELECT * FROM ESTADO_SUPERVISOR WHERE (estado_color, estado_icon) = ('dark', 'ing-cancelar')
  43. )
  44. SELECT
  45. usuario.*, registro.*, profesor.*, horarios.*, fechas.*,
  46. COALESCE(estado_supervisor.estado_supervisor_id, sin_registro.estado_supervisor_id) as estado_supervisor_id,
  47. COALESCE(estado_supervisor.nombre, sin_registro.nombre) as nombre,
  48. COALESCE(estado_supervisor.estado_color, sin_registro.estado_color) as estado_color,
  49. COALESCE(estado_supervisor.estado_icon, sin_registro.estado_icon) as estado_icon,
  50. justificador.usuario_nombre as justificador_nombre,
  51. justificador.usuario_clave as justificador_clave,
  52. facultad.facultad_nombre as justificador_facultad,
  53. rol.rol_titulo as justificador_rol
  54. FROM horarios
  55. JOIN fechas using (horario_id)
  56. JOIN horario_profesor using (horario_id)
  57. JOIN profesor using (profesor_id)
  58. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  59. LEFT join estado_supervisor using (estado_supervisor_id)
  60. CROSS JOIN sin_registro
  61. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  62. LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
  63. LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
  64. left join facultad on facultad.facultad_id = justificador.facultad_id
  65. WHERE fechas.registro_fecha_ideal BETWEEN COALESCE(:fecha_inicio, LEAST(CURRENT_DATE, PERIODO_FECHA_FIN)) AND COALESCE(:fecha_fin, LEAST(CURRENT_DATE, PERIODO_FECHA_FIN))
  66. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  67. [
  68. ':periodo_id' => $user->periodo_id,
  69. ':facultad_id' => $user->facultad['facultad_id'],
  70. ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? null,
  71. ':fecha_fin' => $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null,
  72. ]
  73. );
  74. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  75. } else {
  76. http_response_code(405);
  77. echo json_encode(['error' => 'method not allowed']);
  78. exit;
  79. }
  80. } catch (PDOException $th) {
  81. http_response_code(500);
  82. echo json_encode([
  83. 'error' => $th->getMessage(),
  84. // 'query' => $db->getLastQuery(),
  85. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  86. exit;
  87. } catch (Exception $th) {
  88. http_response_code(500);
  89. echo json_encode([
  90. 'error' => $th->getMessage(),
  91. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  92. exit;
  93. }