Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / share / html / Ticket / Display.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 %#                                          <sales@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., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28 %#
29 %#
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %#
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %#
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %#
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, 
49     Title => $title,
50     LinkRel => \%link_rel &>
51 <& /Elements/Tabs &>
52
53 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@Actions, ARGSRef => \%ARGS, Ticket => $TicketObj);
54
55 <& /Elements/ListActions, actions => \@Actions &>
56 <& Elements/ShowUpdateStatus, Ticket => $TicketObj &>
57
58 % $m->callback( %ARGS, Ticket => $TicketObj, Transactions => $transactions, Attachments => $attachments, CallbackName => 'BeforeShowSummary' );
59 <div class="summary">
60 <&| /Widgets/TitleBox, title => loc('Ticket metadata') &>
61 <& /Ticket/Elements/ShowSummary,  Ticket => $TicketObj, Attachments => $attachments &>
62 </&>
63 </div>
64 <br />
65
66 % $m->callback( Ticket => $TicketObj, %ARGS, Transactions => $transactions, Attachments => $attachments, CallbackName => 'BeforeShowHistory' );
67
68 % if (not $ForceShowHistory and RT->Config->Get( 'DeferTransactionLoading', $session{'CurrentUser'} )) {
69     <& /Ticket/Elements/ClickToShowHistory,
70         Ticket => $TicketObj,
71     &>
72 % } else {
73     <& /Ticket/Elements/ShowHistory ,
74           Ticket => $TicketObj,
75           Tickets => $Tickets,
76           Transactions => $transactions,
77           Collapsed => $ARGS{'Collapsed'},
78           ShowHeaders => $ARGS{'ShowHeaders'},
79           Attachments => $attachments,
80           AttachmentContent => $attachment_content
81     &>
82 % }
83
84 % $m->callback( %ARGS,
85 %     Ticket       => $TicketObj,
86 %     Transactions => $transactions,
87 %     Attachments  => $attachments,
88 %     CallbackName => 'AfterShowHistory',
89 % );
90
91 <%ARGS>
92 $id => undef
93 $TicketObj => undef
94 $ShowHeaders => 0
95 $Collapsed => undef
96 $ForceShowHistory => 0
97 </%ARGS>
98
99 <%INIT>
100
101 $m->callback( TicketObj => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'Initial' );
102
103 if ( ! $ARGS{'NoRedirect'} && RT::Interface::Web->MobileClient()) {
104     $id ||= $TicketObj->id if $TicketObj;
105     RT::Interface::Web::Redirect(RT->Config->Get('WebURL').'m/ticket/show?id='.$id);
106     $m->abort;
107 }
108
109
110 my (@Actions, $Tickets, $title);
111
112
113 unless ($id || $TicketObj) {
114     Abort('No ticket specified');
115 }
116
117 if ($ARGS{'id'} eq 'new') {
118     # {{{ Create a new ticket
119
120     # Massage customer IDs into member links.
121     my @cust_uris = map { 
122       /^(\d+)$/ && "freeside://freeside/cust_main/$1"
123     } split(' ', $ARGS{'new-Customer'});
124     
125     $ARGS{'new-MemberOf'} = 
126       join(' ', $ARGS{'new-MemberOf'}, @cust_uris);
127
128     my $Queue = RT::Queue->new( $session{'CurrentUser'} );
129     $Queue->Load($ARGS{'Queue'});
130     unless ( $Queue->id ) {
131         Abort('Queue not found');
132     }
133
134     unless ( $Queue->CurrentUserHasRight('CreateTicket') ) {
135         Abort('You have no permission to create tickets in that queue.');
136     }
137
138     ($TicketObj, @Actions) = CreateTicket(
139         Attachments => delete $session{'Attachments'},
140         %ARGS,
141     );
142     unless ( $TicketObj->CurrentUserHasRight('ShowTicket') ) {
143         Abort("No permission to view newly created ticket #".$TicketObj->id.".");
144     }
145 } else { 
146     $TicketObj ||= LoadTicket($ARGS{'id'});
147
148     $TicketObj->CurrentUser->PrincipalObj->HasRights( Object => $TicketObj );
149
150     my $SkipProcessing;
151
152     $m->callback( CallbackName => 'BeforeProcessArguments',
153         TicketObj => $TicketObj, Tickets => $Tickets,
154         ActionsRef => \@Actions, ARGSRef => \%ARGS,
155         SkipProcessing => \$SkipProcessing );
156
157     if ( !$SkipProcessing ) {
158         if ( defined $ARGS{'Action'} ) {
159             if ($ARGS{'Action'} =~ /^(Steal|Delete|Take|SetTold)$/) {
160                 my $action = $1;
161                 my ($res, $msg) = $TicketObj->$action();
162                 push(@Actions, $msg);
163             }
164         }
165
166         $m->callback(CallbackName => 'ProcessArguments', 
167                 Ticket => $TicketObj, 
168                 ARGSRef => \%ARGS, 
169                 Actions => \@Actions);
170         
171         $ARGS{UpdateAttachments} = $session{'Attachments'};
172         push @Actions,
173             ProcessUpdateMessage(
174             ARGSRef   => \%ARGS,
175             Actions   => \@Actions,
176             TicketObj => $TicketObj,
177             );
178         delete $session{'Attachments'};
179
180         #Process status updates
181         push @Actions, ProcessTicketWatchers(ARGSRef => \%ARGS, TicketObj => $TicketObj );
182         push @Actions, ProcessTicketBasics(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
183         push @Actions, ProcessTicketLinks(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
184         push @Actions, ProcessTicketDates(   ARGSRef => \%ARGS, TicketObj => $TicketObj );
185         push @Actions, ProcessTicketCustomFieldUpdates(ARGSRef => \%ARGS, TicketObj => $TicketObj );
186         # If this fails due to required fields being empty, it will set
187         # notes('RedirectToBasics').
188         push @Actions, ProcessTicketStatus(  ARGSRef => \%ARGS, TicketObj => $TicketObj );
189
190         push @Actions, ProcessTicketReminders( ARGSRef => \%ARGS, TicketObj => $TicketObj );
191
192         # XXX: we shouldn't block actions here if user has no right to see the ticket,
193         # but we should allow him to see actions he has done
194         unless ($TicketObj->CurrentUserHasRight('ShowTicket')) {
195             Abort("No permission to view ticket");
196         }
197         if ( $ARGS{'MarkAsSeen'} ) {
198             $TicketObj->SetAttribute(
199                 Name => 'User-'. $TicketObj->CurrentUser->id .'-SeenUpTo',
200                 Content => $TicketObj->LastUpdated,
201             );
202             push @Actions, loc('Marked all messages as seen');
203         }
204     }
205 }
206
207
208 $title = loc("Ticket #[_1]: [_2]", $TicketObj->Id, $TicketObj->Subject || '');
209
210 $m->callback(
211     CallbackName => 'BeforeDisplay',
212     TicketObj => \$TicketObj,
213     Tickets => \$Tickets,
214     Actions => \@Actions,
215     title => \$title,
216     ARGSRef => \%ARGS,
217 );
218
219 # This code does automatic redirection if any updates happen. 
220 my $path = '/Ticket/'. ( $m->notes('RedirectToBasics') ? 'Modify.html'
221                                                        : 'Display.html' );
222 MaybeRedirectForResults(
223     Actions   => \@Actions,
224     $TicketObj->Type eq 'approval' && RT->Config->Get('ForceApprovalsView')
225         ? (Path      => "/Approvals/Display.html", Force => 1)
226         : (Path      => $path)
227     ,
228     Anchor    => $ARGS{'Anchor'},
229     Arguments => { id => $TicketObj->id },
230 );
231
232 # Get the transactoins before the attachments, for great ACL justice
233 my $transactions = $m->comp('Elements/FindTransactions',Ticket => $TicketObj, Tickets => $Tickets || undef);
234 my $attachments = $m->comp('Elements/FindAttachments', Ticket => $TicketObj, Tickets => $Tickets);
235 my $attachment_content = $m->comp('Elements/LoadTextAttachments', Ticket => $TicketObj);
236
237 my %link_rel;
238 if (defined $session{'tickets'} and ($ARGS{'Query'} or $session{'CurrentSearchHash'}->{'Query'})) {
239     my $item_map = $session{'tickets'}->ItemMap;
240     $link_rel{first} = "Ticket/Display.html?id=" . $item_map->{first}                if $item_map->{$TicketObj->Id}{prev};
241     $link_rel{prev}  = "Ticket/Display.html?id=" . $item_map->{$TicketObj->Id}{prev} if $item_map->{$TicketObj->Id}{prev};
242     $link_rel{next}  = "Ticket/Display.html?id=" . $item_map->{$TicketObj->Id}{next} if $item_map->{$TicketObj->Id}{next};
243     $link_rel{last}  = "Ticket/Display.html?id=" . $item_map->{last}                 if $item_map->{$TicketObj->Id}{next};
244 }
245 </%INIT>