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
26include dirname(__FILE__).'/js/conf.import.js.php';
27
28$rulesTable = (new CTable())
29	->setHeader(['', _('Update existing'), _('Create new'), _('Delete missing')]);
30
31$titles = [
32	'groups' => _('Groups'),
33	'hosts' => _('Hosts'),
34	'templates' => _('Templates'),
35	'templateScreens' => _('Template screens'),
36	'templateLinkage' => _('Template linkage'),
37	'applications' => _('Applications'),
38	'items' => _('Items'),
39	'discoveryRules' => _('Discovery rules'),
40	'triggers' => _('Triggers'),
41	'graphs' => _('Graphs'),
42	'httptests' => _('Web scenarios'),
43	'screens' => _('Screens'),
44	'maps' => _('Maps')
45];
46
47$user_type = CWebUser::getType();
48
49if ($user_type == USER_TYPE_SUPER_ADMIN) {
50	$titles['images'] = _('Images');
51	$titles['mediaTypes'] = _('Media types');
52	$titles['valueMaps'] = _('Value mappings');
53}
54
55foreach ($titles as $key => $title) {
56	$cbExist = null;
57	$cbMissed = null;
58	$cbDeleted = null;
59
60	if (array_key_exists('updateExisting', $data['rules'][$key])) {
61		$cbExist = (new CCheckBox('rules['.$key.'][updateExisting]'))
62			->setChecked($data['rules'][$key]['updateExisting']);
63
64		if ($key !== 'maps' && $key !== 'screens' && $user_type != USER_TYPE_SUPER_ADMIN
65				&& $user_type != USER_TYPE_ZABBIX_ADMIN) {
66			$cbExist->setAttribute('disabled', 'disabled');
67		}
68
69		if ($key === 'images') {
70			$cbExist->onClick('updateWarning(this, '.json_encode(_('Images for all maps will be updated!')).')');
71		}
72
73		if ($key === 'valueMaps') {
74			$cbExist->onClick(
75				'updateWarning(this, '.json_encode(_('Value mappings for value maps will be updated!')).')'
76			);
77		}
78	}
79
80	if (array_key_exists('createMissing', $data['rules'][$key])) {
81		$cbMissed = (new CCheckBox('rules['.$key.'][createMissing]'))
82			->setChecked($data['rules'][$key]['createMissing']);
83	}
84
85	if ($key !== 'maps' && $key !== 'screens' && $user_type != USER_TYPE_SUPER_ADMIN
86			&& $user_type != USER_TYPE_ZABBIX_ADMIN) {
87		$cbMissed->setAttribute('disabled', 'disabled');
88	}
89
90	if (array_key_exists('deleteMissing', $data['rules'][$key])) {
91		$cbDeleted = (new CCheckBox('rules['.$key.'][deleteMissing]'))
92			->setChecked($data['rules'][$key]['deleteMissing'])
93			->addClass('deleteMissing');
94
95		if ($key !== 'maps' && $key !== 'screens' && $user_type != USER_TYPE_SUPER_ADMIN
96				&& $user_type != USER_TYPE_ZABBIX_ADMIN) {
97			$cbDeleted->setAttribute('disabled', 'disabled');
98		}
99
100		if ($key === 'templateLinkage') {
101			$cbDeleted->onClick('updateWarning(this, '.json_encode(
102				_('Template and host properties that are inherited through template linkage will be unlinked and cleared.')
103			).')');
104		}
105	}
106
107	$rulesTable->addRow([
108		$title,
109		(new CCol($cbExist))->addClass(ZBX_STYLE_CENTER),
110		(new CCol($cbMissed))->addClass(ZBX_STYLE_CENTER),
111		(new CCol($cbDeleted))->addClass(ZBX_STYLE_CENTER)
112	]);
113}
114
115// form list
116$form_list = (new CFormList())
117	->addRow((new CLabel(_('Import file'), 'import_file'))->setAsteriskMark(),
118		(new CFile('import_file'))
119			->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)
120			->setAriaRequired()
121			->setAttribute('autofocus', 'autofocus')
122	)
123	->addRow(_('Rules'), new CDiv($rulesTable));
124
125// tab
126$tab_view = (new CTabView())->addTab('importTab', _('Import'), $form_list);
127
128// form
129$tab_view->setFooter(makeFormFooter(
130	new CSubmit('import', _('Import')),
131	[new CRedirectButton(_('Cancel'), $data['backurl'])]
132));
133
134$form = (new CForm('post', null, 'multipart/form-data'))
135	->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE)
136	->addVar('rules_preset', $data['rules_preset'])
137	->addItem($tab_view);
138
139// widget
140(new CWidget())
141	->setTitle(_('Import'))
142	->addItem($form)
143	->show();
144