action_auditoria.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 * FROM horario_view WHERE (periodo_id, facultad_id) = (:periodo_id, COALESCE(:facultad_id, facultad_id))
  21. ),
  22. fechas AS (
  23. SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id
  24. FROM horarios h
  25. ),
  26. sin_registro AS (
  27. SELECT * FROM ESTADO_SUPERVISOR WHERE (estado_color, estado_icon) = ('dark', 'ing-cancelar')
  28. )
  29. SELECT
  30. usuario.*, registro.*, profesor.*, horarios.*, fechas.*,
  31. coalesce(estado_supervisor.estado_supervisor_id, sin_registro.estado_supervisor_id) as estado_supervisor_id,
  32. coalesce(estado_supervisor.nombre, sin_registro.nombre) as nombre,
  33. coalesce(estado_supervisor.estado_color, sin_registro.estado_color) as estado_color,
  34. coalesce(estado_supervisor.estado_icon, sin_registro.estado_icon) as estado_icon,
  35. justificador.usuario_nombre as justificador_nombre,
  36. justificador.usuario_clave as justificador_clave,
  37. facultad.facultad_nombre as justificador_facultad,
  38. rol.rol_titulo as justificador_rol
  39. FROM horarios
  40. JOIN fechas using (horario_id)
  41. JOIN horario_profesor using (horario_id)
  42. JOIN profesor using (profesor_id)
  43. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  44. LEFT join estado_supervisor using (estado_supervisor_id)
  45. CROSS JOIN sin_registro
  46. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  47. LEFT JOIN USUARIO JUSTIFICADOR ON JUSTIFICADOR.usuario_id = REGISTRO.justificador_id
  48. LEFT JOIN ROL on ROL.rol_id = justificador.rol_id
  49. left join facultad on facultad.facultad_id = justificador.facultad_id
  50. 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))
  51. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  52. [
  53. ':periodo_id' => $user->periodo_id,
  54. ':facultad_id' => $user->facultad['facultad_id'],
  55. ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? null,
  56. ':fecha_fin' => $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null,
  57. ]
  58. );
  59. $last_query = [
  60. 'query' => $db->getLastQuery(),
  61. ];
  62. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  63. } else {
  64. http_response_code(405);
  65. echo json_encode(['error' => 'method not allowed']);
  66. exit;
  67. }
  68. } catch (PDOException $th) {
  69. http_response_code(500);
  70. echo json_encode([
  71. 'error' => $th->getMessage(),
  72. 'query' => $db->getLastQuery(),
  73. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  74. exit;
  75. } catch (Exception $th) {
  76. http_response_code(500);
  77. echo json_encode([
  78. 'error' => $th->getMessage(),
  79. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  80. exit;
  81. }