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$this->addJsFile('inputsecret.js'); 27$this->addJsFile('textareaflexible.js'); 28$this->addJsFile('macrovalue.js'); 29 30$this->includeJsFile('administration.macros.edit.js.php'); 31 32$widget = (new CWidget()) 33 ->setTitle(_('Macros')) 34 ->setTitleSubmenu(getAdministrationGeneralSubmenu()); 35 36$table = (new CTable()) 37 ->setId('tbl_macros') 38 ->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_CONTAINER) 39 ->addClass('global-macro-table') 40 ->setColumns([ 41 (new CTableColumn(_('Macro')))->addClass('table-col-macro'), 42 (new CTableColumn(_('Value')))->addClass('table-col-value'), 43 (new CTableColumn(_('Description')))->addClass('table-col-description'), 44 (new CTableColumn())->addClass('table-col-action') 45 ]); 46 47foreach ($data['macros'] as $i => $macro) { 48 $macro_input = (new CTextAreaFlexible('macros['.$i.'][macro]', $macro['macro'])) 49 ->addClass('macro') 50 ->setWidth(ZBX_TEXTAREA_MACRO_WIDTH) 51 ->setAttribute('placeholder', '{$MACRO}'); 52 53 if ($i == 0) { 54 $macro_input->setAttribute('autofocus', 'autofocus'); 55 } 56 57 $macro_value = new CMacroValue($macro['type'], 'macros['.$i.']'); 58 59 if ($macro['type'] == ZBX_MACRO_TYPE_SECRET) { 60 $macro_value->addRevertButton(); 61 $macro_value->setRevertButtonVisibility(array_key_exists('value', $macro) 62 && array_key_exists('globalmacroid', $macro) 63 ); 64 } 65 66 if (array_key_exists('value', $macro)) { 67 $macro_value->setAttribute('value', $macro['value']); 68 } 69 70 $description_input = (new CTextAreaFlexible('macros['.$i.'][description]', $macro['description'])) 71 ->setWidth(ZBX_TEXTAREA_MACRO_VALUE_WIDTH) 72 ->setMaxlength(DB::getFieldLength('globalmacro', 'description')) 73 ->setAttribute('placeholder', _('description')); 74 75 $button_cell = [ 76 (new CButton('macros['.$i.'][remove]', _('Remove'))) 77 ->addClass(ZBX_STYLE_BTN_LINK) 78 ->addClass('element-table-remove') 79 ]; 80 if (array_key_exists('globalmacroid', $macro)) { 81 $button_cell[] = new CVar('macros['.$i.'][globalmacroid]', $macro['globalmacroid']); 82 } 83 84 $table->addRow([ 85 (new CCol($macro_input))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT), 86 (new CCol($macro_value))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT), 87 (new CCol($description_input))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT), 88 (new CCol($button_cell))->addClass(ZBX_STYLE_NOWRAP) 89 ], 'form_row'); 90} 91 92$table->setFooter(new CCol( 93 (new CButton('macro_add', _('Add'))) 94 ->addClass(ZBX_STYLE_BTN_LINK) 95 ->addClass('element-table-add') 96)); 97 98$macros_form_list = (new CFormList('macrosFormList'))->addRow($table); 99 100$tab_view = (new CTabView())->addTab('macros', _('Macros'), $macros_form_list); 101 102$save_button = (new CSubmit('update', _('Update')))->setAttribute('data-removed-count', 0); 103 104$tab_view->setFooter(makeFormFooter($save_button)); 105 106$form = (new CForm()) 107 ->setName('macrosForm') 108 ->disablePasswordAutofill() 109 ->setAction((new CUrl('zabbix.php'))->setArgument('action', 'macros.update')->getUrl()) 110 ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE) 111 ->addItem($tab_view); 112 113$widget 114 ->addItem($form) 115 ->show(); 116