xref: /plugin/bez/ctl/tasks.php (revision 168ecf58403c616ef3ef3bff8acd7252fdbee588)
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/tasktypes.php";
6include_once DOKU_PLUGIN."bez/models/users.php";
7include_once DOKU_PLUGIN."bez/models/issues.php";
8
9if	(!$helper->user_viewer()) {
10	$errors[] = $bezlang['error_issues'];
11	$controller->preventDefault();
12}
13
14$tasko = new Tasks();
15$taskao = new Taskactions();
16$taskso = new Taskstates();
17$tasktypeso = new Tasktypes();
18$usro = new Users();
19$isso = new Issues();
20
21if (count($_POST) > 0)
22	$raw_filters = $_POST;
23elseif (count($params) == 0 && isset($_COOKIE[bez_tasks_filters]))
24	$raw_filters = $_COOKIE[bez_tasks_filters];
25
26if (isset($raw_filters)) {
27	$filters = $tasko->validate_filters($raw_filters);
28	$query_uri = '';
29	foreach ($filters as $k => $v)
30		if ($v != '-all')
31			$query_uri .= ':'.urlencode($k).':'.urlencode($v);
32
33	if ($query_uri == "")
34		$query_uri = ":year:-all";
35
36	header('Location: ?id='.$this->id('tasks').$query_uri);
37}
38
39/*rekordy parzyste to nagłówki, nieparzyste to ich wartości.*/
40/*np. status:1:type:2:podmiot:PCA*/
41$value = array('issue' => '-all', 'action' => '-all', 'taskstate' => '-all',
42				'executor' => '-all', 'year' => '-all', 'tasktype' => '-all',
43				'month' => '-all', 'task' => '', 'reason' => '');
44for ($i = 0; $i < count($params); $i += 2)
45	$value[urldecode($params[$i])] = urldecode($params[$i+1]);
46
47//save filters
48foreach ($value as $k => $v)
49	setcookie("bez_tasks_filters[$k]", $v);
50
51$template['uri'] = $uri;
52
53$template['issues'] = $isso->get_ids();
54
55$template['actions'] = $taskao->get();
56
57$template['states'] = $taskso->get();
58$template['executors'] = $usro->get();
59$template['years'] = $tasko->get_years();
60
61$tasks = $tasko->get_filtered($value);
62
63
64$template['tasks_stats']['total'] = count($tasks);
65
66$tcost = 0;
67$thours = 0;
68foreach ($tasks as &$task) {
69	$tcost += (int)$task['cost'];
70	if ($task['start_time'] != '') {
71		$start_time = strtotime($task['start_time']);
72		$finish_time = strtotime($task['finish_time']);
73		$secs = $finish_time - $start_time;
74		$hours = $secs / 3600;
75		$hours_s = sprintf("%.1f", $hours);
76		$task['hours'] = $hours_s;
77		$thours += $hours;
78	} else
79		$task['hours'] = '';
80}
81$template['tasks'] = $tasks;
82
83$template['tasks_stats']['totalcost'] = $tcost;
84$template['tasks_stats']['totalhours'] = sprintf("%.1f", $thours);
85
86$tasktypes = $tasktypeso->get();
87$template['tasktypes'] = $tasktypes;
88
89
90if ($nparams['taskstate'] == '0')
91	$template['view'] = 'plan';
92else
93	$template['view'] = 'realization';
94
95$template['months'] = array('jan', 'feb', 'mar', 'apr', 'may', 'june', 'july', 'aug',
96							'sept', 'oct', 'nov', 'dec');
97