1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2012 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 <input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Id %>" />
70 <table width="100%" border="0">
71 <& /Ticket/Elements/EditBasics,
75 comp => '/Ticket/Elements/ShowQueue',
77 QueueObj => $QueueObj,
81 comp => '/Elements/SelectStatus',
84 Default => $ARGS{Status} || $QueueObj->Lifecycle->DefaultOnCreate,
87 QueueObj => $QueueObj,
91 comp => '/Elements/SelectOwner',
94 Default => $ARGS{Owner} || RT->Nobody->Id,
96 QueueObj => $QueueObj,
102 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
104 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
105 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
108 % $m->callback( CallbackName => 'AfterBasics', QueueObj => $QueueObj, ARGSRef => \%ARGS );
111 <div id="ticket-create-message">
112 <&| /Widgets/TitleBox, title => $title, class => 'messagedetails' &>
113 <table border="0" cellpadding="0" cellspacing="0">
116 <&|/l&>Requestors</&>:
118 <td class="value" colspan="5">
119 <& /Elements/EmailInput, Name => 'Requestors', Size => undef, Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress &>
120 % $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
127 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'Cc', Size => undef, Default => $ARGS{Cc} &></td>
131 <td class="label"> </td>
132 <td class="comment" colspan="5">
134 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)</&>
143 <td class="value" colspan="5"><& /Elements/EmailInput, Name => 'AdminCc', Size => undef, Default => $ARGS{AdminCc} &></td>
147 <td class="label"> </td>
148 <td class="comment" colspan="5">
150 <&|/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.)</&>
159 <td class="value" colspan="5">
160 <input type="text" name="Subject" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
161 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
165 % if ( $gnupg_widget ) {
166 <tr><td> </td><td colspan="5">
167 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
173 <&|/l&>Describe the issue below</&>:<br />
174 % if ( RT->Config->Get('ArticleOnTicketCreate')) {
175 <& /Articles/Elements/BeforeMessageBox, %ARGS, QueueObj => $QueueObj &>
177 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
178 % if (exists $ARGS{Content}) {
179 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
181 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
183 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
189 <& /Ticket/Elements/AddAttachments, %ARGS, QueueObj => $QueueObj &>
192 <& /Elements/Submit, Label => loc("Create"), id => 'SubmitTicket' &>
196 <div id="Ticket-Create-details">
197 <a name="details"></a>
198 <table width="100%" border="0">
200 <td width="50%" valign="top" class="boxcontainer">
201 <div class="ticket-info-basics">
202 <&| /Widgets/TitleBox, title => loc('The Basics'),
203 title_class=> 'inverse',
204 color => "#993333" &>
206 <tr><td class="label"><&|/l&>Priority</&>:</td>
207 <td><& /Elements/SelectPriority,
208 Name => "InitialPriority",
209 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
211 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
212 <td><& /Elements/SelectPriority,
213 Name => "FinalPriority",
214 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
216 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
218 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
221 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
223 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
226 <td class="label"><&|/l&>Time Left</&>:</td>
228 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
233 <div class="ticket-info-dates">
234 <&|/Widgets/TitleBox, title => loc("Dates"),
235 title_class=> 'inverse',
236 color => "#663366" &>
239 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
240 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
248 <td valign="top" class="boxcontainer">
249 <div class="ticket-info-links">
250 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
252 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
254 <tr><td class="label"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} || '' %>" /></td></tr>
255 <tr><td class="label"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} || '' %>" /></td></tr>
256 <tr><td class="label"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} || '' %>" /></td></tr>
257 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
258 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
259 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
270 <& /Elements/Submit, Label => loc("Create") &>
275 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
276 my $Queue = $ARGS{Queue};
277 $session{DefaultQueue} = $Queue;
280 my $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
281 $CloneTicketObj->Load($CloneTicket)
282 or Abort( loc("Ticket could not be loaded") );
285 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
286 Cc => join( ',', $CloneTicketObj->CcAddresses ),
287 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
288 InitialPriority => $CloneTicketObj->Priority,
291 $clone->{$_} = $CloneTicketObj->$_()
292 for qw/Owner Subject FinalPriority TimeEstimated TimeWorked
295 $clone->{$_} = $CloneTicketObj->$_->AsString
296 for grep { $CloneTicketObj->$_->Unix }
297 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
299 my $members = $CloneTicketObj->Members;
300 my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
301 my $refers = $CloneTicketObj->RefersTo;
302 my $get_link_value = sub {
303 my ($link, $type) = @_;
304 my $uri_method = $type . 'URI';
305 my $local_method = 'Local' . $type;
306 my $uri = $link->$uri_method;
307 return if $uri->IsLocal and
309 $uri->Object->isa('RT::Ticket') and
310 $uri->Object->Type eq 'reminder';
312 return $link->$local_method || $uri->URI;
314 while ( my $refer = $refers->Next ) {
315 my $refer_value = $get_link_value->($refer, 'Target');
316 push @refers, $refer_value if defined $refer_value;
318 $clone->{'new-RefersTo'} = join ' ', @refers;
320 my $refers_by = $CloneTicketObj->ReferredToBy;
321 while ( my $refer_by = $refers_by->Next ) {
322 my $refer_by_value = $get_link_value->($refer_by, 'Base');
323 push @refers_by, $refer_by_value if defined $refer_by_value;
325 $clone->{'RefersTo-new'} = join ' ', @refers_by;
327 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
328 while ( my $cf = $cfs->Next ) {
330 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
332 while ( my $cf_value = $cf_values->Next ) {
333 push @cf_values, $cf_value->Content;
335 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
339 for ( keys %$clone ) {
340 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
347 my $title = loc("Create a new ticket");
349 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
350 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
352 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
354 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
356 my $CFs = $QueueObj->TicketCustomFields();
358 my $ValidCFs = $m->comp(
359 '/Elements/ValidateCustomFields',
360 CustomFields => $CFs,
364 # deal with deleting uploaded attachments
365 foreach my $key (keys %ARGS) {
366 if ($key =~ m/^DeleteAttach-(.+)$/) {
367 delete $session{'Attachments'}{$1};
369 $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
372 # store the uploaded attachment in session
373 if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
374 my $attachment = MakeMIMEEntity(
375 AttachmentFieldName => 'Attach'
378 my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
379 $session{'Attachments'} = {
380 %{$session{'Attachments'} || {}},
381 $file_path => $attachment,
385 # delete temporary storage entry to make WebUI clean
386 unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
387 delete $session{'Attachments'};
390 my $checks_failure = 0;
392 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
393 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
394 self => $gnupg_widget,
395 QueueObj => $QueueObj,
399 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
400 my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
401 self => $gnupg_widget,
402 Operation => 'Create',
403 QueueObj => $QueueObj,
405 $checks_failure = 1 unless $status;
408 # check email addresses for RT's
410 foreach my $field ( qw(Requestors Cc AdminCc) ) {
411 my $value = $ARGS{ $field };
412 next unless defined $value && length $value;
414 my @emails = Email::Address->parse( $value );
415 foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
416 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?$/) );
420 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
425 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
426 checks_failure => $checks_failure, results => \@results );
428 $m->comp( '/Articles/Elements/CheckSkipCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
429 checks_failure => $checks_failure, results => \@results );
431 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
432 if ( $ValidCFs && !$checks_failure && !$skip_create ) {
433 $m->comp('Display.html', %ARGS);
434 $RT::Logger->crit("After display call; error is $@");
437 elsif ( !$ValidCFs ) {
439 while (my $CF = $CFs->Next) {
440 my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
441 push @results, $CF->Name . ': ' . $msg;
445 PageMenu->child( basics => raw_html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Basics') . q[</a>]);
446 PageMenu->child( details => raw_html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Details') . q[</a>]);
451 $DependedOnBy => undef
453 $QuoteTransaction => undef
454 $CloneTicket => undef