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 CPartial $this 24 */ 25 26if ($data['readonly'] && !$data['macros']) { 27 $table = new CObject(_('No macros found.')); 28} 29else { 30 $table = (new CTable()) 31 ->setId('tbl_macros') 32 ->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_CONTAINER) 33 ->setHeader([ 34 (new CColHeader(_('Macro')))->setWidth(ZBX_TEXTAREA_MACRO_WIDTH), 35 (new CColHeader(_('Value')))->setWidth(ZBX_TEXTAREA_MACRO_VALUE_WIDTH), 36 _('Description'), 37 $data['readonly'] ? null : '' 38 ]); 39 40 foreach ($data['macros'] as $i => $macro) { 41 $macro_input = (new CTextAreaFlexible('macros['.$i.'][macro]', $macro['macro'])) 42 ->setReadonly($data['readonly']) 43 ->addClass('macro') 44 ->setWidth(ZBX_TEXTAREA_MACRO_WIDTH) 45 ->setAttribute('placeholder', '{$MACRO}'); 46 $macro_value = (new CMacroValue($macro['type'], 'macros['.$i.']', null, false)) 47 ->setReadonly($data['readonly']); 48 $macro_cell = [$macro_input]; 49 50 if (!$data['readonly']) { 51 if (array_key_exists('hostmacroid', $macro)) { 52 $macro_cell[] = new CVar('macros['.$i.'][hostmacroid]', $macro['hostmacroid']); 53 } 54 55 $action_btn = (new CButton('macros['.$i.'][remove]', _('Remove'))) 56 ->addClass(ZBX_STYLE_BTN_LINK) 57 ->addClass('element-table-remove'); 58 } 59 else { 60 $action_btn = null; 61 } 62 63 if ($macro['type'] == ZBX_MACRO_TYPE_SECRET) { 64 $macro_value->addRevertButton(); 65 $macro_value->setRevertButtonVisibility(array_key_exists('value', $macro) 66 && array_key_exists('hostmacroid', $macro) 67 ); 68 } 69 70 if (array_key_exists('value', $macro)) { 71 $macro_value->setAttribute('value', $macro['value']); 72 } 73 74 $table->addRow([ 75 (new CCol($macro_cell))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT), 76 (new CCol($macro_value))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT), 77 (new CCol( 78 (new CTextAreaFlexible('macros['.$i.'][description]', $macro['description'])) 79 ->setWidth(ZBX_TEXTAREA_MACRO_VALUE_WIDTH) 80 ->setMaxlength(DB::getFieldLength('hostmacro', 'description')) 81 ->setReadonly($data['readonly']) 82 ->setAttribute('placeholder', _('description')) 83 ))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT), 84 $action_btn ? (new CCol($action_btn))->addClass(ZBX_STYLE_NOWRAP) : null 85 ], 'form_row'); 86 } 87 88 // buttons 89 if (!$data['readonly']) { 90 $table->setFooter(new CCol( 91 (new CButton('macro_add', _('Add'))) 92 ->addClass(ZBX_STYLE_BTN_LINK) 93 ->addClass('element-table-add') 94 )); 95 } 96} 97 98$table->show(); 99 100// Initializing input secret and macro value init script separately. 101(new CScriptTag("jQuery('.input-secret').inputSecret();"))->show(); 102(new CScriptTag("jQuery('.input-group').macroValue();"))->show(); 103