File: /home/storage/5/78/dd/wicomm2/public_html/clientes/performance-healthcheck/index.php
<?php
declare(strict_types=1);
require __DIR__ . '/config.php';
$config = app_config();
$items = [];
$error = null;
try {
$rows = md_search_clients($config, 200);
$items = array_values(array_filter(array_map(function($r) {
$id = $r['id'] ?? $r['Id'] ?? $r['documentId'] ?? null;
if (!$id) return null;
return [
'id' => (string)$id,
'client_name' => (string)($r['client_name'] ?? ''),
'client_url' => (string)($r['client_url'] ?? ''),
'client_plataform' => (string)($r['client_plataform'] ?? ''),
];
}, $rows), fn($x) => $x !== null));
} catch (Throwable $e) {
$error = $e->getMessage();
}
function h(string $v): string {
return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
}
?>
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Performance Check</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main class="wrap">
<header class="top">
<div>
<h1>Escolher loja</h1>
<p class="muted">Selecione um cliente da entidade AP para ver o histórico e executar novas análises.</p>
</div>
</header>
<section class="card">
<div class="row">
<input id="filter" class="input" placeholder="Buscar por nome, URL ou plataforma">
</div>
<?php if ($error): ?>
<div style="margin-top:12px" class="card">
<h2>Erro ao carregar</h2>
<p class="muted"><?php echo h($error); ?></p>
<p class="muted">Valide VTEX_ACCOUNT, VTEX_APP_KEY, VTEX_APP_TOKEN e o acesso à entidade AP.</p>
</div>
<?php else: ?>
<div style="margin-top:12px; overflow:auto;">
<table class="table">
<thead>
<tr>
<th>Cliente</th>
<th>Plataforma</th>
<th>Ações</th>
</tr>
</thead>
<tbody id="clients">
<?php foreach ($items as $it): ?>
<?php var_dump($it) ?>
<tr>
<td>
<b><?php echo h($it['client_name']); ?></b>
<div class="muted"><?php echo h($it['client_url']); ?></div>
</td>
<td><?php echo h($it['client_plataform']); ?></td>
<td>
<a class="btn" href="result.php?id=<?php echo rawurlencode($it['id']); ?>">Ver histórico</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php if (!$items): ?>
<p style="margin-top:12px" class="muted">Nenhum registro encontrado na entidade AP.</p>
<?php endif; ?>
<?php endif; ?>
</section>
</main>
<script>
(function() {
const input = document.getElementById('filter');
const tbody = document.getElementById('clients');
if (!input || !tbody) return;
input.addEventListener('input', function() {
const term = (input.value || '').toLowerCase().trim();
const rows = tbody.querySelectorAll('tr');
rows.forEach(tr => {
const text = (tr.textContent || '').toLowerCase();
tr.style.display = text.includes(term) ? '' : 'none';
});
});
})();
</script>
</body>
</html>