drink-it-cold/views/admin_mailings.php
torsten 9f8365b9e7 feat(mailing): Beispieltext als Vorlage im Rundmail-Formular
mailing_template() liefert Betreff und Text der Jahresend-Mail; das Formular ist
damit vorbefüllt und der Hinweis verlinkt auf 'Beispieltext wieder einsetzen'.
2026-11-30 08:19:22 +01:00

157 lines
7.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/** @var list<array{email: string, bookings: int, last_booking: ?string}> $recipients */
/** @var int $optoutCount */
/** @var list<array<string, mixed>> $mailings */
/** @var array{subject: string, body: string, from_template?: bool} $values */
/** @var array<string, string> $errors */
/** @var bool $mailEnabled */
/** @var int $batchSize */
$errorFor = static fn (string $key): string => (string) ($errors[$key] ?? '');
$lastBooking = $recipients ? (string) ($recipients[count($recipients) - 1]['last_booking'] ?? '') : '';
?>
<div class="page-head page-head--compact">
<div>
<p class="eyebrow">Verwaltung</p>
<h1>Kundenrundmail</h1>
<p class="page-head__lede">Dankeschön oder Saisonhinweis an alle Kunden, die gebucht haben.
Die Adressen kommen aus den Buchungen – gepflegt wird nichts doppelt. Text mit
<code>{jahr}</code> setzt automatisch das laufende Jahr ein.</p>
</div>
</div>
<?php require __DIR__ . '/_admin_nav.php'; ?>
<?php if (!$mailEnabled): ?>
<div class="alert alert--warning" role="status">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Mailversand ist ausgeschaltet.</strong>
<p>In der Konfiguration steht <code>app.mail_enabled</code> auf aus. Anlegen und Testen ist
möglich, der Versand an Kunden nicht.</p>
</div>
</div>
<?php endif; ?>
<section class="panel">
<div class="panel__head">
<div>
<h2>Empfänger</h2>
<p><?= count($recipients) ?> Kunden mit gültiger Adresse in einer Buchung<?= $lastBooking !== '' ? ', letzte Buchung am ' . e(date('d.m.Y', strtotime($lastBooking))) : '' ?>.</p>
</div>
<div class="panel__actions">
<span class="muted small"><?= $optoutCount ?> abgemeldet</span>
</div>
</div>
<p class="muted small">Abgemeldete Adressen werden automatisch übersprungen. Jede Mail enthält einen
Abmeldelink; Buchungsbestätigungen und Erinnerungen bleiben davon unberührt.</p>
</section>
<section class="panel">
<div class="panel__head">
<div>
<h2>Neue Rundmail</h2>
<p>Erst als Testmail an die eigene Adresse schicken, dann anlegen. Der Versand läuft danach in
Häppchen von <?= (int) $batchSize ?> Mails.</p>
<p class="muted small">Die Felder sind mit einem <strong>Beispieltext</strong> vorbefüllt – einfach
anpassen. <a href="<?= e(url('/admin/mailings')) ?>">Beispieltext wieder einsetzen</a>
(ersetzt eigene Änderungen).</p>
</div>
</div>
<?php if ($errors): ?>
<div class="alert alert--error" role="alert">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte die markierten Felder prüfen.</strong>
<?php foreach ($errors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<form method="post" action="<?= e(url('/admin/mailings')) ?>" class="form-grid form-grid--single">
<?= csrf_field() ?>
<label class="field<?= $errorFor('subject') !== '' ? ' has-error' : '' ?>">
<span>Betreff</span>
<input type="text" name="subject" value="<?= e($values['subject']) ?>" maxlength="190" required
placeholder="Zum Jahresende: vielen Dank für Ihr Vertrauen in {jahr}">
<?php if ($errorFor('subject')): ?><em class="field-error"><?= e($errorFor('subject')) ?></em><?php endif; ?>
</label>
<label class="field<?= $errorFor('body') !== '' ? ' has-error' : '' ?>">
<span>Text</span>
<textarea name="body" rows="10" maxlength="5000" required
placeholder="Hallo liebe Kundin, hallo lieber Kunde,&#10;&#10;wir sagen Danke für {jahr} …"><?= e($values['body']) ?></textarea>
<?php if ($errorFor('body')): ?><em class="field-error"><?= e($errorFor('body')) ?></em><?php endif; ?>
</label>
<p class="muted small">Abschließend setzt das System automatisch den Satz „Sie erhalten diese
Nachricht, weil Sie bei Drink it cold einen Kühlanhänger gebucht haben.“ und den Abmeldelink
darunter.</p>
<div class="btn-row">
<button type="submit" name="action" value="test" class="btn">Testmail an mich</button>
<button type="submit" name="action" value="create" class="btn primary">An <?= count($recipients) ?> Kunden anlegen</button>
</div>
</form>
</section>
<section class="panel">
<div class="panel__head">
<div>
<h2>Bisherige Rundmails</h2>
<p>Der Stand je Empfänger steht im Protokoll; „Weiter senden“ schickt die nächste Häppchen-Größe.</p>
</div>
</div>
<?php if (!$mailings): ?>
<p class="muted">Noch keine Rundmail angelegt.</p>
<?php else: ?>
<div class="table-wrap">
<table class="data-table">
<thead>
<tr>
<th scope="col">Angelegt</th>
<th scope="col">Betreff</th>
<th scope="col">Empfänger</th>
<th scope="col">Stand</th>
<th scope="col">Aktion</th>
</tr>
</thead>
<tbody>
<?php foreach ($mailings as $mailing): ?>
<?php
$pending = (int) $mailing['pending'];
$sent = (int) $mailing['sent_count'];
$failed = (int) $mailing['failed_count'];
$total = (int) $mailing['recipient_count'];
?>
<tr>
<td><?= e(date('d.m.Y H:i', strtotime((string) $mailing['created_at']))) ?></td>
<td><?= e((string) $mailing['subject']) ?></td>
<td><?= $total ?></td>
<td>
<?= $sent ?> versendet<?= $failed > 0 ? ', ' . $failed . ' fehlgeschlagen' : '' ?>
<?= $pending > 0 ? ' · ' . $pending . ' offen' : ' · fertig' ?>
</td>
<td>
<?php if ($pending > 0): ?>
<form method="post" action="<?= e(url('/admin/mailings')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="action" value="send">
<input type="hidden" name="mailing_id" value="<?= (int) $mailing['id'] ?>">
<input type="hidden" name="batch" value="<?= (int) $batchSize ?>">
<button type="submit" class="btn small primary"<?= $mailEnabled ? '' : ' disabled' ?>>
<?= $pending > (int) $batchSize
? 'Nächste ' . (int) $batchSize . ' senden'
: 'Rest (' . $pending . ') senden' ?>
</button>
</form>
<?php else: ?>
<span class="muted small">abgeschlossen</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</section>