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