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" />
59 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
61 % if ($gnupg_widget) {
62 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
65 <div id="Ticket-Create-basics">
68 <div id="ticket-create-metadata">
69 <&| /Widgets/TitleBox, title => loc("Basics"), class=>'ticket-info-basics' &>
70 <table width="100%" border="0">
71 <& /Ticket/Elements/EditBasics,
75 comp => '/Elements/SelectQueue',
78 Default => $QueueObj->Name,
79 QueueObj => $QueueObj,
82 OnChange => "document.getElementsByName('id')[0].value = 'refresh'; form.submit()",
86 comp => '/Elements/SelectStatus',
89 Default => $ARGS{Status} || $QueueObj->Lifecycle->DefaultOnCreate,
92 QueueObj => $QueueObj,
96 comp => '/Elements/SelectOwner',
99 Default => $ARGS{Owner} || RT->Nobody->Id,
101 QueueObj => $QueueObj,
107 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
109 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1, KeepValue => 1 &>
110 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1, KeepValue => 1 &>
113 % $m->callback( CallbackName => 'AfterBasics', QueueObj => $QueueObj, ARGSRef => \%ARGS );
116 <div id="ticket-create-message">
117 <&| /Widgets/TitleBox, title => $title, class => 'messagedetails' &>
118 <table border="0" cellpadding="0" cellspacing="0">
121 <&|/l&>Requestors</&>:
123 <td class="value" colspan="5">
124 <& /Elements/EmailInput, Name => 'Requestors', Size => undef, Default => exists($ARGS{Requestors}) ? $ARGS{Requestors} : $session{CurrentUser}->EmailAddress &>
125 % $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
132 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'Cc', Size => undef, Default => $ARGS{Cc} &></td>
136 <td class="label"> </td>
137 <td class="comment" colspan="5">
139 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)</&>
148 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'AdminCc', Size => undef, Default => $ARGS{AdminCc} &></td>
152 <td class="label"> </td>
153 <td class="comment" colspan="5">
155 <&|/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.)</&>
164 <td class="value" colspan="5">
165 <input type="text" name="Subject" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
166 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
170 % if ( $gnupg_widget ) {
171 <tr><td> </td><td colspan="5">
172 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
178 <&|/l&>Describe the issue below</&>:<br />
179 % if ( RT->Config->Get('ArticleOnTicketCreate')) {
180 <& /Articles/Elements/BeforeMessageBox, %ARGS, QueueObj => $QueueObj &>
182 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
183 % if (exists $ARGS{Content}) {
184 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
186 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
188 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
194 <& /Ticket/Elements/AddAttachments, %ARGS, QueueObj => $QueueObj &>
197 <& /Elements/Submit, Label => loc("Create"), id => 'SubmitTicket' &>
201 <div id="Ticket-Create-details">
202 <a name="details"></a>
203 <table width="100%" border="0">
205 <td width="50%" valign="top" class="boxcontainer">
206 <div class="ticket-info-basics">
207 <&| /Widgets/TitleBox, title => loc('The Basics'),
208 title_class=> 'inverse',
209 color => "#993333" &>
211 <tr><td class="label"><&|/l&>Priority</&>:</td>
212 <td><& /Elements/SelectPriority,
213 Name => "InitialPriority",
214 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
216 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
217 <td><& /Elements/SelectPriority,
218 Name => "FinalPriority",
219 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
221 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
223 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
226 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
228 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
231 <td class="label"><&|/l&>Time Left</&>:</td>
233 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
238 <div class="ticket-info-dates">
239 <&|/Widgets/TitleBox, title => loc("Dates"),
240 title_class=> 'inverse',
241 color => "#663366" &>
244 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
245 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
253 <td valign="top" class="boxcontainer">
254 <div class="ticket-info-links">
255 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
257 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
259 <tr><td class="label"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} || '' %>" /></td></tr>
260 <tr><td class="label"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} || '' %>" /></td></tr>
261 <tr><td class="label"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} || '' %>" /></td></tr>
262 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
263 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
264 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
265 <tr><td class="label">Customer ID</td><td><input size="10" name="new-Customer" value="<% $ARGS{'new-Customer'} || '' %>" /></td></tr>
275 <& /Elements/Submit, Label => loc("Create") &>
280 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
281 my $Queue = $ARGS{Queue};
282 $session{DefaultQueue} = $Queue;
285 my $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
286 $CloneTicketObj->Load($CloneTicket)
287 or Abort( loc("Ticket could not be loaded") );
290 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
291 Cc => join( ',', $CloneTicketObj->CcAddresses ),
292 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
293 InitialPriority => $CloneTicketObj->Priority,
296 $clone->{$_} = $CloneTicketObj->$_()
297 for qw/Owner Subject FinalPriority Status/;
298 # not TimeWorked, TimeEstimated, or TimeLeft
300 $clone->{$_} = $CloneTicketObj->$_->AsString
301 for grep { $CloneTicketObj->$_->Unix }
302 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
304 my $members = $CloneTicketObj->Members;
305 my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
306 my $refers = $CloneTicketObj->RefersTo;
307 my $get_link_value = sub {
308 my ($link, $type) = @_;
309 my $uri_method = $type . 'URI';
310 my $local_method = 'Local' . $type;
311 my $uri = $link->$uri_method;
312 return if $uri->IsLocal and
314 $uri->Object->isa('RT::Ticket') and
315 $uri->Object->Type eq 'reminder';
317 return $link->$local_method || $uri->URI;
319 while ( my $refer = $refers->Next ) {
320 my $refer_value = $get_link_value->($refer, 'Target');
321 push @refers, $refer_value if defined $refer_value;
323 $clone->{'new-RefersTo'} = join ' ', @refers;
325 my $refers_by = $CloneTicketObj->ReferredToBy;
326 while ( my $refer_by = $refers_by->Next ) {
327 my $refer_by_value = $get_link_value->($refer_by, 'Base');
328 push @refers_by, $refer_by_value if defined $refer_by_value;
330 $clone->{'RefersTo-new'} = join ' ', @refers_by;
332 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
333 while ( my $cf = $cfs->Next ) {
334 next if $cf->FirstAttribute('NoClone');
336 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
338 while ( my $cf_value = $cf_values->Next ) {
339 push @cf_values, $cf_value->Content;
342 if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
343 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = \@cf_values;
346 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
351 # Pass customer links along (even though cloning of parent links
352 # in general is disabled).
353 my $customers = $CloneTicketObj->Customers;
355 while ( my $customer = $customers->Next ) {
356 my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
357 push @customers, $custnum if $custnum;
359 $clone->{'new-Customer'} = join(' ', @customers);
361 for ( keys %$clone ) {
362 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
369 my $title = loc("Create a new ticket");
371 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
372 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
374 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
376 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
378 my $CFs = $QueueObj->TicketCustomFields();
380 my $ValidCFs = $m->comp(
381 '/Elements/ValidateCustomFields',
382 CustomFields => $CFs,
386 ProcessAttachments(ARGSRef => \%ARGS);
388 my $checks_failure = 0;
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,
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,
403 $checks_failure = 1 unless $status;
406 # check email addresses for RT's
408 foreach my $field ( qw(Requestors Cc AdminCc) ) {
409 my $value = $ARGS{ $field };
410 next unless defined $value && length $value;
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?$/) );
418 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
423 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
424 checks_failure => $checks_failure, results => \@results );
426 $m->comp( '/Articles/Elements/CheckSkipCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
427 checks_failure => $checks_failure, results => \@results );
429 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
430 if ( $ValidCFs && !$checks_failure && !$skip_create ) {
432 # For some reason it's done by a Mason component named "Display.html"
433 # and the call is buried in obscure error-handling stuff.
434 # This comment exists to make it more visually obvious.
435 # ************************************************************
437 $m->comp('Display.html', %ARGS);
439 # ************************************************************
440 # Execution should not continue here. Display.html calls
441 # Redirect() which does an $m->abort. We only get here if the
442 # code dies before then, hence "$@".
443 $RT::Logger->crit("After display call; error is $@");
446 elsif ( !$ValidCFs ) {
448 while (my $CF = $CFs->Next) {
449 my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
450 push @results, $CF->Name . ': ' . $msg;
454 PageMenu->child( basics => raw_html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Basics') . q[</a>]);
455 PageMenu->child( details => raw_html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Details') . q[</a>]);
460 $DependedOnBy => undef
462 $QuoteTransaction => undef
463 $CloneTicket => undef