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