mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
100 lines
4.8 KiB
PHP
100 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* contenus-motscles-fragment.php
|
|
*
|
|
* HTMX fragment: returns the mots-clés table for the contenus page,
|
|
* optionally filtered by a search query.
|
|
*/
|
|
require_once __DIR__ . '/../../bootstrap.php';
|
|
require_once __DIR__ . '/../../src/AdminAuth.php';
|
|
AdminAuth::requireLogin();
|
|
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
|
|
require_once __DIR__ . '/../../src/Database.php';
|
|
|
|
$searchQuery = trim($_GET['q'] ?? '');
|
|
|
|
try {
|
|
$db = new Database();
|
|
$tags = ($searchQuery !== '') ? $db->searchTags($searchQuery) : $db->getAllTagsWithCount();
|
|
} catch (Exception $e) {
|
|
die('<div class="flash-error">Erreur : ' . htmlspecialchars($e->getMessage()) . '</div>');
|
|
}
|
|
?>
|
|
<div id="motscles-bulk-actions" class="admin-bulk-actions" style="display:none;position:sticky;top:0;z-index:10">
|
|
<strong><span id="motscles-selected-count">0</span> mot(s)-clé(s) sélectionné(s)</strong>
|
|
<div class="admin-bulk-btns">
|
|
<button type="button" class="btn btn--sm btn--secondary" onclick="motsclesCancelSelection()" title="Annuler la sélection">
|
|
<img src="/assets/icons/x-close.svg" width="32" height="32" alt="" aria-hidden="true">
|
|
Annuler
|
|
</button>
|
|
<button type="button" class="btn btn--sm btn--red admin-btn-delete"
|
|
onclick="motsclesConfirmBulkDelete()"
|
|
title="Supprimer les mots-clés sélectionnés">
|
|
<img src="/assets/icons/trash.svg" width="32" height="32" alt="" aria-hidden="true">
|
|
Supprimer
|
|
</button>
|
|
<button type="button" class="btn btn--sm btn--warning admin-btn-merge"
|
|
onclick="motsclesConfirmBulkMerge()"
|
|
title="Fusionner les mots-clés sélectionnés">
|
|
<img src="/assets/icons/link-chain.svg" width="32" height="32" alt="" aria-hidden="true">
|
|
Fusionner
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="motscles-bulk-form" method="post" action="actions/tag.php">
|
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
|
<input type="hidden" name="action" value="merge_bulk">
|
|
<input type="hidden" name="return" value="/admin/contenus.php">
|
|
<input type="hidden" name="target_id" id="motscles-bulk-target" value="">
|
|
<div id="motscles-bulk-checkboxes"></div>
|
|
</form>
|
|
|
|
<table class="admin-table--sticky">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" style="width:1%"><input type="checkbox" onchange="motsclesToggleAll(this)"></th>
|
|
<th scope="col">Nom</th>
|
|
<th scope="col" style="width:1%;white-space:nowrap">TFE Associé</th>
|
|
<th scope="col" style="width:1%">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($tags)): ?>
|
|
<tr><td colspan="4" class="admin-empty">Aucun mot-clé trouvé.</td></tr>
|
|
<?php else: ?>
|
|
<?php foreach ($tags as $tag): ?>
|
|
<tr>
|
|
<td style="width:1%"><input type="checkbox" name="selected_tags[]" value="<?= (int)$tag['id'] ?>" onchange="motsclesUpdateBulk()"></td>
|
|
<td id="motscles-name-<?= (int)$tag['id'] ?>" data-name="<?= htmlspecialchars($tag['name']) ?>">
|
|
<span class="tag-name-cell"><?= htmlspecialchars($tag['name']) ?></span>
|
|
<button type="button" class="admin-icon-btn admin-icon-btn--edit" title="Renommer"
|
|
onclick="motsclesStartRename(<?= (int)$tag['id'] ?>)">
|
|
<img src="/assets/icons/pencil-note.svg" width="32" height="32" alt="" aria-hidden="true">
|
|
</button>
|
|
</td>
|
|
<td class="admin-tags-count" style="width:1%;white-space:nowrap"><?= (int)$tag['thesis_count'] ?></td>
|
|
<td class="admin-actions-col" style="width:1%">
|
|
<div class="admin-actions">
|
|
<form method="post" action="actions/tag.php" class="admin-inline-form">
|
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
|
<input type="hidden" name="action" value="delete">
|
|
<input type="hidden" name="return" value="/admin/contenus.php">
|
|
<input type="hidden" name="tag_id" value="<?= (int)$tag['id'] ?>">
|
|
<button type="button" class="admin-icon-btn admin-icon-btn--delete" title="Supprimer"
|
|
onclick="motsclesConfirmDelete(this, <?= htmlspecialchars(json_encode($tag['name']), ENT_QUOTES) ?>)">
|
|
<img src="/assets/icons/trash.svg" width="32" height="32" alt="" aria-hidden="true">
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|