'unauthorized'])); } $user = unserialize($_SESSION['user']); // check method if ($_SERVER['REQUEST_METHOD'] !== 'GET') { http_response_code(405); die(json_encode(['error' => 'method not allowed'])); } const JSON_OPTIONS = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR; try { $data = $db->querySingle("SELECT *, LEAST(periodo_fecha_fin, CURRENT_DATE) as fecha_final FROM periodo WHERE periodo_id = ?", array($user->periodo_id)); $last_query = [ 'query' => $db->getLastQuery(), ]; echo json_encode($data, JSON_OPTIONS); } catch (PDOException $th) { http_response_code(500); echo json_encode([ 'error' => $th->getMessage(), 'query' => $db->getLastQuery(), ], JSON_OPTIONS); exit; } catch (Exception $th) { http_response_code(500); echo json_encode([ 'error' => $th->getMessage(), ], JSON_OPTIONS); exit; }