<?php
$user_id = $_SESSION['user_id'];

// 获取登录记录
$logs = $db->fetchAll("SELECT * FROM user_login_log 
                       WHERE user_id = $user_id 
                       ORDER BY id DESC LIMIT 50");
?>

<div class="page-header">
    <h2>登录记录</h2>
    <p>最近50次登录记录</p>
</div>

<div style="overflow-x: auto;">
    <table class="data-table" style="width: 100%;">
        <thead>
            <tr>
                <th>登录时间</th>
                <th>IP地址</th>
                <th>位置</th>
                <th>设备</th>
            </tr>
        </thead>
        <tbody>
            <?php if (empty($logs)): ?>
                <tr>
                    <td colspan="4" style="text-align: center;">暂无登录记录</td>
                </tr>
            <?php else: ?>
                <?php foreach ($logs as $log): ?>
                    <tr>
                        <td><?php echo $log['created_at']; ?></td>
                        <td><?php echo $log['ip']; ?></td>
                        <td><?php echo htmlspecialchars($log['city'] ?: '未知'); ?></td>
                        <td><?php echo htmlspecialchars($log['device'] ?: '未知'); ?></td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>