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();