1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
include('include/views/js/administration.general.valuemapping.edit.js.php');
$widget = (new CWidget())
->setTitle(_('Value mapping'))
->setControls((new CTag('nav', true,
(new CForm())
->cleanItems()
->addItem((new CList())
->addItem(makeAdministrationGeneralMenu('adm.valuemapping.php'))
)
))
->setAttribute('aria-label', _('Content controls'))
);
$form = (new CForm())
->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE)
->addVar('form', $data['form']);
if ($data['valuemapid'] != 0) {
$form->addVar('valuemapid', $data['valuemapid']);
}
$form_list = (new CFormList())
->addRow(
(new CLabel(_('Name'), 'name'))->setAsteriskMark(),
(new CTextBox('name', $data['name'], false, 64))
->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAriaRequired()
->setAttribute('autofocus', 'autofocus')
);
$table = (new CTable())
->setId('mappings_table')
->setHeader([_('Value'), '', _('Mapped to'), _('Action')])
->setAttribute('style', 'width: 100%;');
foreach ($data['mappings'] as $i => $mapping) {
$table->addRow([
(new CTextBox('mappings['.$i.'][value]', $mapping['value'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH),
'⇒',
(new CTextBox('mappings['.$i.'][newvalue]', $mapping['newvalue'], false, 64))
->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
->setAriaRequired(),
(new CButton('mappings['.$i.'][remove]', _('Remove')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-remove')
],
'form_row'
);
}
$table->addRow([
(new CCol(
(new CButton('mapping_add', _('Add')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-add')
))->setColSpan(4)
]);
$form_list->addRow(
(new CLabel(_('Mappings'), $table->getId()))->setAsteriskMark(),
(new CDiv($table))
->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_STANDARD_WIDTH.'px;')
);
// append form list to tab
$tab_view = (new CTabView())->addTab('valuemap_tab', _('Value mapping'), $form_list);
// append buttons
if ($data['valuemapid'] != 0) {
if ($data['valuemap_count'] == 0) {
$confirm_message = _('Delete selected value mapping?');
}
else {
$confirm_message = _n(
'Delete selected value mapping? It is used for %d item!',
'Delete selected value mapping? It is used for %d items!',
$data['valuemap_count']
);
}
$tab_view->setFooter(makeFormFooter(
new CSubmit('update', _('Update')),
[
new CButton('clone', _('Clone')),
(new CRedirectButton(_('Delete'),
'adm.valuemapping.php?action=valuemap.delete&valuemapids[]='.$data['valuemapid'].'&sid='.$data['sid'],
$confirm_message
))->setId('delete'),
new CButtonCancel()
]
));
}
else {
$tab_view->setFooter(makeFormFooter(
new CSubmit('add', _('Add')),
[new CButtonCancel()]
));
}
$form->addItem($tab_view);
$widget->addItem($form);
return $widget;
|