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