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/** 23 * @var CView $this 24 */ 25 26$form_list = (new CFormList()); 27 28if ($data['type'] == MEDIA_TYPE_WEBHOOK) { 29 $i = 0; 30 31 foreach ($data['parameters'] as $parameter) { 32 $fieldid = 'parameters['.$i.']'; 33 $form_list 34 ->addRow(new CLabel($parameter['name'], $fieldid.'[value]'), [ 35 new CVar($fieldid.'[name]', $parameter['name']), 36 (new CTextBox($fieldid.'[value]', $parameter['value']))->setWidth(ZBX_TEXTAREA_BIG_WIDTH) 37 ]); 38 $i++; 39 } 40 41 if (!$i) { 42 $form_list->addRow(_('Webhook does not have parameters.')); 43 } 44 45 $form_list 46 ->addRow(new CLabel(_('Response')), [ 47 (new CTextArea('')) 48 ->setId('webhook_response_value') 49 ->setWidth(ZBX_TEXTAREA_BIG_WIDTH) 50 ->setEnabled(false), 51 (new CDiv(''))->setId('webhook_response_type'), 52 (new CDiv((new CLinkAction('Open log')) 53 ->setId('mediatypetest_log') 54 ->addClass(ZBX_STYLE_DISABLED) 55 ->onClick('openLogPopup(this)'))) 56 ]); 57} 58else { 59 $form_list 60 ->addRow( 61 (new CLabel(_('Send to'), 'sendto'))->setAsteriskMark(), 62 (new CTextBox('sendto', $data['sendto'], false, 1024)) 63 ->setWidth(ZBX_TEXTAREA_BIG_WIDTH) 64 ->setAttribute('autofocus', 'autofocus') 65 ->setAriaRequired() 66 ->setEnabled($data['enabled']) 67 ) 68 ->addRow( 69 new CLabel(_('Subject'), 'subject'), 70 (new CTextBox('subject', $data['subject'], false, 1024)) 71 ->setWidth(ZBX_TEXTAREA_BIG_WIDTH) 72 ->setEnabled($data['enabled']) 73 ) 74 ->addRow( 75 (new CLabel(_('Message'), 'message'))->setAsteriskMark($data['type'] != MEDIA_TYPE_EXEC), 76 (new CTextArea('message', $data['message'], ['rows' => 10])) 77 ->setWidth(ZBX_TEXTAREA_BIG_WIDTH) 78 ->setAriaRequired($data['type'] != MEDIA_TYPE_EXEC) 79 ->setEnabled($data['enabled']) 80 ); 81} 82 83$form = (new CForm()) 84 ->cleanItems() 85 ->setName('mediatypetest_form') 86 ->addVar('action', 'popup.mediatypetest.send') 87 ->addVar('mediatypeid', $data['mediatypeid']) 88 ->addItem([ 89 $form_list, 90 (new CInput('submit', 'submit'))->addStyle('display: none;') 91 ]); 92 93$output = [ 94 'header' => $data['title'], 95 'script_inline' => $this->readJsFile('popup.mediatypetest.edit.js.php'), 96 'body' => (new CDiv([$data['errors'], $form]))->toString(), 97 'buttons' => [ 98 [ 99 'title' => _('Test'), 100 'keepOpen' => true, 101 'isSubmit' => true, 102 'enabled' => $data['enabled'], 103 'action' => 'return mediatypeTestSend(overlay);' 104 ] 105 ] 106]; 107 108if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 109 CProfiler::getInstance()->stop(); 110 $output['debug'] = CProfiler::getInstance()->make()->toString(); 111} 112 113echo json_encode($output); 114