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$data_table = (new CTable()) 27 ->addStyle('width: 100%;') 28 ->setHeader([ 29 _('Expression Variable Elements'), 30 _('Result type'), 31 _('Value') 32 ]); 33 34foreach ($data['data_table_rows'] as $row) { 35 $data_table->addRow($row); 36} 37 38$form_list = (new CFormList()) 39 ->addRow(_('Test data'), 40 (new CDiv($data_table)) 41 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 42 ->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 43 ); 44 45$result_table = (new CTable()) 46 ->addStyle('width: 100%;') 47 ->setHeader([ 48 _('Expression'), 49 _('Result'), 50 _('Error') 51 ]); 52 53foreach ($data['eHTMLTree'] as $e) { 54 $expression = $e['expression']['value']; 55 $result = ''; 56 $style = null; 57 $error = null; 58 59 if (array_key_exists($expression, $data['results'])) { 60 if (array_key_exists('value', $data['results'][$expression])) { 61 $result = $data['results'][$expression]['value'] ? 'TRUE' : 'FALSE'; 62 $style = $data['results'][$expression]['value'] ? ZBX_STYLE_GREEN : ZBX_STYLE_RED; 63 } 64 if (array_key_exists('error', $data['results'][$expression])) { 65 $error = makeErrorIcon($data['results'][$expression]['error']); 66 } 67 } 68 69 $result_table->addRow([ 70 (new CCol($e['list'])) 71 ->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS) 72 ->addStyle('max-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;'), 73 (new CCol($result))->addClass($style), 74 new CCol($error) 75 ]); 76} 77 78$expression = $data['expression']; 79$result = ''; 80$style = null; 81$error = null; 82 83if (array_key_exists($expression, $data['results'])) { 84 if (array_key_exists('value', $data['results'][$expression])) { 85 $result = $data['results'][$expression]['value'] ? 'TRUE' : 'FALSE'; 86 $style = $data['results'][$expression]['value'] ? ZBX_STYLE_GREEN : ZBX_STYLE_RED; 87 } 88 if (array_key_exists('error', $data['results'][$expression])) { 89 $error = makeErrorIcon($data['results'][$expression]['error']); 90 } 91} 92 93$result_table->setFooter([ 94 (new CCol($data['outline'])) 95 ->setAttribute('title', $data['outline']) 96 ->addClass(ZBX_STYLE_OVERFLOW_ELLIPSIS) 97 ->addStyle('max-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;'), 98 (new CCol($result))->addClass($style), 99 new CCol($error) 100]); 101 102$form_list->addRow(_('Result'), 103 (new CDiv($result_table)) 104 ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) 105 ->addStyle('min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') 106); 107 108$output = [ 109 'header' => $data['title'], 110 'body' => (new CDiv([ 111 $data['message'], 112 (new CForm()) 113 ->cleanItems() 114 ->setId('expression_testing_from') 115 ->addItem((new CVar('expression', $data['expression']))->removeId()) 116 ->addItem((new CVar('test_expression', 1))->removeId()) 117 ->addItem([ 118 $form_list, 119 (new CInput('submit', 'submit'))->addStyle('display: none;') 120 ]) 121 ]))->toString(), 122 'buttons' => [ 123 [ 124 'title' => _('Test'), 125 'enabled' => $data['allowed_testing'], 126 'class' => '', 127 'keepOpen' => true, 128 'isSubmit' => true, 129 'action' => 'return reloadPopup(document.forms["expression_testing_from"], "popup.testtriggerexpr");' 130 ] 131 ] 132]; 133 134if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) { 135 CProfiler::getInstance()->stop(); 136 $output['debug'] = CProfiler::getInstance()->make()->toString(); 137} 138 139echo json_encode($output); 140