rt 4.0.23
[freeside.git] / rt / share / html / Ticket / Create.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2015 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="submit" name="SubmitTicket" value="Create" style="display:none">
57   <input type="hidden" class="hidden" name="id" value="new" />
58   
59 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
60
61 % if ($gnupg_widget) {
62   <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
63 % }
64
65 <div id="Ticket-Create-basics">
66 <a name="basics"></a>
67
68 <div id="ticket-create-metadata">
69     <&| /Widgets/TitleBox, title => loc("Basics"), class=>'ticket-info-basics' &>
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, KeepValue => 1 &>
110       <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1, KeepValue => 1 &>
111     </table>
112   </&>
113 % $m->callback( CallbackName => 'AfterBasics', QueueObj => $QueueObj, ARGSRef => \%ARGS );
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 Status/;
298         # not TimeWorked, TimeEstimated, or 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     my $get_link_value = sub {
308         my ($link, $type) = @_;
309         my $uri_method = $type . 'URI';
310         my $local_method = 'Local' . $type;
311         my $uri = $link->$uri_method;
312         return if $uri->IsLocal and
313                 $uri->Object and
314                 $uri->Object->isa('RT::Ticket') and
315                 $uri->Object->Type eq 'reminder';
316
317         return $link->$local_method || $uri->URI;
318     };
319     while ( my $refer = $refers->Next ) {
320         my $refer_value = $get_link_value->($refer, 'Target');
321         push @refers, $refer_value if defined $refer_value;
322     }
323     $clone->{'new-RefersTo'} = join ' ', @refers;
324
325     my $refers_by = $CloneTicketObj->ReferredToBy;
326     while ( my $refer_by = $refers_by->Next ) {
327         my $refer_by_value = $get_link_value->($refer_by, 'Base');
328         push @refers_by, $refer_by_value if defined $refer_by_value;
329     }
330     $clone->{'RefersTo-new'} = join ' ', @refers_by;
331
332     my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
333     while ( my $cf = $cfs->Next ) {
334         next if $cf->FirstAttribute('NoClone');
335         my $cf_id     = $cf->id;
336         my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
337         my @cf_values;
338         while ( my $cf_value = $cf_values->Next ) {
339             push @cf_values, $cf_value->Content;
340         }
341
342         if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
343             $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = \@cf_values;
344         }
345         else {
346             $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
347               @cf_values;
348         }
349     }
350
351     # Pass customer links along (even though cloning of parent links
352     # in general is disabled).
353     my $customers = $CloneTicketObj->Customers;
354     my @customers;
355     while ( my $customer = $customers->Next ) {
356       my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
357       push @customers, $custnum if $custnum;
358     }
359     $clone->{'new-Customer'} = join(' ', @customers);
360
361     for ( keys %$clone ) {
362         $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
363     }
364
365 }
366
367 my @results;
368
369 my $title = loc("Create a new ticket");
370
371 my $QueueObj = RT::Queue->new($session{'CurrentUser'});
372 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
373
374 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
375
376 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
377
378 my $CFs = $QueueObj->TicketCustomFields();
379
380 my $ValidCFs = $m->comp(
381     '/Elements/ValidateCustomFields',
382     CustomFields => $CFs,
383     ARGSRef => \%ARGS
384 );
385
386 ProcessAttachments(ARGSRef => \%ARGS);
387
388 my $checks_failure = 0;
389
390 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
391 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
392     self      => $gnupg_widget,
393     QueueObj  => $QueueObj,
394 );
395
396
397 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
398     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
399         self      => $gnupg_widget,
400         Operation => 'Create',
401         QueueObj  => $QueueObj,
402     );
403     $checks_failure = 1 unless $status;
404 }
405
406 # check email addresses for RT's
407 {
408     foreach my $field ( qw(Requestors Cc AdminCc) ) {
409         my $value = $ARGS{ $field };
410         next unless defined $value && length $value;
411
412         my @emails = Email::Address->parse( $value );
413         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
414             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?$/) );
415             $checks_failure = 1;
416             $email = undef;
417         }
418         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
419     }
420 }
421
422 my $skip_create = 0;
423 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create, 
424               checks_failure => $checks_failure, results => \@results );
425
426 $m->comp( '/Articles/Elements/CheckSkipCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
427               checks_failure => $checks_failure, results => \@results );
428
429 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
430     if ( $ValidCFs && !$checks_failure && !$skip_create ) {
431 # CREATE THE TICKET.
432 # For some reason it's done by a Mason component named "Display.html"
433 # and the call is buried in obscure error-handling stuff.
434 # This comment exists to make it more visually obvious.
435 # ************************************************************
436
437         $m->comp('Display.html', %ARGS);
438
439 # ************************************************************
440 # Execution should not continue here.  Display.html calls 
441 # Redirect() which does an $m->abort.  We only get here if the 
442 # code dies before then, hence "$@".
443         $RT::Logger->crit("After display call; error is $@");
444         $m->abort();
445     }
446     elsif ( !$ValidCFs ) {
447         # Invalid CFs
448         while (my $CF = $CFs->Next) {
449             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
450             push @results, $CF->Name . ': ' . $msg;
451         }
452     }
453 }
454 PageMenu->child( basics => raw_html =>  q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Basics') . q[</a>]);
455 PageMenu->child( details => raw_html =>  q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Details') . q[</a>]);
456 </%INIT>
457
458 <%ARGS>
459 $DependsOn => undef
460 $DependedOnBy => undef
461 $MemberOf => undef
462 $QuoteTransaction => undef
463 $CloneTicket => undef
464 </%ARGS>