<?php
/**
 * View update check log
 * Access: https://bwgeo.demoing.info/wp-content/uploads/plugin-updates/view-log.php
 */

// Simple auth - require secret parameter
if (($_GET['key'] ?? '') !== 'bw2026schema') {
    http_response_code(403);
    die('Access denied. Add ?key=bw2026schema');
}

$log_file = __DIR__ . '/update-log.json';
$log = file_exists($log_file) ? json_decode(file_get_contents($log_file), true) : [];

header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
    <title>BW AI Schema Pro - Update Check Log</title>
    <style>
        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; margin: 20px; }
        table { border-collapse: collapse; width: 100%; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background: #f5f5f5; }
        tr:hover { background: #f9f9f9; }
        .old { color: #999; }
        .current { color: green; font-weight: bold; }
        .outdated { color: orange; }
        h1 { margin-bottom: 5px; }
        .stats { color: #666; margin-bottom: 20px; }
    </style>
</head>
<body>
    <h1>BW AI Schema Pro - Update Check Log</h1>
    <p class="stats"><?= count($log) ?> sites tracked | Current version: 2.0.9</p>
    
    <table>
        <tr>
            <th>Site</th>
            <th>Version</th>
            <th>WP</th>
            <th>Last Check</th>
            <th>First Seen</th>
            <th>Checks</th>
        </tr>
        <?php foreach ($log as $domain => $info): 
            $version_class = $info['installed_version'] === '2.0.9' ? 'current' : 'outdated';
        ?>
        <tr>
            <td><a href="<?= htmlspecialchars($info['site_url']) ?>" target="_blank"><?= htmlspecialchars($domain) ?></a></td>
            <td class="<?= $version_class ?>"><?= htmlspecialchars($info['installed_version']) ?></td>
            <td><?= htmlspecialchars($info['wp_version']) ?></td>
            <td><?= htmlspecialchars($info['last_check']) ?></td>
            <td><?= htmlspecialchars($info['first_seen']) ?></td>
            <td><?= htmlspecialchars($info['checks']) ?></td>
        </tr>
        <?php endforeach; ?>
    </table>
    
    <?php if (empty($log)): ?>
    <p>No sites have checked for updates yet.</p>
    <?php endif; ?>
</body>
</html>
