1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 %# <sales@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
50 onload => "function () { hide('Ticket-Create-details') }" &>
53 <& /Elements/ListActions, actions => \@results &>
55 <form action="<% RT->Config->Get('WebPath') %>/Ticket/Create.html" method="post" enctype="multipart/form-data" name="TicketCreate">
56 <input type="submit" name="SubmitTicket" value="Create" style="display:none">
57 <input type="hidden" class="hidden" name="id" value="new" />
58 <input type="hidden" class="hidden" name="Token" value="<% $ARGS{'Token'} %>" />
60 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
62 % if ($gnupg_widget) {
63 <& /Elements/Crypt/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
66 <div id="Ticket-Create-basics">
69 <div id="ticket-create-metadata">
70 <&| /Widgets/TitleBox, title => loc("Basics"), class=>'ticket-info-basics' &>
71 <table width="100%" border="0">
72 <& /Ticket/Elements/EditBasics,
76 comp => '/Elements/SelectQueue',
79 Default => $QueueObj->Name,
80 QueueObj => $QueueObj,
83 OnChange => "document.getElementsByName('id')[0].value = 'refresh'; form.submit()",
87 comp => '/Ticket/Elements/SelectStatus',
90 QueueObj => $QueueObj,
94 comp => '/Elements/SelectOwner',
97 Default => $ARGS{Owner} || RT->Nobody->Id,
99 QueueObj => $QueueObj,
105 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
107 <& /Elements/EditCustomFields,
110 CustomFields => $QueueObj->TicketCustomFields,
111 Grouping => 'Basics',
115 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1, KeepValue => 1, &>
118 % $m->callback( CallbackName => 'AfterBasics', QueueObj => $QueueObj, ARGSRef => \%ARGS );
120 <& /Elements/EditCustomFieldCustomGroupings,
123 CustomFieldGenerator => sub { $QueueObj->TicketCustomFields },
129 <div id="ticket-create-message">
130 <&| /Widgets/TitleBox, title => $title, class => 'messagedetails' &>
131 <table border="0" cellpadding="0" cellspacing="0">
134 <&|/l&>Requestors</&>:
136 <td class="value" colspan="5">
137 <& /Elements/EmailInput, Name => 'Requestors', Size => undef, Default => $ARGS{Requestors} // $session{CurrentUser}->EmailAddress, AutocompleteMultiple => 1 &>
138 % $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
145 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'Cc', Size => undef, Default => $ARGS{Cc}, AutocompleteMultiple => 1 &></td>
149 <td class="label"> </td>
150 <td class="comment" colspan="5">
152 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)</&>
161 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'AdminCc', Size => undef, Default => $ARGS{AdminCc}, AutocompleteMultiple => 1 &></td>
165 <td class="label"> </td>
166 <td class="comment" colspan="5">
168 <&|/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.)</&>
173 <& /Elements/EditCustomFields,
176 CustomFields => $QueueObj->TicketCustomFields,
177 Grouping => 'People',
186 <td class="value" colspan="5">
187 <input type="text" name="Subject" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
188 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
192 % if ( $gnupg_widget ) {
193 <tr><td> </td><td colspan="5">
194 <& /Elements/Crypt/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
200 <&|/l&>Describe the issue below</&>:<br />
201 % if ( RT->Config->Get('ArticleOnTicketCreate')) {
202 <& /Articles/Elements/BeforeMessageBox, %ARGS, QueueObj => $QueueObj &>
204 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
205 % if (exists $ARGS{Content}) {
206 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
208 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
210 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
216 <& /Ticket/Elements/AddAttachments, %ARGS, QueueObj => $QueueObj &>
219 <& /Elements/Submit, Label => loc("Create"), id => 'SubmitTicket' &>
223 <div id="Ticket-Create-details">
224 <a name="details"></a>
225 <table width="100%" border="0">
227 <td width="50%" valign="top" class="boxcontainer">
228 <div class="ticket-info-basics">
229 <&| /Widgets/TitleBox, title => loc('The Basics'),
230 title_class=> 'inverse',
231 color => "#993333" &>
233 <tr><td class="label"><&|/l&>Priority</&>:</td>
234 <td><& /Elements/SelectPriority,
235 Name => "InitialPriority",
236 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
238 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
239 <td><& /Elements/SelectPriority,
240 Name => "FinalPriority",
241 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
243 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
245 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '' &>
248 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
250 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '' &>
253 <td class="label"><&|/l&>Time Left</&>:</td>
255 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '' &>
260 <div class="ticket-info-dates">
261 <&|/Widgets/TitleBox, title => loc("Dates"),
262 title_class=> 'inverse',
263 color => "#663366" &>
266 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
267 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
268 <& /Elements/EditCustomFields,
271 CustomFields => $QueueObj->TicketCustomFields,
283 <td valign="top" class="boxcontainer">
284 <div class="ticket-info-links">
285 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
287 <& /Elements/AddLinks,
289 CustomFields => $QueueObj->TicketCustomFields,
299 <& /Elements/Submit, Label => loc("Create") &>
304 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
305 my $Queue = $ARGS{Queue};
306 $session{DefaultQueue} = $Queue;
308 my $current_user = $session{'CurrentUser'};
311 my $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
312 $CloneTicketObj->Load($CloneTicket)
313 or Abort( loc("Ticket could not be loaded") );
316 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
317 Cc => join( ',', $CloneTicketObj->CcAddresses ),
318 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
319 InitialPriority => $CloneTicketObj->Priority,
322 $clone->{$_} = $CloneTicketObj->$_()
323 for qw/Owner Subject FinalPriority Status/;
324 # not TimeWorked, TimeEstimated, or TimeLeft
326 $clone->{$_} = $CloneTicketObj->$_->AsString
327 for grep { $CloneTicketObj->$_->IsSet }
328 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
330 my $get_link_value = sub {
331 my ($link, $type) = @_;
332 my $uri_method = $type . 'URI';
333 my $local_method = 'Local' . $type;
334 my $uri = $link->$uri_method;
335 return if $uri->IsLocal and
337 $uri->Object->isa('RT::Ticket') and
338 $uri->Object->Type eq 'reminder';
340 return $link->$local_method || $uri->URI;
342 my (@refers, @refers_by);
343 my $refers = $CloneTicketObj->RefersTo;
344 while ( my $refer = $refers->Next ) {
345 my $refer_value = $get_link_value->($refer, 'Target');
346 push @refers, $refer_value if defined $refer_value;
348 $clone->{'new-RefersTo'} = join ' ', @refers;
350 my $refers_by = $CloneTicketObj->ReferredToBy;
351 while ( my $refer_by = $refers_by->Next ) {
352 my $refer_by_value = $get_link_value->($refer_by, 'Base');
353 push @refers_by, $refer_by_value if defined $refer_by_value;
355 $clone->{'RefersTo-new'} = join ' ', @refers_by;
357 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
358 while ( my $cf = $cfs->Next ) {
359 next if $cf->FirstAttribute('NoClone');
361 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
363 while ( my $cf_value = $cf_values->Next ) {
364 push @cf_values, $cf_value->Content;
367 if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
368 $clone->{GetCustomFieldInputName( CustomField => $cf )} = \@cf_values;
371 $clone->{GetCustomFieldInputName( CustomField => $cf )} = join "\n",
376 # Pass customer links along (even though cloning of parent links
377 # in general is disabled).
378 my $customers = $CloneTicketObj->Customers;
380 while ( my $customer = $customers->Next ) {
381 my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
382 push @customers, $custnum if $custnum;
384 $clone->{'new-Customer'} = join(' ', @customers);
386 for ( keys %$clone ) {
387 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
394 my $title = loc("Create a new ticket");
396 my $QueueObj = RT::Queue->new($current_user);
397 $QueueObj->Load($Queue) || Abort(loc("Queue [_1] could not be loaded.", $Queue||''));
399 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
401 $m->scomp( '/Articles/Elements/SubjectOverride', ARGSRef => \%ARGS, QueueObj => $QueueObj, results => \@results );
403 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
405 my $ticket = RT::Ticket->new($current_user); # empty ticket object
407 ProcessAttachments(ARGSRef => \%ARGS);
409 my $checks_failure = 0;
412 my ($status, @msg) = $m->comp(
413 '/Elements/ValidateCustomFields',
414 CustomFields => $QueueObj->TicketCustomFields,
423 my $gnupg_widget = $m->comp('/Elements/Crypt/SignEncryptWidget:new', Arguments => \%ARGS );
424 $m->comp( '/Elements/Crypt/SignEncryptWidget:Process',
425 self => $gnupg_widget,
426 QueueObj => $QueueObj,
430 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
431 my $status = $m->comp('/Elements/Crypt/SignEncryptWidget:Check',
432 self => $gnupg_widget,
433 Operation => 'Create',
434 QueueObj => $QueueObj,
436 $checks_failure = 1 unless $status;
439 # check email addresses for RT's
441 foreach my $field ( qw(Requestors Cc AdminCc) ) {
442 my $value = $ARGS{ $field };
443 next unless defined $value && length $value;
445 my @emails = Email::Address->parse( $value );
446 foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
447 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?$/) );
451 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
456 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
457 checks_failure => $checks_failure, results => \@results );
459 $m->comp( '/Articles/Elements/CheckSkipCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
460 checks_failure => $checks_failure, results => \@results );
462 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
463 if ( !$checks_failure && !$skip_create ) {
465 # For some reason it's done by a Mason component named "Display.html"
466 # and the call is buried in obscure error-handling stuff.
467 # This comment exists to make it more visually obvious.
468 # ************************************************************
470 $m->comp('Display.html', %ARGS);
472 # ************************************************************
473 # Execution should not continue here. Display.html calls
474 # Redirect() which does an $m->abort. We only get here if the
475 # code dies before then, hence "$@".
476 $RT::Logger->crit("After display call; error is $@");
480 PageMenu->child( basics => raw_html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Basics') . q[</a>]);
481 PageMenu->child( details => raw_html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Details') . q[</a>]);
486 $DependedOnBy => undef
488 $QuoteTransaction => undef
489 $CloneTicket => undef