1<?php
2
3use \dokuwiki\plugin\bez;
4
5if ($this->model->get_level() < BEZ_AUTH_USER) {
6    throw new bez\meta\PermissionDeniedException();
7}
8
9
10$thread_id = $this->get_param('id');
11if ($thread_id != '') {
12	/** @var \dokuwiki\plugin\bez\mdl\Thread $thread */
13	$thread = $this->model->threadFactory->get_one($thread_id);
14} else {
15    $thread = $this->model->threadFactory->create_object();
16}
17
18$this->tpl->set('thread', $thread);
19
20if ($this->get_param('action') == 'edit') {
21    if ($thread_id == '') {
22        throw new Exception('there is now row with given id');
23    }
24    $this->tpl->set_values($thread->get_assoc());
25} elseif ($this->get_param('action') == 'update') {
26
27    $this->model->threadFactory->update_save($thread, $_POST);
28
29    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
30} elseif ($this->get_param('action') == 'add') {
31//
32//    $defaults = array();
33//    if ($this->model->acl->get_level() >= BEZ_AUTH_LEADER) {
34//        $defaults['coordinator'] = $_POST['coordinator'];
35//    }
36//    unset($_POST['coordinator']);
37//    $thread = $this->model->threadFactory->create_object($defaults);
38
39    $this->model->threadFactory->initial_save($thread, $_POST);
40
41    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
42
43}
44
45$this->tpl->set('labels', $this->model->labelFactory->get_all());