<?php
/**
 * (c) ININOUT & PYXIS. All Rights Reserved.
 * Wszelkie modyfikacje tego pliku wymagaja zgloszenia oraz zgody autorow.
 * Any modifications to this file require notification and consent of the authors.
 */
/**
 * i-BOK 5 - AJAX endpoint do odświeżenia sesji
 */
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/inc/session.php';
require_once __DIR__ . '/inc/security.php';

header('Content-Type: application/json');

if (empty($_SESSION['logged_in'])) {
    echo json_encode(['ok' => false, 'reason' => 'not_logged_in']);
    exit;
}

$timeout = defined('IBOK_SESSION_TIMEOUT_MINUTES') ? IBOK_SESSION_TIMEOUT_MINUTES * 60 : 1800;

if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity']) > $timeout) {
    echo json_encode(['ok' => false, 'reason' => 'expired']);
    exit;
}

$_SESSION['last_activity'] = time();
echo json_encode(['ok' => true, 'remaining' => $timeout]);
