action_auditoria.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. materia_nombre as materia,
  29. carrera_nombre as carrera,
  30. facultad_nombre as facultad,
  31. nivel_nombre as nivel,
  32. horario_hora + duracion_interval as horario_fin
  33. FROM horario
  34. left JOIN materia USING (materia_id)
  35. JOIN carrera USING (carrera_id)
  36. JOIN nivel USING (nivel_id)
  37. JOIN facultad ON facultad.facultad_id = carrera.facultad_id
  38. JOIN PERIODO_CARRERA USING (carrera_id)
  39. JOIN PERIODO USING (periodo_id)
  40. JOIN SALON USING (salon_id)
  41. JOIN duracion USING (duracion_id)
  42. WHERE (periodo_id, facultad.facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad.facultad_id))
  43. ),
  44. fechas AS (
  45. SELECT fechas_clase(h.horario_id, true) as registro_fecha_ideal, h.horario_id
  46. FROM horarios h
  47. ),
  48. sin_registro AS (
  49. SELECT * FROM ESTADO_SUPERVISOR WHERE (estado_color, estado_icon) = ('dark', 'ing-cancelar')
  50. )
  51. SELECT
  52. usuario.*, registro.*, profesor.*, horarios.*, fechas.*,
  53. COALESCE(estado_supervisor.estado_supervisor_id, sin_registro.estado_supervisor_id) as estado_supervisor_id,
  54. COALESCE(estado_supervisor.nombre, sin_registro.nombre) as nombre,
  55. COALESCE(estado_supervisor.estado_color, sin_registro.estado_color) as estado_color,
  56. COALESCE(estado_supervisor.estado_icon, sin_registro.estado_icon) as estado_icon,
  57. justificador.usuario_nombre as justificador_nombre,
  58. justificador.usuario_clave as justificador_clave,
  59. facultad.facultad_nombre as justificador_facultad,
  60. rol.rol_titulo as justificador_rol
  61. FROM horarios
  62. JOIN fechas using (horario_id)
  63. JOIN horario_profesor using (horario_id)
  64. JOIN profesor using (profesor_id)
  65. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  66. LEFT join estado_supervisor using (estado_supervisor_id)
  67. CROSS JOIN sin_registro
  68. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  69. LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
  70. LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
  71. left join facultad on facultad.facultad_id = justificador.facultad_id
  72. WHERE (fechas.registro_fecha_ideal + HORARIO_HORA) BETWEEN
  73. GREATEST(HORARIO_FECHA_INICIO, PERIODO_FECHA_INICIO, :fecha_inicio) AND LEAST(:fecha_fin, PERIODO_FECHA_FIN, HORARIO_FECHA_FIN)
  74. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  75. $params
  76. );
  77. // $user->print_to_log(json_encode($params));
  78. echo json_encode(array_merge($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  79. } else {
  80. http_response_code(405);
  81. echo json_encode(['error' => 'method not allowed']);
  82. exit;
  83. }
  84. } catch (PDOException $th) {
  85. http_response_code(500);
  86. echo json_encode([
  87. 'error' => $th->getMessage(),
  88. // 'query' => $db->getLastQuery(),
  89. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  90. exit;
  91. } catch (Exception $th) {
  92. http_response_code(500);
  93. echo json_encode([
  94. 'error' => $th->getMessage(),
  95. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  96. exit;
  97. }