1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2014 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="hidden" class="hidden" name="id" value="new" />
58 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
60 % if ($gnupg_widget) {
61 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
64 <div id="Ticket-Create-basics">
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,
74 comp => '/Elements/SelectQueue',
77 Default => $QueueObj->Name,
78 QueueObj => $QueueObj,
81 OnChange => "document.getElementsByName('id')[0].value = 'refresh'; form.submit()",
85 comp => '/Elements/SelectStatus',
88 Default => $ARGS{Status} || $QueueObj->Lifecycle->DefaultOnCreate,
91 QueueObj => $QueueObj,
95 comp => '/Elements/SelectOwner',
98 Default => $ARGS{Owner} || RT->Nobody->Id,
100 QueueObj => $QueueObj,
106 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
108 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1, KeepValue => 1 &>
109 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1, KeepValue => 1 &>
112 % $m->callback( CallbackName => 'AfterBasics', QueueObj => $QueueObj, ARGSRef => \%ARGS );
115 <div id="ticket-create-message">
116 <&| /Widgets/TitleBox, title => $title, class => 'messagedetails' &>
117 <table border="0" cellpadding="0" cellspacing="0">
120 <&|/l&>Requestors</&>:
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 );
131 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'Cc', Size => undef, Default => $ARGS{Cc} &></td>
135 <td class="label"> </td>
136 <td class="comment" colspan="5">
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.)</&>
147 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'AdminCc', Size => undef, Default => $ARGS{AdminCc} &></td>
151 <td class="label"> </td>
152 <td class="comment" colspan="5">
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.)</&>
163 <td class="value" colspan="5">
164 <input type="text" name="Subject" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
165 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
169 % if ( $gnupg_widget ) {
170 <tr><td> </td><td colspan="5">
171 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
177 <&|/l&>Describe the issue below</&>:<br />
178 % if ( RT->Config->Get('ArticleOnTicketCreate')) {
179 <& /Articles/Elements/BeforeMessageBox, %ARGS, QueueObj => $QueueObj &>
181 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
182 % if (exists $ARGS{Content}) {
183 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
185 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
187 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
193 <& /Ticket/Elements/AddAttachments, %ARGS, QueueObj => $QueueObj &>
196 <& /Elements/Submit, Label => loc("Create"), id => 'SubmitTicket' &>
200 <div id="Ticket-Create-details">
201 <a name="details"></a>
202 <table width="100%" border="0">
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" &>
210 <tr><td class="label"><&|/l&>Priority</&>:</td>
211 <td><& /Elements/SelectPriority,
212 Name => "InitialPriority",
213 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
215 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
216 <td><& /Elements/SelectPriority,
217 Name => "FinalPriority",
218 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
220 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
222 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
225 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
227 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
230 <td class="label"><&|/l&>Time Left</&>:</td>
232 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
237 <div class="ticket-info-dates">
238 <&|/Widgets/TitleBox, title => loc("Dates"),
239 title_class=> 'inverse',
240 color => "#663366" &>
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>
252 <td valign="top" class="boxcontainer">
253 <div class="ticket-info-links">
254 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
256 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
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>
274 <& /Elements/Submit, Label => loc("Create") &>
279 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
280 my $Queue = $ARGS{Queue};
281 $session{DefaultQueue} = $Queue;
284 my $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
285 $CloneTicketObj->Load($CloneTicket)
286 or Abort( loc("Ticket could not be loaded") );
289 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
290 Cc => join( ',', $CloneTicketObj->CcAddresses ),
291 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
292 InitialPriority => $CloneTicketObj->Priority,
295 $clone->{$_} = $CloneTicketObj->$_()
296 for qw/Owner Subject FinalPriority Status/;
297 # not TimeWorked, TimeEstimated, or TimeLeft
299 $clone->{$_} = $CloneTicketObj->$_->AsString
300 for grep { $CloneTicketObj->$_->Unix }
301 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
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
313 $uri->Object->isa('RT::Ticket') and
314 $uri->Object->Type eq 'reminder';
316 return $link->$local_method || $uri->URI;
318 while ( my $refer = $refers->Next ) {
319 my $refer_value = $get_link_value->($refer, 'Target');
320 push @refers, $refer_value if defined $refer_value;
322 $clone->{'new-RefersTo'} = join ' ', @refers;
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;
329 $clone->{'RefersTo-new'} = join ' ', @refers_by;
331 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
332 while ( my $cf = $cfs->Next ) {
333 next if $cf->FirstAttribute('NoClone');
335 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
337 while ( my $cf_value = $cf_values->Next ) {
338 push @cf_values, $cf_value->Content;
341 if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
342 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = \@cf_values;
345 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
350 # Pass customer links along (even though cloning of parent links
351 # in general is disabled).
352 my $customers = $CloneTicketObj->Customers;
354 while ( my $customer = $customers->Next ) {
355 my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
356 push @customers, $custnum if $custnum;
358 $clone->{'new-Customer'} = join(' ', @customers);
360 for ( keys %$clone ) {
361 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
368 my $title = loc("Create a new ticket");
370 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
371 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
373 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
375 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
377 my $CFs = $QueueObj->TicketCustomFields();
379 my $ValidCFs = $m->comp(
380 '/Elements/ValidateCustomFields',
381 CustomFields => $CFs,
385 ProcessAttachments(ARGSRef => \%ARGS);
387 my $checks_failure = 0;
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,
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,
402 $checks_failure = 1 unless $status;
405 # check email addresses for RT's
407 foreach my $field ( qw(Requestors Cc AdminCc) ) {
408 my $value = $ARGS{ $field };
409 next unless defined $value && length $value;
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?$/) );
417 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
422 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
423 checks_failure => $checks_failure, results => \@results );
425 $m->comp( '/Articles/Elements/CheckSkipCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
426 checks_failure => $checks_failure, results => \@results );
428 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
429 if ( $ValidCFs && !$checks_failure && !$skip_create ) {
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 # ************************************************************
436 $m->comp('Display.html', %ARGS);
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 $@");
445 elsif ( !$ValidCFs ) {
447 while (my $CF = $CFs->Next) {
448 my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
449 push @results, $CF->Name . ': ' . $msg;
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>]);
459 $DependedOnBy => undef
461 $QuoteTransaction => undef
462 $CloneTicket => undef