50c6f9327df577bd9269e4480ef42f772bb385b4
[freeside.git] / rt / share / html / Ticket / Update.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2011 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, Title => $title &>
49 <& /Ticket/Elements/Tabs, 
50     Ticket => $TicketObj, 
51     Title=> $title &>
52     
53 % $m->callback(CallbackName => 'BeforeActionList', ARGSRef => \%ARGS, Ticket => $TicketObj);
54 <& /Elements/ListActions, actions => \@results &>
55
56 <form action="Update.html" name="TicketUpdate"
57     method="post" enctype="multipart/form-data">
58 % $m->callback( CallbackName => 'FormStart', ARGSRef => \%ARGS, Ticket => $TicketObj, CanRespond => $CanRespond, CanComment => $CanComment, ResponseDefault => $ResponseDefault, CommentDefault => $CommentDefault );
59 <input type="hidden" class="hidden" name="QuoteTransaction" value="<% $ARGS{QuoteTransaction}||'' %>" />
60 <input type="hidden" class="hidden" name="DefaultStatus" value="<% $DefaultStatus ||''%>" />
61 <input type="hidden" class="hidden" name="Action" value="<% $ARGS{Action}||'' %>" />
62
63 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
64
65 <table width="100%" border="0">
66 % $m->callback(CallbackName => 'AfterTableOpens', ARGSRef => \%ARGS, Ticket => $TicketObj);
67
68 <tr><td class="label"><&|/l&>Status</&>:</td>
69 <td>
70 <& /Elements/SelectStatus, Name=>"Status", DefaultLabel => loc("[_1] (Unchanged)", loc($TicketObj->Status)), Default => $ARGS{'Status'} || ($TicketObj->Status eq $DefaultStatus ? undef : $DefaultStatus)&>
71 <span class="label"><&|/l&>Owner</&>:</span>
72 <& /Elements/SelectOwner,
73     Name         => "Owner",
74     TicketObj    => $TicketObj,
75     QueueObj     => $TicketObj->QueueObj,
76     DefaultLabel => loc("[_1] (Unchanged)", $m->scomp('/Elements/ShowUser', User => $TicketObj->OwnerObj)),
77     Default      => $ARGS{'Owner'}
78 &>
79 <span class="label"><&|/l&>Worked</&>:</span>
80 <& /Elements/EditTimeValue,
81     Name => 'UpdateTimeWorked',
82     Default => $ARGS{UpdateTimeWorked}||'',
83     InUnits => $ARGS{'UpdateTimeWorked-TimeUnits'}||'minutes',
84 &>
85 </td></tr>
86 % my $skip;
87 % $m->callback( %ARGS, CallbackName => 'BeforeUpdateType', skip => \$skip );
88 % if (!$skip) {
89 <input type="hidden" class="hidden" name="id" value="<%$TicketObj->Id%>" /><br />
90 % }
91 <tr><td class="label"><&|/l&>Update Type</&>:</td>
92 <td><select name="UpdateType">
93 % if ($CanComment) {
94 <option value="private" <% ($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq "private") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$CommentDefault |n %>><&|/l&>Comments (Not sent to requestors)</&></option>
95 % }
96 % if ($CanRespond) {
97 <option value="response" <% ($ARGS{'UpdateType'} && $ARGS{'UpdateType'} eq "response") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$ResponseDefault |n %>><&|/l&>Reply to requestors</&></option>
98 % }
99 </select> 
100 % $m->callback( %ARGS, CallbackName => 'AfterUpdateType' );
101 </td></tr>
102 <tr><td class="label"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || $TicketObj->Subject()%>" />
103 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
104 </td></tr>
105
106 <& /Ticket/Elements/UpdateCc, %ARGS, TicketObj => $TicketObj &>
107
108 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, TicketObj => $TicketObj &>
109
110 % if (exists $session{'Attachments'}) {
111 <tr><td><&|/l&>Attached file</&>:</td>
112 <td>
113 <&|/l&>Check box to delete</&><br />
114 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
115 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
116 % } # end of foreach
117 </td>
118 </tr>
119 % } # end of if
120
121 <tr><td class="label"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" /><input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" /><input type="hidden" class="hidden" name="UpdateAttach" value="1" />
122 </td></tr>
123
124 % if ( $gnupg_widget ) {
125 <tr><td>&nbsp;</td><td>
126 <& /Elements/GnuPG/SignEncryptWidget,
127     self => $gnupg_widget,
128     TicketObj => $TicketObj,
129 &>
130 </td></tr>
131 % }
132 % $m->callback( %ARGS, CallbackName => 'AfterGnuPG' );
133
134 <tr><td class="label" valign="top"><&|/l&>Message</&>:</td><td>
135 % $m->callback( %ARGS, CallbackName => 'BeforeMessageBox' );
136 % if (exists $ARGS{UpdateContent}) {
137 % # preserve QuoteTransaction so we can use it to set up sane references/in/reply to
138 % my $temp = $ARGS{'QuoteTransaction'};
139 % delete $ARGS{'QuoteTransaction'};
140 <& /Elements/MessageBox, Name=>"UpdateContent", Default=>$ARGS{UpdateContent}, IncludeSignature => 0, %ARGS&>
141 % $ARGS{'QuoteTransaction'} = $temp;
142 % } else {
143 % my $IncludeSignature = 1;
144 % $IncludeSignature = 0 if $Action ne 'Respond' && !RT->Config->Get('MessageBoxIncludeSignatureOnComment');
145 <& /Elements/MessageBox, Name=>"UpdateContent", IncludeSignature => $IncludeSignature, %ARGS &>
146 % }
147 </td></tr>
148 </table>
149
150
151
152
153 <& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket' &>
154 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
155 <&|/Widgets/TitleBox, title => loc('Scrips and Recipients') &>
156 <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
157 </&>
158
159 % }
160 </form>
161 <%INIT>
162 my $CanRespond = 0;
163 my $CanComment = 0;
164 my $checks_failure = 0;
165 my $title;
166
167 my $TicketObj = LoadTicket($id);
168
169 my @results;
170
171 $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, checks_failure => \$checks_failure, results => \@results, CallbackName => 'Initial' );
172
173 unless($DefaultStatus){
174     $DefaultStatus=($ARGS{'Status'} ||$TicketObj->Status());
175 }
176
177 unless (RT->Config->Get('SuppressAutoOpenOnUpdate', $session{'CurrentUser'})) {
178     if ($DefaultStatus eq 'new') {
179         $DefaultStatus = 'open';
180     }
181 }
182
183 if ($DefaultStatus eq 'resolved') {
184     $title = loc("Resolve ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject);
185 } else {
186     $title = loc("Update ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject);
187 }
188
189 # Things needed in the template - we'll do the processing here, just
190 # for the convenience:
191
192 my ($CommentDefault, $ResponseDefault);
193 if ($Action ne 'Respond') {
194     $CommentDefault = qq[ selected="selected"]; 
195     $ResponseDefault = "";
196 } else {
197     $CommentDefault = ""; 
198     $ResponseDefault = qq[ selected="selected"];
199 }
200
201
202
203 $CanRespond = 1 if ( $TicketObj->CurrentUserHasRight('ReplyToTicket') or
204                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
205
206 $CanComment = 1 if ( $TicketObj->CurrentUserHasRight('CommentOnTicket') or
207                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
208
209
210 # {{{ deal with deleting uploaded attachments
211 foreach my $key (keys %ARGS) {
212     if ($key =~ m/^DeleteAttach-(.+)$/) {
213         delete $session{'Attachments'}{$1};
214     }
215     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
216 }
217 # }}}
218
219 # {{{ store the uploaded attachment in session
220 if ($ARGS{'Attach'}) {            # attachment?
221     my $attachment = MakeMIMEEntity(
222         AttachmentFieldName => 'Attach'
223     );
224
225     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
226     $session{'Attachments'} = {
227         %{$session{'Attachments'} || {}},
228         $file_path => $attachment,
229     };
230 }
231 # }}}
232
233 # delete temporary storage entry to make WebUI clean
234 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
235     delete $session{'Attachments'};
236 }
237 # }}}
238
239 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
240 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
241     self => $gnupg_widget,
242     TicketObj => $TicketObj,
243 );
244
245 if ( $ARGS{'SubmitTicket'} ) {
246     my $CFs = $TicketObj->TransactionCustomFields;
247     my $ValidCFs = $m->comp(
248         '/Elements/ValidateCustomFields',
249         CustomFields => $CFs,
250         NamePrefix => "Object-RT::Transaction--CustomField-",
251         ARGSRef => \%ARGS
252     );
253     unless ( $ValidCFs ) {
254         $checks_failure = 1;
255         while (my $CF = $CFs->Next) {
256             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
257             push @results, loc($CF->Name) . ': ' . $msg;
258         }
259     }
260     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
261         self      => $gnupg_widget,
262         TicketObj => $TicketObj,
263     );
264     $checks_failure = 1 unless $status;
265 }
266
267 # check email addresses for RT's
268 {
269     foreach my $field ( qw(UpdateCc UpdateBcc) ) {
270         my $value = $ARGS{ $field };
271         next unless defined $value && length $value;
272
273         my @emails = Email::Address->parse( $value );
274         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
275             push @results, loc("[_1] is an address RT receives mail at. Adding it as a '[_2]' would create a mail loop", $email->format, loc(substr($field, 6)) );
276             $checks_failure = 1;
277             $email = undef;
278         }
279         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
280     }
281 }
282 my $skip_update = 0;
283 $m->callback( CallbackName => 'BeforeUpdate', ARGSRef => \%ARGS, skip_update => \$skip_update,
284               checks_failure => $checks_failure, results => \@results, TicketObj => $TicketObj );
285
286 if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) {
287     $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'BeforeDisplay' );
288     return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
289 }
290 </%INIT>
291
292 <%ARGS>
293 $id => undef
294 $Action => undef
295 $DefaultStatus => undef
296 </%ARGS>