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