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$this->addJSfile('js/multiselect.js'); 23$this->includeJSfile('app/views/administration.script.edit.js.php'); 24 25$widget = (new CWidget())->setTitle(_('Scripts')); 26 27$scriptForm = (new CForm()) 28 ->setId('scriptForm') 29 ->setName('scripts') 30 ->addVar('form', 1) 31 ->addVar('scriptid', $data['scriptid']); 32 33$scriptFormList = new CFormList(); 34 35$scriptFormList->addRow(_('Name'), 36 (new CTextBox('name', $data['name'])) 37 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 38 ->setAttribute('autofocus', 'autofocus') 39 ->setAttribute('placeholder', _('<Sub-menu/Sub-menu.../>Script')) 40); 41 42$scriptFormList->addRow(_('Type'), 43 new CComboBox('type', $data['type'], null, [ 44 ZBX_SCRIPT_TYPE_IPMI => _('IPMI'), 45 ZBX_SCRIPT_TYPE_CUSTOM_SCRIPT => _('Script') 46 ]) 47); 48 49// execute on 50$scriptFormList->addRow(_('Execute on'), 51 (new CRadioButtonList('execute_on', (int) $data['execute_on'])) 52 ->addValue(_('Zabbix agent'), ZBX_SCRIPT_EXECUTE_ON_AGENT) 53 ->addValue(_('Zabbix server'), ZBX_SCRIPT_EXECUTE_ON_SERVER) 54 ->setModern(true) 55); 56$scriptFormList->addRow(_('Commands'), 57 (new CTextArea('command', $data['command'])) 58 ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 59 ->setMaxLength(255) 60); 61$scriptFormList->addRow(_('Command'), 62 (new CTextBox('commandipmi', $data['commandipmi']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 63); 64$scriptFormList->addRow(_('Description'), 65 (new CTextArea('description', $data['description']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) 66); 67 68// user groups 69$user_groups = [0 => _('All')]; 70foreach ($data['usergroups'] as $user_group) { 71 $user_groups[$user_group['usrgrpid']] = $user_group['name']; 72} 73$scriptFormList->addRow(_('User group'), new CComboBox('usrgrpid', $data['usrgrpid'], null, $user_groups)); 74 75// host groups 76$scriptFormList->addRow(_('Host group'), new CComboBox('hgstype', $data['hgstype'], null, [ 77 0 => _('All'), 78 1 => _('Selected') 79])); 80$scriptFormList->addRow(null, (new CMultiSelect([ 81 'name' => 'groupid', 82 'selectedLimit' => 1, 83 'objectName' => 'hostGroup', 84 'data' => $data['hostgroup'], 85 'popup' => [ 86 'parameters' => 'srctbl=host_groups&dstfrm='.$scriptForm->getName().'&dstfld1=groupid&srcfld1=groupid' 87 ] 88]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'hostGroupSelection'); 89 90// access 91$scriptFormList->addRow(_('Required host permissions'), new CComboBox('host_access', $data['host_access'], null, [ 92 PERM_READ => _('Read'), 93 PERM_READ_WRITE => _('Write') 94])); 95$scriptFormList->addRow(new CLabel(_('Enable confirmation'), 'enable_confirmation'), 96 (new CCheckBox('enable_confirmation'))->setChecked($data['enable_confirmation'] == 1) 97); 98 99$confirmationLabel = new CLabel(_('Confirmation text'), 'confirmation'); 100$scriptFormList->addRow($confirmationLabel, [ 101 (new CTextBox('confirmation', $data['confirmation']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 102 SPACE, 103 (new CButton('testConfirmation', _('Test confirmation')))->addClass(ZBX_STYLE_BTN_GREY) 104]); 105 106$scriptView = (new CTabView())->addTab('scripts', _('Script'), $scriptFormList); 107 108// footer 109$cancelButton = (new CRedirectButton(_('Cancel'), 'zabbix.php?action=script.list'))->setId('cancel'); 110 111if ($data['scriptid'] == 0) { 112 $addButton = (new CSubmitButton(_('Add'), 'action', 'script.create'))->setId('add'); 113 114 $scriptView->setFooter(makeFormFooter( 115 $addButton, 116 [$cancelButton] 117 )); 118} 119else { 120 $updateButton = (new CSubmitButton(_('Update'), 'action', 'script.update'))->setId('update'); 121 $cloneButton = (new CSimpleButton(_('Clone')))->setId('clone'); 122 $deleteButton = (new CRedirectButton(_('Delete'), 123 'zabbix.php?action=script.delete&sid='.$data['sid'].'&scriptids[]='.$data['scriptid'], 124 _('Delete script?') 125 )) 126 ->setId('delete'); 127 128 $scriptView->setFooter(makeFormFooter( 129 $updateButton, 130 [ 131 $cloneButton, 132 $deleteButton, 133 $cancelButton 134 ] 135 )); 136} 137 138$scriptForm->addItem($scriptView); 139 140$widget->addItem($scriptForm)->show(); 141