From 4ada86876033fa171e2896d7e3d3c5645d8062db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:46:47 +0200 Subject: Adding upstream version 0.10.0. Signed-off-by: Daniel Baumann --- library/Reporting/Actions/SendMail.php | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 library/Reporting/Actions/SendMail.php (limited to 'library/Reporting/Actions') diff --git a/library/Reporting/Actions/SendMail.php b/library/Reporting/Actions/SendMail.php new file mode 100644 index 0000000..7c70bf5 --- /dev/null +++ b/library/Reporting/Actions/SendMail.php @@ -0,0 +1,84 @@ +getName(), + $report->getTimeframe()->getName(), + date('Y-m-d H:i') + ); + + $mail = new Mail(); + + $mail->setFrom(Config::module('reporting')->get('mail', 'from', 'reporting@icinga')); + + if (isset($config['subject'])) { + $mail->setSubject($config['subject']); + } + + switch ($config['type']) { + case 'pdf': + $mail->attachPdf(Pdfexport::first()->htmlToPdf($report->toPdf()), $name); + + break; + case 'csv': + $mail->attachCsv($report->toCsv(), $name); + + break; + case 'json': + $mail->attachJson($report->toJson(), $name); + + break; + default: + throw new \InvalidArgumentException(); + } + + $recipients = array_filter(preg_split('/[\s,]+/', $config['recipients'])); + + $mail->send(null, $recipients); + } + + public function initConfigForm(Form $form, Report $report) + { + $types = ['pdf' => 'PDF']; + + if ($report->providesData()) { + $types['csv'] = 'CSV'; + $types['json'] = 'JSON'; + } + + $form->addElement('select', 'type', [ + 'required' => true, + 'label' => t('Type'), + 'options' => $types + ]); + + $form->addElement('text', 'subject', [ + 'label' => t('Subject'), + 'placeholder' => Mail::DEFAULT_SUBJECT + ]); + + $form->addElement('textarea', 'recipients', [ + 'required' => true, + 'label' => t('Recipients') + ]); + } +} -- cgit v1.2.3