xref: /plugin/bez/ctl/thread_report.php (revision 16c7b168a60daa2c9b9ddcfa51e05d123a2a17dc)
1<?php
2
3use \dokuwiki\plugin\bez;
4
5if ($this->model->acl->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	$this->tpl->set('thread', $thread);
15}
16
17if ($this->get_param('action') == 'edit') {
18    if (!isset($thread)) {
19        throw new Exception('there is now row with given id');
20    }
21    $this->tpl->set_values($thread->get_assoc());
22} elseif ($this->get_param('action') == 'update') {
23
24    $prev_coordiantor = $thread->coordinator;
25    $this->model->threadFactory->update_save($thread, $_POST);
26
27    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
28} elseif ($this->get_param('action') == 'add') {
29    //$template['form_action'] = 'add';
30
31    $defaults = array();
32    if ($this->model->acl->get_level() >= BEZ_AUTH_LEADER) {
33        $defaults['coordinator'] = $_POST['coordinator'];
34    }
35    unset($_POST['coordinator']);
36    $thread = $this->model->threadFactory->create_object($defaults);
37
38    $this->model->threadFactory->initial_save($thread, $_POST);
39
40    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
41
42}
43
44$this->tpl->set('labels', $this->model->labelFactory->get_all());