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