import rt 3.4.6
[freeside.git] / rt / html / REST / 1.0 / Forms / ticket / history
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# END BPS TAGGED BLOCK }}}
46 %# REST/1.0/Forms/ticket/history
47 %#
48 <%ARGS>
49 $id
50 $args => undef
51 $format => undef
52 $fields => undef
53 </%ARGS>
54 <%perl>
55 my $ticket = new RT::Ticket $session{CurrentUser};
56 my ($c, $o, $k, $e) = ("", [], {}, "");
57
58 $ticket->Load($id);
59 unless ($ticket->Id) {
60     return [ "# Ticket $id does not exist.", [], {}, 1 ];
61 }
62
63 my $trans = $ticket->Transactions();
64 my $total = $trans->Count();
65
66 chomp $args;
67 my @arglist = split('/', $args);
68 my ($type, $tid);
69
70 if ($arglist[0] eq 'type') {
71     $type = $arglist[1];
72 } elsif ($arglist[0] eq 'id') {
73     $tid = $arglist[1];
74 } else {
75     $type = $args;
76 }
77
78 if ($type) {
79     # Create, Set, Status, Correspond, Comment, Give, Steal, Take, Told
80     # CustomField, AddLink, DeleteLink, AddWatcher, DelWatcher
81     if ($args =~ /^links?$/) {
82         $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Link');
83     }
84     elsif ($args =~ /^watchers?$/) {
85         $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Watcher');
86     }
87     else {
88         $trans->Limit(FIELD => 'Type', OPERATOR => '=', VALUE => $type);
89     }
90 } elsif ($tid) {
91     $trans->Limit(FIELD => 'Id', OPERATOR => '=', VALUE => $tid);
92 }
93
94 if ($tid) {
95     my @data;
96     my $t = new RT::Transaction $session{CurrentUser};
97     $t->Load($tid);
98
99     push @data, [ id    => $t->Id   ];
100     push @data, [ Ticket    => $t->Ticket   ]
101         if (!%$fields || exists $fields->{lc 'Ticket'});
102     push @data, [ TimeTaken    => $t->TimeTaken   ]
103         if (!%$fields || exists $fields->{lc 'TimeTaken'});
104     push @data, [ Type    => $t->Type   ]
105         if (!%$fields || exists $fields->{lc 'Type'});
106     push @data, [ Field    => $t->Field   ]
107         if (!%$fields || exists $fields->{lc 'Field'});
108     push @data, [ OldValue    => $t->OldValue   ]
109         if (!%$fields || exists $fields->{lc 'OldValue'});
110     push @data, [ NewValue    => $t->NewValue   ]
111         if (!%$fields || exists $fields->{lc 'NewValue'});
112     push @data, [ Data    => $t->Data   ]
113         if (!%$fields || exists $fields->{lc 'Data'});
114     push @data, [ Description    => $t->Description   ]
115         if (!%$fields || exists $fields->{lc 'Description'});
116     push @data, [ Content    => $t->Content   ]
117         if (!%$fields || exists $fields->{lc 'Content'});
118
119
120     if (!%$fields || exists $fields->{lc 'Content'}) {    
121         my $creator = new RT::User $session{CurrentUser};
122         $creator->Load($t->Creator);
123         push @data, [ Creator    => $creator->Name   ];
124     }
125     push @data, [ Created    => $t->Created   ]
126         if (!%$fields || exists $fields->{lc 'Created'});
127
128     if (!%$fields || exists $fields->{lc 'Attachments'}) {
129         my $attachlist;
130         my $attachments = $t->Attachments;
131         while (my $a = $attachments->Next) {
132             my $size = length($a->Content);
133             if ($size > 1024) { $size  = int($size/102.4)/10 . "k" }
134             else              { $size .= "b" }
135             $attachlist .= "\n" . $a->Id.": ".($a->Filename || "untitled")." (".$size.")";
136         }
137         
138         push @data, [Attachments => $attachlist];
139     }
140
141     my %k = map {@$_} @data;
142     $o = [ map {$_->[0]} @data ];
143     $k = \%k;
144
145 } else {
146     my (@data, $tids);
147     $format ||= "s";
148     $format = "l" if (%$fields);
149
150     while (my $t = $trans->Next) {
151         my $tid = $t->Id;
152
153         if ($format eq "l") {
154             $tids .= "," if $tids;
155             $tids .= $tid;
156         } else {
157             push @$o, $tid;
158             $k->{$tid} = $t->Description;
159         }
160     }
161
162     if ($format eq "l") {
163         my @tid;
164         push @tid, "ticket/$id/history/id/$tids";
165         my $fieldstring;
166         foreach my $key (keys %$fields) {
167             $fieldstring .= "," if $fieldstring;
168             $fieldstring .= $key;
169         }
170         my ($content, $forms);
171
172         $m->subexec("$RT::WebPath/REST/1.0/show", 
173                     id => \@tid, 
174                     format => $format,
175                     fields => $fieldstring);
176         return [ $c, $o, $k, $e ];
177     }
178 }
179
180 if (!$c) {
181     my $sub = $trans->Count();
182     $c = "# $sub/$total ($args/total)";
183 }
184
185 return [ $c, $o, $k, $e ];
186
187 </%perl>