action_auditoria.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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('memory_limit', '256M');
  6. ini_set('post_max_size', '256M');
  7. ini_set('display_errors', 1);
  8. ini_set('display_startup_errors', 1);
  9. error_reporting(E_ALL);
  10. $ruta = "../";
  11. require_once $ruta . "class/c_login.php";
  12. if (!isset($_SESSION['user'])) {
  13. http_response_code(401);
  14. die(json_encode(['error' => 'unauthorized']));
  15. }
  16. $user = unserialize($_SESSION['user']);
  17. // check method
  18. try {
  19. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  20. $baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
  21. $params = [
  22. ':periodo_id' => $user->periodo_id,
  23. ':facultad_id' => $user->facultad['facultad_id'],
  24. ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'),
  25. ':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime($baseDate . ' +24 hours')) : date('Y-m-d H:i:s'),
  26. ];
  27. $data = $db->query(
  28. "WITH horarios AS (
  29. SELECT
  30. horario_id,
  31. facultad.facultad_id,
  32. horario_fecha_inicio,
  33. horario_fecha_fin,
  34. horario_grupo,
  35. horario_hora,
  36. periodo_fecha_inicio,
  37. periodo_fecha_fin,
  38. salon,
  39. materia_nombre as materia,
  40. carrera_nombre as carrera,
  41. facultad_nombre as facultad,
  42. nivel_nombre as nivel,
  43. horario_hora + duracion_interval as horario_fin
  44. FROM horario
  45. left JOIN materia USING (materia_id)
  46. JOIN carrera USING (carrera_id)
  47. JOIN nivel USING (nivel_id)
  48. JOIN facultad ON facultad.facultad_id = carrera.facultad_id
  49. JOIN PERIODO_CARRERA USING (carrera_id)
  50. JOIN PERIODO USING (periodo_id)
  51. JOIN SALON USING (salon_id)
  52. JOIN duracion USING (duracion_id)
  53. WHERE (periodo_id, facultad.facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad.facultad_id))
  54. ),
  55. fechas AS (
  56. SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
  57. FROM horarios h
  58. )
  59. SELECT
  60. usuario.usuario_nombre,
  61. registro.registro_id,
  62. registro.registro_fecha,
  63. registro.registro_retardo,
  64. registro.registro_justificada,
  65. registro_fecha_supervisor,
  66. justificacion,
  67. comentario,
  68. registro_fecha_justificacion,
  69. profesor.profesor_id, profesor_nombre, profesor_clave, profesor_correo,
  70. horario_id,
  71. materia, carrera, horarios.facultad_id, facultad, nivel, horario_hora, horario_fin, horario_grupo, horarios.salon,
  72. fechas.registro_fecha_ideal,
  73. estado_supervisor.estado_supervisor_id as estado_supervisor_id,
  74. estado_supervisor.nombre as nombre,
  75. estado_supervisor.estado_color as estado_color,
  76. estado_supervisor.estado_icon as estado_icon,
  77. justificador.usuario_nombre as justificador_nombre,
  78. justificador.usuario_clave as justificador_clave,
  79. facultad.facultad_nombre as justificador_facultad,
  80. rol.rol_titulo as justificador_rol,
  81. registro.reposicion_id,
  82. reposicion_fecha,
  83. reposicion_hora,
  84. salon_reposicion.salon as reposicion_salon,
  85. CASE WHEN registro_retardo THEN 'warning' ELSE 'primary' END as color
  86. FROM horarios
  87. JOIN fechas using (horario_id)
  88. JOIN horario_profesor using (horario_id)
  89. JOIN profesor using (profesor_id)
  90. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  91. LEFT JOIN reposicion USING (reposicion_id)
  92. LEFT JOIN salon as salon_reposicion ON salon_reposicion.salon_id = reposicion.salon_id
  93. join estado_supervisor ON estado_supervisor.estado_supervisor_id = COALESCE(registro.estado_supervisor_id, 0)
  94. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  95. LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
  96. LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
  97. left join facultad on facultad.facultad_id = justificador.facultad_id
  98. WHERE (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
  99. GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(:fecha_fin, PERIODO_FECHA_FIN, HORARIO_FECHA_FIN)
  100. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  101. $params
  102. );
  103. // $user->print_to_log(json_encode($params));
  104. echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  105. } else {
  106. http_response_code(405);
  107. echo json_encode(['error' => 'method not allowed']);
  108. exit;
  109. }
  110. } catch (PDOException $th) {
  111. http_response_code(500);
  112. echo json_encode([
  113. 'error' => $th->getMessage(),
  114. // 'query' => $db->getLastQuery(),
  115. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  116. exit;
  117. } catch (Exception $th) {
  118. http_response_code(500);
  119. echo json_encode([
  120. 'error' => $th->getMessage(),
  121. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  122. exit;
  123. }