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$widget = (new CWidget()) 27 ->setTitle(_('Item prototypes')) 28 ->setControls( 29 (new CTag('nav', true, 30 (new CList())->addItem(new CRedirectButton(_('Create item prototype'), 31 (new CUrl('disc_prototypes.php')) 32 ->setArgument('form', 'create') 33 ->setArgument('parent_discoveryid', $data['parent_discoveryid']) 34 ->getUrl() 35 )) 36 ))->setAttribute('aria-label', _('Content controls')) 37 ) 38 ->addItem(get_header_host_table('items', $data['hostid'], $data['parent_discoveryid'])); 39 40// create form 41$itemForm = (new CForm()) 42 ->setName('items') 43 ->addVar('parent_discoveryid', $data['parent_discoveryid']); 44 45$url = (new CUrl('disc_prototypes.php')) 46 ->setArgument('parent_discoveryid', $data['parent_discoveryid']) 47 ->getUrl(); 48 49// create table 50$itemTable = (new CTableInfo()) 51 ->setHeader([ 52 (new CColHeader( 53 (new CCheckBox('all_items'))->onClick("checkAll('".$itemForm->getName()."', 'all_items', 'group_itemid');") 54 ))->addClass(ZBX_STYLE_CELL_WIDTH), 55 _('Wizard'), 56 make_sorting_header(_('Name'),'name', $data['sort'], $data['sortorder'], $url), 57 make_sorting_header(_('Key'), 'key_', $data['sort'], $data['sortorder'], $url), 58 make_sorting_header(_('Interval'), 'delay', $data['sort'], $data['sortorder'], $url), 59 make_sorting_header(_('History'), 'history', $data['sort'], $data['sortorder'], $url), 60 make_sorting_header(_('Trends'), 'trends', $data['sort'], $data['sortorder'], $url), 61 make_sorting_header(_('Type'), 'type', $data['sort'], $data['sortorder'], $url), 62 _('Applications'), 63 make_sorting_header(_('Create enabled'), 'status', $data['sort'], $data['sortorder'], $url), 64 make_sorting_header(_('Discover'), 'discover', $data['sort'], $data['sortorder'], $url) 65 ]); 66 67$update_interval_parser = new CUpdateIntervalParser(['usermacros' => true, 'lldmacros' => true]); 68 69foreach ($data['items'] as $item) { 70 $description = []; 71 $description[] = makeItemTemplatePrefix($item['itemid'], $data['parent_templates'], ZBX_FLAG_DISCOVERY_PROTOTYPE); 72 73 if ($item['type'] == ITEM_TYPE_DEPENDENT) { 74 if ($item['master_item']['type'] == ITEM_TYPE_HTTPTEST) { 75 $description[] = CHtml::encode($item['master_item']['name_expanded']); 76 } 77 else { 78 $link = ($item['master_item']['source'] === 'itemprototypes') 79 ? (new CUrl('disc_prototypes.php'))->setArgument('parent_discoveryid', $data['parent_discoveryid']) 80 : (new CUrl('items.php')) 81 ->setArgument('filter_set', '1') 82 ->setArgument('filter_hostids', [$item['hostid']]); 83 84 $description[] = (new CLink(CHtml::encode($item['master_item']['name_expanded']), 85 $link 86 ->setArgument('form', 'update') 87 ->setArgument('itemid', $item['master_item']['itemid']) 88 ->getUrl() 89 )) 90 ->addClass(ZBX_STYLE_LINK_ALT) 91 ->addClass(ZBX_STYLE_TEAL); 92 } 93 94 $description[] = NAME_DELIMITER; 95 } 96 97 $description[] = new CLink( 98 $item['name_expanded'], 99 (new CUrl('disc_prototypes.php')) 100 ->setArgument('form', 'update') 101 ->setArgument('parent_discoveryid', $data['parent_discoveryid']) 102 ->setArgument('itemid', $item['itemid']) 103 ->getUrl() 104 ); 105 106 $status = (new CLink( 107 ($item['status'] == ITEM_STATUS_DISABLED) ? _('No') : _('Yes'), 108 (new CUrl('disc_prototypes.php')) 109 ->setArgument('group_itemid[]', $item['itemid']) 110 ->setArgument('parent_discoveryid', $data['parent_discoveryid']) 111 ->setArgument('action', ($item['status'] == ITEM_STATUS_DISABLED) 112 ? 'itemprototype.massenable' 113 : 'itemprototype.massdisable' 114 ) 115 ->getUrl() 116 )) 117 ->addClass(ZBX_STYLE_LINK_ACTION) 118 ->addClass(itemIndicatorStyle($item['status'])) 119 ->addSID(); 120 121 if (!empty($item['applications'])) { 122 order_result($item['applications'], 'name'); 123 124 $applications = zbx_objectValues($item['applications'], 'name'); 125 $applications = implode(', ', $applications); 126 if (empty($applications)) { 127 $applications = ''; 128 } 129 } 130 else { 131 $applications = ''; 132 } 133 134 if (in_array($item['value_type'], [ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT])) { 135 $item['trends'] = ''; 136 } 137 138 // Hide zeros for trapper, SNMP trap and dependent items. 139 if ($item['type'] == ITEM_TYPE_TRAPPER || $item['type'] == ITEM_TYPE_SNMPTRAP 140 || $item['type'] == ITEM_TYPE_DEPENDENT) { 141 $item['delay'] = ''; 142 } 143 elseif ($update_interval_parser->parse($item['delay']) == CParser::PARSE_SUCCESS) { 144 $item['delay'] = $update_interval_parser->getDelay(); 145 } 146 147 $item_menu = CMenuPopupHelper::getItemPrototype($item['itemid'], $data['parent_discoveryid']); 148 149 $wizard = (new CSpan( 150 (new CButton(null))->addClass(ZBX_STYLE_ICON_WZRD_ACTION)->setMenuPopup($item_menu) 151 ))->addClass(ZBX_STYLE_REL_CONTAINER); 152 153 $nodiscover = ($item['discover'] == ZBX_PROTOTYPE_NO_DISCOVER); 154 $discover = (new CLink($nodiscover ? _('No') : _('Yes'), 155 (new CUrl('disc_prototypes.php')) 156 ->setArgument('group_itemid[]', $item['itemid']) 157 ->setArgument('parent_discoveryid', $data['parent_discoveryid']) 158 ->setArgument('visible[discover]', '1') 159 ->setArgument('massupdate', 'discover') 160 ->setArgument('discover', $nodiscover ? ZBX_PROTOTYPE_DISCOVER : ZBX_PROTOTYPE_NO_DISCOVER) 161 ->setArgumentSID() 162 ->getUrl() 163 )) 164 ->addSID() 165 ->addClass(ZBX_STYLE_LINK_ACTION) 166 ->addClass($nodiscover ? ZBX_STYLE_RED : ZBX_STYLE_GREEN); 167 168 $itemTable->addRow([ 169 new CCheckBox('group_itemid['.$item['itemid'].']', $item['itemid']), 170 $wizard, 171 $description, 172 (new CDiv(CHtml::encode($item['key_'])))->addClass(ZBX_STYLE_WORDWRAP), 173 $item['delay'], 174 $item['history'], 175 $item['trends'], 176 item_type2str($item['type']), 177 $applications, 178 $status, 179 $discover 180 ]); 181} 182 183// append table to form 184$itemForm->addItem([ 185 $itemTable, 186 $data['paging'], 187 new CActionButtonList('action', 'group_itemid', 188 [ 189 'itemprototype.massenable' => ['name' => _('Create enabled'), 190 'confirm' => _('Create items from selected prototypes as enabled?') 191 ], 192 'itemprototype.massdisable' => ['name' => _('Create disabled'), 193 'confirm' => _('Create items from selected prototypes as disabled?') 194 ], 195 'itemprototype.massupdateform' => ['name' => _('Mass update')], 196 'itemprototype.massdelete' => ['name' => _('Delete'), 197 'confirm' => _('Delete selected item prototypes?') 198 ] 199 ], 200 $data['parent_discoveryid'] 201 ) 202]); 203 204// append form to widget 205$widget->addItem($itemForm); 206 207$widget->show(); 208