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 }}}
50 onload => "function () { hide(document.getElementById('Ticket-Create-details')) }" &>
52 current_toptab => "Ticket/Create.html",
54 actions => $actions &>
55 <& /Elements/ListActions, actions => \@results &>
56 <form action="<% RT->Config->Get('WebPath') %>/Ticket/Create.html" method="post" enctype="multipart/form-data" name="TicketCreate">
57 <input type="hidden" class="hidden" name="id" value="new" />
58 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
59 % if ($gnupg_widget) {
60 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
62 <div id="Ticket-Create-basics">
64 <&| /Widgets/TitleBox, title => $title &>
65 <table border="0" cellpadding="0" cellspacing="0">
66 <tr><td class="label"><&|/l&>Queue</&>:</td>
67 %#<td class="value"><& Elements/ShowQueue, QueueObj => $QueueObj &>
68 %#<input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Name %>" />
69 <td class="value"><& /Elements/SelectQueue,
71 Default => $QueueObj->Name,
74 OnChange => "document.getElementsByName('id')[0].value = ''; form.submit()" &>
76 <td class="label"><&|/l&>Status</&>:
79 <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}||'new', DefaultValue => 0, SkipDeleted => 1 &>
85 <& /Elements/SelectOwner, Name => "Owner", QueueObj => $QueueObj, Default => $ARGS{Owner}||$RT::Nobody->Id, DefaultValue => 0 &>
87 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
91 <&|/l&>Requestors</&>:
93 <td class="value" colspan="5">
94 <& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress &>
95 % $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
102 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'Cc', Size => '40', Default => $ARGS{Cc} &></td>
103 <td class="comment" colspan="2"><i><font size="-2">
104 <&|/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>
111 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'AdminCc', Size => '40', Default => $ARGS{AdminCc} &></td>
112 <td class="comment" colspan="2"><i><font size="-2">
113 <&|/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>
120 <td class="value" colspan="5">
121 <input name="Subject" size="60" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
122 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
127 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj &>
130 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj &>
132 % if (exists $session{'Attachments'}) {
134 <&|/l&>Attached file</&>:
137 <&|/l&>Check box to delete</&><br />
138 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
139 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
146 <&|/l&>Attach file</&>:
148 <td class="value" colspan="5">
149 <input type="file" name="Attach" />
150 <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
154 % if ( $gnupg_widget ) {
155 <tr><td> </td><td colspan="5">
156 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
162 <&|/l&>Describe the issue below</&>:<br />
163 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
164 % if (exists $ARGS{Content}) {
165 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
167 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
169 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
176 <& /Elements/Submit, Label => loc("Create")&>
179 <div id="Ticket-Create-details">
180 <a name="details"></a>
181 <table width="100%" border="0">
183 <td width="50%" valign="top" class="boxcontainer">
184 <div class="ticket-info-basics">
185 <&| /Widgets/TitleBox, title => loc('The Basics'),
186 title_class=> 'inverse',
187 color => "#993333" &>
189 <tr><td class="label"><&|/l&>Priority</&>:</td>
190 <td><& /Elements/SelectPriority,
191 Name => "InitialPriority",
192 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
194 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
195 <td><& /Elements/SelectPriority,
196 Name => "FinalPriority",
197 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
199 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
201 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
204 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
206 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
209 <td class="label"><&|/l&>Time Left</&>:</td>
211 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
216 <div class="ticket-info-dates">
217 <&|/Widgets/TitleBox, title => loc("Dates"),
218 title_class=> 'inverse',
219 color => "#663366" &>
222 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
223 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
231 <td valign="top" class="boxcontainer">
232 <div class="ticket-info-links">
233 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
235 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
237 <tr><td class="label"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} || '' %>" /></td></tr>
238 <tr><td class="label"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} || '' %>" /></td></tr>
239 <tr><td class="label"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} || '' %>" /></td></tr>
240 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
241 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
242 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
253 <& /Elements/Submit, Label => loc("Create") &>
258 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
259 my $Queue = $ARGS{Queue};
263 $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
264 $CloneTicketObj->Load($CloneTicket)
265 or Abort( loc("Ticket could not be loaded") );
268 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
269 Cc => join( ',', $CloneTicketObj->CcAddresses ),
270 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
271 InitialPriority => $CloneTicketObj->Priority,
274 $clone->{$_} = $CloneTicketObj->$_()
275 for qw/Owner Subject FinalPriority TimeEstimated TimeWorked
278 $clone->{$_} = $CloneTicketObj->$_->AsString
279 for grep { $CloneTicketObj->$_->Unix }
280 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
282 my $members = $CloneTicketObj->Members;
283 my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
284 my $refers = $CloneTicketObj->RefersTo;
285 while ( my $refer = $refers->Next ) {
286 push @refers, $refer->LocalTarget;
288 $clone->{'new-RefersTo'} = join ' ', @refers;
290 my $refers_by = $CloneTicketObj->ReferredToBy;
291 while ( my $refer_by = $refers_by->Next ) {
292 push @refers_by, $refer_by->LocalBase;
294 $clone->{'RefersTo-new'} = join ' ', @refers_by;
295 if (0) { # Temporarily disabled
296 my $depends = $CloneTicketObj->DependsOn;
297 while ( my $depend = $depends->Next ) {
298 push @depends, $depend->LocalTarget;
300 $clone->{'new-DependsOn'} = join ' ', @depends;
302 my $depends_by = $CloneTicketObj->DependedOnBy;
303 while ( my $depend_by = $depends_by->Next ) {
304 push @depends_by, $depend_by->LocalBase;
306 $clone->{'DependsOn-new'} = join ' ', @depends_by;
308 while ( my $member = $members->Next ) {
309 push @members, $member->LocalBase;
311 $clone->{'MemberOf-new'} = join ' ', @members;
313 my $members_of = $CloneTicketObj->MemberOf;
314 while ( my $member_of = $members_of->Next ) {
315 push @members_of, $member_of->LocalTarget;
317 $clone->{'new-MemberOf'} = join ' ', @members_of;
321 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
322 while ( my $cf = $cfs->Next ) {
324 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
326 while ( my $cf_value = $cf_values->Next ) {
327 push @cf_values, $cf_value->Content;
329 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
333 for ( keys %$clone ) {
334 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
341 my $title = loc("Create a new ticket");
343 my $QueueObj = new RT::Queue($session{'CurrentUser'});
344 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
346 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
348 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
350 my $CFs = $QueueObj->TicketCustomFields();
352 my $ValidCFs = $m->comp(
353 '/Elements/ValidateCustomFields',
354 CustomFields => $CFs,
358 # {{{ deal with deleting uploaded attachments
359 foreach my $key (keys %ARGS) {
360 if ($key =~ m/^DeleteAttach-(.+)$/) {
361 delete $session{'Attachments'}{$1};
363 $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
367 # {{{ store the uploaded attachment in session
368 if ($ARGS{'Attach'}) { # attachment?
369 my $attachment = MakeMIMEEntity(
370 AttachmentFieldName => 'Attach'
373 my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
374 $session{'Attachments'} = {
375 %{$session{'Attachments'} || {}},
376 $file_path => $attachment,
381 # delete temporary storage entry to make WebUI clean
382 unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
383 delete $session{'Attachments'};
386 my $checks_failure = 0;
388 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
389 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
390 self => $gnupg_widget,
391 QueueObj => $QueueObj,
395 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
396 my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
397 self => $gnupg_widget,
398 Operation => 'Create',
399 QueueObj => $QueueObj,
401 $checks_failure = 1 unless $status;
404 # check email addresses for RT's
406 foreach my $field ( qw(Requestors Cc AdminCc) ) {
407 my $value = $ARGS{ $field };
408 next unless defined $value && length $value;
410 my @emails = Email::Address->parse( $value );
411 foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
412 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?$/) );
416 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
421 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
422 checks_failure => $checks_failure, results => \@results );
424 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
425 if ( $ValidCFs && !$checks_failure && !$skip_create ) {
426 $m->comp('Display.html', %ARGS);
427 $RT::Logger->crit("After display call; error is $@");
430 elsif ( !$ValidCFs ) {
432 while (my $CF = $CFs->Next) {
433 my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
434 push @results, $CF->Name . ': ' . $msg;
441 html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Show basics') . q[</a>],
444 html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Show details') . q[</a>],
451 $DependedOnBy => undef
453 $QuoteTransaction => undef
454 $CloneTicket => undef