xref: /plugin/bez/ctl/task_form.php (revision f9fa039b77cec86e9120fa96112381b41706a66f)
1<?php
2//~ include_once DOKU_PLUGIN."bez/models/bezcache.php";
3
4$template['tid'] = isset($nparams['tid']) ? $nparams['tid'] : '-1';
5$template['action'] = isset($nparams['action']) ? $nparams['action'] : '-default';
6
7if (isset($_POST['tasktype'])) {
8    $tasktype = $_POST['tasktype'];
9} else {
10    $tasktype = $nparams['tasktype'];
11}
12$template['tasktype'] = $tasktype;
13
14try {
15
16    $task = $this->model->tasks->create_object_program(
17                            array('tasktype' => $tasktype));
18
19    //$template['auth_level'] = $task->get_level();
20    //$template['user'] = $task->get_user();
21    $value['tasktype'] = $tasktype;
22
23    if (count($_POST) > 0) {
24        //checkboxes
25        if (!isset($_POST['all_day_event'])) {
26            $_POST['all_day_event'] = '0';
27        }
28
29        $task->set_data($_POST);
30        //update tasktype for admins
31
32        $tid = $this->model->tasks->save($task);
33//            $title = 'Dodano zadanie';
34//            $exec = $task->executor;
35//            $subject = "[$conf[title]] $title: #z$tid";
36//            $to = $this->model->users->get_user_full_name($exec).' <'.$this->model->users->get_user_email($exec).'>';
37//            $body = "$uri?id=".$this->id('show_task', 'tid', $tid);
38//            $this->helper->mail($to, $subject, $body);
39
40        //don't send notification when user binds himself to the task.
41        if ($task->reporter !== $task->executor) {
42            $task->mail_notify_add(NULL, array($task->executor),
43                       array('action' => $bezlang['mail_task_added_programme']));
44        }
45        header("Location: ?id=bez:task:tid:$tid");
46    } else {
47        if (isset($nparams['duplicate'])) {
48            $tid = (int)$nparams['duplicate'];
49            $task = $this->model->tasks->get_one($tid);
50            $value = $task->get_assoc();
51        } else {
52            $value['all_day_event'] = '1';
53        }
54    }
55//        $template['task_button'] = $bezlang['add'];
56//        $template['task_action'] = $this->id('task_report', 'tasktype', $nparams['tasktype']);
57    $template['users'] = $this->model->users->get_all();
58    $template['tasktypes'] = $this->model->tasktypes->get_all();
59
60} catch (ValidationException $e) {
61	$errors = $e->get_errors();
62	$value = $_POST;
63} catch (DBException $e) {
64    echo nl2br($e);
65//	header("Location: ?id=bez:tasks");
66}
67
68
69
70//$template['user'] = $task->get_user();
71//$template['user_name'] = $this->model->users->get_user_full_name($template['user']);
72//
73//$template['users'] = $this->model->users->get_all();
74//$template['tasktypes'] = $this->model->tasktypes->get_all();
75//$template['tasktype_name'] = $this->model->tasktypes->get_one($nparams['tasktype'])->type;
76