1<?php
2/** @var action_plugin_bez $this */
3
4use \dokuwiki\plugin\bez;
5
6if ($this->model->get_level() < BEZ_AUTH_ADMIN) {
7    throw new bez\meta\PermissionDeniedException();
8}
9
10$labels = $this->model->labelFactory->get_all();
11
12$id = null;
13if (isset($_POST['id'])) {
14    $id = (int)$_POST['id'];
15} else {
16    $id = $this->get_param('id');
17}
18
19if ($id) {
20    $label = $this->model->labelFactory->get_one($id);
21} else {
22    $label = $this->model->labelFactory->create_object();
23}
24
25$this->tpl->set('labels', $labels);
26$this->tpl->set('label', $label);
27
28
29if ($this->get_param('action') === 'edit') {
30
31    $this->tpl->set_values($label->get_assoc());
32
33} else if ($this->get_param('action') === 'remove') {
34
35    $this->model->labelFactory->delete($label);
36
37    header('Location: '.$this->url('types'));
38
39} elseif (count($_POST) > 0) {
40    $label->set_data($_POST);
41    $this->model->labelFactory->save($label);
42
43    header('Location: '.$this->url('types'));
44}
45