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