-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathSendForm.php
82 lines (65 loc) · 2.44 KB
/
SendForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2
namespace Icinga\Module\Reporting\Web\Forms;
use Icinga\Module\Reporting\Actions\SendMail;
use Icinga\Module\Reporting\Database;
use Icinga\Module\Reporting\Hook\EmailAddressBookHook;
use Icinga\Module\Reporting\ProvidedReports;
use Icinga\Module\Reporting\Report;
use Icinga\Module\Reporting\Web\Forms\Decorator\CompatDecorator;
use ipl\I18n\Translation;
use ipl\Web\Compat\CompatForm;
class SendForm extends CompatForm
{
use Database;
use ProvidedReports;
use Translation;
/** @var Report */
protected $report;
public function setReport(Report $report)
{
$this->report = $report;
return $this;
}
protected function assemble()
{
$this->setDefaultElementDecorator(new CompatDecorator());
(new SendMail())->initConfigForm($this, $this->report);
$emailAddressBooks = EmailAddressBookHook::getEmailAddressBooks();
$this->addElement('radio', 'source_radio', [
'label' => $this->translate('E-Mail Source'),
'options' => [
'manual' => $this->translate('Manual input'),
'contacts' => $this->translate('Contacts'),
],
'disabled' => count($emailAddressBooks) === 0,
'value' => 'contacts',
'class' => 'autosubmit',
'description' => count($emailAddressBooks) === 0 ? $this->translate("No contacts available") : null
]);
if ($this->getPopulatedValue('source_radio', 'manual') === 'contacts') {
$emails = [null => $this->translate('Select Contacts')];
foreach ($emailAddressBooks as $addressBook) {
$emails = array_merge($emails, $addressBook->getContactEmails());
}
$this->addElement('select', 'emails_list', [
'multiple' => true,
'label' => $this->translate('Contacts'),
'options' => $emails
]);
} else {
$this->addElement('textarea', 'emails_manual', [
'label' => $this->translate('Contact E-Mails')
]);
}
$this->addElement('submit', 'submit', [
'label' => $this->translate('Send Report')
]);
}
public function onSuccess()
{
$values = $this->getValues();
$sendMail = new SendMail();
$sendMail->execute($this->report, $values);
}
}