1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2011 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 }}}
48 %# use Data::Dumper; warn Dumper \%ARGS; #DEBUG
51 onload => "function () { hide(document.getElementById('Ticket-Create-details')) }" &>
53 current_toptab => "Ticket/Create.html",
55 actions => $actions &>
56 <& /Elements/ListActions, actions => \@results &>
57 <form action="<% RT->Config->Get('WebPath') %>/Ticket/Create.html" method="post" enctype="multipart/form-data" name="TicketCreate">
58 <input type="hidden" class="hidden" name="id" value="new" />
59 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
60 % if ($gnupg_widget) {
61 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
63 <div id="Ticket-Create-basics">
65 <&| /Widgets/TitleBox, title => $title &>
66 <table border="0" cellpadding="0" cellspacing="0">
67 <tr><td class="label"><&|/l&>Queue</&>:</td>
68 %#<td class="value"><& Elements/ShowQueue, QueueObj => $QueueObj &>
69 %#<input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Name %>" />
70 <td class="value"><& /Elements/SelectQueue,
72 Default => $QueueObj->Name,
75 OnChange => "document.getElementsByName('id')[0].value = 'refresh'; form.submit()" &>
77 <td class="label"><&|/l&>Status</&>:
80 <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}||'new', DefaultValue => 0, SkipDeleted => 1 &>
86 <& /Elements/SelectOwner, Name => "Owner", QueueObj => $QueueObj, Default => $ARGS{Owner}||$RT::Nobody->Id, DefaultValue => 0 &>
88 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
92 <&|/l&>Requestors</&>:
94 <td class="value" colspan="5">
95 <& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => exists($ARGS{Requestors}) ? $ARGS{Requestors} : $session{CurrentUser}->EmailAddress &>
96 % $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
103 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'Cc', Size => '40', Default => $ARGS{Cc} &></td>
104 <td class="comment" colspan="2"><i><font size="-2">
105 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)</&></font></i>
112 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'AdminCc', Size => '40', Default => $ARGS{AdminCc} &></td>
113 <td class="comment" colspan="2"><i><font size="-2">
114 <&|/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.)</&></font></i>
121 <td class="value" colspan="5">
122 <input name="Subject" size="60" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
123 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
128 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj &>
131 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj &>
133 % if (exists $session{'Attachments'}) {
135 <&|/l&>Attached file</&>:
138 <&|/l&>Check box to delete</&><br />
139 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
140 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
147 <&|/l&>Attach file</&>:
149 <td class="value" colspan="5">
150 <input type="file" name="Attach" />
151 <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
155 % if ( $gnupg_widget ) {
156 <tr><td> </td><td colspan="5">
157 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
163 <&|/l&>Describe the issue below</&>:<br />
164 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
165 % if (exists $ARGS{Content}) {
166 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
168 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
170 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
177 <& /Elements/Submit, Label => loc("Create")&>
180 <div id="Ticket-Create-details">
181 <a name="details"></a>
182 <table width="100%" border="0">
184 <td width="50%" valign="top" class="boxcontainer">
185 <div class="ticket-info-basics">
186 <&| /Widgets/TitleBox, title => loc('The Basics'),
187 title_class=> 'inverse',
188 color => "#993333" &>
190 <tr><td class="label"><&|/l&>Priority</&>:</td>
191 <td><& /Elements/SelectPriority,
192 Name => "InitialPriority",
193 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
195 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
196 <td><& /Elements/SelectPriority,
197 Name => "FinalPriority",
198 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
200 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
202 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
205 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
207 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
210 <td class="label"><&|/l&>Time Left</&>:</td>
212 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
217 <div class="ticket-info-dates">
218 <&|/Widgets/TitleBox, title => loc("Dates"),
219 title_class=> 'inverse',
220 color => "#663366" &>
223 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
224 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
232 <td valign="top" class="boxcontainer">
233 <div class="ticket-info-links">
234 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
236 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
238 <tr><td class="label"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} || '' %>" /></td></tr>
239 <tr><td class="label"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} || '' %>" /></td></tr>
240 <tr><td class="label"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} || '' %>" /></td></tr>
241 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
242 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
243 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
244 <tr><td class="label">Customer ID</td><td><input size="10" name="new-Customer" value="<% $ARGS{'new-Customer'} || '' %>" /></td></tr>
255 <& /Elements/Submit, Label => loc("Create") &>
260 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
261 my $Queue = $ARGS{Queue};
265 $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
266 $CloneTicketObj->Load($CloneTicket)
267 or Abort( loc("Ticket could not be loaded") );
270 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
271 Cc => join( ',', $CloneTicketObj->CcAddresses ),
272 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
273 InitialPriority => $CloneTicketObj->Priority,
276 $clone->{$_} = $CloneTicketObj->$_()
277 for qw/Owner Subject FinalPriority TimeEstimated TimeWorked
280 $clone->{$_} = $CloneTicketObj->$_->AsString
281 for grep { $CloneTicketObj->$_->Unix }
282 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
284 my $members = $CloneTicketObj->Members;
285 my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
286 my $refers = $CloneTicketObj->RefersTo;
287 while ( my $refer = $refers->Next ) {
288 push @refers, $refer->LocalTarget;
290 $clone->{'new-RefersTo'} = join ' ', @refers;
292 my $refers_by = $CloneTicketObj->ReferredToBy;
293 while ( my $refer_by = $refers_by->Next ) {
294 push @refers_by, $refer_by->LocalBase;
296 $clone->{'RefersTo-new'} = join ' ', @refers_by;
297 if (0) { # Temporarily disabled
298 my $depends = $CloneTicketObj->DependsOn;
299 while ( my $depend = $depends->Next ) {
300 push @depends, $depend->LocalTarget;
302 $clone->{'new-DependsOn'} = join ' ', @depends;
304 my $depends_by = $CloneTicketObj->DependedOnBy;
305 while ( my $depend_by = $depends_by->Next ) {
306 push @depends_by, $depend_by->LocalBase;
308 $clone->{'DependsOn-new'} = join ' ', @depends_by;
310 while ( my $member = $members->Next ) {
311 push @members, $member->LocalBase;
313 $clone->{'MemberOf-new'} = join ' ', @members;
315 my $members_of = $CloneTicketObj->MemberOf;
316 while ( my $member_of = $members_of->Next ) {
317 push @members_of, $member_of->LocalTarget;
319 $clone->{'new-MemberOf'} = join ' ', @members_of;
323 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
324 while ( my $cf = $cfs->Next ) {
326 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
328 while ( my $cf_value = $cf_values->Next ) {
329 push @cf_values, $cf_value->Content;
331 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
335 # Pass customer links along (even though cloning of parent links
336 # in general is disabled).
337 my $customers = $CloneTicketObj->Customers;
339 while ( my $customer = $customers->Next ) {
340 my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
341 push @customers, $custnum if $custnum;
343 $clone->{'new-Customer'} = join(' ', @customers);
345 for ( keys %$clone ) {
346 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
353 my $title = loc("Create a new ticket");
355 my $QueueObj = new RT::Queue($session{'CurrentUser'});
356 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
358 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
360 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
362 my $CFs = $QueueObj->TicketCustomFields();
364 my $ValidCFs = $m->comp(
365 '/Elements/ValidateCustomFields',
366 CustomFields => $CFs,
370 # {{{ deal with deleting uploaded attachments
371 foreach my $key (keys %ARGS) {
372 if ($key =~ m/^DeleteAttach-(.+)$/) {
373 delete $session{'Attachments'}{$1};
375 $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
379 # {{{ store the uploaded attachment in session
380 if ($ARGS{'Attach'}) { # attachment?
381 my $attachment = MakeMIMEEntity(
382 AttachmentFieldName => 'Attach'
385 my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
386 $session{'Attachments'} = {
387 %{$session{'Attachments'} || {}},
388 $file_path => $attachment,
393 # delete temporary storage entry to make WebUI clean
394 unless (keys %{$session{'Attachments'}} and
395 ($ARGS{'id'} eq 'new' or $ARGS{'id'} eq 'refresh')) {
396 delete $session{'Attachments'};
399 my $checks_failure = 0;
401 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
402 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
403 self => $gnupg_widget,
404 QueueObj => $QueueObj,
408 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
409 my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
410 self => $gnupg_widget,
411 Operation => 'Create',
412 QueueObj => $QueueObj,
414 $checks_failure = 1 unless $status;
417 # check email addresses for RT's
419 foreach my $field ( qw(Requestors Cc AdminCc) ) {
420 my $value = $ARGS{ $field };
421 next unless defined $value && length $value;
423 my @emails = Email::Address->parse( $value );
424 foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
425 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?$/) );
429 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
434 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
435 checks_failure => $checks_failure, results => \@results );
437 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
438 if ( $ValidCFs && !$checks_failure && !$skip_create ) {
440 # For some reason it's done by a Mason component named "Display.html"
441 # and the call is buried in obscure error-handling stuff.
442 # This comment exists to make it more visually obvious.
443 # ************************************************************
445 $m->comp('Display.html', %ARGS);
447 # ************************************************************
448 # Execution should not continue here. Display.html calls
449 # Redirect() which does an $m->abort. We only get here if the
450 # code dies before then, hence "$@".
451 $RT::Logger->crit("After display call; error is $@");
454 elsif ( !$ValidCFs ) {
456 while (my $CF = $CFs->Next) {
457 my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
458 push @results, $CF->Name . ': ' . $msg;
465 html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Show basics') . q[</a>],
468 html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Show details') . q[</a>],
475 $DependedOnBy => undef
477 $QuoteTransaction => undef
478 $CloneTicket => undef