<?php
require_once(__DIR__ . '/../json_db.php');
session_start();
header('Content-Type: application/json');

$userId = isset($_POST['user_id']) ? intval($_POST['user_id']) : 0;
if ($userId <= 0) {
    echo json_encode(['ok' => false]);
    exit;
}

// Save last viewed timestamp = now
$now = date('Y-m-d H:i:s');
$jsonDB->update('users', $userId, ['last_viewed_at' => $now]);

echo json_encode(['ok' => true, 'last_viewed_at' => $now]);
