100 lines
4.4 KiB
PHP
100 lines
4.4 KiB
PHP
<?php ob_start(); ?>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="mb-0">Catégories</h1>
|
|
<a href="/" class="btn btn-secondary btn-sm">← Retour</a>
|
|
</div>
|
|
|
|
<div class="row g-4">
|
|
|
|
<!-- Liste des catégories existantes -->
|
|
<div class="col-lg-9">
|
|
<h5 class="mb-3">Catégories existantes</h5>
|
|
|
|
<?php if (empty($cats)): ?>
|
|
<p class="text-muted">Aucune catégorie définie.</p>
|
|
<?php else: ?>
|
|
<div class="d-flex flex-column gap-2">
|
|
<?php foreach ($cats as $cat => $count):
|
|
$gradient = coverGradient($cat, $cats); ?>
|
|
<div class="card">
|
|
<div class="card-body py-2 px-3 d-flex align-items-center gap-3">
|
|
|
|
<!-- Swatch -->
|
|
<div style="width:40px;height:40px;border-radius:8px;flex-shrink:0;background:<?= htmlspecialchars($gradient) ?>"></div>
|
|
|
|
<!-- Nom + count -->
|
|
<div style="min-width:140px">
|
|
<strong><?= htmlspecialchars($cat) ?></strong>
|
|
<small class="text-muted ms-2"><?= $count ?> article<?= $count > 1 ? 's' : '' ?></small>
|
|
</div>
|
|
|
|
<!-- Renommer -->
|
|
<form method="POST" action="/?action=rename_category"
|
|
class="d-flex align-items-center gap-2 flex-grow-1"
|
|
data-confirm="Renommer « <?= htmlspecialchars($cat) ?> » ?">
|
|
<input type="hidden" name="old" value="<?= htmlspecialchars($cat) ?>">
|
|
<input type="text" name="new" class="form-control form-control-sm"
|
|
placeholder="Nouveau nom" required>
|
|
<button type="submit" class="btn btn-outline-primary btn-sm text-nowrap">Renommer</button>
|
|
</form>
|
|
|
|
<!-- Privée -->
|
|
<?php $isPriv = in_array($cat, $privateCats, true); ?>
|
|
<form method="POST" action="/?action=toggle_private_category">
|
|
<input type="hidden" name="category" value="<?= htmlspecialchars($cat) ?>">
|
|
<button type="submit"
|
|
class="btn btn-sm text-nowrap <?= $isPriv ? 'btn-secondary' : 'btn-outline-secondary' ?>">
|
|
🔒 <?= $isPriv ? 'Privée' : 'Publique' ?>
|
|
</button>
|
|
</form>
|
|
|
|
<!-- Supprimer -->
|
|
<form method="POST" action="/?action=delete_category"
|
|
data-confirm="Retirer la catégorie « <?= htmlspecialchars($cat) ?> » de tous les articles ?">
|
|
<input type="hidden" name="category" value="<?= htmlspecialchars($cat) ?>">
|
|
<button type="submit" class="btn btn-outline-danger btn-sm">Supprimer</button>
|
|
</form>
|
|
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Palette & Nouvelle catégorie -->
|
|
<div class="col-lg-3">
|
|
<h5 class="mb-3">Nouvelle catégorie</h5>
|
|
<div class="card mb-3">
|
|
<div class="card-body">
|
|
<p class="text-muted small mb-3">
|
|
Créez une catégorie en l'assignant à un article.
|
|
La prochaine reçoit la couleur n°<?= count($cats) % 16 + 1 ?>.
|
|
</p>
|
|
|
|
<!-- Palette des 16 couleurs -->
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<?php
|
|
$nextIdx = count($cats) % 16;
|
|
foreach (COLOR_PALETTE_16 as $i => $rgb):
|
|
$g = _paletteGradient($rgb, 0);
|
|
$active = $i === $nextIdx;
|
|
?>
|
|
<div title="Couleur <?= $i + 1 ?>"
|
|
style="width:28px;height:28px;border-radius:6px;background:<?= htmlspecialchars($g) ?>;
|
|
<?= $active ? 'outline:2px solid #0d6efd;outline-offset:2px' : 'opacity:.75' ?>">
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
$content = ob_get_clean();
|
|
$title = 'Catégories';
|
|
include __DIR__ . '/layout.php';
|