cloned tickets inherit customer links, #11169
[freeside.git] / rt / share / html / Ticket / Create.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,
49     Title => $title,
50     onload => "function () { hide(document.getElementById('Ticket-Create-details')) }" &>
51 <& /Elements/Tabs, 
52     current_toptab => "Ticket/Create.html", 
53     Title => $title,
54     actions => $actions &>
55 <& /Elements/ListActions, actions => \@results &>
56 <form action="<% RT->Config->Get('WebPath') %>/Ticket/Create.html" method="post" enctype="multipart/form-data" name="TicketCreate">
57 <input type="hidden" class="hidden" name="id" value="new" />
58 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
59 % if ($gnupg_widget) {
60 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
61 % }
62 <div id="Ticket-Create-basics">
63 <a name="basics"></a>
64 <&| /Widgets/TitleBox, title => $title &>
65 <table border="0" cellpadding="0" cellspacing="0">
66 <tr><td class="label"><&|/l&>Queue</&>:</td>
67 %#<td class="value"><& Elements/ShowQueue, QueueObj => $QueueObj &>
68 %#<input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Name %>" />
69 <td class="value"><& /Elements/SelectQueue, 
70   Name => 'Queue', 
71   Default => $QueueObj->Name,
72   ShowNullOption => 0,
73   ShowAllQueues => 0,
74   OnChange => "document.getElementsByName('id')[0].value = ''; form.submit()" &>
75 </td>
76 <td class="label"><&|/l&>Status</&>:
77 </td>
78 <td class="value">
79 <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}||'new', DefaultValue => 0, SkipDeleted => 1 &>
80 </td>
81 <td class="label">
82 <&|/l&>Owner</&>:
83 </td>
84 <td class="value">
85 <& /Elements/SelectOwner, Name => "Owner", QueueObj => $QueueObj, Default => $ARGS{Owner}||$RT::Nobody->Id, DefaultValue => 0 &>
86 </td>
87 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
88 </tr>
89 <tr>
90 <td class="label">
91 <&|/l&>Requestors</&>:
92 </td>
93 <td class="value" colspan="5">
94 <& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress &>
95 % $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
96 </td>
97 </tr>
98 <tr>
99 <td class="label">
100 <&|/l&>Cc</&>:
101 </td>
102 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'Cc', Size => '40', Default => $ARGS{Cc} &></td>
103 <td class="comment" colspan="2"><i><font size="-2">
104 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)</&></font></i>
105 </td>
106 </tr>
107 <tr>
108 <td class="label">
109 <&|/l&>Admin Cc</&>:
110 </td>
111 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'AdminCc', Size => '40', Default => $ARGS{AdminCc} &></td>
112 <td class="comment" colspan="2"><i><font size="-2">
113 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of administrative email addresses. These people <strong>will</strong> receive future updates.)</&></font></i>
114 </td>
115 </tr>
116 <tr>
117 <td class="label">
118 <&|/l&>Subject</&>:
119 </td>
120 <td class="value" colspan="5">
121 <input name="Subject" size="60" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
122 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
123 </td>
124 </tr>
125 <tr>
126 <td colspan="6">
127 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj &>
128 </td>
129 </tr>
130 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj &>
131 <tr>
132 % if (exists $session{'Attachments'}) {
133 <td class="label">
134 <&|/l&>Attached file</&>:
135 </td>
136 <td colspan="5">
137 <&|/l&>Check box to delete</&><br />
138 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
139 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
140 % } # end of foreach
141 </td>
142 </tr>
143 <tr>
144 % } # end of if
145 <td class="label">
146 <&|/l&>Attach file</&>:
147 </td>
148 <td class="value" colspan="5">
149 <input type="file" name="Attach" />
150 <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
151 </td>
152 </tr>
153
154 % if ( $gnupg_widget ) {
155 <tr><td>&nbsp;</td><td colspan="5">
156 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
157 </td></tr>
158 % }
159
160 <tr>
161 <td colspan="6">
162 <&|/l&>Describe the issue below</&>:<br />
163 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
164 % if (exists $ARGS{Content}) {
165 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
166 % } else {
167 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
168 %}
169 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
170
171 <br />
172 </td>
173 </tr>
174 </table>
175 </&>
176 <& /Elements/Submit, Label => loc("Create")&>
177 </div>
178
179 <div id="Ticket-Create-details">
180 <a name="details"></a>
181 <table width="100%" border="0">
182 <tr>
183 <td width="50%" valign="top" class="boxcontainer">
184     <div class="ticket-info-basics">
185           <&| /Widgets/TitleBox, title => loc('The Basics'), 
186                 title_class=> 'inverse',  
187                 color => "#993333" &>
188 <table border="0">
189 <tr><td class="label"><&|/l&>Priority</&>:</td>
190 <td><& /Elements/SelectPriority,
191     Name => "InitialPriority",
192     Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
193 &></td></tr>
194 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
195 <td><& /Elements/SelectPriority,
196     Name => "FinalPriority",
197     Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
198 &></td></tr>
199 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
200 <td>
201 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
202
203 </td></tr>
204 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
205 <td>
206 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
207 </td></tr>
208 <tr>
209 <td class="label"><&|/l&>Time Left</&>:</td>
210 <td>
211 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
212 </td></tr>
213 </table>
214 </&>
215 <br />
216 <div class="ticket-info-dates">
217 <&|/Widgets/TitleBox, title => loc("Dates"),
218                 title_class=> 'inverse',  
219                  color => "#663366" &>
220
221 <table>
222 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
223 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
224 </table>
225 </&>
226 </div>
227 </div>
228 <br />
229 </td>
230
231 <td valign="top" class="boxcontainer">
232 <div class="ticket-info-links">
233 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
234
235 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
236 <table border="0">
237 <tr><td class="label"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} || '' %>" /></td></tr>
238 <tr><td class="label"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} || '' %>" /></td></tr>
239 <tr><td class="label"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} || '' %>" /></td></tr>
240 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
241 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
242 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
243 <tr><td class="label">Customer ID</td><td><input size="10" name="new-Customer" value="<% $ARGS{'new-Customer'} || '' %>" /></td></tr>
244
245
246 </table>
247 </&>
248 </div>
249 <br />
250
251 </td>
252 </tr>
253 </table>
254 <& /Elements/Submit, Label => loc("Create") &>
255 </div>
256 </form>
257
258 <%INIT>
259 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
260 my $Queue = $ARGS{Queue};
261
262 my $CloneTicketObj;
263 if ($CloneTicket) {
264     $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
265     $CloneTicketObj->Load($CloneTicket)
266         or Abort( loc("Ticket could not be loaded") );
267
268     my $clone = {
269         Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
270         Cc         => join( ',', $CloneTicketObj->CcAddresses ),
271         AdminCc    => join( ',', $CloneTicketObj->AdminCcAddresses ),
272         InitialPriority => $CloneTicketObj->Priority,
273     };
274
275     $clone->{$_} = $CloneTicketObj->$_()
276         for qw/Owner Subject FinalPriority TimeEstimated TimeWorked
277         Status TimeLeft/;
278
279     $clone->{$_} = $CloneTicketObj->$_->AsString
280         for grep { $CloneTicketObj->$_->Unix }
281         map      { $_ . "Obj" } qw/Starts Started Due Resolved/;
282
283     my $members = $CloneTicketObj->Members;
284     my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
285     my $refers = $CloneTicketObj->RefersTo;
286     while ( my $refer = $refers->Next ) {
287         push @refers, $refer->LocalTarget;
288     }
289     $clone->{'new-RefersTo'} = join ' ', @refers;
290
291     my $refers_by = $CloneTicketObj->ReferredToBy;
292     while ( my $refer_by = $refers_by->Next ) {
293         push @refers_by, $refer_by->LocalBase;
294     }
295     $clone->{'RefersTo-new'} = join ' ', @refers_by;
296     if (0) {    # Temporarily disabled
297         my $depends = $CloneTicketObj->DependsOn;
298         while ( my $depend = $depends->Next ) {
299             push @depends, $depend->LocalTarget;
300         }
301         $clone->{'new-DependsOn'} = join ' ', @depends;
302
303         my $depends_by = $CloneTicketObj->DependedOnBy;
304         while ( my $depend_by = $depends_by->Next ) {
305             push @depends_by, $depend_by->LocalBase;
306         }
307         $clone->{'DependsOn-new'} = join ' ', @depends_by;
308
309         while ( my $member = $members->Next ) {
310             push @members, $member->LocalBase;
311         }
312         $clone->{'MemberOf-new'} = join ' ', @members;
313
314         my $members_of = $CloneTicketObj->MemberOf;
315         while ( my $member_of = $members_of->Next ) {
316             push @members_of, $member_of->LocalTarget;
317         }
318         $clone->{'new-MemberOf'} = join ' ', @members_of;
319
320     }
321
322     my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
323     while ( my $cf = $cfs->Next ) {
324         my $cf_id     = $cf->id;
325         my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
326         my @cf_values;
327         while ( my $cf_value = $cf_values->Next ) {
328             push @cf_values, $cf_value->Content;
329         }
330         $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
331             @cf_values;
332     }
333
334     # Pass customer links along (even though cloning of parent links
335     # in general is disabled).
336     my $customers = $CloneTicketObj->Customers;
337     my @customers;
338     while ( my $customer = $customers->Next ) {
339       my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
340       push @customers, $custnum if $custnum;
341     }
342     $clone->{'new-Customer'} = join(' ', @customers);
343
344     for ( keys %$clone ) {
345         $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
346     }
347
348 }
349
350 my @results;
351
352 my $title = loc("Create a new ticket");
353
354 my $QueueObj = new RT::Queue($session{'CurrentUser'});
355 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
356
357 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
358
359 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
360
361 my $CFs = $QueueObj->TicketCustomFields();
362
363 my $ValidCFs = $m->comp(
364     '/Elements/ValidateCustomFields',
365     CustomFields => $CFs,
366     ARGSRef => \%ARGS
367 );
368
369 # {{{ deal with deleting uploaded attachments
370 foreach my $key (keys %ARGS) {
371     if ($key =~ m/^DeleteAttach-(.+)$/) {
372         delete $session{'Attachments'}{$1};
373     }
374     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
375 }
376 # }}}
377
378 # {{{ store the uploaded attachment in session
379 if ($ARGS{'Attach'}) {                  # attachment?
380     my $attachment = MakeMIMEEntity(
381         AttachmentFieldName => 'Attach'
382     );
383
384     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
385     $session{'Attachments'} = {
386         %{$session{'Attachments'} || {}},
387         $file_path => $attachment,
388     };
389 }
390 # }}}
391
392 # delete temporary storage entry to make WebUI clean
393 unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
394     delete $session{'Attachments'};
395 }
396
397 my $checks_failure = 0;
398
399 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
400 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
401     self      => $gnupg_widget,
402     QueueObj  => $QueueObj,
403 );
404
405
406 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
407     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
408         self      => $gnupg_widget,
409         Operation => 'Create',
410         QueueObj  => $QueueObj,
411     );
412     $checks_failure = 1 unless $status;
413 }
414
415 # check email addresses for RT's
416 {
417     foreach my $field ( qw(Requestors Cc AdminCc) ) {
418         my $value = $ARGS{ $field };
419         next unless defined $value && length $value;
420
421         my @emails = Email::Address->parse( $value );
422         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
423             push @results, loc("[_1] is an address RT receives mail at. Adding it as a '[_2]' would create a mail loop", $email->format, loc($field =~ /^(.*?)s?$/) );
424             $checks_failure = 1;
425             $email = undef;
426         }
427         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
428     }
429 }
430
431 my $skip_create = 0;
432 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create, 
433               checks_failure => $checks_failure, results => \@results );
434
435 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
436     if ( $ValidCFs && !$checks_failure && !$skip_create ) {
437 # CREATE THE TICKET.
438 # For some reason it's done by a Mason component named "Display.html"
439 # and the call is buried in obscure error-handling stuff.
440 # This comment exists to make it more visually obvious.
441 # ************************************************************
442
443         $m->comp('Display.html', %ARGS);
444
445 # ************************************************************
446 # Execution should not continue here.  Display.html calls 
447 # Redirect() which does an $m->abort.  We only get here if the 
448 # code dies before then, hence "$@".
449         $RT::Logger->crit("After display call; error is $@");
450         $m->abort();
451     }
452     elsif ( !$ValidCFs ) {
453         # Invalid CFs
454         while (my $CF = $CFs->Next) {
455             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
456             push @results, $CF->Name . ': ' . $msg;
457         }
458     }
459 }
460
461 my $actions = {
462     A => {
463         html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Show basics') . q[</a>],
464     },
465     B => {
466         html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Show details') . q[</a>],
467     },
468 };
469 </%INIT>
470
471 <%ARGS>
472 $DependsOn => undef
473 $DependedOnBy => undef
474 $MemberOf => undef
475 $QuoteTransaction => undef
476 $CloneTicket => undef
477 </%ARGS>