This commit was generated by cvs2svn to compensate for changes in r3921,
[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-2004 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, [ EffectiveTicket    => $t->EffectiveTicket   ]
101         if (!%$fields || exists $fields->{lc 'EffectiveTicket'});
102     push @data, [ Ticket    => $t->Ticket   ]
103         if (!%$fields || exists $fields->{lc 'Ticket'});
104     push @data, [ TimeTaken    => $t->TimeTaken   ]
105         if (!%$fields || exists $fields->{lc 'TimeTaken'});
106     push @data, [ Type    => $t->Type   ]
107         if (!%$fields || exists $fields->{lc 'Type'});
108     push @data, [ Field    => $t->Field   ]
109         if (!%$fields || exists $fields->{lc 'Field'});
110     push @data, [ OldValue    => $t->OldValue   ]
111         if (!%$fields || exists $fields->{lc 'OldValue'});
112     push @data, [ NewValue    => $t->NewValue   ]
113         if (!%$fields || exists $fields->{lc 'NewValue'});
114     push @data, [ Data    => $t->Data   ]
115         if (!%$fields || exists $fields->{lc 'Data'});
116     push @data, [ Description    => $t->Description   ]
117         if (!%$fields || exists $fields->{lc 'Description'});
118     push @data, [ Content    => $t->Content   ]
119         if (!%$fields || exists $fields->{lc 'Content'});
120
121
122     if (!%$fields || exists $fields->{lc 'Content'}) {    
123         my $creator = new RT::User $session{CurrentUser};
124         $creator->Load($t->Creator);
125         push @data, [ Creator    => $creator->Name   ];
126     }
127     push @data, [ Created    => $t->Created   ]
128         if (!%$fields || exists $fields->{lc 'Created'});
129
130     if (!%$fields || exists $fields->{lc 'Attachments'}) {
131         my $attachlist;
132         my $attachments = $t->Attachments;
133         while (my $a = $attachments->Next) {
134             my $size = length($a->Content);
135             if ($size > 1024) { $size  = int($size/102.4)/10 . "k" }
136             else              { $size .= "b" }
137             $attachlist .= "\n" . $a->Id.": ".($a->Filename || "untitled")." (".$size.")";
138         }
139         
140         push @data, [Attachments => $attachlist];
141     }
142
143     my %k = map {@$_} @data;
144     $o = [ map {$_->[0]} @data ];
145     $k = \%k;
146
147 } else {
148     my (@data, $tids);
149     $format ||= "s";
150     $format = "l" if (%$fields);
151
152     while (my $t = $trans->Next) {
153         my $tid = $t->Id;
154
155         if ($format eq "l") {
156             $tids .= "," if $tids;
157             $tids .= $tid;
158         } else {
159             push @$o, $tid;
160             $k->{$tid} = $t->Description;
161         }
162     }
163
164     if ($format eq "l") {
165         my @tid;
166         push @tid, "ticket/$id/history/id/$tids";
167         my $fieldstring;
168         foreach my $key (keys %$fields) {
169             $fieldstring .= "," if $fieldstring;
170             $fieldstring .= $key;
171         }
172         my ($content, $forms);
173
174         $m->subexec("$RT::WebPath/REST/1.0/show", 
175                     id => \@tid, 
176                     format => $format,
177                     fields => $fieldstring);
178         return [ $c, $o, $k, $e ];
179     }
180 }
181
182 if (!$c) {
183     my $sub = $trans->Count();
184     $c = "# $sub/$total ($args/total)";
185 }
186
187 return [ $c, $o, $k, $e ];
188
189 </%perl>