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