<?php
require 'db.php';

$stmt = $pdo->query("
    SELECT 
        .id,
        ls.user_id,
        CASE 
            WHEN ls.is_active = 1 
                 AND ls.last_activity > NOW() - INTERVAL 15 MINUTE 
            THEN 1 ELSE 0
        END AS is_online
    FROM login_sessions ls
");

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
