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