mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
- Add searchLanguages, getAllLanguagesWithCount, renameLanguage, mergeLanguage, deleteLanguage to Database - Create actions/language.php handler with rename/merge/merge_bulk/delete actions - Add merge_bulk action to actions/tag.php - Add Mots-clés section to contenus template with HTMX search, select checkboxes, rename/delete/merge buttons, and multi-select merge toolbar - Add Langues section to contenus template with same pattern - Create contenus-tags-fragment.php and contenus-languages-fragment.php HTMX fragments - Remove form-settings- from flat-fieldset CSS selector so fieldsets in contenus retain border/padding - contenus.php: add 'Gérer les mots-clés' link to /admin/tags.php - contenus.php: add Langues fieldset with HTMX search + table (rename/merge/delete/bulk) - tags.php: add HTMX search bar, checkbox column, bulk merge toolbar - Create tags-fragment.php and contenus-langues-fragment.php for HTMX - Remove tab component and associated CSS - Simplify JS: separate tags/langues-prefixed functions - Fix redirects: tag.php defaults to /admin/tags.php, supports return override - Keep tags.php standalone page and Mots-clés button unchanged
73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../../bootstrap.php';
|
|
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
|
AdminAuth::requireLogin();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST'
|
|
|| !isset($_POST['csrf_token'], $_SESSION['csrf_token'])
|
|
|| !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
|
|
http_response_code(403);
|
|
die("Accès refusé.");
|
|
}
|
|
|
|
require_once __DIR__ . '/../../../src/Database.php';
|
|
require_once __DIR__ . '/../../../src/AdminLogger.php';
|
|
require_once __DIR__ . '/../../../src/ErrorHandler.php';
|
|
|
|
try {
|
|
$db = new Database();
|
|
$logger = AdminLogger::make();
|
|
$action = $_POST['action'] ?? '';
|
|
|
|
switch ($action) {
|
|
case 'rename':
|
|
$id = filter_var($_POST['language_id'] ?? '', FILTER_VALIDATE_INT);
|
|
$newName = trim($_POST['new_name'] ?? '');
|
|
if (!$id || $newName === '') throw new Exception("Paramètres invalides.");
|
|
$db->renameLanguage($id, $newName);
|
|
break;
|
|
|
|
case 'merge':
|
|
$sourceId = filter_var($_POST['source_id'] ?? '', FILTER_VALIDATE_INT);
|
|
$targetId = filter_var($_POST['target_id'] ?? '', FILTER_VALIDATE_INT);
|
|
if (!$sourceId || !$targetId) throw new Exception("Paramètres invalides.");
|
|
$db->mergeLanguage($sourceId, $targetId);
|
|
break;
|
|
|
|
case 'merge_bulk':
|
|
$targetId = filter_var($_POST['target_id'] ?? '', FILTER_VALIDATE_INT);
|
|
$sourceIds = isset($_POST['selected_langs']) && is_array($_POST['selected_langs'])
|
|
? array_map('intval', $_POST['selected_langs'])
|
|
: [];
|
|
if (!$targetId || empty($sourceIds)) throw new Exception("Paramètres invalides.");
|
|
$sourceIds = array_values(array_diff($sourceIds, [$targetId]));
|
|
if (empty($sourceIds)) throw new Exception("Aucune source à fusionner.");
|
|
foreach ($sourceIds as $sid) {
|
|
$db->mergeLanguage($sid, $targetId);
|
|
}
|
|
break;
|
|
|
|
case 'delete':
|
|
$id = filter_var($_POST['language_id'] ?? '', FILTER_VALIDATE_INT);
|
|
if (!$id) throw new Exception("ID invalide.");
|
|
$db->deleteLanguage($id);
|
|
break;
|
|
|
|
default:
|
|
throw new Exception("Action inconnue.");
|
|
}
|
|
|
|
App::flash('success', "Opération effectuée.");
|
|
} catch (Exception $e) {
|
|
ErrorHandler::log('language', $e);
|
|
App::flash('error', ErrorHandler::userMessage($e));
|
|
}
|
|
|
|
$redirect = '/admin/contenus.php';
|
|
// Allow the caller to override the redirect
|
|
if (!empty($_POST['return']) && str_starts_with($_POST['return'], '/')) {
|
|
$redirect = $_POST['return'];
|
|
}
|
|
header('Location: ' . $redirect);
|
|
exit();
|