createTabs()->activate('preview'); $template = Template::fromDb($this->params->getRequired('id')); if ($template === null) { throw new \Exception('Template not found'); } $template ->setMacros([ 'date' => (new DateTime())->format('jS M, Y'), 'time_frame' => 'Time Frame', 'time_frame_absolute' => 'Time Frame (absolute)', 'title' => 'Icinga Report Preview' ]) ->setPreview(true); $this->addContent($template); } public function editAction() { $this->assertPermission('reporting/templates'); $this->createTabs()->activate('edit'); $select = (new Select()) ->from('template') ->columns(['id', 'settings']) ->where(['id = ?' => $this->params->getRequired('id')]); $template = $this->getDb()->select($select)->fetch(); if ($template === false) { throw new \Exception('Template not found'); } $template->settings = json_decode($template->settings, true); $form = (new TemplateForm()) ->setTemplate($template); $form->handleRequest(ServerRequest::fromGlobals()); $this->redirectForm($form, 'reporting/templates'); $this->addContent($form); } protected function createTabs() { $tabs = $this->getTabs(); if ($this->hasPermission('reporting/templates')) { $tabs->add('edit', [ 'title' => $this->translate('Edit template'), 'label' => $this->translate('Edit Template'), 'url' => 'reporting/template/edit?id=' . $this->params->getRequired('id') ]); } $tabs->add('preview', [ 'title' => $this->translate('Preview template'), 'label' => $this->translate('Preview'), 'url' => 'reporting/template?id=' . $this->params->getRequired('id') ]); return $tabs; } }