xref: /plugin/bez/ctl/task_form.php (revision 8d31684b59cd74df19e69f525a2cd4ce398f2bf9)
1<?php
2
3$template['tid'] = isset($nparams['tid']) ? $nparams['tid'] : '-1';
4$template['action'] = isset($nparams['action']) ? $nparams['action'] : '-default';
5
6if (isset($_POST['tasktype'])) {
7    $tasktype = $_POST['tasktype'];
8} else {
9    $tasktype = $nparams['tasktype'];
10}
11$template['tasktype'] = $tasktype;
12
13try {
14
15    $task = $this->model->tasks->create_object(
16                            array('tasktype' => $tasktype));
17    $template['task'] = $task;
18
19    //$template['auth_level'] = $task->get_level();
20    //$template['user'] = $task->get_user();
21    $value['tasktype'] = $tasktype;
22    $value['executor'] = $this->model->user_nick;
23
24    if (count($_POST) > 0) {
25        //checkboxes
26        if (!isset($_POST['all_day_event'])) {
27            $_POST['all_day_event'] = '0';
28        }
29
30        $task->set_data($_POST);
31        //update tasktype for admins
32
33        $tid = $this->model->tasks->save($task);
34
35
36        //don't send notification when user binds himself to the task.
37        if ($task->reporter !== $task->executor) {
38            $task->mail_notify_add(NULL, array($task->executor),
39                       array('action' => $bezlang['mail_task_added_programme']));
40        }
41        header("Location: ?id=bez:task:tid:$tid");
42    } else {
43        if (isset($nparams['duplicate'])) {
44            $tid = (int)$nparams['duplicate'];
45            $task = $this->model->tasks->get_one($tid);
46            $value = $task->get_assoc();
47        } else {
48            $value['all_day_event'] = '1';
49        }
50    }
51
52    $template['users'] = $this->model->users->get_all();
53    $template['tasktypes'] = $this->model->tasktypes->get_all();
54
55} catch (ValidationException $e) {
56	$errors = $e->get_errors();
57	$value = $_POST;
58} catch (DBException $e) {
59    echo nl2br($e);
60//	header("Location: ?id=bez:tasks");
61}
62
63