action_auditoria.php 6.0 KB

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