From 8cebbf17d2cbd18b356a32689d4afd3cd691db4c Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Wed, 14 Feb 2024 15:37:18 +0100 Subject: [PATCH] extended bulkmail --- include/bulkmail.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/include/bulkmail.php b/include/bulkmail.php index 2da4e7f..0baeed9 100644 --- a/include/bulkmail.php +++ b/include/bulkmail.php @@ -8,8 +8,10 @@ class Bulkmail extends Renderer { ['label' => 'Signatur', 'type' => 'combobox', 'size' => 5, 'name' => 'signature', 'combine_with_next_line' => false, 'values' => ['Persönliche Signatur', 'Vorstandssignatur'], ], + ['label' => 'An normale Mitglieder', 'type' => 'checkbox', 'size' => 50, 'name' => 'custommembers', 'size' => 1, 'value' => 1, 'combine_with_next_line' => false], + ['label' => 'An den Vorstand', 'type' => 'checkbox', 'size' => 50, 'name' => 'board', 'size' => 1, 'value' => 1, 'combine_with_next_line' => false], ]; - protected string $formSendButtonLabel = 'Email an alle aktiven Mitglieder absenden'; + protected string $formSendButtonLabel = 'Email an ausgewählte Empfängergruppe senden'; protected function formAction(): void { $this->sendEmail($this->generateSubject(), $this->generateBody(), $this->generateSignature(filter_input(INPUT_POST, 'signature'))); @@ -26,23 +28,32 @@ class Bulkmail extends Renderer { protected function sendEmail(string $subject, string $body, string $signature): void { $mail = $this->initSmtpMailer();; $bccRecipients = $this->loadReceivers(); + $sendToCustomMembers = intval(filter_input(INPUT_POST, 'custommembers')) === 1; + $sendToBoard = intval(filter_input(INPUT_POST, 'board')) === 1; + $sendTo = []; try { $mail->setFrom('foerderverein-ajs@gmx.de', 'Förderverein der Steffi-Jones-Schule'); $mail->addReplyTo('foerderverein-ajs@gmx.de', 'Förderverein der Steffi-Jones-Schule'); $mail->addAddress('vorstand@fvajs.de', 'Vorstand des FVAJS'); foreach ($bccRecipients as $recipient) { - $mail->addBCC($recipient); + if (($sendToCustomMembers && $recipient['position'] === null) + || ($sendToBoard && $recipient['position'] !== null)) { + $mail->addBCC($recipient['email']); + $sendTo[] = $recipient['email']; + } else { + var_dump($recipient['position']); + } } $this->sendMail($mail, $subject, $body, $signature); } catch (Exception $e) { $this->templateName = 'error_smtp'; } $this->templateName = 'bulkmail_success'; - $this->content['recipients'] = implode('
', $bccRecipients); + $this->content['recipients'] = implode('
', $sendTo); } protected function loadReceivers(): array { - $query = 'SELECT c.first_name, c.last_name, c.email, c.salt + $query = 'SELECT c.first_name, c.last_name, c.email, c.salt, c.position_id FROM clubmember c JOIN clubmember_status cs ON cs.id = c.membership_status @@ -50,7 +61,7 @@ class Bulkmail extends Renderer { $dbResult = mysqli_query($this->dbConnection, $query); $recipientsList = []; while ($row = mysqli_fetch_assoc($dbResult)) { - $recipientsList[] = $this->decode($row['email'], $row['salt']); + $recipientsList[] = ['email' => $this->decode($row['email'], $row['salt']), 'position' => $row['position_id'] ]; } return $recipientsList; }