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