action_auditoria.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. FROM horarios
  28. JOIN fechas using (horario_id)
  29. JOIN horario_profesor using (horario_id)
  30. JOIN profesor using (profesor_id)
  31. LEFT JOIN registro USING (horario_id, registro_fecha_ideal, profesor_id)
  32. left join estado_supervisor using (estado_supervisor_id)
  33. LEFT JOIN USUARIO ON USUARIO.usuario_id = REGISTRO.supervisor_id
  34. ORDER BY fechas.registro_fecha_ideal DESC, horarios.horario_id, profesor_nombre",
  35. [
  36. ':periodo_id' => $user->periodo_id,
  37. ':facultad_id' => $user->facultad['facultad_id'],
  38. ]
  39. );
  40. $last_query = [
  41. 'query' => $db->getLastQuery(),
  42. ];
  43. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  44. } else {
  45. http_response_code(405);
  46. echo json_encode(['error' => 'method not allowed']);
  47. exit;
  48. }
  49. } catch (PDOException $th) {
  50. http_response_code(500);
  51. echo json_encode([
  52. 'error' => $th->getMessage(),
  53. 'query' => $db->getLastQuery(),
  54. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  55. exit;
  56. } catch (Exception $th) {
  57. http_response_code(500);
  58. echo json_encode([
  59. 'error' => $th->getMessage(),
  60. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  61. exit;
  62. }