xref: /plugin/bez/ctl/thread_report.php (revision 53df74e7ac5ae4234aac1fa716a33878a039026f)
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
30    $defaults = array();
31    if ($this->model->acl->get_level() >= BEZ_AUTH_LEADER) {
32        $defaults['coordinator'] = $_POST['coordinator'];
33    }
34    unset($_POST['coordinator']);
35    $thread = $this->model->threadFactory->create_object($defaults);
36
37    $this->model->threadFactory->initial_save($thread, $_POST);
38
39    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
40
41}
42
43$this->tpl->set('labels', $this->model->labelFactory->get_all());