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