action_avisos.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. 'SELECT * FROM AVISO',
  20. [
  21. ':facultad_id' => $user->facultad['facultad_id'],
  22. ':fecha_inicio' => $_GET['fecha'] ?? $_GET['fecha_inicio'] ?? null,
  23. ':fecha_fin' => $_GET['fecha'] ?? $_GET['fecha_fin'] ?? null,
  24. ]
  25. );
  26. $last_query = [
  27. 'query' => $db->getLastQuery(),
  28. ];
  29. echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  30. } else {
  31. http_response_code(405);
  32. echo json_encode(['error' => 'method not allowed']);
  33. exit;
  34. }
  35. } catch (PDOException $th) {
  36. http_response_code(500);
  37. echo json_encode([
  38. 'error' => $th->getMessage(),
  39. 'query' => $db->getLastQuery(),
  40. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR);
  41. exit;
  42. } catch (Exception $th) {
  43. http_response_code(500);
  44. echo json_encode([
  45. 'error' => $th->getMessage(),
  46. ], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  47. exit;
  48. }