import rt 3.0.12
[freeside.git] / rt / html / SelfService / Display.html
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 <& /SelfService/Elements/Header, Title => loc('#[_1]: [_2]', $Ticket->id, $Ticket->Subject) &>
25
26 <& /Elements/ListActions, actions => \@results &>
27
28   <TABLE WIDTH="100%" class="ticketsummary" >
29       <TR>
30         <TD VALIGN=TOP WIDTH="50%">
31           <& /Elements/TitleBoxStart, title => loc('The Basics'), 
32                 title_class=> 'inverse',  
33                 color => "#993333" &>
34                 <& /Ticket/Elements/ShowBasics, Ticket => $Ticket &>
35           <& /Elements/TitleBoxEnd &>
36 </TD>
37         <TD VALIGN=TOP WIDTH="50%">
38           <& /Elements/TitleBoxStart, title => loc("Dates"),
39                 title_class=> 'inverse',
40                  color => "#663366" &>
41           <& /Ticket/Elements/ShowDates, Ticket => $Ticket, UpdatedLink => 0 &>
42           <& /Elements/TitleBoxEnd &>
43 </TD>
44 </TR>
45 </TABLE>
46
47
48
49 %#!!pape: selfservice_find_attachments.patch {{
50 <& /Ticket/Elements/ShowHistory, Ticket => $Ticket, AttachPath => "Attachment", Attachments => $attachments, UpdatePath => "Update.html" &>
51 %#!!pape: selfservice_find_attachments.patch }}
52
53
54
55 <%INIT>
56
57 my ( $field, @results );
58
59 # {{{ Load the ticket
60 #If we get handed two ids, mason will make them an array. bleck.
61 # We want teh first one. Just because there's no other sensible way
62 # to deal
63 my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id);
64
65 my $Ticket = new RT::Ticket( $session{'CurrentUser'} );
66 if ( $id[0] eq 'new' ) {
67
68     # {{{ Create a new ticket
69
70     my $Queue = new RT::Queue( $session{'CurrentUser'} );
71     unless ( $Queue->Load( $ARGS{'Queue'} ) ) {
72         $m->comp( 'Error.html', Why => loc('Queue not found') );
73         $m->abort;
74     }
75
76     unless ( $Queue->CurrentUserHasRight('CreateTicket') ) {
77         $m->comp( 'Error.html',
78              Why =>
79                loc('You have no permission to create tickets in that queue.') );
80         $m->abort;
81     }
82
83     my @Requestors = split ( /\s*,\s*/, $ARGS{'Requestors'} );
84     my @Cc         = split ( /\s*,\s*/, $ARGS{'Cc'} );
85
86     my $MIMEObj = MakeMIMEEntity( Subject             => $ARGS{'Subject'},
87                                   From                => $ARGS{'From'},
88                                   Cc                  => $ARGS{'Cc'},
89                                   Body                => $ARGS{'Content'},
90                                   AttachmentFieldName => 'Attach' );
91
92     #TODO in Create_Details.html: priorities and due-date
93     my ( $id, $Trans, $ErrMsg ) = $Ticket->Create( Queue     => $ARGS{Queue},
94                                                    Requestor => \@Requestors,
95                                                    Cc        => \@Cc,
96                                                    Subject   => $ARGS{Subject},
97                                                    MIMEObj   => $MIMEObj );
98     unless ( $id && $Trans ) {
99         $m->comp( 'Error.html', Why => $ErrMsg );
100         $m->abort();
101     }
102
103     push ( @results, $ErrMsg );
104
105     # }}}
106
107 # delete temporary storage entry to make WebUI clean
108 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
109     delete $session{'Attachments'};
110 }
111 # }}}
112 }
113 else {
114     unless ( $Ticket->Load( $id[0] ) ) {
115         $m->comp( 'Error.html',
116                   Why => loc( "Couldn't load ticket '[_1]'", $id ) );
117         $m->abort();
118     }
119 }
120
121 # }}}
122
123 unless ( $Ticket->CurrentUserHasRight('ShowTicket') ) {
124     $m->comp( 'Error.html',
125               Why => loc("No permission to display that ticket") );
126     $m->abort();
127 }
128
129 my ( $code, $msg );
130
131 #Update the status
132 if (     ( defined $ARGS{'Status'} )
133      and ( $ARGS{'Status'} ne $Ticket->Status ) ) {
134     ( $code, $msg ) = $Ticket->SetStatus( $ARGS{'Status'} );
135     push @results, "$msg";
136 }
137
138 # {{{ store the uploaded attachment in session
139 if ($ARGS{'Attach'}) {                  # attachment?
140     $session{'Attachments'} = {} unless defined $session{'Attachments'};
141
142     my $subject = "$ARGS{'Attach'}";
143     # since CGI.pm deutf8izes the magic field, we need to add it back.
144     Encode::_utf8_on($subject);
145     # strip leading directories
146     $subject =~ s#^.*[\\/]##;
147
148     my $attachment = MakeMIMEEntity(
149         Subject             => $subject,
150         Body                => "",
151         AttachmentFieldName => 'Attach'
152     );
153
154     $session{'Attachments'} = { %{$session{'Attachments'} || {}},
155                                 $ARGS{'Attach'} => $attachment };
156 }
157 # }}}
158
159 if ( $session{'Attachments'} || 
160      (   $ARGS{'UpdateContent'} ne ''
161          && $ARGS{'UpdateContent'} ne "-- \n"
162          . $session{'CurrentUser'}->UserObj->Signature )) {
163     $ARGS{UpdateAttachments} = $session{'Attachments'};
164 }
165 ProcessUpdateMessage( ARGSRef   => \%ARGS,
166                       Actions   => \@results,
167                       TicketObj => $Ticket );
168
169 # delete temporary storage entry to make WebUI clean
170 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
171     delete $session{'Attachments'};
172 }
173 # }}}
174
175 my $Transactions = $Ticket->Transactions;
176
177 #!!pape: selfservice_find_attachments.patch {{
178 my $attachments = $m->comp('/Ticket/Elements/FindAttachments', Ticket => $Ticket);
179 #!!pape: selfservice_find_attachments.patch }}
180
181 </%INIT>
182
183
184 <%ARGS>
185 $id => undef
186 </%ARGS>