From ee160faaae724c259629dba6b97431cd1d6d0cbd Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 21 Sep 2007 02:24:31 +0000 Subject: [PATCH] fix problems with time queue search: ticket subjects need to be HTML-escaped, 'remaining time' calculation had a NULL vs 0 issue, and link to tickets --- httemplate/search/timeworked.html | 63 ++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/httemplate/search/timeworked.html b/httemplate/search/timeworked.html index 858cc6281..6bff4149b 100644 --- a/httemplate/search/timeworked.html +++ b/httemplate/search/timeworked.html @@ -12,7 +12,7 @@ '', # checkbox column ], 'fields' => [ sub { shift->[0] }, - sub { shift->[1] }, + sub { encode_entities(shift->[1]) }, sub { shift->[2] }, sub { my $seconds = shift->[3]; (($seconds < 0) ? '-' : '') . @@ -26,6 +26,13 @@ qq!!; }, ], + 'links' => [ + $link, + $link, + '', + '', + '', + ], 'html_foot' => sub { '
'. ''. @@ -49,18 +56,29 @@ die "access denied" my @groupby = (); -my $transactiontime = "CASE transactions.type when 'Set' THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60 ELSE timetaken*60 END"; -push @groupby, "transactions.type"; -push @groupby, "newvalue"; -push @groupby, "oldvalue"; -push @groupby, "timetaken"; +my $transactiontime = " + CASE transactions.type when 'Set' + THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60 + ELSE timetaken*60 + END +"; + +push @groupby, qw( transactions.type newvalue oldvalue timetaken ); my $appliedtimeclause = "coalesce (sum(acct_rt_transaction.seconds), 0)"; -my $appliedtimeselect = "SELECT sum(seconds) FROM acct_rt_transaction where transaction_id = transactions.id"; +my $appliedtimeselect = " + coalesce( + ( SELECT sum(seconds) FROM acct_rt_transaction + WHERE transaction_id = transactions.id + ), + 0 + ) +"; + push @groupby, "transactions.id"; -my $wheretimeleft = "($transactiontime != ($appliedtimeselect) OR ($appliedtimeselect) is NULL)"; +my $wheretimeleft = "$transactiontime != $appliedtimeselect"; push @groupby, "tickets.id"; push @groupby, "tickets.subject"; @@ -68,7 +86,32 @@ push @groupby, "transactions.created"; my $groupby = join(',', @groupby); -my $query = "SELECT tickets.id,tickets.subject,to_char(transactions.created, 'Dy Mon DD HH24:MI:SS YYYY'),$transactiontime-$appliedtimeclause,transactions.id FROM transactions JOIN tickets ON transactions.objectid = tickets.id LEFT JOIN acct_rt_transaction on transactions.id = acct_rt_transaction.transaction_id WHERE objecttype='RT::Ticket' AND ((transactions.type='Set' AND field='TimeWorked') OR transactions.type='Comment' OR transactions.type='Correspond') AND ($wheretimeleft) GROUP BY $groupby ORDER BY transactions.created"; -my $count_query = "SELECT count(*) FROM transactions WHERE objecttype='RT::Ticket' AND ((transactions.type='Set' AND field='TimeWorked') OR transactions.type='Comment' OR transactions.type='Correspond') AND ($wheretimeleft)"; +my $where = " + WHERE objecttype='RT::Ticket' + AND ( ( transactions.type='Set' AND field='TimeWorked' ) + OR transactions.type='Comment' + OR transactions.type='Correspond' + ) + AND $wheretimeleft +"; + #AND $wheretimeleft + +my $query = " + SELECT tickets.id, tickets.subject, + to_char(transactions.created, 'Dy Mon DD HH24:MI:SS YYYY'), + $transactiontime-$appliedtimeclause, + transactions.id + FROM transactions + JOIN tickets ON transactions.objectid = tickets.id + LEFT JOIN acct_rt_transaction + ON transactions.id = acct_rt_transaction.transaction_id + $where + GROUP BY $groupby + ORDER BY transactions.created +"; + +my $count_query = "SELECT COUNT(*) FROM transactions $where"; + +my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->[0]; } ]; -- 2.11.0