periodo_datos.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
  17. http_response_code(405);
  18. die(json_encode(['error' => 'method not allowed']));
  19. }
  20. const JSON_OPTIONS = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR;
  21. try {
  22. $data = $db->querySingle("SELECT *, LEAST(periodo_fecha_fin, CURRENT_DATE) as fecha_final FROM periodo WHERE periodo_id = ?", array($user->periodo_id));
  23. $last_query = [
  24. 'query' => $db->getLastQuery(),
  25. ];
  26. echo json_encode($data, JSON_OPTIONS);
  27. } catch (PDOException $th) {
  28. http_response_code(500);
  29. echo json_encode([
  30. 'error' => $th->getMessage(),
  31. 'query' => $db->getLastQuery(),
  32. ], JSON_OPTIONS);
  33. exit;
  34. } catch (Exception $th) {
  35. http_response_code(500);
  36. echo json_encode([
  37. 'error' => $th->getMessage(),
  38. ], JSON_OPTIONS);
  39. exit;
  40. }