diff --git a/server/admin/licenses.php b/server/admin/licenses.php index 8a586cc..c800d74 100644 --- a/server/admin/licenses.php +++ b/server/admin/licenses.php @@ -78,7 +78,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { elseif ($action === 'reset_machines') { $id = (int)($_POST['id'] ?? 0); $db->prepare('DELETE FROM license_machines WHERE license_id = ?')->execute([$id]); - $message = "Machines libérées pour la license #{$id}."; + $message = "Toutes les machines libérées pour la license #{$id}."; + } + elseif ($action === 'remove_machine') { + $licenseId = (int)($_POST['license_id'] ?? 0); + $machineId = trim((string)($_POST['machine_id'] ?? '')); + if ($licenseId <= 0 || $machineId === '') { + throw new Exception('license_id et machine_id requis'); + } + $stmt = $db->prepare('DELETE FROM license_machines WHERE license_id = ? AND machine_id = ?'); + $stmt->execute([$licenseId, $machineId]); + $count = $stmt->rowCount(); + $shortId = substr($machineId, 0, 12); + $message = $count > 0 + ? "Machine {$shortId}… libérée pour la license #{$licenseId}." + : "Aucune machine correspondante trouvée pour license #{$licenseId}."; } } catch (Exception $e) { $message = $e->getMessage(); @@ -93,6 +107,18 @@ $licenses = $db->query( ORDER BY l.id DESC' )->fetchAll(); +// Pré-fetch toutes les machines de toutes les licenses en une seule requête, +// indexées par license_id pour l'affichage par-row sans N+1. +$allMachines = $db->query( + 'SELECT license_id, machine_id, machine_label, first_seen, last_seen + FROM license_machines + ORDER BY last_seen DESC' +)->fetchAll(); +$machinesByLicense = []; +foreach ($allMachines as $m) { + $machinesByLicense[(int)$m['license_id']][] = $m; +} + Layout::header('Licenses', 'licenses'); ?>
| Machine ID (SHA-256) | +Label | +1ère activation | +Dernière vue | +Action | +
|---|---|---|---|---|
+
+ = htmlspecialchars(substr($mid, 0, 16)) ?>…= htmlspecialchars(substr($mid, -8)) ?>
+
+ |
+ = htmlspecialchars($m['machine_label'] ?? '—') ?> | += date('d/m/Y H:i', strtotime($m['first_seen'])) ?> | ++ = date('d/m/Y H:i', strtotime($m['last_seen'])) ?> + + stale + + | ++ + | +