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