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$itemWidget = (new CWidget())->setTitle(_('Items'));
23
24if (!empty($this->data['hostid'])) {
25	$itemWidget->addItem(get_header_host_table('items', $this->data['hostid']));
26}
27
28// create form
29$itemForm = (new CForm())
30	->setName('itemForm')
31	->addVar('group_itemid', $this->data['itemids'])
32	->addVar('hostid', $this->data['hostid'])
33	->addVar('action', $this->data['action']);
34
35// create form list
36$itemFormList = new CFormList('itemFormList');
37
38// append type to form list
39$itemFormList->addRow(
40	[
41		_('Type'),
42		SPACE,
43		(new CVisibilityBox('visible[type]', 'type', _('Original')))
44			->setChecked(isset($this->data['visible']['type']))
45	],
46	new CComboBox('type', $this->data['type'], null, $this->data['itemTypes'])
47);
48
49// append hosts to form list
50if ($this->data['displayInterfaces']) {
51	$interfacesComboBox = new CComboBox('interfaceid', $this->data['interfaceid']);
52	$interfacesComboBox->addItem(new CComboItem(0, '', null, false));
53
54	// Set up interface groups sorted by priority.
55	$interface_types = zbx_objectValues($this->data['hosts']['interfaces'], 'type');
56	$interface_groups = [];
57	foreach ([INTERFACE_TYPE_AGENT, INTERFACE_TYPE_SNMP, INTERFACE_TYPE_JMX, INTERFACE_TYPE_IPMI] as $interface_type) {
58		if (in_array($interface_type, $interface_types)) {
59			$interface_groups[$interface_type] = new COptGroup(interfaceType2str($interface_type));
60		}
61	}
62
63	// add interfaces to groups
64	foreach ($this->data['hosts']['interfaces'] as $interface) {
65		$option = new CComboItem(
66			$interface['interfaceid'],
67			$interface['useip'] ? $interface['ip'].' : '.$interface['port'] : $interface['dns'].' : '.$interface['port'],
68			$interface['interfaceid'] == $this->data['interfaceid'] ? 'yes' : 'no'
69		);
70		$option->setAttribute('data-interfacetype', $interface['type']);
71		$interface_groups[$interface['type']]->addItem($option);
72	}
73	foreach ($interface_groups as $interface_group) {
74		$interfacesComboBox->addItem($interface_group);
75	}
76
77	$span = (new CSpan(_('No interface found')))
78		->addClass(ZBX_STYLE_RED)
79		->setId('interface_not_defined')
80		->setAttribute('style', 'display: none;');
81
82	$interfaceVisBox = (new CVisibilityBox('visible[interface]', 'interfaceDiv', _('Original')))
83		->setChecked(isset($this->data['visible']['interface']))
84		->setAttribute('data-multiple-interface-types', $this->data['multiple_interface_types']);
85	$itemFormList->addRow(
86		[_('Host interface'), SPACE, $interfaceVisBox],
87		(new CDiv([$interfacesComboBox, $span]))->setId('interfaceDiv'),
88		'interface_row'
89	);
90	$itemForm->addVar('selectedInterfaceId', $this->data['interfaceid']);
91}
92
93// append snmp community to form list
94$itemFormList->addRow(
95	[
96		_('SNMP community'),
97		SPACE,
98		(new CVisibilityBox('visible[community]', 'snmp_community', _('Original')))
99			->setChecked(isset($this->data['visible']['community']))
100	],
101	(new CTextBox('snmp_community', $this->data['snmp_community']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
102);
103
104// append snmpv3 contextname to form list
105$itemFormList->addRow(
106	[
107		_('Context name'),
108		SPACE,
109		(new CVisibilityBox('visible[contextname]', 'snmpv3_contextname', _('Original')))
110			->setChecked(isset($this->data['visible']['contextname']))
111	],
112	(new CTextBox('snmpv3_contextname', $this->data['snmpv3_contextname']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
113);
114
115// append snmpv3 securityname to form list
116$itemFormList->addRow(
117	[
118		_('Security name'),
119		SPACE,
120		(new CVisibilityBox('visible[securityname]', 'snmpv3_securityname', _('Original')))
121			->setChecked(isset($this->data['visible']['securityname']))
122	],
123	(new CTextBox('snmpv3_securityname', $this->data['snmpv3_securityname']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
124);
125
126// append snmpv3 securitylevel to form list
127$itemFormList->addRow(
128	[
129		_('Security level'),
130		SPACE,
131		(new CVisibilityBox('visible[securitylevel]', 'snmpv3_securitylevel', _('Original')))
132			->setChecked(isset($this->data['visible']['securitylevel']))
133	],
134	new CComboBox('snmpv3_securitylevel', $this->data['snmpv3_securitylevel'], null, [
135		ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV => 'noAuthNoPriv',
136		ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV => 'authNoPriv',
137		ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV => 'authPriv'
138	])
139);
140
141// append snmpv3 authprotocol to form list
142$itemFormList->addRow(
143	[
144		_('Authentication protocol'),
145		SPACE,
146		(new CVisibilityBox('visible[authprotocol]', 'authprotocol_div', _('Original')))
147			->setChecked(isset($this->data['visible']['authprotocol']))
148	],
149	(new CDiv(
150		(new CRadioButtonList('snmpv3_authprotocol', (int) $this->data['snmpv3_authprotocol']))
151			->addValue(_('MD5'), ITEM_AUTHPROTOCOL_MD5)
152			->addValue(_('SHA'), ITEM_AUTHPROTOCOL_SHA)
153			->setModern(true)
154	))->setId('authprotocol_div')
155);
156
157// append snmpv3 authpassphrase to form list
158$itemFormList->addRow(
159	[
160		_('Authentication passphrase'),
161		SPACE,
162		(new CVisibilityBox('visible[authpassphrase]', 'snmpv3_authpassphrase', _('Original')))
163			->setChecked(isset($this->data['visible']['authpassphrase']))
164	],
165	(new CTextBox('snmpv3_authpassphrase', $this->data['snmpv3_authpassphrase']))
166		->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
167);
168
169// append snmpv3 privprotocol to form list
170$itemFormList->addRow(
171	[
172		_('Privacy protocol'),
173		SPACE,
174		(new CVisibilityBox('visible[privprotocol]', 'privprotocol_div', _('Original')))
175			->setChecked(isset($this->data['visible']['privprotocol']))
176	],
177	(new CDiv(
178		(new CRadioButtonList('snmpv3_privprotocol', (int) $this->data['snmpv3_privprotocol']))
179			->addValue(_('DES'), ITEM_PRIVPROTOCOL_DES)
180			->addValue(_('AES'), ITEM_PRIVPROTOCOL_AES)
181			->setModern(true)
182	))
183		->setId('privprotocol_div')
184);
185
186// append snmpv3 privpassphrase to form list
187$itemFormList->addRow(
188	[
189		_('Privacy passphrase'),
190		SPACE,
191		(new CVisibilityBox('visible[privpassphrase]', 'snmpv3_privpassphrase', _('Original')))
192			->setChecked(isset($this->data['visible']['privpassphrase']))
193	],
194	(new CTextBox('snmpv3_privpassphrase', $this->data['snmpv3_privpassphrase']))
195		->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
196);
197
198// append port to form list
199$itemFormList->addRow(
200	[
201		_('Port'),
202		SPACE,
203		(new CVisibilityBox('visible[port]', 'port', _('Original')))
204			->setChecked(isset($this->data['visible']['port']))
205	],
206	(new CTextBox('port', $this->data['port']))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
207);
208
209// append value type to form list
210$itemFormList->addRow(
211	[
212		_('Type of information'),
213		SPACE,
214		(new CVisibilityBox('visible[value_type]', 'value_type', _('Original')))
215			->setChecked(isset($this->data['visible']['value_type']))
216	],
217	new CComboBox('value_type', $this->data['value_type'], null, [
218		ITEM_VALUE_TYPE_UINT64 => _('Numeric (unsigned)'),
219		ITEM_VALUE_TYPE_FLOAT => _('Numeric (float)'),
220		ITEM_VALUE_TYPE_STR => _('Character'),
221		ITEM_VALUE_TYPE_LOG => _('Log'),
222		ITEM_VALUE_TYPE_TEXT => _('Text')
223	])
224);
225
226// append data type to form list
227$itemFormList->addRow(
228	[
229		_('Data type'),
230		SPACE,
231		(new CVisibilityBox('visible[data_type]', 'data_type', _('Original')))
232			->setChecked(isset($this->data['visible']['data_type']))
233	],
234	new CComboBox('data_type', $this->data['data_type'], null, item_data_type2str())
235);
236
237// append units to form list
238$itemFormList->addRow(
239	[
240		_('Units'),
241		SPACE,
242		(new CVisibilityBox('visible[units]', 'units', _('Original')))
243			->setChecked(isset($this->data['visible']['units']))
244	],
245	(new CTextBox('units', $this->data['units']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
246);
247
248// append authtype to form list
249$itemFormList->addRow(
250	[
251		_('Authentication method'),
252		SPACE,
253		(new CVisibilityBox('visible[authtype]', 'authtype', _('Original')))
254			->setChecked(isset($this->data['visible']['authtype']))
255	],
256	new CComboBox('authtype', $this->data['authtype'], null, [
257		ITEM_AUTHTYPE_PASSWORD => _('Password'),
258		ITEM_AUTHTYPE_PUBLICKEY => _('Public key')
259	])
260);
261
262// append username to form list
263$itemFormList->addRow(
264	[
265		_('User name'),
266		SPACE,
267		(new CVisibilityBox('visible[username]', 'username', _('Original')))
268			->setChecked(isset($this->data['visible']['username']))
269	],
270	(new CTextBox('username', $this->data['username']))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
271);
272
273// append publickey to form list
274$itemFormList->addRow(
275	[
276		_('Public key file'),
277		SPACE,
278		(new CVisibilityBox('visible[publickey]', 'publickey', _('Original')))
279			->setChecked(isset($this->data['visible']['publickey']))
280	],
281	(new CTextBox('publickey', $this->data['publickey']))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
282);
283
284// append privatekey to form list
285$itemFormList->addRow(
286	[
287		_('Private key file'),
288		SPACE,
289		(new CVisibilityBox('visible[privatekey]', 'privatekey', _('Original')))
290			->setChecked(isset($this->data['visible']['privatekey']))
291	],
292	(new CTextBox('privatekey', $this->data['privatekey']))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
293);
294
295// append password
296$itemFormList->addRow(
297	[
298		_('Password'),
299		SPACE,
300		(new CVisibilityBox('visible[password]', 'password', _('Original')))
301			->setChecked(isset($this->data['visible']['password']))
302	],
303	(new CTextBox('password', $this->data['password']))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
304);
305
306// append formula to form list
307$itemFormList->addRow(
308	[
309		_('Custom multiplier').' (0 - '._('Disabled').')',
310		SPACE,
311		(new CVisibilityBox('visible[formula]', 'formula', _('Original')))
312			->setChecked(isset($this->data['visible']['formula']))
313	],
314	(new CTextBox('formula', $this->data['formula']))
315		->setWidth(ZBX_TEXTAREA_SMALL_WIDTH)
316		->setAttribute('style', 'text-align: right;')
317);
318
319// append delay to form list
320$itemFormList->addRow(
321	[
322		_('Update interval (in sec)'),
323		SPACE,
324		(new CVisibilityBox('visible[delay]', 'delay', _('Original')))
325			->setChecked(isset($this->data['visible']['delay']))
326	],
327	(new CNumericBox('delay', $this->data['delay'], 5))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
328);
329
330// Append delay_flex to form list.
331$delayFlexTable = (new CTable())
332	->setId('delayFlexTable')
333	->setHeader([_('Type'), _('Interval'), _('Period'), _('Action')])
334	->setAttribute('style', 'width: 100%;');
335
336foreach ($data['delay_flex'] as $i => $delay_flex) {
337	$type_input = (new CRadioButtonList('delay_flex['.$i.'][type]', (int) $delay_flex['type']))
338		->addValue(_('Flexible'), ITEM_DELAY_FLEX_TYPE_FLEXIBLE)
339		->addValue(_('Scheduling'), ITEM_DELAY_FLEX_TYPE_SCHEDULING)
340		->setModern(true);
341
342	if ($delay_flex['type'] == ITEM_DELAY_FLEX_TYPE_FLEXIBLE) {
343		$delay_input = (new CNumericBox('delay_flex['.$i.'][delay]', $delay_flex['delay'], 5, false, true, false))
344			->setAttribute('placeholder', 50);
345		$period_input = (new CTextBox('delay_flex['.$i.'][period]', $delay_flex['period'], false, 255))
346			->setAttribute('placeholder', ZBX_DEFAULT_INTERVAL);
347		$schedule_input = (new CTextBox('delay_flex['.$i.'][schedule]', '', false, 255))
348			->setAttribute('placeholder', 'wd1-5h9-18')
349			->setAttribute('style', 'display: none;');
350	}
351	else {
352		$delay_input = (new CNumericBox('delay_flex['.$i.'][delay]', '', 5, false, true, false))
353			->setAttribute('placeholder', 50)
354			->setAttribute('style', 'display: none;');
355		$period_input = (new CTextBox('delay_flex['.$i.'][period]', '', false, 255))
356			->setAttribute('placeholder', ZBX_DEFAULT_INTERVAL)
357			->setAttribute('style', 'display: none;');
358		$schedule_input = (new CTextBox('delay_flex['.$i.'][schedule]', $delay_flex['schedule'], false, 255))
359			->setAttribute('placeholder', 'wd1-5h9-18');
360	}
361
362	$button = (new CButton('delay_flex['.$i.'][remove]', _('Remove')))
363		->addClass(ZBX_STYLE_BTN_LINK)
364		->addClass('element-table-remove');
365
366	$delayFlexTable->addRow([$type_input, [$delay_input, $schedule_input], $period_input, $button], 'form_row');
367}
368
369$delayFlexTable->addRow([(new CButton('interval_add', _('Add')))
370	->addClass(ZBX_STYLE_BTN_LINK)
371	->addClass('element-table-add')]);
372
373$itemFormList->addRow(
374	[
375		_('Custom intervals'),
376		SPACE,
377		(new CVisibilityBox('visible[delay_flex]', 'delayFlexDiv', _('Original')))
378			->setChecked(isset($this->data['visible']['delay_flex']))
379	],
380	(new CDiv($delayFlexTable))
381		->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)
382		->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_STANDARD_WIDTH.'px;')
383		->setId('delayFlexDiv')
384)
385	->addRow(
386		[
387			_('History storage period (in days)'), SPACE,
388			(new CVisibilityBox('visible[history]', 'history', _('Original')))
389				->setChecked(isset($this->data['visible']['history']))
390		],
391		(new CNumericBox('history', $this->data['history'], 8))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
392)
393	->addRow(
394		[
395			_('Trend storage period (in days)'),
396			SPACE,
397			(new CVisibilityBox('visible[trends]', 'trends', _('Original')))
398			->setChecked(isset($this->data['visible']['trends']))
399		],
400		(new CNumericBox('trends', $this->data['trends'], 8))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH)
401);
402
403// append status to form list
404$statusComboBox = new CComboBox('status', $this->data['status']);
405foreach ([ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED] as $status) {
406	$statusComboBox->addItem($status, item_status2str($status));
407}
408$itemFormList->addRow(
409	[
410		_('Status'),
411		SPACE,
412		(new CVisibilityBox('visible[status]', 'status', _('Original')))
413			->setChecked(isset($this->data['visible']['status']))
414	],
415	$statusComboBox
416);
417
418// append logtime to form list
419$itemFormList->addRow(
420	[
421		_('Log time format'),
422		SPACE,
423		(new CVisibilityBox('visible[logtimefmt]', 'logtimefmt', _('Original')))
424			->setChecked(isset($this->data['visible']['logtimefmt']))
425	],
426	(new CTextBox('logtimefmt', $this->data['logtimefmt']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
427);
428
429// append delta to form list
430$itemFormList->addRow(
431	[
432		_('Store value'),
433		SPACE,
434		(new CVisibilityBox('visible[delta]', 'delta', _('Original')))
435			->setChecked(isset($this->data['visible']['delta']))
436	],
437	new CComboBox('delta', $this->data['delta'], null, [
438		0 => _('As is'),
439		1 => _('Delta (speed per second)'),
440		2 => _('Delta (simple change)')
441	])
442);
443
444// append valuemap to form list
445$valueMapsComboBox = new CComboBox('valuemapid', $this->data['valuemapid']);
446$valueMapsComboBox->addItem(0, _('As is'));
447foreach ($this->data['valuemaps'] as $valuemap) {
448	$valueMapsComboBox->addItem($valuemap['valuemapid'], $valuemap['name']);
449}
450$valueMapLink = (new CLink(_('show value mappings'), 'adm.valuemapping.php'))
451	->setAttribute('target', '_blank');
452
453$itemFormList->addRow(
454	[
455		_('Show value'),
456		SPACE,
457		(new CVisibilityBox('visible[valuemapid]', 'valuemap', _('Original')))
458			->setChecked(isset($this->data['visible']['valuemapid']))
459	],
460	(new CDiv([$valueMapsComboBox, SPACE, $valueMapLink]))
461		->setId('valuemap')
462);
463
464// append trapper hosts to form list
465$itemFormList->addRow(
466	[
467		_('Allowed hosts'),
468		SPACE,
469		(new CVisibilityBox('visible[trapper_hosts]', 'trapper_hosts', _('Original')))
470			->setChecked(isset($this->data['visible']['trapper_hosts']))
471	],
472	(new CTextBox('trapper_hosts', $this->data['trapper_hosts']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
473);
474
475// append applications to form list
476if ($this->data['displayApplications']) {
477	// replace applications
478	$appToReplace = null;
479	if (hasRequest('applications')) {
480		$getApps = API::Application()->get([
481			'applicationids' => getRequest('applications'),
482			'output' => ['applicationid', 'name']
483		]);
484		foreach ($getApps as $getApp) {
485			$appToReplace[] = [
486				'id' => $getApp['applicationid'],
487				'name' => $getApp['name']
488			];
489		}
490	}
491
492	$replaceApp = (new CDiv(
493		(new CMultiSelect([
494			'name' => 'applications[]',
495			'objectName' => 'applications',
496			'objectOptions' => ['hostid' => $this->data['hostid']],
497			'data' => $appToReplace,
498			'popup' => [
499				'parameters' => 'srctbl=applications&dstfrm='.$itemForm->getName().'&dstfld1=applications_'.
500					'&srcfld1=applicationid&multiselect=1&noempty=1&only_hostid='.$this->data['hostid']
501			]
502		]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
503	))->setId('replaceApp');
504
505	$itemFormList->addRow(
506		[_('Replace applications'), SPACE,
507			(new CVisibilityBox('visible[applications]', 'replaceApp', _('Original')))
508				->setChecked(isset($this->data['visible']['applications']))
509		],
510		$replaceApp
511	);
512
513	// add new or existing applications
514	$appToAdd = null;
515	if (hasRequest('new_applications')) {
516		foreach (getRequest('new_applications') as $newApplication) {
517			if (is_array($newApplication) && isset($newApplication['new'])) {
518				$appToAdd[] = [
519					'id' => $newApplication['new'],
520					'name' => $newApplication['new'].' ('._x('new', 'new element in multiselect').')',
521					'isNew' => true
522				];
523			}
524			else {
525				$appToAddId[] = $newApplication;
526			}
527		}
528
529		if (isset($appToAddId)) {
530			$getApps = API::Application()->get([
531				'applicationids' => $appToAddId,
532				'output' => ['applicationid', 'name']
533			]);
534			foreach ($getApps as $getApp) {
535				$appToAdd[] = [
536					'id' => $getApp['applicationid'],
537					'name' => $getApp['name']
538				];
539			}
540		}
541	}
542
543	$newApp = (new CDiv(
544		(new CMultiSelect([
545			'name' => 'new_applications[]',
546			'objectName' => 'applications',
547			'objectOptions' => ['hostid' => $this->data['hostid']],
548			'data' => $appToAdd,
549			'addNew' => true,
550			'popup' => [
551				'parameters' => 'srctbl=applications&dstfrm='.$itemForm->getName().'&dstfld1=new_applications_'.
552					'&srcfld1=applicationid&multiselect=1&noempty=1&only_hostid='.$this->data['hostid']
553			]
554		]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
555	))->setId('newApp');
556
557	$itemFormList->addRow(
558		[_('Add new or existing applications'), SPACE,
559			(new CVisibilityBox('visible[new_applications]', 'newApp', _('Original')))
560				->setChecked(isset($this->data['visible']['new_applications']))
561		],
562		$newApp
563	);
564}
565
566// append description to form list
567$itemFormList->addRow(
568	[
569		_('Description'),
570		SPACE,
571		(new CVisibilityBox('visible[description]', 'description', _('Original')))
572			->setChecked(isset($this->data['visible']['description']))
573	],
574	(new CTextArea('description', $this->data['description']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
575);
576// append tabs to form
577$itemTab = new CTabView();
578$itemTab->addTab('itemTab', _('Mass update'), $itemFormList);
579
580// append buttons to form
581$itemTab->setFooter(makeFormFooter(
582	new CSubmit('massupdate', _('Update')),
583	[new CButtonCancel(url_param('hostid'))]
584));
585
586$itemForm->addItem($itemTab);
587$itemWidget->addItem($itemForm);
588
589require_once dirname(__FILE__).'/js/configuration.item.massupdate.js.php';
590
591return $itemWidget;
592