action_auditoria.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.periodo_fecha_inicio,
  37. PERIODO.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_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 USING (periodo_id)
  50. JOIN SALON USING (salon_id)
  51. WHERE (PERIODO.periodo_id, facultad.facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad.facultad_id))
  52. ),
  53. fechas AS (
  54. SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
  55. FROM horarios h
  56. )
  57. SELECT
  58. usuario.usuario_nombre,
  59. registro.registro_id,
  60. registro.registro_fecha,
  61. registro.registro_retardo,
  62. registro.registro_justificada,
  63. registro_fecha_supervisor,
  64. justificacion,
  65. comentario,
  66. registro_fecha_justificacion,
  67. profesor.profesor_id, profesor_nombre, profesor_clave, profesor_correo,
  68. horario_id,
  69. materia, carrera, horarios.facultad_id, facultad, nivel, horario_hora, horario_fin, horario_grupo, horarios.salon,
  70. fechas.registro_fecha_ideal,
  71. estado_supervisor.estado_supervisor_id as estado_supervisor_id,
  72. estado_supervisor.nombre as nombre,
  73. estado_supervisor.estado_color as estado_color,
  74. estado_supervisor.estado_icon as estado_icon,
  75. justificador.usuario_nombre as justificador_nombre,
  76. justificador.usuario_clave as justificador_clave,
  77. facultad.facultad_nombre as justificador_facultad,
  78. rol.rol_titulo as justificador_rol,
  79. registro.reposicion_id,
  80. reposicion_fecha,
  81. reposicion_hora,
  82. salon_reposicion.salon as reposicion_salon,
  83. CASE WHEN registro_retardo THEN 'warning' ELSE 'primary' END as color
  84. FROM horarios
  85. JOIN fechas using (horario_id)
  86. JOIN horario_profesor using (horario_id)
  87. JOIN profesor using (profesor_id)
  88. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  89. LEFT JOIN reposicion USING (reposicion_id)
  90. LEFT JOIN salon as salon_reposicion ON salon_reposicion.salon_id = reposicion.salon_id
  91. join estado_supervisor ON estado_supervisor.estado_supervisor_id = COALESCE(registro.estado_supervisor_id, 0)
  92. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  93. LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
  94. LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
  95. left join facultad on facultad.facultad_id = justificador.facultad_id
  96. WHERE (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
  97. GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(:fecha_fin, PERIODO_FECHA_FIN, HORARIO_FECHA_FIN)
  98. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  99. $params
  100. );
  101. // $user->print_to_log(json_encode($params));
  102. echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  103. } else {
  104. http_response_code(405);
  105. echo json_encode(['error' => 'method not allowed']);
  106. exit;
  107. }
  108. } catch (PDOException $th) {
  109. http_response_code(500);
  110. echo json_encode([
  111. 'error' => $th->getMessage(),
  112. // 'query' => $db->getLastQuery(),
  113. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  114. exit;
  115. } catch (Exception $th) {
  116. http_response_code(500);
  117. echo json_encode([
  118. 'error' => $th->getMessage(),
  119. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  120. exit;
  121. }