xref: /plugin/bez/ctl/task.php (revision ef159648ef3ff6e0d9504925f53e30d9aa2bbff5)
1<?php
2
3if (!isset($nparams['tid'])) {
4    header('Location: ?id=bez:tasks');
5}
6$template['tid'] = $nparams['tid'];
7$template['action'] = isset($nparams['action']) ? $nparams['action'] : '-default';
8$template['state'] = isset($nparams['state']) ? $nparams['state'] : '-1';
9try {
10    $task = $this->model->tasks->get_one($template['tid']);
11    $template['task'] = $task;
12
13
14    if ($task->cause !== NULL && $task->cause !== '') {
15        $template['commcause'] = $this->model->commcauses->get_one($task->cause);
16    }
17
18    if ($task->issue !== NULL && $task->issue !== '') {
19        $template['issue'] = $this->model->issues->get_one($task->issue);
20    }
21
22
23    if ($template['action'] === 'task_change_state') {
24        if (count($_POST) > 0) {
25            if (isset($_POST['no_evaluation'])) {
26                $_POST['reason'] = '';
27            }
28
29            $task->set_state(array(
30                        'state' => $nparams['state'],
31                        'reason' => $_POST['reason'])
32                    );
33            $this->model->tasks->save($task);
34
35            if (isset($template['issue'])) {
36                $template['issue']->update_last_activity();
37                $this->model->issues->save($template['issue']);
38            }
39
40            $redirect = true;
41        } else {
42            $value = $task->get_assoc();
43        }
44    } elseif ($template['action'] === 'task_reopen') {
45        $task->set_state(array('state' => '0'));
46        $this->model->tasks->save($task);
47
48        if (isset($template['issue'])) {
49            $template['issue']->update_last_activity();
50            $this->model->issues->save($template['issue']);
51        }
52
53        $notify_users = array();
54        if ($task->reporter !== $this->model->user_nick) {
55            //prevent duplicates
56            $notify_users[$task->reporter] = $task->reporter;
57        }
58        if ($task->executor !== $this->model->user_nick) {
59            //prevent duplicates
60            $notify_users[$task->executor] = $task->executor;
61        }
62
63        $task->mail_notify_add($template['issue'], $notify_users,
64                                array('action' => $bezlang['mail_task_reopened']));
65
66        $redirect = true;
67    } elseif($template['action'] === 'task_edit') {
68        $template['auth_level'] = $task->get_level();
69
70        $template['users'] = $this->model->users->get_all();
71        $template['tasktypes'] = $this->model->tasktypes->get_all();
72
73        if (isset($template['issue'])) {
74            $template['causes'] = $this->model->commcauses->get_all(array(
75                'issue' => $template['issue']->id,
76                'type' => array('!=', '0'),
77            ));
78        }
79
80        if (count($_POST) > 0) {
81            //checkboxes
82            if (!isset($_POST['all_day_event'])) {
83                $_POST['all_day_event'] = '0';
84            }
85            $task->set_data($_POST);
86            //for reason
87            $task->set_state($_POST);
88
89            $this->model->tasks->save($task);
90                //~ $bezcache = new Bezcache();
91                //~ $bezcache->task_toupdate($task->id);
92
93            header("Location: ?id=bez:task:tid:".$task->id);
94        } else {
95            $value = $task->get_assoc();
96        }
97    }
98
99    if ($redirect) {
100        header("Location: ?id=bez:task:tid:".$template['tid']);
101    }
102
103} catch (DBException $e) {
104    echo nl2br($e);
105}
106
107