starting to work...
[freeside.git] / rt / share / html / SelfService / 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 <& /SelfService/Elements/Header, Title => loc('#[_1]: [_2]', $Ticket->id, $Ticket->Subject) &>
49
50 % $m->callback(CallbackName => 'BeforeActionList', %ARGS, Actions => \@results, ARGSRef => \%ARGS, Ticket => $Ticket );
51
52 <& /Elements/ListActions, actions => \@results &>
53
54   <table width="100%" class="ticketsummary" >
55       <tr>
56         <td valign="top" width="50%" class="boxcontainer">
57           <&| /Widgets/TitleBox, title => loc('The Basics'),
58                 ($LinkBasicsTitle ? (title_href => $title_box_link) : ()),
59                 title_class=> 'inverse',
60                 color => "#993333" &>
61                 <& /Ticket/Elements/ShowBasics, Ticket => $Ticket &>
62                 <& /Ticket/Elements/ShowCustomFields, Ticket => $Ticket &>
63           </&>
64 </td>
65         <td valign="top" width="50%" class="boxcontainer">
66           <&| /Widgets/TitleBox, title => loc("Dates"),
67                 title_class=> 'inverse',
68                  color => "#663366" &>
69           <& /Ticket/Elements/ShowDates, Ticket => $Ticket, UpdatedLink => 0 &>
70           </&>
71 </td>
72 </tr>
73 </table>
74
75
76
77 <& /Ticket/Elements/ShowHistory, 
78       Ticket => $Ticket, 
79       URIFile => "Display.html", 
80       ShowHeaders => $ARGS{'ShowHeaders'},
81       DownloadableHeaders => 0,
82       AttachPath => "Attachment", 
83       Attachments => $attachments, 
84       UpdatePath => "Update.html" 
85 &>
86
87
88
89 <%INIT>
90
91 my ( $field, @results );
92
93 $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
94
95 # Load the ticket
96 #If we get handed two ids, mason will make them an array. bleck.
97 # We want teh first one. Just because there's no other sensible way
98 # to deal
99 my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id);
100
101 my $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
102
103 # store the uploaded attachment in session
104 if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
105     $session{'Attachments'} = {} unless defined $session{'Attachments'};
106
107     my $attachment = MakeMIMEEntity(
108         AttachmentFieldName => 'Attach'
109     );
110
111     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
112     $session{'Attachments'} = {
113         %{ $session{'Attachments'} || {} },
114         $file_path => $attachment,
115     };
116 }
117
118 if ( defined ($id[0]) && $id[0] eq 'new' ) {
119
120     # {{{ Create a new ticket
121
122     my $Queue = RT::Queue->new( $session{'CurrentUser'} );
123     unless ( $Queue->Load( $ARGS{'Queue'} ) ) {
124         $m->comp( 'Error.html', Why => loc('Queue not found') );
125         $m->abort;
126     }
127
128     unless ( $Queue->CurrentUserHasRight('CreateTicket') ) {
129         $m->comp( 'Error.html',
130             Why =>
131               loc('You have no permission to create tickets in that queue.') );
132         $m->abort;
133     }
134
135
136     ( $Ticket, @results ) =
137     CreateTicket( Attachments => $session{'Attachments'}, %ARGS );
138
139     unless ( $Ticket->id ) {
140         $m->comp( 'Error.html', Why => join( "\n", @results ));
141               $m->abort();
142         }
143
144
145         # delete temporary storage entry to make WebUI clean
146         unless ( keys %{ $session{'Attachments'} } and $ARGS{'UpdateAttach'} ) {
147             delete $session{'Attachments'};
148         }
149
150     }
151     else {
152         unless ( $Ticket->Load( $id[0] ) ) {
153             $m->comp( 'Error.html',
154                 Why => loc( "Couldn't load ticket '[_1]'", $id ) );
155             $m->abort();
156         }
157
158     my ( $code, $msg );
159
160
161     if (
162         $session{'Attachments'}
163         || ( defined $ARGS{'UpdateContent'}
164             && $ARGS{'UpdateContent'} ne ''
165             && $ARGS{'UpdateContent'} ne "-- \n"
166             . $session{'CurrentUser'}->UserObj->Signature )
167       )
168     {
169         $ARGS{UpdateAttachments} = $session{'Attachments'};
170     }
171     push @results, ProcessUpdateMessage(
172         ARGSRef   => \%ARGS,
173         TicketObj => $Ticket
174     );
175             delete $session{'Attachments'};
176
177     # delete temporary storage entry to make WebUI clean
178     unless ( keys %{ $session{'Attachments'} } and $ARGS{'UpdateAttach'} ) {
179         delete $session{'Attachments'};
180     }
181
182     my @cfupdates = ProcessObjectCustomFieldUpdates(Object => $Ticket, ARGSRef => \%ARGS);
183     push (@results, @cfupdates);
184
185
186     #Update the status
187     if (    ( defined $ARGS{'Status'} )
188         and $ARGS{'Status'}
189         and ( $ARGS{'Status'} ne $Ticket->Status ) )
190     {
191         ( $code, $msg ) = $Ticket->SetStatus( $ARGS{'Status'} );
192         push @results, "$msg";
193     }
194
195
196     }
197
198     # This code does automatic redirection if any updates happen.
199
200     unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
201         $m->comp( 'Error.html',
202             Why => loc("No permission to display that ticket") );
203         # XXX: Why abort? then we loose footer //ruz
204         $m->abort();
205     }
206
207     if (@results) {
208         # We've done something, so we need to clear the decks to avoid
209         # resubmission on refresh.
210         # But we need to store Actions somewhere too, so we don't lose them.
211         my $key = Digest::MD5::md5_hex(rand(1024));
212         push @{ $session{"Actions"}->{$key}  ||= [] }, @results;
213         $session{'i'}++;
214         RT::Interface::Web::Redirect( RT->Config->Get('WebURL') ."SelfService/Display.html?id=". $Ticket->id."&results=".$key);
215     }
216
217     my $Transactions = $Ticket->Transactions;
218
219     my $attachments =
220       $m->comp( '/Ticket/Elements/FindAttachments', Ticket => $Ticket );
221
222     my $LinkBasicsTitle = $Ticket->CurrentUserHasRight('ModifyTicket')
223                           || $Ticket->CurrentUserHasRight('ReplyToTicket');
224     my $title_box_link = RT->Config->Get('WebPath')."/SelfService/Update.html?id=".$Ticket->Id;
225     $m->callback(CallbackName => 'BeforeDisplay', Ticket => \$Ticket, ARGSRef => \%ARGS, title_box_link => \$title_box_link);
226 </%INIT>
227
228
229 <%ARGS>
230 $id => undef
231 </%ARGS>