action_auditoria.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?
  2. #input $_GET['id_espacio_sgu']
  3. #output rutas: [ ...ruta, salones: [{...salon}] ]
  4. header('Content-Type: application/json charset=utf-8');
  5. $information = [
  6. 'GET' => [
  7. #'periodo_id',
  8. ],
  9. ];
  10. $ruta = "../";
  11. require_once "../class/c_login.php";
  12. // check method
  13. try {
  14. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  15. array_walk($information['GET'], function ($value) {
  16. if (!array_key_exists($value, $_GET)) {
  17. http_response_code(400);
  18. echo json_encode(['error' => "$value is required"]);
  19. exit;
  20. }
  21. });
  22. $data = $db->query(
  23. "WITH horarios AS (
  24. SELECT * FROM horario_view WHERE (periodo_id, facultad_id) = (:periodo_id, :facultad_id)
  25. ),
  26. fechas AS (
  27. SELECT fechas_clase(h.horario_id) as registro_fecha_ideal, h.horario_id
  28. FROM horarios h
  29. )
  30. SELECT estado_supervisor.*, usuario.*, registro.*, profesor.*, horarios.*, fechas.*
  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. [
  39. ':periodo_id' => $_GET['periodo_id'],
  40. ':facultad_id' => $_GET['facultad_id'],
  41. ]
  42. );
  43. $last_query = [
  44. 'query' => $db->getLastQuery(),
  45. ];
  46. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  47. } else {
  48. http_response_code(405);
  49. echo json_encode(['error' => 'method not allowed']);
  50. exit;
  51. }
  52. } catch (PDOException $th) {
  53. http_response_code(500);
  54. echo json_encode([
  55. 'error' => $th->getMessage(),
  56. 'query' => $db->getLastQuery(),
  57. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  58. exit;
  59. } catch (Exception $th) {
  60. http_response_code(500);
  61. echo json_encode([
  62. 'error' => $th->getMessage(),
  63. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  64. exit;
  65. }