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
22ob_start(); ?>
23jQuery(document).ready(function($) {
24	$('#email_send_to').dynamicRows({
25		template: '#email_send_to_table_row'
26	});
27
28	// Show/hide multiple "Send to" inputs and single "Send to" input and populate hidden "type" field.
29	$('#mediatypeid')
30		.on('change', function() {
31			var mediatypes_by_type = <?= (new CJson())->encode($data['mediatypes']) ?>,
32				mediatypeid = $(this).val();
33
34			$('#type').val(mediatypes_by_type[mediatypeid]);
35
36			if (mediatypes_by_type[mediatypeid] == <?= MEDIA_TYPE_EMAIL ?>) {
37				$('#mediatype_send_to').hide();
38				$('#mediatype_email_send_to').show();
39			}
40			else {
41				$('#mediatype_send_to').show();
42				$('#mediatype_email_send_to').hide();
43			}
44		})
45		.trigger("change");
46});
47
48/**
49 * Send media form data to server for validation before adding them to user media tab.
50 *
51 * @param {string} formname		form name that is sent to server for validation
52 */
53function validateMedia(formname) {
54	var form = window.document.forms[formname];
55
56	jQuery(form).trimValues(['#period', '#sendto', 'input[name^="sendto_emails"]']);
57
58	jQuery.ajax({
59		url: jQuery(form).attr('action'),
60		data: jQuery(form).serialize(),
61		success: function(ret) {
62			jQuery(form).parent().find('.msg-bad, .msg-good').remove();
63
64			if (typeof ret.errors !== 'undefined') {
65				jQuery(ret.errors).insertBefore(jQuery(form));
66			}
67			else {
68				add_media(ret.dstfrm, ret.media, ret.mediatypeid, ret.sendto, ret.period, ret.active, ret.severity);
69			}
70		},
71		dataType: 'json',
72		type: 'post'
73	});
74}
75<?php return ob_get_clean(); ?>
76