2026-11-30 08:11:06 +01:00
< ? php
/** @var list<array{email: string, bookings: int, last_booking: ?string}> $recipients */
/** @var int $optoutCount */
/** @var list<array<string, mixed>> $mailings */
2026-11-30 08:19:22 +01:00
/** @var array{subject: string, body: string, from_template?: bool} $values */
2026-11-30 08:11:06 +01:00
/** @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 >
2026-11-30 15:40:34 +01:00
< p class = " page-head__lede " > Dankeschön oder Saisonhinweis an alle Kunden der letzten 13 Monate .
Die Adressen kommen aus den Buchungen – gepflegt wird nichts doppelt . Stornierte
Buchungen bleiben außen vor , laufende Mietzeiten zählen mit . Text mit
2026-11-30 08:11:06 +01:00
< 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 >
2026-11-30 15:40:34 +01:00
< p >< ? = count ( $recipients ) ?> Kunden mit gültiger Adresse in einer Buchung der letzten 13 Monate<?= $lastBooking !== '' ? ', letzte Buchung am ' . e(date('d.m.Y', strtotime($lastBooking))) : '' ?>.</p>
2026-11-30 08:11:06 +01:00
</ 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 >
2026-11-30 15:40:34 +01:00
< p class = " muted small " > Ausgewählt werden nicht stornierte Buchungen mit Beginn in den letzten
13 Monaten – auch solche , deren Mietzeit noch läuft .</ p >
2026-11-30 08:11:06 +01:00
</ 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>
2026-11-30 08:19:22 +01:00
< 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 >
2026-11-30 08:11:06 +01:00
</ 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, 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 >
2026-11-30 15:40:34 +01:00
< p > Ein Klick auf den Betreff öffnet das Protokoll mit dem Status jeder einzelnen Mail .
„Senden“ schickt die Rundmail in Häppchen , bis alle Empfänger durch sind – die Seite
zeigt den Fortschritt und bleibt dabei bedienbar .</ p >
2026-11-30 08:11:06 +01:00
</ 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>
2026-11-30 15:40:34 +01:00
< td >< a href = " <?= e(url('/admin/mailings/' . (int) $mailing['id'] )) ?> " >< ? = e ( mailing_render (( string ) $mailing [ 'subject' ])) ?> </a></td>
2026-11-30 08:11:06 +01:00
< td >< ? = $total ?> </td>
< td >
< ? = $sent ?> versendet<?= $failed > 0 ? ', ' . $failed . ' fehlgeschlagen' : '' ?>
< ? = $pending > 0 ? ' · ' . $pending . ' offen' : ' · fertig' ?>
</ td >
< td >
< ? php if ( $pending > 0 ) : ?>
2026-11-30 15:40:34 +01:00
< form method = " post " action = " <?= e(url('/admin/mailings')) ?> "
data - send - mailing
data - total = " <?= $total ?> "
data - sent = " <?= $sent ?> "
data - failed = " <?= $failed ?> " >
2026-11-30 08:11:06 +01:00
< ? = 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' ?> >
2026-11-30 15:40:34 +01:00
< ? = $sent > 0 ? 'Weiter senden (' . $pending . ' offen)' : 'Senden (' . $pending . ')' ?>
2026-11-30 08:11:06 +01:00
</ button >
2026-11-30 15:40:34 +01:00
< p class = " muted small " data - mailing - status aria - live = " polite " ></ p >
2026-11-30 08:11:06 +01:00
</ form >
< ? php else : ?>
< span class = " muted small " > abgeschlossen </ span >
< ? php endif ; ?>
</ td >
</ tr >
< ? php endforeach ; ?>
</ tbody >
</ table >
</ div >
< ? php endif ; ?>
</ section >