future ticket resolve fixes, #13583
[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 valign="baseline" class="label"><&|/l&>Status</&>:</td>
69 <td valign="baseline">
70 <script type="text/javascript">
71 function changeStatus() {
72   var Status_select = document.getElementById('Status');
73   var x = Status_select.options[Status_select.selectedIndex].value;
74   var text = document.getElementById('WillResolve_Date');
75   var button = document.getElementById('WillResolve_Date_date_button');
76   if (x == 'resolved' || x == 'rejected' || x == 'deleted') {
77     text.disabled = true;
78     button.style.display = 'none';
79   }
80   else {
81     text.disabled = false;
82     button.style.display = 'inline';
83   }
84 }
85 </script>
86 <& /Elements/SelectStatus, 
87     Name=>"Status",
88     DefaultLabel => loc("[_1] (Unchanged)", loc($TicketObj->Status)),
89     Default => $ARGS{'Status'}
90               || ($TicketObj->Status eq $DefaultStatus ? undef : $DefaultStatus,
91     onchange => 'changeStatus()'
92 )&>
93 <span class="label"><&|/l&>Resolve this Ticket on</&>:</span>
94 <& /Elements/SelectDate, 
95     menu_prefix => 'WillResolve',
96     current => 0,
97     ShowTime => 0,
98 &>
99 % if ( $TicketObj->WillResolve ) {
100 <span class="label"> (<% $TicketObj->WillResolveObj->AsString %>)</span>
101 % }
102 <script type="text/javascript">
103 changeStatus();
104 </script>
105 </td>
106 <td rowspan=4 valign="top">
107 <table style="float:right;">
108 <tr>
109 <td class="label"><&|/l&>Worked</&>:</td>
110 <td><& /Elements/EditTimeValue,
111     Name => 'UpdateTimeWorked',
112     Default => $ARGS{UpdateTimeWorked}||'',
113     InUnits => $ARGS{'UpdateTimeWorked-TimeUnits'}||'minutes',
114 &>
115 </td></tr>
116 <& /Ticket/Elements/EditTransactionCustomFields, 
117     %ARGS,
118     TicketObj   => $TicketObj,
119     UILocation  => 'TimeWorked',
120 &>
121 </table></td></tr>
122 % my $skip;
123 % $m->callback( %ARGS, CallbackName => 'BeforeUpdateType', skip => \$skip );
124 % if (!$skip) {
125 <input type="hidden" class="hidden" name="id" value="<%$TicketObj->Id%>" /><br />
126 % }
127 <tr><td class="label"><&|/l&>Owner</&>:</td>
128 <td><& /Elements/SelectOwner,
129     Name         => "Owner",
130     TicketObj    => $TicketObj,
131     QueueObj     => $TicketObj->QueueObj,
132     DefaultLabel => loc("[_1] (Unchanged)", $m->scomp('/Elements/ShowUser', User => $TicketObj->OwnerObj)),
133     Default      => $ARGS{'Owner'}
134 &></td>
135 </tr>
136 <tr><td class="label"><&|/l&>Update Type</&>:</td>
137 <td><select name="UpdateType">
138 % if ($CanComment) {
139 <option value="private" <% ($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq "private") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$CommentDefault |n %>><&|/l&>Comments (Not sent to requestors)</&></option>
140 % }
141 % if ($CanRespond) {
142 <option value="response" <% ($ARGS{'UpdateType'} && $ARGS{'UpdateType'} eq "response") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$ResponseDefault |n %>><&|/l&>Reply to requestors</&></option>
143 % }
144 </select> 
145 % $m->callback( %ARGS, CallbackName => 'AfterUpdateType' );
146 </td></tr>
147 <tr><td class="label"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || $TicketObj->Subject()%>" />
148 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
149 </td></tr>
150
151 <& /Ticket/Elements/UpdateCc, %ARGS, TicketObj => $TicketObj &>
152
153 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, TicketObj => $TicketObj &>
154
155 % if (exists $session{'Attachments'}) {
156 <tr><td><&|/l&>Attached file</&>:</td>
157 <td>
158 <&|/l&>Check box to delete</&><br />
159 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
160 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
161 % } # end of foreach
162 </td>
163 </tr>
164 % } # end of if
165
166 <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" />
167 </td></tr>
168
169 % if ( $gnupg_widget ) {
170 <tr><td>&nbsp;</td><td>
171 <& /Elements/GnuPG/SignEncryptWidget,
172     self => $gnupg_widget,
173     TicketObj => $TicketObj,
174 &>
175 </td></tr>
176 % }
177 % $m->callback( %ARGS, CallbackName => 'AfterGnuPG' );
178
179 <tr><td class="label" valign="top"><&|/l&>Message</&>:</td><td colspan=2>
180 % $m->callback( %ARGS, CallbackName => 'BeforeMessageBox' );
181 % if (exists $ARGS{UpdateContent}) {
182 % # preserve QuoteTransaction so we can use it to set up sane references/in/reply to
183 % my $temp = $ARGS{'QuoteTransaction'};
184 % delete $ARGS{'QuoteTransaction'};
185 <& /Elements/MessageBox, Name=>"UpdateContent", Default=>$ARGS{UpdateContent}, IncludeSignature => 0, %ARGS&>
186 % $ARGS{'QuoteTransaction'} = $temp;
187 % } else {
188 % my $IncludeSignature = 1;
189 % $IncludeSignature = 0 if $Action ne 'Respond' && !RT->Config->Get('MessageBoxIncludeSignatureOnComment');
190 <& /Elements/MessageBox, Name=>"UpdateContent", IncludeSignature => $IncludeSignature, %ARGS &>
191 % }
192 </td></tr>
193 </table>
194
195
196
197
198 <& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket' &>
199 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
200 <&|/Widgets/TitleBox, title => loc('Scrips and Recipients') &>
201 <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
202 </&>
203
204 % }
205 </form>
206 <%INIT>
207 my $CanRespond = 0;
208 my $CanComment = 0;
209 my $checks_failure = 0;
210 my $title;
211
212 my $TicketObj = LoadTicket($id);
213
214 my @results;
215
216 $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, checks_failure => \$checks_failure, results => \@results, CallbackName => 'Initial' );
217
218 unless($DefaultStatus){
219     $DefaultStatus=($ARGS{'Status'} ||$TicketObj->Status());
220 }
221
222 unless (RT->Config->Get('SuppressAutoOpenOnUpdate', $session{'CurrentUser'})) {
223     if ($DefaultStatus eq 'new') {
224         $DefaultStatus = 'open';
225     }
226 }
227
228 if ($DefaultStatus eq 'resolved') {
229     $title = loc("Resolve ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject);
230 } else {
231     $title = loc("Update ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject);
232 }
233
234 # Things needed in the template - we'll do the processing here, just
235 # for the convenience:
236
237 my ($CommentDefault, $ResponseDefault);
238 if ($Action ne 'Respond') {
239     $CommentDefault = qq[ selected="selected"]; 
240     $ResponseDefault = "";
241 } else {
242     $CommentDefault = ""; 
243     $ResponseDefault = qq[ selected="selected"];
244 }
245
246
247
248 $CanRespond = 1 if ( $TicketObj->CurrentUserHasRight('ReplyToTicket') or
249                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
250
251 $CanComment = 1 if ( $TicketObj->CurrentUserHasRight('CommentOnTicket') or
252                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
253
254
255 # {{{ deal with deleting uploaded attachments
256 foreach my $key (keys %ARGS) {
257     if ($key =~ m/^DeleteAttach-(.+)$/) {
258         delete $session{'Attachments'}{$1};
259     }
260     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
261 }
262 # }}}
263
264 # {{{ store the uploaded attachment in session
265 if ($ARGS{'Attach'}) {            # attachment?
266     my $attachment = MakeMIMEEntity(
267         AttachmentFieldName => 'Attach'
268     );
269
270     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
271     $session{'Attachments'} = {
272         %{$session{'Attachments'} || {}},
273         $file_path => $attachment,
274     };
275 }
276 # }}}
277
278 # delete temporary storage entry to make WebUI clean
279 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
280     delete $session{'Attachments'};
281 }
282 # }}}
283
284 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
285 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
286     self => $gnupg_widget,
287     TicketObj => $TicketObj,
288 );
289
290 if ( $ARGS{'SubmitTicket'} ) {
291     my $CFs = $TicketObj->TransactionCustomFields;
292     my $ValidCFs = $m->comp(
293         '/Elements/ValidateCustomFields',
294         CustomFields => $CFs,
295         NamePrefix => "Object-RT::Transaction--CustomField-",
296         ARGSRef => \%ARGS
297     );
298     unless ( $ValidCFs ) {
299         $checks_failure = 1;
300         while (my $CF = $CFs->Next) {
301             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
302             push @results, loc($CF->Name) . ': ' . $msg;
303         }
304     }
305     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
306         self      => $gnupg_widget,
307         TicketObj => $TicketObj,
308     );
309     $checks_failure = 1 unless $status;
310 }
311
312 # check email addresses for RT's
313 {
314     foreach my $field ( qw(UpdateCc UpdateBcc) ) {
315         my $value = $ARGS{ $field };
316         next unless defined $value && length $value;
317
318         my @emails = Email::Address->parse( $value );
319         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
320             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)) );
321             $checks_failure = 1;
322             $email = undef;
323         }
324         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
325     }
326 }
327 my $skip_update = 0;
328 $m->callback( CallbackName => 'BeforeUpdate', ARGSRef => \%ARGS, skip_update => \$skip_update,
329               checks_failure => $checks_failure, results => \@results, TicketObj => $TicketObj );
330
331 if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) {
332     $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'BeforeDisplay' );
333     return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
334 }
335 </%INIT>
336
337 <%ARGS>
338 $id => undef
339 $Action => undef
340 $DefaultStatus => undef
341 </%ARGS>