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