addItem((new CVar(CCsrfTokenHelper::CSRF_TOKEN_NAME, CCsrfTokenHelper::get('copy')))->removeId()); // Enable form submitting on Enter. $form->addItem((new CSubmitButton())->addClass(ZBX_STYLE_FORM_SUBMIT_HIDDEN)); switch ($data['element_type']) { case 'items': $form ->addVar('itemids', $data['itemids']) ->addVar('source', 'items'); $header = _n('Copy %1$s item', 'Copy %1$s items', count($data['itemids'])); break; case 'triggers': $form ->addVar('triggerids', $data['triggerids']) ->addVar('source', 'triggers'); if (array_key_exists('src_hostid', $data)) { $form->addVar('src_hostid', $data['src_hostid']); } $header = _n('Copy %1$s trigger', 'Copy %1$s triggers', count($data['triggerids'])); break; case 'graphs': $form ->addVar('graphids', $data['graphids']) ->addVar('source', 'graphs'); $header = _n('Copy %1$s graph', 'Copy %1$s graphs', count($data['graphids'])); break; } $form_grid = (new CFormGrid()) ->addItem([ new CLabel(_('Target type'), 'copy_type'), new CFormField( (new CRadioButtonList('copy_type', COPY_TYPE_TO_TEMPLATE_GROUP)) ->addValue(_('Template groups'), COPY_TYPE_TO_TEMPLATE_GROUP) ->addValue(_('Host groups'), COPY_TYPE_TO_HOST_GROUP) ->addValue(_('Templates'), COPY_TYPE_TO_TEMPLATE) ->addValue(_('Hosts'), COPY_TYPE_TO_HOST) ->setModern() ->setName('copy_type') ) ]) ->addItem([ (new CLabel(_('Target'), 'copy_targetids_ms'))->setAsteriskMark(), (new CFormField())->setId('copy_targets') ]) ->addItem( (new CScriptTag(' copy_popup.init('.json_encode([ 'action' => 'copy.create' ]).'); '))->setOnDocumentReady() ); $form->addItem($form_grid); $buttons = [ [ 'title' => _('Copy'), 'class' => 'js-update', 'keepOpen' => true, 'isSubmit' => true, 'action' => 'copy_popup.submit();' ] ]; $output = [ 'header' => $header, 'body' => $form->toString(), 'buttons' => $buttons, 'script_inline' => getPagePostJs().$this->readJsFile('copy.edit.js.php') ]; echo json_encode($output);