xref: /plugin/bez/ctl/task_form.php (revision 5c4f5b9586015b9688a72a89d8d79cafe4a6fac2)
1<?php
2include_once DOKU_PLUGIN."bez/models/issues.php";
3include_once DOKU_PLUGIN."bez/models/tasks.php";
4include_once DOKU_PLUGIN."bez/models/causes.php";
5include_once DOKU_PLUGIN."bez/models/users.php";
6include_once DOKU_PLUGIN."bez/models/tasktypes.php";
7include_once DOKU_PLUGIN."bez/models/bezcache.php";
8
9//~ $tasko = new Tasks();
10$causo = new Causes();
11//~ $usro = new Users();
12//~ $tasktypeso = new Tasktypes();
13$bezcache = new Bezcache();
14
15$issue_id = (int)$nparams['id'];
16
17/*casue*/
18$cause_id = '';
19if (isset($nparams['cid']) && $nparams['cid'] != '') {
20	$cause_id = (int)$nparams['cid'];
21	$template['cause'] = $causo->join($causo->getone($cause_id));
22}
23
24/*edycja*/
25if (isset($nparams['tid'])) {
26	$action = $nparams['action'];
27	$tid = (int)$nparams['tid'];
28
29	$task = $this->model->tasks->get_one($tid);
30	$template['auth_level'] = $task->get_level();
31
32	//$task_states = $task->get_states();
33
34	//~ $template['raw_state'] = $task['state'];
35	//~ $template['state']  = $task_states[$task['state']];
36	if (isset($nparams['id'])) {
37		$template['causes'] = $causo->get($issue_id);
38	}
39
40	if (!$action)
41		$action = 'edit';
42
43	if ($action == 'edit') {
44		$value = $task->get_assoc();
45		//~ $value['cause_id'] = $task['cause'];
46	} else if ($action == 'update') {
47		//~ $cause_id = $_POST['cause_id'];
48		//~ if ($cause_id != '')
49			//~ $cause_id = (int)$cause_id;
50
51		//~ $data = $tasko->update($_POST, array('cause' => $cause_id), $tid);
52		//~ if (count($errors) == 0) {
53
54			//~ $title = 'Zmiana w zadaniu';
55			//~ $exec = $data['executor'];
56			//~ $subject = "[$conf[title]] $title: #$issue_id #z$tid";
57			//~ $to = $usro->name($exec).' <'.$usro->email($exec).'>';
58			//~ if (isset($nparams['id']))
59				//~ $body = "$uri?id=".$this->id('issue_task', 'id', $issue_id, 'tid', $tid);
60			//~ else
61				//~ $body = "$uri?id=".$this->id('show_task', 'tid', $tid);
62
63			//~ $this->helper->mail($to, $subject, $body);
64
65			//~ $cause_id = $_POST['cause_id'];
66			//~ if (!isset($nparams['id']))
67				//~ header("Location: ?id=bez:show_task:tid:$tid");
68			//~ elseif ($cause_id == '')
69				//~ header("Location: ?id=bez:issue_task:id:$issue_id:tid:$tid");
70			//~ else
71				//~ header("Location: ?id=bez:issue_cause_task:id:$issue_id:cid:$cause_id:tid:$tid");
72		//~ }
73		//~ $value = $_POST;
74		try {
75			//checkboxes
76			if (!isset($_POST['all_day_event'])) {
77				$_POST['all_day_event'] = '0';
78			}
79			$task->set_data($_POST);
80			$task->set_acl($_POST);
81
82			if ($task->any_errors()) {
83				$errors = $task->get_errors();
84				$value = $_POST;
85			} else {
86				$this->model->tasks->save($task);
87				$bezcache->task_toupdate($task->id);
88
89
90				$cause_id = $_POST['cause_id'];
91				if (!isset($nparams['id'])) {
92					header("Location: ?id=bez:show_task:tid:$tid");
93				} elseif ($cause_id == '') {
94					header("Location: ?id=bez:issue_task:id:$issue_id:tid:$tid");
95				} else {
96					header("Location: ?id=bez:issue_cause_task:id:$issue_id:cid:$cause_id:tid:$tid");
97				}
98			}
99		} catch (Exception $e) {
100			echo nl2br($e);
101		}
102	}
103
104	$template['task_button'] = $bezlang['change_task_button'];
105	$template['task_action'] = $this->id('task_form', 'id', $task->issue, 'cid', $task->cause, 'tid', $task->id, 'action', 'update');
106
107
108
109/*dodawania*/
110} else {
111	$defaults = array('issue' => $issue_id, 'cause' => $cause_id, 'tasktype' => $_POST['tasktype']);
112	//~ if (isset($_POST['tasktype']) && $_POST['tasktype'] != '') {
113		//~ $defaults['tasktype'] = $_POST['tasktype'];
114	//~ }
115
116	$task = $this->model->tasks->create_object($defaults);
117
118	$template['auth_level'] = $task->get_level();
119
120	if (count($_POST) > 0) {
121		//~ $data = array('reporter' => $INFO['client'], 'date' => time(), 'issue' => $issue_id, 'cause' => $cause_id);
122		//~ $data = $tasko->add($_POST, $data);
123		//~ if (count($errors) == 0) {
124			//~ $tid = $tasko->lastid();
125			//~ $title = 'Dodano zadanie';
126			//~ $exec = $data['executor'];
127			//~ $subject = "[$conf[title]] $title: #$issue_id #z$tid";
128			//~ $to = $usro->name($exec).' <'.$usro->email($exec).'>';
129			//~ $body = "$uri?id=".$this->id('issue_task', 'id', $issue_id, 'tid', $tid);
130			//~ $this->helper->mail($to, $subject, $body);
131
132			//~ if ($cause_id == '')
133				//~ header("Location: ?id=bez:issue_task:id:$issue_id:tid:$tid");
134			//~ else
135				//~ header("Location: ?id=bez:issue_cause_task:id:$issue_id:cid:$cause_id:tid:$tid");
136		//~ }
137		//~ $value = $_POST;
138		try {
139			//checkboxes
140			if (!isset($_POST['all_day_event'])) {
141				$_POST['all_day_event'] = '0';
142			}
143			$task->set_data($_POST);
144			if ($task->any_errors()) {
145				$errors = $task->get_errors();
146				$value = $_POST;
147			} else {
148				$tid = $this->model->tasks->save($task);
149				$issue_id = $taks->issue;
150				$cause_id = $this->cause;
151
152				$title = 'Dodano zadanie';
153				$exec = $task->executor;
154				$subject = "[$conf[title]] $title: #$issue_id #z$tid";
155				$to = $this->model->users->get_user_full_name($exec).' <'.$this->model->users->get_user_email($exec).'>';
156				if ($cause_id == '') {
157					$body = "$uri?id=".$this->id('issue_task', 'id', $issue_id, 'tid', $tid);
158				} else {
159					$body = "$uri?id=".$this->id('issue_cause_task', 'id', $issue_id, 'cid', $cause_id, 'tid', $tid);
160				}
161				$this->helper->mail($to, $subject, $body);
162
163				if ($cause_id == '') {
164					header("Location: ?id=bez:issue_task:id:$issue_id:tid:$tid");
165				} else {
166					header("Location: ?id=bez:issue_cause_task:id:$issue_id:cid:$cause_id:tid:$tid");
167				}
168			}
169		} catch (Exception $e) {
170			echo nl2br($e);
171		}
172	} else {
173		$value['all_day_event'] = '1';
174	}
175
176	$template['task_button'] = $bezlang['add'];
177	$template['task_action'] = $this->id('task_form', 'id', $issue_id, 'cid', $cause_id, 'action', 'add');
178
179}
180
181if (isset($nparams['id'])) {
182	$isso = new Issues();
183	$template['issue'] = $isso->get($issue_id);
184
185	//~ $template['anytasks'] = $tasko->any_task($issue_id);
186	//~ $template['opentasks'] = $tasko->any_open($issue_id);
187	//~ $template['cause_without_task'] = $isso->cause_without_task($issue_id);
188}
189
190$template['users'] = $this->model->users->get_all();
191$template['tasktypes'] = $this->model->tasktypes->get_all();
192