xref: /plugin/bez/ctl/task_form.php (revision 48ab8737be612e4552ba4d7b8e87354e2328dafc)
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();
43        }
44        header("Location: ?id=bez:task:tid:$tid");
45    } else {
46        if (isset($nparams['duplicate'])) {
47            $tid = (int)$nparams['duplicate'];
48            $task = $this->model->tasks->get_one($tid);
49            $value = $task->get_assoc();
50        } else {
51            $value['all_day_event'] = '1';
52        }
53    }
54//        $template['task_button'] = $bezlang['add'];
55//        $template['task_action'] = $this->id('task_report', 'tasktype', $nparams['tasktype']);
56    $template['users'] = $this->model->users->get_all();
57    $template['tasktypes'] = $this->model->tasktypes->get_all();
58
59} catch (ValidationException $e) {
60	$errors = $e->get_errors();
61	$value = $_POST;
62} catch (DBException $e) {
63    echo nl2br($e);
64//	header("Location: ?id=bez:tasks");
65}
66
67
68
69//$template['user'] = $task->get_user();
70//$template['user_name'] = $this->model->users->get_user_full_name($template['user']);
71//
72//$template['users'] = $this->model->users->get_all();
73//$template['tasktypes'] = $this->model->tasktypes->get_all();
74//$template['tasktype_name'] = $this->model->tasktypes->get_one($nparams['tasktype'])->type;
75