action_horario.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if (!isset($_GET['profesor_id'])) {
  19. throw new Exception('missing parameters');
  20. }
  21. $data = $db->query(
  22. "SELECT *, (EXTRACT(EPOCH FROM (horario_fin - horario_hora) ) / EXTRACT(EPOCH FROM interval '15 minute'))::INT AS bloques
  23. FROM horario_view
  24. JOIN horario_profesor ON horario_profesor.horario_id = horario_view.horario_id
  25. WHERE horario_profesor.profesor_id = :profesor_id
  26. AND (facultad_id = :facultad_id OR :facultad_id IS NULL)",
  27. [
  28. 'profesor_id' => $_GET['profesor_id'],
  29. 'facultad_id' => $user->facultad['facultad_id'],
  30. ]
  31. );
  32. $last_query = [
  33. 'query' => $db->getLastQuery(),
  34. ];
  35. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  36. } else {
  37. throw new Exception('invalid method');
  38. }
  39. } catch (PDOException $th) {
  40. http_response_code(500);
  41. echo json_encode([
  42. 'error' => $th->getMessage(),
  43. 'query' => $db->getLastQuery(),
  44. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  45. exit;
  46. } catch (Exception $th) {
  47. http_response_code(500);
  48. echo json_encode([
  49. 'error' => $th->getMessage(),
  50. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  51. exit;
  52. }