action_auditoria.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. $baseDate = $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null;
  19. $params = [
  20. ':periodo_id' => $user->periodo_id,
  21. ':facultad_id' => $user->facultad['facultad_id'],
  22. ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? date('Y-m-d'),
  23. ':fecha_fin' => $baseDate ? date('Y-m-d H:i:s', strtotime($baseDate . ' +24 hours')) : date('Y-m-d H:i:s'),
  24. ];
  25. $data = $db->query(
  26. "WITH horarios AS (
  27. SELECT
  28. horario_id,
  29. horario_fecha_inicio,
  30. horario_fecha_fin,
  31. horario_grupo,
  32. horario_hora,
  33. periodo_fecha_inicio,
  34. periodo_fecha_fin,
  35. salon,
  36. materia_nombre as materia,
  37. carrera_nombre as carrera,
  38. facultad_nombre as facultad,
  39. nivel_nombre as nivel,
  40. horario_hora + duracion_interval as horario_fin
  41. FROM horario
  42. left JOIN materia USING (materia_id)
  43. JOIN carrera USING (carrera_id)
  44. JOIN nivel USING (nivel_id)
  45. JOIN facultad ON facultad.facultad_id = carrera.facultad_id
  46. JOIN PERIODO_CARRERA USING (carrera_id)
  47. JOIN PERIODO USING (periodo_id)
  48. JOIN SALON USING (salon_id)
  49. JOIN duracion USING (duracion_id)
  50. WHERE (periodo_id, facultad.facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad.facultad_id))
  51. ),
  52. fechas AS (
  53. SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
  54. FROM horarios h
  55. ),
  56. sin_registro AS (
  57. SELECT * FROM ESTADO_SUPERVISOR WHERE (estado_color, estado_icon) = ('dark', 'ing-cancelar')
  58. )
  59. SELECT
  60. usuario.usuario_nombre,
  61. registro.registro_id, registro.registro_fecha, registro.registro_retardo, registro.registro_justificada, comentario, registro_fecha_supervisor justificacion, registro_fecha_justificacion,
  62. profesor.profesor_id, profesor_nombre, profesor_clave, profesor_correo,
  63. horarios.*,
  64. registro_fecha_ideal,
  65. COALESCE(estado_supervisor.estado_supervisor_id, sin_registro.estado_supervisor_id) as estado_supervisor_id,
  66. COALESCE(estado_supervisor.nombre, sin_registro.nombre) as nombre,
  67. COALESCE(estado_supervisor.estado_color, sin_registro.estado_color) as estado_color,
  68. COALESCE(estado_supervisor.estado_icon, sin_registro.estado_icon) as estado_icon,
  69. justificador.usuario_nombre as justificador_nombre,
  70. justificador.usuario_clave as justificador_clave,
  71. facultad.facultad_nombre as justificador_facultad,
  72. rol.rol_titulo as justificador_rol
  73. FROM horarios
  74. JOIN fechas using (horario_id)
  75. JOIN horario_profesor using (horario_id)
  76. JOIN profesor using (profesor_id)
  77. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  78. LEFT join estado_supervisor using (estado_supervisor_id)
  79. CROSS JOIN sin_registro
  80. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  81. LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
  82. LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
  83. left join facultad on facultad.facultad_id = justificador.facultad_id
  84. WHERE (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
  85. GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(:fecha_fin, PERIODO_FECHA_FIN, HORARIO_FECHA_FIN)
  86. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  87. $params
  88. );
  89. // $user->print_to_log(json_encode($params));
  90. echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  91. } else {
  92. http_response_code(405);
  93. echo json_encode(['error' => 'method not allowed']);
  94. exit;
  95. }
  96. } catch (PDOException $th) {
  97. http_response_code(500);
  98. echo json_encode([
  99. 'error' => $th->getMessage(),
  100. // 'query' => $db->getLastQuery(),
  101. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  102. exit;
  103. } catch (Exception $th) {
  104. http_response_code(500);
  105. echo json_encode([
  106. 'error' => $th->getMessage(),
  107. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  108. exit;
  109. }