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