1<?php
2/*
3** Zabbix
4** Copyright (C) 2001-2021 Zabbix SIA
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19**/
20
21
22$options = $data['options'];
23$severity_row = (new CList())->addClass(ZBX_STYLE_LIST_CHECK_RADIO);
24
25foreach ($data['severities'] as $severity => $severity_name) {
26	$severity_row->addItem(
27		(new CCheckBox('severity['.$severity.']', $severity))
28			->setLabel($severity_name)
29			->setChecked(str_in_array($severity, $options['severities']))
30	);
31}
32
33// Create table of email addresses.
34$email_send_to_table = (new CTable())->setId('email_send_to');
35
36foreach ($options['sendto_emails'] as $i => $email) {
37	$email_send_to_table->addRow([
38		(new CTextBox('sendto_emails['.$i.']', $email))
39			->setAriaRequired()
40			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
41			(new CButton('sendto_emails['.$i.'][remove]', _('Remove')))
42				->addClass(ZBX_STYLE_BTN_LINK)
43				->addClass('element-table-remove')
44	], 'form_row dynamic-row');
45}
46
47$email_send_to_table->setFooter(new CCol(
48	(new CButton('email_send_to_add', _('Add')))
49		->addClass(ZBX_STYLE_BTN_LINK)
50		->addClass('element-table-add')
51), 'dynamic-row-control');
52
53$type_combobox = new CComboBox('mediatypeid', $options['mediatypeid']);
54foreach ($data['db_mediatypes'] as $mediatypeid => $value) {
55	$type_combobox->addItem($mediatypeid, $value['description'], null, true,
56		($value['status'] == MEDIA_TYPE_STATUS_DISABLED) ? ZBX_STYLE_RED : null
57	);
58}
59
60// Create media form.
61$media_form = (new CFormList(_('Media')))
62	->addRow(_('Type'), $type_combobox)
63	->addRow(
64		(new CLabel(_('Send to'), 'sendto'))->setAsteriskMark(),
65		(new CTextBox('sendto', $options['sendto'], false, 1024))
66			->setAriaRequired()
67			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH),
68		'mediatype_send_to'
69	)
70	->addRow(
71		(new CLabel(_('Send to'), 'mediatype_email_send_to'))->setAsteriskMark(),
72		$email_send_to_table,
73		'mediatype_email_send_to'
74	)
75	->addRow((new CLabel(_('When active'), 'period'))->setAsteriskMark(),
76		(new CTextBox('period', $options['period'], false, 1024))
77			->setAriaRequired()
78			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
79	)
80	->addRow(_('Use if severity'), $severity_row)
81	->addRow(_('Enabled'),
82		(new CCheckBox('active', MEDIA_STATUS_ACTIVE))->setChecked($options['active'] == MEDIA_STATUS_ACTIVE)
83	);
84
85$form = (new CForm())
86	->cleanItems()
87	->setName('media_form')
88	->addVar('action', 'popup.media')
89	->addVar('add', '1')
90	->addVar('media', $options['media'])
91	->addVar('type', $options['type'])
92	->addVar('dstfrm', $options['dstfrm'])
93	->setId('media_form')
94	->addItem([
95		$media_form,
96		(new CInput('submit', 'submit'))->addStyle('display: none;'),
97		(new CTag('script'))
98			->addItem((new CRow([
99				(new CCol((new CTextBox('sendto_emails[#{rowNum}]', ''))
100					->setAriaRequired()
101					->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
102				)),
103				(new CCol((new CButton('sendto_emails[#{rowNum}][remove]', _('Remove')))
104					->addClass(ZBX_STYLE_BTN_LINK)
105					->addClass('element-table-remove')
106				))
107			]))
108				->addClass('form_row')
109				->addClass('dynamic-row'))
110				->setAttribute('type', 'text/x-jquery-tmpl')
111				->setAttribute('id', 'email_send_to_table_row')
112	]);
113
114$output = [
115	'header' => $data['title'],
116	'script_inline' => require 'app/views/popup.media.js.php',
117	'body' => $form->toString(),
118	'buttons' => [
119		[
120			'title' => ($options['media'] !== -1) ? _('Update') : _('Add'),
121			'class' => '',
122			'keepOpen' => true,
123			'isSubmit' => true,
124			'action' => 'return validateMedia("'.$form->getName().'");'
125		]
126	]
127];
128
129if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
130	CProfiler::getInstance()->stop();
131	$output['debug'] = CProfiler::getInstance()->make()->toString();
132}
133
134echo (new CJson())->encode($output);
135