xref: /plugin/bez/ctl/tasks.php (revision d6002863ed649bcc6a7301ca988622c05c6727b3)
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' && $v != '')
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
59$template['executors'] = $usro->get();
60$template['groups'] = $usro->groups();
61
62$template['years'] = $tasko->get_years();
63
64$tasks = $tasko->get_filtered($value);
65
66
67$template['tasks_stats']['total'] = count($tasks);
68
69$tcost = 0;
70$thours = 0;
71foreach ($tasks as &$task) {
72	$tcost += (int)$task['cost'];
73	if ($task['start_time'] != '') {
74		$start_time = strtotime($task['start_time']);
75		$finish_time = strtotime($task['finish_time']);
76		$secs = $finish_time - $start_time;
77		$hours = $secs / 3600;
78		$hours_s = sprintf("%.1f", $hours);
79		$task['hours'] = $hours_s;
80		$thours += $hours;
81	} else
82		$task['hours'] = '';
83}
84$template['tasks'] = $tasks;
85
86$template['tasks_stats']['totalcost'] = $tcost;
87$template['tasks_stats']['totalhours'] = sprintf("%.1f", $thours);
88
89$tasktypes = $tasktypeso->get();
90$template['tasktypes'] = $tasktypes;
91
92
93if ($nparams['taskstate'] == '0')
94	$template['view'] = 'plan';
95else
96	$template['view'] = 'realization';
97
98$template['months'] = array(1 => 'jan',
99							2 => 'feb',
100							3 => 'mar',
101							4 => 'apr',
102							5 => 'may',
103							6 => 'june',
104							7 => 'july',
105							8 => 'aug',
106							9 => 'sept',
107							10 => 'oct',
108							11 => 'nov',
109							12 => 'dec');
110