prepare(
'INSERT INTO map_layers (name, layer_key, color, is_visible, sort_order, description)
VALUES (?, ?, ?, 1, (SELECT COALESCE(MAX(m2.sort_order), 0) + 1 FROM (SELECT sort_order FROM map_layers) AS m2), ?)'
);
$stmt->execute([$name, $layerKey, $color, $description]);
$feedback = 'Couche créée.';
} catch (Throwable $e) {
$feedback = 'Erreur lors de la création (clé déjà utilisée ?) : ' . $e->getMessage();
$feedbackType = 'error';
}
}
} elseif ($action === 'toggle_visibility') {
$layerId = filter_input(INPUT_POST, 'layer_id', FILTER_VALIDATE_INT);
if ($layerId) {
$stmt = $db->prepare('UPDATE map_layers SET is_visible = 1 - is_visible WHERE id = ?');
$stmt->execute([$layerId]);
$feedback = 'Visibilité mise à jour.';
}
} elseif ($action === 'update_color') {
$layerId = filter_input(INPUT_POST, 'layer_id', FILTER_VALIDATE_INT);
$color = sanitize_hex_color((string)($_POST['color'] ?? ''));
if ($layerId && $color !== null) {
$stmt = $db->prepare('UPDATE map_layers SET color = ? WHERE id = ?');
$stmt->execute([$color, $layerId]);
$feedback = 'Couleur mise à jour.';
} else {
$feedback = 'Couleur invalide.';
$feedbackType = 'error';
}
} elseif ($action === 'delete_layer') {
$layerId = filter_input(INPUT_POST, 'layer_id', FILTER_VALIDATE_INT);
$confirmed = isset($_POST['confirm']) && $_POST['confirm'] === '1';
if (!$confirmed || !$layerId) {
$feedback = 'Suppression refusée : confirmation manquante.';
$feedbackType = 'error';
} else {
$stmt = $db->prepare('DELETE FROM map_layers WHERE id = ? LIMIT 1');
$stmt->execute([$layerId]);
$feedback = $stmt->rowCount() > 0 ? 'Couche supprimée.' : 'Couche introuvable.';
}
}
}
$layers = $db->query('SELECT id, name, layer_key, color, is_visible, sort_order, description FROM map_layers ORDER BY sort_order ASC')->fetchAll(PDO::FETCH_ASSOC);
$user = current_admin_username();
?>
Couches cartographiques — NetMonster Admin
Couches cartographiques
Gérez les couches affichées sur la carte (visibilité, couleur, ordre). Toute suppression demande une confirmation explicite.
= htmlspecialchars($feedback, ENT_QUOTES, 'UTF-8') ?>
Couches existantes (= count($layers) ?>)
| Ordre |
Nom |
Clé |
Couleur |
Visible |
Description |
Actions |
| = (int)$layer['sort_order'] ?> |
= htmlspecialchars((string)$layer['name'], ENT_QUOTES, 'UTF-8') ?> |
= htmlspecialchars((string)$layer['layer_key'], ENT_QUOTES, 'UTF-8') ?> |
|
|
= htmlspecialchars((string)$layer['description'], ENT_QUOTES, 'UTF-8') ?> |
|
| Aucune couche configurée. |