RT count still running on 3.8.10 - porting to RT4.
[usit-rt.git] / share / html / m / ticket / create
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
5%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
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
16%# from www.gnu.org.
17%#
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.
22%#
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.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
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.)
37%#
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.
46%#
47%# END BPS TAGGED BLOCK }}}
48<%ARGS>
49$QuoteTransaction => undef
50$CloneTicket => undef
51</%ARGS>
52<%init>
53$m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
54my $Queue = $ARGS{Queue};
55
56my $escape = sub { $m->interp->apply_escapes(shift, 'h') };
57
58my $showrows = sub {
59 my @pairs = @_;
60
61 while (@pairs) {
62 my $key = shift @pairs;
63 my $val = shift @pairs;
64
65 $m->out("<div class=\"entry\"><span class=\"label\">$key</span><div class=\"value\">$val</div></div>");
66
67 }
68
69};
70
71
72my $CloneTicketObj;
73if ($CloneTicket) {
74 $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
75 $CloneTicketObj->Load($CloneTicket)
76 or Abort( loc("Ticket could not be loaded") );
77
78 my $clone = {
79 Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
80 Cc => join( ',', $CloneTicketObj->CcAddresses ),
81 AdminCc => join( ',', $CloneTicketObj->AdminCcAddresses ),
82 InitialPriority => $CloneTicketObj->Priority,
83 };
84
85 $clone->{$_} = $CloneTicketObj->$_()
86 for qw/Owner Subject FinalPriority TimeEstimated TimeWorked
87 Status TimeLeft/;
88
89 $clone->{$_} = $CloneTicketObj->$_->AsString
90 for grep { $CloneTicketObj->$_->Unix }
91 map { $_ . "Obj" } qw/Starts Started Due Resolved/;
92
93 my $members = $CloneTicketObj->Members;
94 my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
95 my $refers = $CloneTicketObj->RefersTo;
96 while ( my $refer = $refers->Next ) {
97 push @refers, $refer->LocalTarget;
98 }
99 $clone->{'new-RefersTo'} = join ' ', @refers;
100
101 my $refers_by = $CloneTicketObj->ReferredToBy;
102 while ( my $refer_by = $refers_by->Next ) {
103 push @refers_by, $refer_by->LocalBase;
104 }
105 $clone->{'RefersTo-new'} = join ' ', @refers_by;
106 if (0) { # Temporarily disabled
107 my $depends = $CloneTicketObj->DependsOn;
108 while ( my $depend = $depends->Next ) {
109 push @depends, $depend->LocalTarget;
110 }
111 $clone->{'new-DependsOn'} = join ' ', @depends;
112
113 my $depends_by = $CloneTicketObj->DependedOnBy;
114 while ( my $depend_by = $depends_by->Next ) {
115 push @depends_by, $depend_by->LocalBase;
116 }
117 $clone->{'DependsOn-new'} = join ' ', @depends_by;
118
119 while ( my $member = $members->Next ) {
120 push @members, $member->LocalBase;
121 }
122 $clone->{'MemberOf-new'} = join ' ', @members;
123
124 my $members_of = $CloneTicketObj->MemberOf;
125 while ( my $member_of = $members_of->Next ) {
126 push @members_of, $member_of->LocalTarget;
127 }
128 $clone->{'new-MemberOf'} = join ' ', @members_of;
129
130 }
131
132 my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
133 while ( my $cf = $cfs->Next ) {
134 my $cf_id = $cf->id;
135 my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
136 my @cf_values;
137 while ( my $cf_value = $cf_values->Next ) {
138 push @cf_values, $cf_value->Content;
139 }
140 $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
141 @cf_values;
142 }
143
144 for ( keys %$clone ) {
145 $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
146 }
147
148}
149
150my @results;
151
152my $title = loc("Create a ticket");
153
154my $QueueObj = RT::Queue->new($session{'CurrentUser'});
155$QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
156
157$m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
158
159$QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
160
161my $CFs = $QueueObj->TicketCustomFields();
162
163my $ValidCFs = $m->comp(
164 '/Elements/ValidateCustomFields',
165 CustomFields => $CFs,
166 ARGSRef => \%ARGS
167);
168
169# deal with deleting uploaded attachments
170foreach my $key (keys %ARGS) {
171 if ($key =~ m/^DeleteAttach-(.+)$/) {
172 delete $session{'Attachments'}{$1};
173 }
174 $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
175}
176
177# store the uploaded attachment in session
178if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
179 my $attachment = MakeMIMEEntity(
180 AttachmentFieldName => 'Attach'
181 );
182
183 my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
184 $session{'Attachments'} = {
185 %{$session{'Attachments'} || {}},
186 $file_path => $attachment,
187 };
188}
189
190# delete temporary storage entry to make WebUI clean
191unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
192 delete $session{'Attachments'};
193}
194
195my $checks_failure = 0;
196
197my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
198$m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
199 self => $gnupg_widget,
200 QueueObj => $QueueObj,
201);
202
203
204if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
205 my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
206 self => $gnupg_widget,
207 Operation => 'Create',
208 QueueObj => $QueueObj,
209 );
210 $checks_failure = 1 unless $status;
211}
212
213# check email addresses for RT's
214{
215 foreach my $field ( qw(Requestors Cc AdminCc) ) {
216 my $value = $ARGS{ $field };
217 next unless defined $value && length $value;
218
219 my @emails = Email::Address->parse( $value );
220 foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
221 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?$/) );
222 $checks_failure = 1;
223 $email = undef;
224 }
225 $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
226 }
227}
228
229my $skip_create = 0;
230$m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
231 checks_failure => $checks_failure, results => \@results );
232
233if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
234 if ( $ValidCFs && !$checks_failure && !$skip_create ) {
235 $m->comp('show', %ARGS);
236 $RT::Logger->crit("After display call; error is $@");
237 $m->abort();
238 }
239 elsif ( !$ValidCFs ) {
240 # Invalid CFs
241 while (my $CF = $CFs->Next) {
242 my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
243 push @results, $CF->Name . ': ' . $msg;
244 }
245 }
246}
247
248
249
250
251</%init>
252<&| /m/_elements/wrapper, title => $title &>
253<& /Elements/ListActions, actions => \@results &>
254<form action="<% RT->Config->Get('WebPath') %>/m/ticket/create" method="post" enctype="multipart/form-data" name="TicketCreate" id="ticket-create">
255<input type="hidden" class="hidden" name="id" value="new" />
256% $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
257% if ($gnupg_widget) {
258<& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
259% }
260
261
262<div id="ticket-create-simple">
263<&| /Widgets/TitleBox, title => $QueueObj->Name &>
264
265<%perl>
266$showrows->(
267 loc("Subject") => '<input type="text" name="Subject" size="30" maxsize="200" value="'.$escape->($ARGS{Subject} || '').'" />');
268</%perl>
269 <span class="content-label label"><%loc("Describe the issue below")%></span>
270 <& /Elements/MessageBox, exists $ARGS{Content} ? (Default => $ARGS{Content}, IncludeSignature => 0 ) : ( QuoteTransaction => $QuoteTransaction ), Height => 5 &>
271
272
273<&/Elements/Submit, Label => loc("Create") &>
274
275
276</&>
277</div>
278
279<div id="ticket-create-basics">
280<&| /Widgets/TitleBox &>
281 <input type="hidden" class="hidden" name="Queue" value="<%$QueueObj->id %>" />
282<%perl>
283
284$showrows->(
285
286 # loc('Queue') => $m->scomp( '/Ticket/Elements/ShowQueue', QueueObj => $QueueObj ) ,
287
288 loc('Status') =>
289
290 $m->scomp(
291 "/Elements/SelectStatus",
292 Name => "Status",
293 QueueObj => $QueueObj,
294 Default => $ARGS{Status} || $QueueObj->Lifecycle->DefaultOnCreate,
295 DefaultValue => 0,
296 ),
297
298 loc("Owner") =>
299
300 $m->scomp(
301 "/Elements/SelectOwner",
302 Name => "Owner",
303 QueueObj => $QueueObj,
304 Default => $ARGS{Owner} || RT->Nobody->Id,
305 DefaultValue => 0
306 ),
307
308 loc("Requestors") => $m->scomp(
309 "/Elements/EmailInput",
310 Name => 'Requestors',
311 Size => '40',
312 Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress
313 ),
314
315 loc("Cc") =>
316
317 $m->scomp( "/Elements/EmailInput", Name => 'Cc', Size => '40', Default => $ARGS{Cc} )
318 . '<span class="comment"><i><font size="-2">'
319 . loc(
320 "(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)"
321 )
322 . '</font></i></span>',
323
324 loc("Admin Cc") =>
325
326 $m->scomp( "/Elements/EmailInput", Name => 'AdminCc', Size => '40', Default => $ARGS{AdminCc} )
327 . '<span class="comment"><i><font size="-2">'
328 . loc(
329 "(Sends a carbon-copy of this update to a comma-delimited list of administrative email addresses. These people <strong>will</strong> receive future updates.)"
330 )
331 . '</font></i></span>',
332
333
334);
335
336</%perl>
337
338<& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj &>
339<& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj &>
340
341% if (exists $session{'Attachments'}) {
342
343<%loc("Attached file") %>
344
345<%loc("Check box to delete")%><br />
346% foreach my $attach_name (keys %{$session{'Attachments'}}) {
347<input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
348% } # end of foreach
349
350
351% } # end of if
352
353<%perl>
354$showrows->(
355 loc("Attach file") =>
356
357 '<input type="file" name="Attach" />
358<input type="submit" class="button" name="AddMoreAttach" value="' . loc("Add More Files") . '" />'
359);
360</%perl>
361
362
363% if ( $gnupg_widget ) {
364<& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
365% }
366
367
368 <div class="ticket-info-basics">
369 <&| /Widgets/TitleBox, title => loc('The Basics'),
370 title_class=> 'inverse',
371 color => "#993333" &>
372<%perl>
373$showrows->(
374 loc("Priority") => $m->scomp(
375 "/Elements/SelectPriority",
376 Name => "InitialPriority",
377 Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
378 ),
379 loc("Final Priority") => $m->scomp(
380 "/Elements/SelectPriority",
381 Name => "FinalPriority",
382 Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
383 ),
384
385 loc("Time Estimated") => '<span class="timefield">'.$m->scomp(
386 "/Elements/EditTimeValue",
387 Name => 'TimeEstimated',
388 Default => $ARGS{TimeEstimated} || '',
389 InUnits => $ARGS{'TimeEstimated-TimeUnits'}
390 ).'</span>',
391
392 loc("Time Worked") => '<span class="timefield">'.$m->scomp(
393 "/Elements/EditTimeValue",
394 Name => 'TimeWorked',
395 Default => $ARGS{TimeWorked} || '',
396 InUnits => $ARGS{'TimeWorked-TimeUnits'}
397 ). '</span>',
398
399 loc("Time Left") => '<span class="timefield">'.$m->scomp(
400 "/Elements/EditTimeValue",
401 Name => 'TimeLeft',
402 Default => $ARGS{TimeLeft} || '',
403 InUnits => $ARGS{'TimeLeft-TimeUnits'}
404 ).'</span>',
405);
406
407</%perl>
408</&>
409<&|/Widgets/TitleBox, title => loc("Dates"),
410 title_class=> 'inverse',
411 color => "#663366" &>
412
413<%perl>
414$showrows->(
415 loc("Starts") => $m->scomp( "/Elements/SelectDate", Name => "Starts", Default => ( $ARGS{Starts} || '' )),
416 loc("Due") => $m->scomp( "/Elements/SelectDate", Name => "Due", Default => ($ARGS{Due} || '' ))
417);
418
419</%perl>
420</&>
421
422<&|/Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
423
424<em><%loc("(Enter ticket ids or URLs, separated with spaces)")%></em>
425
426<%perl>
427$showrows->(
428 loc("Depends on") => '<input type="text" size="10" name="new-DependsOn" value="' . $escape->($ARGS{'new-DependsOn'} || '' ). '" />',
429 loc("Depended on by") => '<input type="text" size="10" name="DependsOn-new" value="' . $escape->($ARGS{'DependsOn-new'} || '' ) . '" />',
430 loc("Parents") => '<input type="text" size="10" name="new-MemberOf" value="' . $escape->($ARGS{'new-MemberOf'} || '') . '" />',
431 loc("Children") => '<input type="text" size="10" name="MemberOf-new" value="' . $escape->($ARGS{'MemberOf-new'} || '') . '" />',
432 loc("Refers to") => '<input type="text" size="10" name="new-RefersTo" value="' . $escape->($ARGS{'new-RefersTo'} || '') . '" />',
433 loc("Referred to by") => '<input type="text" size="10" name="RefersTo-new" value="' . $escape->($ARGS{'RefersTo-new'} || ''). '" />'
434);
435</%perl>
436
437</&>
438
439
440<& /Elements/Submit, Label => loc("Create") &>
441</form>
442</&>
443</&>