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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2021 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.
**/
/**
* @var CPartial $this
*/
if ($data['readonly'] && !$data['macros']) {
$table = new CObject(_('No macros found.'));
}
else {
$link = null;
$is_hostprototype = array_key_exists('parent_hostid', $data);
$inherited_width = $is_hostprototype ? ZBX_TEXTAREA_MACRO_INHERITED_WIDTH : ZBX_TEXTAREA_MACRO_VALUE_WIDTH;
$table = (new CTable())
->setId('tbl_macros')
->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_CONTAINER)
->addClass('inherited-macros-table');
if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) {
$link = (new CLink(_('configure'), (new CUrl('zabbix.php'))
->setArgument('action', 'macros.edit')
->getUrl()
))
->setAttribute('target', '_blank');
$link = [' (', $link, ')'];
}
$table->setColumns([
(new CTableColumn(_('Macro')))->addClass('table-col-macro'),
(new CTableColumn(_('Effective value')))->addClass('table-col-value'),
(new CTableColumn($data['readonly'] ? null : ''))->addClass('table-col-action'),
$is_hostprototype ? (new CTableColumn())->addClass('table-col-arrow') : null,
$is_hostprototype ? (new CTableColumn())->addClass('table-col-parent-value') : null,
(new CTableColumn())->addClass('table-col-arrow'),
(new CTableColumn(_('Template value')))->addClass('table-col-template-value'),
(new CTableColumn())->addClass('table-col-arrow'),
(new CTableColumn([_('Global value'), $link]))->addClass('table-col-global-value')
]);
foreach ($data['macros'] as $i => $macro) {
$readonly = ($data['readonly'] || !($macro['inherited_type'] & ZBX_PROPERTY_OWN));
$macro_cell = [
(new CTextAreaFlexible('macros['.$i.'][macro]', $macro['macro']))
->setReadonly($data['readonly'] || $macro['inherited_type'] & ZBX_PROPERTY_INHERITED)
->addClass('macro')
->setWidth(ZBX_TEXTAREA_MACRO_WIDTH)
->setAttribute('placeholder', '{$MACRO}'),
new CVar('macros['.$i.'][inherited_type]', $macro['inherited_type'])
];
if (!$data['readonly']) {
if (array_key_exists('hostmacroid', $macro)) {
$macro_cell[] = new CVar('macros['.$i.'][hostmacroid]', $macro['hostmacroid']);
}
if ($macro['inherited_type'] & ZBX_PROPERTY_INHERITED) {
$inherited_macro = $macro[$macro['inherited_level']];
$macro_cell[] = new CVar('macros['.$i.'][inherited][value]', $inherited_macro['value']);
$macro_cell[] = new CVar('macros['.$i.'][inherited][description]', $inherited_macro['description']);
$macro_cell[] = new CVar('macros['.$i.'][inherited][macro_type]', $inherited_macro['type']);
}
}
$macro_value = (new CMacroValue($macro['type'], 'macros['.$i.']', null, false))->setReadonly($readonly);
if ($macro['type'] == ZBX_MACRO_TYPE_SECRET) {
$macro_value->addRevertButton();
$macro_value->setRevertButtonVisibility(array_key_exists('value', $macro)
&& array_key_exists('hostmacroid', $macro)
);
}
if (array_key_exists('value', $macro)) {
$macro_value->setAttribute('value', $macro['value']);
}
$row = [
(new CCol($macro_cell))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT),
(new CCol($macro_value))->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT)
];
if (!$data['readonly']) {
if (($macro['inherited_type'] & ZBX_PROPERTY_BOTH) == ZBX_PROPERTY_BOTH) {
$row[] = (new CCol(
(new CButton('macros['.$i.'][change]', _('Remove')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-change')
))->addClass(ZBX_STYLE_NOWRAP);
}
elseif ($macro['inherited_type'] & ZBX_PROPERTY_INHERITED) {
$row[] = (new CCol(
(new CButton('macros['.$i.'][change]', _x('Change', 'verb')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-change')
))->addClass(ZBX_STYLE_NOWRAP);
}
else {
$row[] = (new CCol(
(new CButton('macros['.$i.'][remove]', _('Remove')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-remove')
))->addClass(ZBX_STYLE_NOWRAP);
}
}
// Parent host macro value.
if ($is_hostprototype) {
$row[] = array_key_exists('parent_host', $macro) ? '⇐' : '';
$row[] = (new CDiv(array_key_exists('parent_host', $macro) ? '"'.$macro['parent_host']['value'].'"' : null))
->setAdaptiveWidth($inherited_width)
->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS);
}
// Template macro value.
$template_macro = null;
if (array_key_exists('template', $macro)) {
if ($macro['template']['rights'] == PERM_READ_WRITE) {
$link = (new CLink(CHtml::encode($macro['template']['name']),
'templates.php?form=update&templateid='.$macro['template']['templateid'])
)
->addClass('unknown')
->setAttribute('target', '_blank');
}
else {
$link = new CSpan(CHtml::encode($macro['template']['name']));
}
$template_macro = [$link, NAME_DELIMITER, '"'.$macro['template']['value'].'"'];
}
$row[] = array_key_exists('template', $macro) ? '⇐' : '';
$row[] = (new CDiv(array_key_exists('template', $macro) ? $template_macro : null))
->setAdaptiveWidth($inherited_width)
->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS);
// Global macro value.
$row[] = array_key_exists('global', $macro) ? '⇐' : '';
$row[] = (new CDiv(array_key_exists('global', $macro) ? '"'.$macro['global']['value'].'"' : null))
->setAdaptiveWidth($inherited_width)
->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS);
$table
->addRow($row, 'form_row')
->addRow((new CRow([
(new CCol(
(new CTextAreaFlexible('macros['.$i.'][description]', $macro['description']))
->setMaxlength(DB::getFieldLength('hostmacro', 'description'))
->setAdaptiveWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
->setAttribute('placeholder', _('description'))
->setReadonly($readonly)
))
->addClass(ZBX_STYLE_TEXTAREA_FLEXIBLE_PARENT)
->setColSpan(count($row))
]))->addClass('form_row'));
}
// buttons
if (!$data['readonly']) {
$table->setFooter(new CCol(
(new CButton('macro_add', _('Add')))
->addClass(ZBX_STYLE_BTN_LINK)
->addClass('element-table-add')
));
}
}
$table->show();
// Initializing input secret and macro value init script separately.
(new CScriptTag("jQuery('.input-secret').inputSecret();"))->show();
(new CScriptTag("jQuery('.input-group').macroValue();"))->show();
|