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