xref: /plugin/bez/ctl/tasks.php (revision 168ecf58403c616ef3ef3bff8acd7252fdbee588)
1c9044e56Sghi<?php
2c9044e56Sghiinclude_once DOKU_PLUGIN."bez/models/tasks.php";
3c9044e56Sghiinclude_once DOKU_PLUGIN."bez/models/taskactions.php";
4c9044e56Sghiinclude_once DOKU_PLUGIN."bez/models/taskstates.php";
5*168ecf58Sghiinclude_once DOKU_PLUGIN."bez/models/tasktypes.php";
67f853d3aSghiinclude_once DOKU_PLUGIN."bez/models/users.php";
7eb950a4cSghiinclude_once DOKU_PLUGIN."bez/models/issues.php";
8c9044e56Sghi
9c9044e56Sghiif	(!$helper->user_viewer()) {
10c9044e56Sghi	$errors[] = $bezlang['error_issues'];
11c9044e56Sghi	$controller->preventDefault();
12c9044e56Sghi}
13c9044e56Sghi
14c9044e56Sghi$tasko = new Tasks();
15c9044e56Sghi$taskao = new Taskactions();
16c9044e56Sghi$taskso = new Taskstates();
17*168ecf58Sghi$tasktypeso = new Tasktypes();
187f853d3aSghi$usro = new Users();
19eb950a4cSghi$isso = new Issues();
20c9044e56Sghi
214fb0d798Sghiif (count($_POST) > 0)
224fb0d798Sghi	$raw_filters = $_POST;
234fb0d798Sghielseif (count($params) == 0 && isset($_COOKIE[bez_tasks_filters]))
244fb0d798Sghi	$raw_filters = $_COOKIE[bez_tasks_filters];
25c9044e56Sghi
264fb0d798Sghiif (isset($raw_filters)) {
274fb0d798Sghi	$filters = $tasko->validate_filters($raw_filters);
28c9044e56Sghi	$query_uri = '';
29c9044e56Sghi	foreach ($filters as $k => $v)
30c9044e56Sghi		if ($v != '-all')
31c9044e56Sghi			$query_uri .= ':'.urlencode($k).':'.urlencode($v);
32c9044e56Sghi
334fb0d798Sghi	if ($query_uri == "")
344fb0d798Sghi		$query_uri = ":year:-all";
354fb0d798Sghi
3605c9d3bcSghi	header('Location: ?id='.$this->id('tasks').$query_uri);
37c9044e56Sghi}
38c9044e56Sghi
39c9044e56Sghi/*rekordy parzyste to nagłówki, nieparzyste to ich wartości.*/
40c9044e56Sghi/*np. status:1:type:2:podmiot:PCA*/
41*168ecf58Sghi$value = array('issue' => '-all', 'action' => '-all', 'taskstate' => '-all',
42*168ecf58Sghi				'executor' => '-all', 'year' => '-all', 'tasktype' => '-all',
43*168ecf58Sghi				'month' => '-all', 'task' => '', 'reason' => '');
44c9044e56Sghifor ($i = 0; $i < count($params); $i += 2)
45c9044e56Sghi	$value[urldecode($params[$i])] = urldecode($params[$i+1]);
46c9044e56Sghi
474fb0d798Sghi//save filters
484fb0d798Sghiforeach ($value as $k => $v)
494fb0d798Sghi	setcookie("bez_tasks_filters[$k]", $v);
50c9044e56Sghi
51c9044e56Sghi$template['uri'] = $uri;
52c9044e56Sghi
53eb950a4cSghi$template['issues'] = $isso->get_ids();
54*168ecf58Sghi
55c9044e56Sghi$template['actions'] = $taskao->get();
56*168ecf58Sghi
57c9044e56Sghi$template['states'] = $taskso->get();
587f853d3aSghi$template['executors'] = $usro->get();
59c9044e56Sghi$template['years'] = $tasko->get_years();
60c9044e56Sghi
61d00bbb0cSghi$tasks = $tasko->get_filtered($value);
62*168ecf58Sghi
63d00bbb0cSghi
64d00bbb0cSghi$template['tasks_stats']['total'] = count($tasks);
65d00bbb0cSghi
66d00bbb0cSghi$tcost = 0;
67*168ecf58Sghi$thours = 0;
68*168ecf58Sghiforeach ($tasks as &$task) {
69d00bbb0cSghi	$tcost += (int)$task['cost'];
70*168ecf58Sghi	if ($task['start_time'] != '') {
71*168ecf58Sghi		$start_time = strtotime($task['start_time']);
72*168ecf58Sghi		$finish_time = strtotime($task['finish_time']);
73*168ecf58Sghi		$secs = $finish_time - $start_time;
74*168ecf58Sghi		$hours = $secs / 3600;
75*168ecf58Sghi		$hours_s = sprintf("%.1f", $hours);
76*168ecf58Sghi		$task['hours'] = $hours_s;
77*168ecf58Sghi		$thours += $hours;
78*168ecf58Sghi	} else
79*168ecf58Sghi		$task['hours'] = '';
80d00bbb0cSghi}
81*168ecf58Sghi$template['tasks'] = $tasks;
82*168ecf58Sghi
83d00bbb0cSghi$template['tasks_stats']['totalcost'] = $tcost;
84*168ecf58Sghi$template['tasks_stats']['totalhours'] = sprintf("%.1f", $thours);
85*168ecf58Sghi
86*168ecf58Sghi$tasktypes = $tasktypeso->get();
87*168ecf58Sghi$template['tasktypes'] = $tasktypes;
88d00bbb0cSghi
89d00bbb0cSghi
90*168ecf58Sghiif ($nparams['taskstate'] == '0')
91*168ecf58Sghi	$template['view'] = 'plan';
92*168ecf58Sghielse
93*168ecf58Sghi	$template['view'] = 'realization';
94*168ecf58Sghi
95*168ecf58Sghi$template['months'] = array('jan', 'feb', 'mar', 'apr', 'may', 'june', 'july', 'aug',
96*168ecf58Sghi							'sept', 'oct', 'nov', 'dec');
97