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