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 26require_once dirname(__FILE__).'/js/configuration.template.list.js.php'; 27 28$filter_tags = $data['filter']['tags']; 29if (!$filter_tags) { 30 $filter_tags = [['tag' => '', 'value' => '', 'operator' => TAG_OPERATOR_LIKE]]; 31} 32 33$filter_tags_table = (new CTable()) 34 ->setId('filter-tags') 35 ->addRow((new CCol( 36 (new CRadioButtonList('filter_evaltype', (int) $data['filter']['evaltype'])) 37 ->addValue(_('And/Or'), TAG_EVAL_TYPE_AND_OR) 38 ->addValue(_('Or'), TAG_EVAL_TYPE_OR) 39 ->setModern(true) 40 ))->setColSpan(4) 41 ); 42 43$i = 0; 44foreach ($filter_tags as $tag) { 45 $filter_tags_table->addRow([ 46 (new CTextBox('filter_tags['.$i.'][tag]', $tag['tag'])) 47 ->setAttribute('placeholder', _('tag')) 48 ->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 49 (new CRadioButtonList('filter_tags['.$i.'][operator]', (int) $tag['operator'])) 50 ->addValue(_('Contains'), TAG_OPERATOR_LIKE) 51 ->addValue(_('Equals'), TAG_OPERATOR_EQUAL) 52 ->setModern(true), 53 (new CTextBox('filter_tags['.$i.'][value]', $tag['value'])) 54 ->setAttribute('placeholder', _('value')) 55 ->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 56 (new CCol( 57 (new CButton('filter_tags['.$i.'][remove]', _('Remove'))) 58 ->addClass(ZBX_STYLE_BTN_LINK) 59 ->addClass('element-table-remove') 60 ))->addClass(ZBX_STYLE_NOWRAP) 61 ], 'form_row'); 62 63 $i++; 64} 65$filter_tags_table->addRow( 66 (new CCol( 67 (new CButton('filter_tags_add', _('Add'))) 68 ->addClass(ZBX_STYLE_BTN_LINK) 69 ->addClass('element-table-add') 70 ))->setColSpan(3) 71); 72 73$filter = new CFilter(new CUrl('templates.php')); 74$filter 75 ->setProfile($data['profileIdx']) 76 ->setActiveTab($data['active_tab']) 77 ->addFilterTab(_('Filter'), [ 78 (new CFormList()) 79 ->addRow( 80 (new CLabel(_('Host groups'), 'filter_groups__ms')), 81 (new CMultiSelect([ 82 'name' => 'filter_groups[]', 83 'object_name' => 'hostGroup', 84 'data' => $data['filter']['groups'], 85 'popup' => [ 86 'parameters' => [ 87 'srctbl' => 'host_groups', 88 'srcfld1' => 'groupid', 89 'dstfrm' => $filter->getName(), 90 'dstfld1' => 'filter_groups_', 91 'templated_hosts' => 1, 92 'editable' => 1, 93 'enrich_parent_groups' => true 94 ] 95 ] 96 ]))->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) 97 ) 98 ->addRow( 99 (new CLabel(_('Linked templates'), 'filter_templates__ms')), 100 (new CMultiSelect([ 101 'name' => 'filter_templates[]', 102 'object_name' => 'templates', 103 'data' => $data['filter']['templates'], 104 'popup' => [ 105 'parameters' => [ 106 'srctbl' => 'templates', 107 'srcfld1' => 'hostid', 108 'srcfld2' => 'host', 109 'dstfrm' => $filter->getName(), 110 'dstfld1' => 'filter_templates_' 111 ] 112 ] 113 ]))->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) 114 ) 115 ->addRow(_('Name'), 116 (new CTextBox('filter_name', $data['filter']['name']))->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) 117 ), 118 (new CFormList())->addRow(_('Tags'), $filter_tags_table) 119 ]); 120 121$widget = (new CWidget()) 122 ->setTitle(_('Templates')) 123 ->setControls((new CTag('nav', true, 124 (new CList()) 125 ->addItem(new CRedirectButton(_('Create template'), 126 (new CUrl('templates.php')) 127 ->setArgument('groupids', array_keys($data['filter']['groups'])) 128 ->setArgument('form', 'create') 129 ->getUrl() 130 ) 131 ) 132 ->addItem( 133 (new CButton('form', _('Import')))->onClick('redirect("conf.import.php?rules_preset=template")') 134 ) 135 ))->setAttribute('aria-label', _('Content controls')) 136 ) 137 ->addItem($filter); 138 139$form = (new CForm())->setName('templates'); 140 141// create table 142$table = (new CTableInfo()) 143 ->setHeader([ 144 (new CColHeader( 145 (new CCheckBox('all_templates'))->onClick("checkAll('".$form->getName()."', 'all_templates', 'templates');") 146 ))->addClass(ZBX_STYLE_CELL_WIDTH), 147 make_sorting_header(_('Name'), 'name', $data['sortField'], $data['sortOrder'], 148 (new CUrl('templates.php'))->getUrl() 149 ), 150 _('Hosts'), 151 _('Applications'), 152 _('Items'), 153 _('Triggers'), 154 _('Graphs'), 155 _('Screens'), 156 _('Discovery'), 157 _('Web'), 158 _('Linked templates'), 159 _('Linked to templates'), 160 _('Tags') 161 ]); 162 163foreach ($data['templates'] as $template) { 164 $name = new CLink($template['name'], 'templates.php?form=update&templateid='.$template['templateid']); 165 166 $linked_templates_output = []; 167 $linked_to_output = []; 168 169 $i = 0; 170 foreach ($template['parentTemplates'] as $parent_template) { 171 $i++; 172 173 if ($i > $data['config']['max_in_table']) { 174 $linked_templates_output[] = ' …'; 175 176 break; 177 } 178 179 if ($linked_templates_output) { 180 $linked_templates_output[] = ', '; 181 } 182 183 $url = (new CUrl('templates.php')) 184 ->setArgument('form', 'update') 185 ->setArgument('templateid', $parent_template['templateid']); 186 187 if (array_key_exists($parent_template['templateid'], $data['editable_templates'])) { 188 $linked_templates_output[] = (new CLink($parent_template['name'], $url)) 189 ->addClass(ZBX_STYLE_LINK_ALT) 190 ->addClass(ZBX_STYLE_GREY); 191 } 192 else { 193 $linked_templates_output[] = (new CSpan($parent_template['name'])) 194 ->addClass(ZBX_STYLE_GREY); 195 } 196 } 197 198 $i = 0; 199 foreach ($template['templates'] as $child_template) { 200 $i++; 201 202 if ($i > $data['config']['max_in_table']) { 203 $linked_to_output[] = ' …'; 204 205 break; 206 } 207 208 if ($linked_to_output) { 209 $linked_to_output[] = ', '; 210 } 211 212 if (array_key_exists($child_template['templateid'], $data['editable_templates'])) { 213 $url = (new CUrl('templates.php')) 214 ->setArgument('form', 'update') 215 ->setArgument('templateid', $child_template['templateid']); 216 $linked_to_output[] = (new CLink($child_template['name'], $url)) 217 ->addClass(ZBX_STYLE_LINK_ALT) 218 ->addClass(ZBX_STYLE_GREY); 219 } 220 else { 221 $linked_to_output[] = (new CSpan($child_template['name'])) 222 ->addClass(ZBX_STYLE_GREY); 223 } 224 } 225 226 $table->addRow([ 227 new CCheckBox('templates['.$template['templateid'].']', $template['templateid']), 228 (new CCol($name))->addClass(ZBX_STYLE_NOWRAP), 229 [ 230 new CLink(_('Hosts'), 231 (new CUrl('hosts.php')) 232 ->setArgument('filter_set', '1') 233 ->setArgument('filter_templates', [$template['templateid']]) 234 ), 235 CViewHelper::showNum(count(array_intersect_key($template['hosts'], $data['editable_hosts']))) 236 ], 237 [ 238 new CLink(_('Applications'), 239 (new CUrl('applications.php')) 240 ->setArgument('filter_set', '1') 241 ->setArgument('filter_hostids', [$template['templateid']]) 242 ), 243 CViewHelper::showNum($template['applications']) 244 ], 245 [ 246 new CLink(_('Items'), 247 (new CUrl('items.php')) 248 ->setArgument('filter_set', '1') 249 ->setArgument('filter_hostids', [$template['templateid']]) 250 ), 251 CViewHelper::showNum($template['items']) 252 ], 253 [ 254 new CLink(_('Triggers'), 255 (new CUrl('triggers.php')) 256 ->setArgument('filter_set', '1') 257 ->setArgument('filter_hostids', [$template['templateid']]) 258 ), 259 CViewHelper::showNum($template['triggers']) 260 ], 261 [ 262 new CLink(_('Graphs'), 263 (new CUrl('graphs.php')) 264 ->setArgument('filter_set', '1') 265 ->setArgument('filter_hostids', [$template['templateid']]) 266 ), 267 CViewHelper::showNum($template['graphs']) 268 ], 269 [ 270 new CLink(_('Screens'), 'screenconf.php?templateid='.$template['templateid']), 271 CViewHelper::showNum($template['screens']) 272 ], 273 [ 274 new CLink(_('Discovery'), 275 (new CUrl('host_discovery.php')) 276 ->setArgument('filter_set', '1') 277 ->setArgument('filter_hostids', [$template['templateid']]) 278 ), 279 CViewHelper::showNum($template['discoveries']) 280 ], 281 [ 282 new CLink(_('Web'), 283 (new CUrl('httpconf.php')) 284 ->setArgument('filter_set', '1') 285 ->setArgument('filter_hostids', [$template['templateid']]) 286 ), 287 CViewHelper::showNum($template['httpTests']) 288 ], 289 $linked_templates_output, 290 $linked_to_output, 291 $data['tags'][$template['templateid']] 292 ]); 293} 294 295$form->addItem([ 296 $table, 297 $data['paging'], 298 new CActionButtonList('action', 'templates', 299 [ 300 'template.export' => ['name' => _('Export'), 'redirect' => 301 (new CUrl('zabbix.php')) 302 ->setArgument('action', 'export.templates.xml') 303 ->setArgument('backurl', (new CUrl('templates.php')) 304 ->setArgument('page', $data['page'] == 1 ? null : $data['page']) 305 ->getUrl()) 306 ->getUrl() 307 ], 308 'template.massupdateform' => ['name' => _('Mass update')], 309 'template.massdelete' => ['name' => _('Delete'), 'confirm' => _('Delete selected templates?')], 310 'template.massdeleteclear' => ['name' => _('Delete and clear'), 311 'confirm' => _('Delete and clear selected templates? (Warning: all linked hosts will be cleared!)') 312 ] 313 ] 314 ) 315]); 316 317$widget->addItem($form); 318 319$widget->show(); 320