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$output = [ 27 'header' => $data['title'] 28]; 29 30$options = $data['options']; 31 32$overrides_popup_form = (new CForm()) 33 ->cleanItems() 34 ->setId('lldoverride_form') 35 ->addItem((new CVar('no', $options['no']))->removeId()) 36 ->addItem((new CVar('templated', $options['templated']))->removeId()) 37 ->addVar('old_name', $options['old_name']) 38 ->addVar('overrides_names', $options['overrides_names']) 39 ->addItem((new CVar('action', 'popup.lldoverride'))->removeId()) 40 ->addItem((new CInput('submit', 'submit')) 41 ->addStyle('display: none;') 42 ->removeId() 43 ); 44 45$overrides_popup_form_list = (new CFormList()) 46 ->addRow( 47 (new CLabel(_('Name'), 'override_name'))->setAsteriskMark(), 48 (new CTextBox('name', $options['old_name'], $options['templated'], DB::getFieldLength('lld_override', 'name'))) 49 ->setAriaRequired() 50 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 51 ->setId('override_name') 52 ) 53 ->addRow( 54 _('If filter matches'), 55 (new CRadioButtonList('stop', (int) $options['stop'])) 56 ->addValue(_('Continue overrides'), ZBX_LLD_OVERRIDE_STOP_NO) 57 ->addValue(_('Stop processing'), ZBX_LLD_OVERRIDE_STOP_YES) 58 ->setModern(true) 59 ->setReadonly($options['templated']) 60 ); 61 62// filters 63$override_evaltype_select = (new CSelect('overrides_evaltype')) 64 ->setId('overrides-evaltype') 65 ->setValue($options['overrides_evaltype']) 66 ->addOptions(CSelect::createOptionsFromArray([ 67 CONDITION_EVAL_TYPE_AND_OR => _('And/Or'), 68 CONDITION_EVAL_TYPE_AND => _('And'), 69 CONDITION_EVAL_TYPE_OR => _('Or'), 70 CONDITION_EVAL_TYPE_EXPRESSION => _('Custom expression') 71 ])); 72 73if ($options['templated']) { 74 $override_evaltype_select->setReadonly(); 75} 76 77$override_evaltype = (new CDiv([ 78 (new CDiv([ 79 _('Type of calculation'), 80 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), 81 $override_evaltype_select, 82 (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN) 83 ]))->addClass(ZBX_STYLE_CELL), 84 (new CDiv([ 85 (new CSpan('')) 86 ->addStyle('white-space: normal;') 87 ->setId('overrides_expression'), 88 (new CTextBox('overrides_formula', $options['overrides_formula'], $options['templated'], 89 DB::getFieldLength('lld_override', 'formula'))) 90 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 91 ->setId('overrides_formula') 92 ->setAttribute('placeholder', 'A or (B and C) …') 93 ]))->addClass(ZBX_STYLE_CELL) 94])) 95 ->addClass(ZBX_STYLE_ROW) 96 ->setId('overrideRow'); 97 98$filter_table = (new CTable()) 99 ->setId('overrides_filters') 100 ->addStyle('width: 100%;') 101 ->setHeader([_('Label'), _('Macro'), '', _('Regular expression'), (new CColHeader(_('Action')))->setWidth('100%')]); 102 103$overrides_filters = $options['overrides_filters']; 104if (!$overrides_filters) { 105 $overrides_filters = [[ 106 'macro' => '', 107 'operator' => CONDITION_OPERATOR_REGEXP, 108 'value' => '', 109 'formulaid' => num2letter(0) 110 ]]; 111} 112else { 113 $overrides_filters = CConditionHelper::sortConditionsByFormulaId($overrides_filters); 114} 115 116$operators = CSelect::createOptionsFromArray([ 117 CONDITION_OPERATOR_REGEXP => _('matches'), 118 CONDITION_OPERATOR_NOT_REGEXP => _('does not match'), 119 CONDITION_OPERATOR_EXISTS => _('exists'), 120 CONDITION_OPERATOR_NOT_EXISTS => _('does not exist') 121]); 122 123foreach ($overrides_filters as $i => $overrides_filter) { 124 $formulaid = [ 125 new CSpan($overrides_filter['formulaid']), 126 new CVar('overrides_filters['.$i.'][formulaid]', $overrides_filter['formulaid']) 127 ]; 128 129 $macro = (new CTextBox('overrides_filters['.$i.'][macro]', $overrides_filter['macro'], $options['templated'], 130 DB::getFieldLength('lld_override_condition', 'macro'))) 131 ->setWidth(ZBX_TEXTAREA_MACRO_WIDTH) 132 ->addClass(ZBX_STYLE_UPPERCASE) 133 ->addClass('macro') 134 ->setAttribute('placeholder', '{#MACRO}') 135 ->setAttribute('data-formulaid', $overrides_filter['formulaid']); 136 137 $operator_select = (new CSelect('overrides_filters['.$i.'][operator]')) 138 ->setValue($overrides_filter['operator']) 139 ->addClass('js-operator') 140 ->addOptions($operators); 141 142 if ($options['templated']) { 143 $operator_select->setReadonly(); 144 } 145 146 $value = (new CTextBox('overrides_filters['.$i.'][value]', $overrides_filter['value'],$options['templated'], 147 DB::getFieldLength('lld_override_condition', 'value'))) 148 ->addClass('js-value') 149 ->setWidth(ZBX_TEXTAREA_MACRO_VALUE_WIDTH) 150 ->setAttribute('placeholder', _('regular expression')); 151 152 if ($overrides_filter['operator'] == CONDITION_OPERATOR_EXISTS 153 || $overrides_filter['operator'] == CONDITION_OPERATOR_NOT_EXISTS) { 154 $value->addClass(ZBX_STYLE_DISPLAY_NONE); 155 } 156 157 $delete_button_cell = [ 158 (new CButton('overrides_filters_'.$i.'_remove', _('Remove'))) 159 ->addClass(ZBX_STYLE_BTN_LINK) 160 ->addClass('element-table-remove') 161 ->setEnabled(!$options['templated']) 162 ]; 163 164 $row = [ 165 $formulaid, 166 $macro, 167 $operator_select, 168 (new CDiv($value))->setWidth(ZBX_TEXTAREA_MACRO_VALUE_WIDTH), 169 (new CCol($delete_button_cell))->addClass(ZBX_STYLE_NOWRAP) 170 ]; 171 172 $filter_table->addRow($row, 'form_row'); 173} 174 175$filter_table->setFooter(new CCol( 176 (new CButton('macro_add', _('Add'))) 177 ->addClass(ZBX_STYLE_BTN_LINK) 178 ->addClass('element-table-add') 179 ->setEnabled(!$options['templated']) 180 ->removeId() 181)); 182 183$overrides_popup_form_list->addRow(_('Filters'), 184 (new CDiv([$override_evaltype, $filter_table])) 185 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 186 ->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 187 ->addStyle('width: 100%;') 188); 189 190// operations 191$operations_list = (new CTable()) 192 ->addClass('lld-overrides-operations-table') 193 ->addStyle('width: 100%;') 194 ->setHeader([ 195 _('Condition'), 196 (new CColHeader(''))->setWidth('50') 197 ]) 198 ->addRow( 199 (new CCol( 200 (new CDiv( 201 (new CButton('param_add', _('Add'))) 202 ->addClass(ZBX_STYLE_BTN_LINK) 203 ->addClass('element-table-add') 204 ->setEnabled(!$options['templated']) 205 ->removeId() 206 ))->addClass('step-action') 207 )) 208 ); 209 210$overrides_popup_form_list->addRow(_('Operations'), 211 (new CDiv($operations_list)) 212 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 213 ->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 214 ->addStyle('width: 100%;') 215 ->addStyle('max-width: 788px;') 216); 217 218$output['buttons'] = [ 219 [ 220 'title' => $options['old_name'] ? _('Update') : _('Add'), 221 'class' => '', 222 'keepOpen' => true, 223 'isSubmit' => true, 224 'enabled' => !$options['templated'], 225 'action' => 'return lldoverrides.overrides.edit_form.validate(overlay);' 226 ] 227]; 228 229$overrides_popup_form->addItem($overrides_popup_form_list); 230 231$output['body'] = (new CDiv($overrides_popup_form))->toString(); 232$output['script_inline'] = 'lldoverrides.overrides.onStepOverlayReadyCb('.$options['no'].');'; 233 234if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 235 CProfiler::getInstance()->stop(); 236 $output['debug'] = CProfiler::getInstance()->make()->toString(); 237} 238 239echo json_encode($output); 240