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