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