import of rt 3.0.4
[freeside.git] / rt / html / Ticket / Elements / ShowTransaction
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 <TR class="<% $RowNum%2 ? 'oddline' : 'evenline'%>" >
25 <TD bgcolor="<%$bgcolor%>"><A NAME="txn-<%$Transaction->Id%>" href="#txn-<%$Transaction->Id%>">#</A>&nbsp;</TD>
26 <TD>&nbsp&nbsp;</TD>
27 <TD><font size=-2><% $transdate|n %></font>&nbsp;</TD>
28 % my $desc = $Transaction->BriefDescription;
29 % $m->comp('/Elements/Callback', _CallbackName => 'ModifyDisplay', text => \$desc, Transaction => $Transaction, %ARGS);
30 <TD ALIGN="LEFT"><b><%$Transaction->CreatorObj->Name%> - <%$TicketString%> <%$desc%>
31
32 </b></TD>
33 <TD><%$TimeTaken%>&nbsp;</TD>
34 <TD ALIGN="RIGHT"><font size=-1><%$titlebar_commands|n%></font></TD>
35 </TR>
36 <%PERL>
37
38 unless ($Collapsed) {
39  $attachments->GotoFirstItem;
40  while (my $message=$attachments->Next) {
41      #we don't want to show any empty transactions, unless they have kids
42      next unless ($message->ContentLength || $message->Children->Count);
43
44   my ($headers, $quoted);
45       if ($ShowHeaders && ($ShowHeaders == $Ticket->Id)) {
46           $headers = $message->Headers;
47       } else {
48           $headers = $message->NiceHeaders;
49       }
50       chomp $headers;
51       if ($headers) {
52            # localize the common headers (like 'Subject:'), too.
53            eval {$headers =~ s/^([^:]+)(?=:)/loc($1)/em; } # we eval here to catch errors when 5.6 panics
54       }
55      # 13456 is a random # of about the biggest size we want to see inline text
56      my $MAX_INLINE_BODY = 13456;
57      if ($message->ContentType =~ m{^(text/plain|message|text$)}i && 
58                                     $message->ContentLength < $MAX_INLINE_BODY ) {
59          require Text::Quoted;
60          $quoted = Text::Quoted::extract($message->Content); 
61      }
62         
63 </%PERL>
64 <TR class="<% $RowNum%2 ? 'oddline' : 'evenline'%>" >                                
65       <TD BGCOLOR="<%$bgcolor%>">&nbsp;&nbsp;</TD>
66       <TD>&nbsp;&nbsp;</TD>
67       <TD COLSPAN=3 VALIGN=TOP>
68 <span class="message">
69         <PRE>
70 <& ShowMessageHeaders, Headers => $headers, Transaction => $Transaction &>
71 </PRE>
72 <& ShowMessageStanza, Depth => 0, Message => $quoted, Transaction => $Transaction &>
73 </span>
74       </TD>
75       <TD VALIGN=TOP ALIGN=RIGHT>
76         
77 % if ($message->Parent == 0  ) {
78 <BR>
79 % }
80 <%PERL>
81 my $size = $message->ContentLength;
82
83 if ($size) {
84     if ($size > 1024) {
85         $size = loc("[_1]k", int($size/102.4)/10);
86     }
87     else {
88         $size = loc("[_1]b", $size);
89     }
90 </%PERL>
91 <font size=-1><A HREF="<%$RT::WebPath%>/Ticket/Attachment/<%$Transaction->Id%>/<%$message->Id%>/<%$message->Filename%>"><&|/l&>Download</&> <% $message->Filename|| loc('(untitled)') %></a> <% $size %></font>
92 % }
93 </TD>
94 </TR>
95 % }
96 % }
97
98
99
100 <%ARGS>
101 $Ticket => undef
102 $Transaction => undef
103 $ShowHeaders => 0
104 $Collapsed => undef
105 $ShowTitleBarCommands => 1
106 $RowNum => 1
107 </%ARGS>
108
109 <%INIT>
110
111
112 my ($TimeTaken, $TicketString, $bgcolor);
113
114 my $transdate = $Transaction->CreatedAsString();
115 $transdate =~ s/\s/&nbsp;/g;
116
117 if ($Transaction->Type =~ /^(Create|Correspond|Comment$)/) {
118         if ($Transaction->IsInbound) {
119                 $bgcolor="#336699";
120         }
121         else {
122                 $bgcolor="#339999";
123         }
124 } elsif (($Transaction->Field =~ /^Owner$/) or 
125          ($Transaction->Type =~ /^(AddWatcher|DelWatcher)$/)) {
126         $bgcolor="#333399";
127
128 } elsif ($Transaction->Type =~ /^(AddLink|DeleteLink)$/) {
129         $bgcolor="#336633";
130 } elsif ($Transaction->Type =~ /^(Status|Set|Told)$/) {
131         if ($Transaction->Field =~ /^(Told|Starts|Started|Due)$/) {
132                 $bgcolor="#663366";     
133         }
134         else {
135                 $bgcolor="#993333";
136         }
137 }
138 else {
139         $bgcolor="#cccccc";
140 }
141
142 if ($Ticket->Id != $Transaction->Ticket) {
143         $TicketString = "Ticket ".$Transaction->Ticket .": ";
144 }
145
146 if ($Transaction->TimeTaken > 0) {
147         $TimeTaken = $Transaction->TimeTaken." min"
148 }
149 my $attachments = $Transaction->Attachments;
150
151 my $titlebar_commands='&nbsp;';
152
153 # If the transaction has anything attached to it at all
154 if ($Transaction->Attachments->First && $ShowTitleBarCommands) {
155         if ($Transaction->TicketObj->CurrentUserHasRight('ReplyToTicket')) {
156                 $titlebar_commands .= 
157                   "[<a href=\"Update.html?id=".
158                   $Transaction->Ticket . "&QuoteTransaction=".$Transaction->Id.
159                   "&Action=Respond\">". loc('Reply') ."</a>]&nbsp;";
160         }
161         if ($Transaction->TicketObj->CurrentUserHasRight('CommentOnTicket')) {
162              $titlebar_commands .= 
163              "[<a href=\"Update.html?id=".$Transaction->Ticket. 
164              "&QuoteTransaction=".$Transaction->Id.
165              "&Action=Comment\">". loc('Comment') ."</a>]";
166         }
167 }
168
169 </%INIT>