diff --git a/admin/languages.php b/admin/languages.php index 94c10f1..7ec90de 100755 --- a/admin/languages.php +++ b/admin/languages.php @@ -83,6 +83,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { } catch (Exception $e) { $syncError = "Error al conectar con LibreTranslate: " . $e->getMessage() . ". Verifica que el servicio esté configurado correctamente en el archivo .env"; } + + } elseif ($action === 'toggle_telegram') { + $id = (int) $_POST['id']; + $stmt = $pdo->prepare("UPDATE supported_languages SET telegram_enabled = NOT telegram_enabled WHERE id = ? AND is_active = TRUE"); + $stmt->execute([$id]); + logActivity(getCurrentUserId(), 'toggle_telegram_language', "Idioma Telegram ID: $id"); + header('Location: languages.php'); + exit; + + } elseif ($action === 'toggle_discord') { + $id = (int) $_POST['id']; + $stmt = $pdo->prepare("UPDATE supported_languages SET discord_enabled = NOT discord_enabled WHERE id = ? AND is_active = TRUE"); + $stmt->execute([$id]); + logActivity(getCurrentUserId(), 'toggle_discord_language', "Idioma Discord ID: $id"); + header('Location: languages.php'); + exit; } } @@ -294,6 +310,8 @@ require_once __DIR__ . '/../templates/header.php'; + + @@ -310,6 +328,32 @@ require_once __DIR__ . '/../templates/header.php'; + + +
+ + + +
+ + + + + + +
+ + + +
+ + + +
diff --git a/admin_send_message.php b/admin_send_message.php index 621432f..4d29d08 100755 --- a/admin_send_message.php +++ b/admin_send_message.php @@ -10,16 +10,19 @@ requireAdmin(); function getTranslationButtons(PDO $pdo, string $text): array { - $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1"); - $languages = $stmt->fetchAll(); + $stmtTelegram = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1"); + $telegramLanguages = $stmtTelegram->fetchAll(); - if (count($languages) <= 1) { + $stmtDiscord = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1"); + $discordLanguages = $stmtDiscord->fetchAll(); + + if (count($telegramLanguages) <= 1 && count($discordLanguages) <= 1) { return []; } return [ - 'telegram' => buildTelegramTranslationButtons($pdo, $languages, $text), - 'discord' => buildDiscordTranslationButtons($languages, $text) + 'telegram' => count($telegramLanguages) > 1 ? buildTelegramTranslationButtons($pdo, $telegramLanguages, $text) : [], + 'discord' => count($discordLanguages) > 1 ? buildDiscordTranslationButtons($discordLanguages, $text) : [] ]; } diff --git a/create_message.php b/create_message.php index dc14a13..4db86d0 100755 --- a/create_message.php +++ b/create_message.php @@ -10,16 +10,19 @@ require_once __DIR__ . '/includes/i18n.php'; function getTranslationButtons(PDO $pdo, string $text): array { - $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1"); - $languages = $stmt->fetchAll(); + $stmtTelegram = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1"); + $telegramLanguages = $stmtTelegram->fetchAll(); - if (count($languages) <= 1) { + $stmtDiscord = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1"); + $discordLanguages = $stmtDiscord->fetchAll(); + + if (count($telegramLanguages) <= 1 && count($discordLanguages) <= 1) { return []; } return [ - 'telegram' => buildTelegramTranslationButtons($pdo, $languages, $text), - 'discord' => buildDiscordTranslationButtons($languages, $text) + 'telegram' => count($telegramLanguages) > 1 ? buildTelegramTranslationButtons($pdo, $telegramLanguages, $text) : [], + 'discord' => count($discordLanguages) > 1 ? buildDiscordTranslationButtons($discordLanguages, $text) : [] ]; } diff --git a/discord_bot.php b/discord_bot.php index 17c0aa2..b7d19ac 100755 --- a/discord_bot.php +++ b/discord_bot.php @@ -150,7 +150,7 @@ function handleTemplateCommand(PDO $pdo, Message $message, string $command): voi function getDiscordTranslationButtons(PDO $pdo, string $text): array { - $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1"); + $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1"); $languages = $stmt->fetchAll(); if (count($languages) <= 1) { @@ -351,7 +351,7 @@ function handleAutoTranslationWithButtons(PDO $pdo, Message $message, string $te $detectedLang = $translator->detectLanguage($textForDetection) ?? $defaultLang; // Obtener idiomas activos de la base de datos - $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1"); + $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1"); $activeLanguages = $stmt->fetchAll(); if (count($activeLanguages) <= 1) { diff --git a/process_queue.php b/process_queue.php index 41d7cc7..b131afb 100755 --- a/process_queue.php +++ b/process_queue.php @@ -13,16 +13,19 @@ define('SLEEP_INTERVAL', 5); function getTranslationButtons(PDO $pdo, string $text): array { - $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1"); - $languages = $stmt->fetchAll(); + $stmtTelegram = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1"); + $telegramLanguages = $stmtTelegram->fetchAll(); - if (count($languages) <= 1) { + $stmtDiscord = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND discord_enabled = 1"); + $discordLanguages = $stmtDiscord->fetchAll(); + + if (count($telegramLanguages) <= 1 && count($discordLanguages) <= 1) { return []; } return [ - 'telegram' => buildTelegramTranslationButtons($pdo, $languages, $text), - 'discord' => buildDiscordTranslationButtons($languages, $text) + 'telegram' => count($telegramLanguages) > 1 ? buildTelegramTranslationButtons($pdo, $telegramLanguages, $text) : [], + 'discord' => count($discordLanguages) > 1 ? buildDiscordTranslationButtons($discordLanguages, $text) : [] ]; } diff --git a/telegram/webhook/telegram_bot_webhook.php b/telegram/webhook/telegram_bot_webhook.php index 388e2e0..3ccde10 100755 --- a/telegram/webhook/telegram_bot_webhook.php +++ b/telegram/webhook/telegram_bot_webhook.php @@ -126,7 +126,7 @@ function handleAutoTranslation(PDO $pdo, Telegram\TelegramSender $sender, src\Tr function getTelegramTranslationButtons(PDO $pdo, string $text): ?array { try { - $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1"); + $stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1 AND telegram_enabled = 1"); $activeLanguages = $stmt->fetchAll(); if (count($activeLanguages) <= 1) {