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
|
<?php
/*
** Zabbix
** Copyright (C) 2001-2018 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.
**/
$allowed_testing = $data['allowed_testing'];
$test = $data['test'];
$data_table = (new CTable())
->addStyle('width: 100%;')
->setHeader([
_('Expression Variable Elements'),
_('Result type'),
_('Value')
]);
foreach ($data['data_table_rows'] as $row) {
$data_table->addRow($row);
}
$form_list = (new CFormList())
->addRow(_('Test data'),
(new CDiv($data_table))
->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;')
);
$result_table = (new CTable())
->addStyle('width: 100%;')
->setHeader([
_('Expression'),
_('Result')
]);
foreach ($data['eHTMLTree'] as $e) {
$result = '';
$style = null;
if ($allowed_testing && $test && array_key_exists('expression', $e)) {
if (evalExpressionData($e['expression']['value'], $data['macros_data'])) {
$result = 'TRUE';
$style = ZBX_STYLE_GREEN;
}
else {
$result = 'FALSE';
$style = ZBX_STYLE_RED;
}
}
$result_table->addRow([
(new CCol($e['list']))
->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS)
->addStyle('max-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;'),
(new CCol($result))->addClass($style)
]);
}
$result = '';
if ($allowed_testing && $test) {
if (evalExpressionData($data['expression'], $data['macros_data'])) {
$result = 'TRUE';
$style = ZBX_STYLE_GREEN;
}
else {
$result = 'FALSE';
$style = ZBX_STYLE_RED;
}
}
$result_table->setFooter([$data['outline'], (new CCol($result))->addClass($style)]);
$form_list->addRow(_('Result'),
(new CDiv($result_table))
->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;')
);
$output = [
'header' => $data['title'],
'body' => (new CDiv([
$data['message'],
(new CForm())
->cleanItems()
->setId('expression_testing_from')
->addItem((new CVar('expression', $data['expression']))->removeId())
->addItem((new CVar('test_expression', 1))->removeId())
->addItem([
$form_list,
(new CInput('submit', 'submit'))->addStyle('display: none;')
])
]))->toString(),
'buttons' => [
[
'title' => _('Test'),
'enabled' => $allowed_testing,
'class' => '',
'keepOpen' => true,
'isSubmit' => true,
'action' => 'return reloadPopup(document.forms["expression_testing_from"], "popup.testtriggerexpr");'
]
]
];
if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
CProfiler::getInstance()->stop();
$output['debug'] = CProfiler::getInstance()->make()->toString();
}
echo (new CJson())->encode($output);
|