xref: /plugin/bez/ctl/thread_report.php (revision 7fbf4c3966fc9b63e77e3ef6f091279dbce0d34f)
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//else {
17	//$template['thread'] = $this->model->issues->create_dummy_object();
18	//$template['priority'] = 'None';
19//}
20
21//$action = '';
22//if (isset($nparams['action'])) {
23//	$action = $nparams['action'];
24//}
25
26//try {
27if ($this->get_param('action') == 'edit') {
28    if (!isset($thread)) {
29        throw new Exception('there is now row with given id');
30    }
31    //$template['form_action'] = 'update';
32    //$value = $thread->get_assoc();
33    $this->tpl->set_values($thread->get_assoc());
34} elseif ($this->get_param('action') == 'update') {
35    //$template['form_action'] = 'update';
36
37//    $prev_coordiantor = $thread->coordinator;
38
39    //$thread->set_data($_POST);
40    $this->model->threadFactory->update_save($thread, $_POST);
41
42
43//    $thread->add_participant($thread->coordinator);
44
45    //save to get ID!!!
46//    $this->model->threadFactory->save($thread);
47//
48//    if ($thread->coordinator !== '-proposal' &&
49//        $INFO['client'] !== $thread->coordinator &&
50//        $thread->coordinator != $prev_coordiantor) {
51//        //coordinator becomes subscribent automaticly
52//        $thread->add_subscribent($thread->coordinator);
53//        $this->model->threadFactory->save($thread);
54//
55//        $thread->mail_inform_coordinator();
56//    }
57
58    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
59} elseif ($this->get_param('action') == 'add') {
60    //$template['form_action'] = 'add';
61
62    $defaults = array();
63    if ($this->model->acl->get_level() >= BEZ_AUTH_LEADER) {
64        $defaults['coordinator'] = $_POST['coordinator'];
65    }
66    unset($_POST['coordinator']);
67    $thread = $this->model->threadFactory->create_object($defaults);
68
69//    $data = array(
70////            'type' => $_POST['type'],
71//        'title' => $_POST['title'],
72//        'content' => $_POST['content']
73//    );
74    //$thread->set_data($data);
75    $this->model->threadFactory->initial_save($thread, $_POST);
76
77//        if ($thread->coordinator !== '-proposal' &&
78//            $INFO['client'] !== $thread->coordinator) {
79//            //coordinator becomes subscribent automaticly
80//            $thread->add_subscribent($issue->coordinator);
81//            $this->model->issues->save($thread);
82//
83//            $thread->mail_inform_coordinator();
84//        }
85
86
87    header('Location: ?id='.$this->id('thread', 'id', $thread->id));
88
89}
90//	else {
91//		$template['form_action'] = 'add';
92//	}
93
94//} catch (bez\meta\ValidationException $e) {
95//	$errors = $e->get_errors();
96//	$value = $_POST;
97//}
98
99//$template['issuetypes'] = $this->model->issuetypes->get_all();
100$this->tpl->set('labels', $this->model->labelFactory->get_all());