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