xref: /plugin/bez/ctl/tasks.php (revision 4fb0d79865ca3cb261d7a9243e2a8341ee908e78)
1<?php
2include_once DOKU_PLUGIN."bez/models/tasks.php";
3include_once DOKU_PLUGIN."bez/models/taskactions.php";
4include_once DOKU_PLUGIN."bez/models/taskstates.php";
5include_once DOKU_PLUGIN."bez/models/users.php";
6include_once DOKU_PLUGIN."bez/models/issues.php";
7
8if	(!$helper->user_viewer()) {
9	$errors[] = $bezlang['error_issues'];
10	$controller->preventDefault();
11}
12
13$tasko = new Tasks();
14$taskao = new Taskactions();
15$taskso = new Taskstates();
16$usro = new Users();
17$isso = new Issues();
18
19if (count($_POST) > 0)
20	$raw_filters = $_POST;
21elseif (count($params) == 0 && isset($_COOKIE[bez_tasks_filters]))
22	$raw_filters = $_COOKIE[bez_tasks_filters];
23
24if (isset($raw_filters)) {
25	$filters = $tasko->validate_filters($raw_filters);
26	$query_uri = '';
27	foreach ($filters as $k => $v)
28		if ($v != '-all')
29			$query_uri .= ':'.urlencode($k).':'.urlencode($v);
30
31	if ($query_uri == "")
32		$query_uri = ":year:-all";
33
34	header('Location: ?id='.$this->id('tasks').$query_uri);
35}
36
37/*rekordy parzyste to nagłówki, nieparzyste to ich wartości.*/
38/*np. status:1:type:2:podmiot:PCA*/
39$value = array('issue' => '-all', 'action' => '-all', 'state' => '-all', 'executor' => '-all', 'year' => '-all');
40for ($i = 0; $i < count($params); $i += 2)
41	$value[urldecode($params[$i])] = urldecode($params[$i+1]);
42
43//save filters
44foreach ($value as $k => $v)
45	setcookie("bez_tasks_filters[$k]", $v);
46
47$template['uri'] = $uri;
48
49$template['issues'] = $isso->get_ids();
50$template['actions'] = $taskao->get();
51$template['states'] = $taskso->get();
52$template['executors'] = $usro->get();
53$template['years'] = $tasko->get_years();
54
55$tasks = $tasko->get_filtered($value);
56$template['tasks'] = $tasks;
57
58$template['tasks_stats']['total'] = count($tasks);
59
60$tcost = 0;
61foreach ($tasks as $task) {
62	$tcost += (int)$task['cost'];
63}
64$template['tasks_stats']['totalcost'] = $tcost;
65
66
67