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