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