action_auditoria.php 3.2 KB

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