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