Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts/reports.php
blob: 7870291a07aec63940f7ec75ef32c998a3c37565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php

  /********************************************************\
  | Show various reports on tasks                          |
  | ~~~~~~~~~~~~~~~~~~~~~~~~                               |
  \********************************************************/

if (!defined('IN_FS')) {
    die('Do not access this file directly.');
}

if (!$user->perms('view_reports')) {
    Flyspray::redirect($baseurl);
}

require_once(BASEDIR . '/includes/events.inc.php');
$page->setTitle($fs->prefs['page_title'] . L('reports'));

/**********************\
*  Event reports       *
\**********************/

$events = array(1 => L('opened'),
                13 => L('reopened'),
                2 => L('closed'),
                3 => L('edited'),
                14 => L('assignmentchanged'),
                29 => L('events.useraddedtoassignees'),
                4 => L('commentadded'),
                5 => L('commentedited'),
                6 => L('commentdeleted'),
                7 => L('attachmentadded'),
                8 => L('attachmentdeleted'),
                11 => L('relatedadded'),
                12 => L('relateddeleted'),
                9 => L('notificationadded'),
                10 => L('notificationdeleted'),
                17 => L('reminderadded'),
                18 => L('reminderdeleted'),
                15 => L('addedasrelated'),
                16 => L('deletedasrelated'),
                19 => L('ownershiptaken'),
                20 => L('closerequestmade'),
                21 => L('reopenrequestmade'),
                22 => L('depadded'),
                23 => L('depaddedother'),
                24 => L('depremoved'),
                25 => L('depremovedother'),
                28 => L('pmreqdenied'),
                32 => L('subtaskadded'),
                33 => L('subtaskremoved'),
                34 => L('supertaskadded'),
                35 => L('supertaskremoved'),
    );

// Should events 19, 20, 21, 29 be here instead? 
$user_events = array(30 => L('created'),
                     31 => L('deleted'));

$page->assign('events', $events);
$page->assign('user_events', $user_events);
$page->assign('theuser', $user);

$sort = strtoupper(Req::enum('sort', array('desc', 'asc')));

$where = array();
$params = array();
$orderby = '';

switch (Req::val('order')) {
    case 'type':
        $orderby = "h.event_type {$sort}, h.event_date {$sort}";
        break;
    case 'user':
        $orderby = "user_id {$sort}, h.event_date {$sort}";
        break;
    case 'date': default:
        $orderby = "h.event_date {$sort}, h.event_type {$sort}";
}

if( is_array(Req::val('events')) ){
	foreach (Req::val('events') as $eventtype) {
		$where[] = 'h.event_type = ?';
		$params[] = $eventtype;
	}
	$where = '(' . implode(' OR ', $where) . ')';

	if ($proj->id) {
		$where = $where . 'AND (t.project_id = ?  OR h.event_type IN(30, 31)) ';
		$params[] = $proj->id;
	}

	if ( Req::val('fromdate') || Req::val('todate')) {
		$where .= ' AND ';
		$fromdate = Req::val('fromdate');
		$todate = Req::val('todate');

		if ($fromdate) {
			$where .= ' h.event_date > ?';
			$params[] = Flyspray::strtotime($fromdate) + 0;
		}
		if ($todate && $fromdate) {
			$where .= ' AND h.event_date < ?';
			$params[] = Flyspray::strtotime($todate) + 86400;
		} else if ($todate) {
			$where .= ' h.event_date < ?';
			$params[] = Flyspray::strtotime($todate) + 86400;
		}
	}

	$histories = $db->query("SELECT h.*
                        FROM  {history} h
                   LEFT JOIN {tasks} t ON h.task_id = t.task_id
                        WHERE $where
                     ORDER BY $orderby", $params, Req::num('event_number', -1));
	$histories = $db->fetchAllArray($histories);
}

$page->uses('histories', 'sort');

$page->pushTpl('reports.tpl');
?>