TCRB senden eingabeut

This commit is contained in:
2026-04-05 10:25:50 +02:00
parent a64e1a729f
commit be35b7398d
4 changed files with 901 additions and 0 deletions
+49
View File
@@ -52,6 +52,7 @@ $stmtUser = $pdo->prepare("
`display_name`,
`telegram_username`,
`telegram_chat_id`,
`telegram_tcrb_v_enabled`,
`telegram_link_token`,
`telegram_link_token_expires_at`,
`telegram_connected_at`,
@@ -151,6 +152,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
SET
`telegram_username` = NULL,
`telegram_chat_id` = NULL,
`telegram_tcrb_v_enabled` = 0,
`telegram_link_token` = NULL,
`telegram_link_token_expires_at` = NULL,
`telegram_connected_at` = NULL,
@@ -164,6 +166,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$successMessage = 'Die Telegram-Verknuepfung wurde entfernt.';
}
if ($action === 'update_tcrb_telegram_notifications') {
$enabled = isset($_POST['telegram_tcrb_v_enabled']) ? 1 : 0;
if ($enabled === 1 && empty($user['telegram_chat_id'])) {
$errors[] = 'Bitte zuerst Telegram verbinden, bevor du T-CrB-Nachrichten aktivierst.';
}
if (empty($errors)) {
$stmtNotification = $pdo->prepare("
UPDATE `app_users`
SET
`telegram_tcrb_v_enabled` = :enabled,
`updated_at` = NOW()
WHERE `id` = :id
");
$stmtNotification->execute([
':enabled' => $enabled,
':id' => $userId,
]);
$successMessage = $enabled === 1
? 'T-CrB-Telegram-Nachrichten wurden aktiviert.'
: 'T-CrB-Telegram-Nachrichten wurden deaktiviert.';
}
}
if ($action === 'change_password') {
$currentPassword = $_POST['current_password'] ?? '';
$newPassword = $_POST['new_password'] ?? '';
@@ -219,6 +247,7 @@ $loggedIn = true;
$publicBasePath = './';
$telegramBotUsername = trim((string) ($telegramConfig['bot_username'] ?? ''));
$telegramHasConnection = !empty($user['telegram_chat_id']);
$telegramTcrbVEnabled = !empty($user['telegram_tcrb_v_enabled']);
$telegramLinkToken = trim((string) ($user['telegram_link_token'] ?? ''));
$telegramLinkExpiresAt = !empty($user['telegram_link_token_expires_at'])
? new DateTimeImmutable((string) $user['telegram_link_token_expires_at'])
@@ -291,6 +320,8 @@ $telegramDeepLink = $telegramLinkIsActive && $telegramBotUsername !== ''
<tr><td>Verbunden seit</td><td><?= h($user['telegram_connected_at'] ?? '—') ?></td></tr>
</table>
<p class="hint"><strong>T CrB letzter V-Wert:</strong> <?= $telegramTcrbVEnabled ? 'Aktiv' : 'Aus' ?></p>
<?php if ($telegramLinkIsActive): ?>
<p class="hint">
Aktiver Verbindungscode bis <?= h($telegramLinkExpiresAt?->format('d.m.Y H:i')) ?>:
@@ -327,6 +358,24 @@ $telegramDeepLink = $telegramLinkIsActive && $telegramBotUsername !== ''
<?php endif; ?>
</p>
<?php endif; ?>
<form method="post" action="" class="form-stack">
<input type="hidden" name="action" value="update_tcrb_telegram_notifications">
<label class="checkbox-row">
<input
type="checkbox"
name="telegram_tcrb_v_enabled"
value="1"
<?= $telegramTcrbVEnabled ? 'checked' : '' ?>
<?= !$telegramHasConnection ? 'disabled' : '' ?>
>
<span>Letzten T CrB-Wert im Filter V per Telegram erhalten</span>
</label>
<?php if (!$telegramHasConnection): ?>
<p class="hint">Die Auswahl wird erst aktiv, nachdem dein Telegram-Konto verbunden ist.</p>
<?php endif; ?>
<button type="submit" class="btn btn-primary" <?= !$telegramHasConnection ? 'disabled' : '' ?>>Benachrichtigung speichern</button>
</form>
</div>
</div>
</div>