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