xref: /plugin/bez/ctl/task.php (revision 6271e09529976632242621f0ab4c4b49005feb24)
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
69        $template['users'] = $this->model->users->get_all();
70        $template['tasktypes'] = $this->model->tasktypes->get_all();
71
72        if (isset($template['issue'])) {
73            $template['causes'] = $this->model->commcauses->get_all(array(
74                'issue' => $template['issue']->id,
75                'type' => array('!=', '0'),
76            ));
77        }
78
79        if (count($_POST) > 0) {
80            //checkboxes
81            if (!isset($_POST['all_day_event'])) {
82                $_POST['all_day_event'] = '0';
83            }
84            $task->set_data($_POST);
85            //for reason
86            //$task->set_state($_POST);
87
88            $this->model->tasks->save($task);
89                //~ $bezcache = new Bezcache();
90                //~ $bezcache->task_toupdate($task->id);
91
92            header("Location: ?id=bez:task:tid:".$task->id);
93        } else {
94            $value = $task->get_assoc();
95        }
96    }
97
98    if ($redirect) {
99        header("Location: ?id=bez:task:tid:".$template['tid']);
100    }
101} catch (ValidationException $e) {
102	$errors = $e->get_errors();
103	$value = $_POST;
104} catch (DBException $e) {
105    echo nl2br($e);
106}
107
108