159 lines
7.0 KiB
PHP
159 lines
7.0 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 if (isAdmin()): ?>
|
|
<hr class="my-5">
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2 class="h4 mb-0">Types de tags</h2>
|
|
</div>
|
|
|
|
<div class="row g-4">
|
|
|
|
<!-- Types existants -->
|
|
<div class="col-lg-9">
|
|
<?php if (empty($tagTypes)): ?>
|
|
<p class="text-muted">Aucun type de tag défini.</p>
|
|
<?php else: ?>
|
|
<div class="d-flex flex-column gap-2">
|
|
<?php foreach ($tagTypes as $_key => $_label): ?>
|
|
<div class="card">
|
|
<div class="card-body py-2 px-3 d-flex align-items-center gap-3">
|
|
<code class="text-muted small" style="min-width:8rem"><?= htmlspecialchars($_key) ?></code>
|
|
<strong class="flex-grow-1"><?= htmlspecialchars($_label) ?></strong>
|
|
<form method="POST" action="/?action=delete_tag_type"
|
|
data-confirm="Supprimer le type «<?= htmlspecialchars($_label) ?>» ? Les tags associés aux articles ne seront pas supprimés.">
|
|
<input type="hidden" name="type_key" value="<?= htmlspecialchars($_key) ?>">
|
|
<button type="submit" class="btn btn-outline-danger btn-sm">Supprimer</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Nouveau type -->
|
|
<div class="col-lg-3">
|
|
<h5 class="mb-3">Nouveau type</h5>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<form method="POST" action="/?action=create_tag_type">
|
|
<div class="mb-2">
|
|
<label class="form-label small fw-semibold">Identifiant</label>
|
|
<input type="text" name="type_key" class="form-control form-control-sm font-monospace"
|
|
placeholder="ex : logiciels" required
|
|
pattern="[a-z0-9_]+" title="Minuscules, chiffres et _ uniquement">
|
|
<div class="form-text">Minuscules, chiffres, _ (sans accent)</div>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label small fw-semibold">Libellé</label>
|
|
<input type="text" name="type_label" class="form-control form-control-sm"
|
|
placeholder="ex : Logiciels" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary btn-sm w-100">Créer</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$content = ob_get_clean();
|
|
$title = 'Catégories';
|
|
include __DIR__ . '/layout.php';
|