import rt 3.6.6
[freeside.git] / rt / html / Ticket / Create.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6 %#                                          <jesse@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/copyleft/gpl.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 => loc("Create a new ticket"),
50     onload => "hide(document.getElementById('Ticket-Create-details'));" &>
51 <& /Elements/Tabs, 
52     current_toptab => "Ticket/Create.html", 
53     Title => loc("Create a new ticket"),
54     actions => $actions &>
55 <& /Elements/ListActions, actions => \@results &>
56 <form action="<%$RT::WebPath%>/Ticket/Create.html" method="post" enctype="multipart/form-data" name="TicketCreate">
57 <input type="hidden" class="hidden" name="id" value="new" />
58 <& /Elements/Callback, _CallbackName => 'FormStart',ARGSRef =>\%ARGS &>
59
60 <div id="Ticket-Create-basics">
61 <a name="basics"></a>
62 <&| /Widgets/TitleBox, title => loc("Create a new ticket") &>
63 <table border="0" cellpadding="0" cellspacing="0">
64 <tr><td class="label"><&|/l&>Queue</&>:</td>
65 <td class="value"><& Elements/ShowQueue, QueueObj => $QueueObj &>
66 <input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Name %>" />
67 </td>
68 <td class="label"><&|/l&>Status</&>:
69 </td>
70 <td class="value">
71 <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}||'new', DefaultValue => 0 &>
72 </td>
73 <td class="label">
74 <&|/l&>Owner</&>:
75 </td>
76 <td class="value">
77 <& /Elements/SelectOwner, Name => "Owner", QueueObj => $QueueObj, Default => $ARGS{Owner}||$RT::Nobody->Id, DefaultValue => 0 &>
78 </td>
79 </tr>
80 <tr>
81 <td class="label">
82 <&|/l&>Requestors</&>:
83 </td>
84 <td class="value" colspan="5">
85 <input name="Requestors" value="<% ($ARGS{Requestors}) || $session{CurrentUser}->EmailAddress %>" size="40" />
86 </td>
87 </tr>
88 <tr>
89 <td class="labeltop">
90 <&|/l&>Cc</&>:
91 </td>
92 <td class="value" colspan="5">
93 <input name="Cc" size="40" value="<% $ARGS{Cc} %>" /><br />
94 <i><font size="-2">
95 <&|/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>
96 </td>
97 </tr>
98 <tr>
99 <td class="labeltop">
100 <&|/l&>Admin Cc</&>:
101 </td>
102 <td class="value" colspan="5">
103 <input name="AdminCc" size="40" value="<% $ARGS{AdminCc} %>" /><br />
104 <i><font size="-2">
105 <&|/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>
106 </td>
107 </tr>
108 <tr>
109 <td class="label">
110 <&|/l&>Subject</&>:
111 </td>
112 <td class="value" colspan="5">
113 <input name="Subject" size="60" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
114 </td>
115 </tr>
116 <tr>
117 <td colspan="6">
118 <& /Ticket/Elements/EditCustomFields, QueueObj => $QueueObj &>
119 </td>
120 </tr>
121 % if ($TxnCFs->Count) {
122 % while (my $CF = $TxnCFs->Next()) {
123 <tr>
124 <td align="right"><% $CF->Name %>:</td>
125 <td><& /Elements/EditCustomField, CustomField => $CF, NamePrefix =>
126     "Object-RT::Transaction--CustomField-" &><em><% $CF->FriendlyType %></em></td>
127 </td></tr>
128 % }
129 % }
130 <tr>
131 % if (exists $session{'Attachments'}) {
132 <td class="label">
133 <&|/l&>Attached file</&>:
134 </td>
135 <td colspan="5">
136 <&|/l&>Check box to delete</&><br />
137 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
138 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
139 % } # end of foreach
140 </td>
141 </tr>
142 <tr>
143 % } # end of if
144 <td>
145 <&|/l&>Attach file</&>:
146 </td>
147 <td class="value" colspan="5">
148 <input type="file" name="Attach" />
149 <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
150 </td>
151 </tr>
152 <tr>
153 <td colspan="6">
154 <&|/l&>Describe the issue below</&>:<br />
155 % if (exists $ARGS{Content}) {
156 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
157 % } else {
158 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
159 %}
160
161 <br />
162 </td>
163 </tr>
164 <tr>
165 <td align="right" colspan="2">
166 </td>
167 </tr>
168 </table>
169 </&>
170 <& /Elements/Submit, Label => loc("Create")&>
171 </div>
172
173 <div id="Ticket-Create-details">
174 <a name="details"></a>
175 <table width="100%" border="0">
176 <tr>
177 <td width="50%" valign="top">
178
179           <&| /Widgets/TitleBox, title => loc('The Basics'), 
180                 title_class=> 'inverse',  
181                 color => "#993333" &>
182 <table border="0">
183 <tr><td align="right"><&|/l&>Priority</&>:</td><td><input size="3" name="InitialPriority" value="<% $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority %>" /></td></tr>
184 <tr><td align="right"><&|/l&>Final Priority</&>:</td><td><input size="3" name="FinalPriority" value="<% $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority %>" /></td></tr>
185 <tr><td align="right"><&|/l&>Time Estimated</&>:</td>
186 <td>
187 <input size="3" name="TimeEstimated" value="<%$ARGS{TimeEstimated}%>" />
188 <& /Elements/SelectTimeUnits, Name =>'TimeEstimated' &>
189
190 </td></tr>
191 <tr><td align="right"><&|/l&>Time Worked</&>:</td>
192 <td>
193 <input size="3" name="TimeWorked" value="<%$ARGS{TimeWorked}%>" />
194 <& /Elements/SelectTimeUnits, Name =>'TimeWorked' &>
195
196 </td></tr>
197 <tr>
198 <td align="right"><&|/l&>Time Left</&>:</td>
199 <td><input size="3" name="TimeLeft" value="<%$ARGS{TimeLeft}%>" />
200 <& /Elements/SelectTimeUnits, Name =>'TimeLeft' &>
201 </td></tr>
202 </table>
203 </&>
204 <br />
205 <&|/Widgets/TitleBox, title => loc("Dates"),
206                 title_class=> 'inverse',  
207                  color => "#663366" &>
208
209 <table>
210 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
211 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
212 </table>
213 </&>
214 <br />
215 </td>
216
217 <td valign="top">
218 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
219
220 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
221 <table border="0">
222 <tr><td align="right"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} %>" /></td></tr>
223 <tr><td align="right"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} %>" /></td></tr>
224 <tr><td align="right"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} %>" /></td></tr>
225 <tr><td align="right"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} %>" /></td></tr>
226 <tr><td align="right"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} %>" /></td></tr>
227 <tr><td align="right"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} %>" /></td></tr>
228
229
230 </table>
231 </&>
232 <br />
233
234 </td>
235 </tr>
236 </table>
237 <& /Elements/Submit, Label => loc("Create") &>
238 </div>
239 </form>
240
241 <%INIT>
242
243 my $CloneTicketObj;
244 if ( $CloneTicket ) {
245     $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
246     $CloneTicketObj->Load($CloneTicket) or Abort(loc("Ticket could not be loaded"));
247     
248     my $clone = {
249         Requestors       => join( ',', $CloneTicketObj->RequestorAddresses ),
250         Cc               => join( ',', $CloneTicketObj->CcAddresses),
251         AdminCc          => join( ',', $CloneTicketObj->AdminCcAddresses),
252         InitialPriority => $CloneTicketObj->Priority, 
253     };
254     
255     $clone->{$_} = $CloneTicketObj->$_() 
256         for qw/Owner Subject FinalPriority TimeEstimated TimeWorked 
257                 Status TimeLeft Starts Started Due Resolved/;
258     
259         my $members = $CloneTicketObj->Members;
260         my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
261         while ( my $member = $members->Next ) {
262             push @members, $member->LocalBase;
263         }
264         $clone->{'MemberOf-new'} = join ' ', @members;
265     
266         my $members_of = $CloneTicketObj->MemberOf;
267         while ( my $member_of = $members_of->Next ) {
268             push @members_of, $member_of->LocalTarget;
269         }
270         $clone->{'new-MemberOf'} = join ' ', @members_of;
271         
272         my $refers = $CloneTicketObj->RefersTo;
273         while ( my $refer = $refers->Next ) {
274             push @refers, $refer->LocalTarget;
275         }
276         $clone->{'new-RefersTo'} = join ' ', @refers;
277     
278         my $refers_by = $CloneTicketObj->ReferredToBy;
279         while ( my $refer_by = $refers_by->Next ) {
280             push @refers_by, $refer_by->LocalBase;
281         }
282         $clone->{'RefersTo-new'} = join ' ', @refers_by;
283     
284         my $depends = $CloneTicketObj->DependsOn;
285         while ( my $depend = $depends->Next ) {
286             push @depends, $depend->LocalTarget;
287         }
288         $clone->{'new-DependsOn'} = join ' ', @depends;
289     
290         my $depends_by = $CloneTicketObj->DependedOnBy;
291         while ( my $depend_by = $depends_by->Next ) {
292             push @depends_by, $depend_by->LocalBase;
293         }
294         $clone->{'DependsOn-new'} = join ' ', @depends_by;
295     
296     
297     
298     my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
299     while ( my $cf = $cfs->Next ) {
300         my $cf_id = $cf->id;
301         my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
302         my @cf_values;
303         while ( my $cf_value = $cf_values->Next ) {
304             push @cf_values, $cf_value->Content;
305         }
306         $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} 
307             = join "\n", @cf_values;
308     }
309     
310     for ( keys %$clone ) {
311         $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
312     }
313
314 }
315
316 my @results;
317 my $QueueObj = new RT::Queue($session{'CurrentUser'});
318 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
319 my $CFs = $QueueObj->TicketCustomFields();
320 my $TxnCFs = $QueueObj->TicketTransactionCustomFields();
321
322 my $ValidCFs = $m->comp(
323     '/Elements/ValidateCustomFields',
324     CustomFields => $CFs,
325     ARGSRef => \%ARGS
326 );
327
328 # if no due date has been set explicitly, then use the
329 # queue's default if it exists
330 if ($QueueObj->DefaultDueIn && !$ARGS{'Due'}) {
331     my $default_due = RT::Date->new($session{'CurrentUser'});
332     $default_due->SetToNow();
333     $default_due->AddDays($QueueObj->DefaultDueIn);
334     $ARGS{'Due'} = $default_due->ISO();
335 }
336
337 # {{{ deal with deleting uploaded attachments
338 foreach my $key (keys %ARGS) {
339     if ($key =~ m/^DeleteAttach-(.+)$/) {
340         delete $session{'Attachments'}{$1};
341     }
342     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
343 }
344
345 # {{{ store the uploaded attachment in session
346 if ($ARGS{'Attach'}) {                  # attachment?
347     $session{'Attachments'} = {} unless defined $session{'Attachments'};
348
349     my $subject = "$ARGS{'Attach'}";
350
351     # strip leading directories
352     $subject =~ s#^.*[\\/]##;
353
354     my $attachment = MakeMIMEEntity(
355         Subject             => $subject,
356         Body                => "",
357         AttachmentFieldName => 'Attach'
358     );
359
360     $session{'Attachments'} = { %{$session{'Attachments'} || {}},
361                                 $ARGS{'Attach'} => $attachment };
362 }
363 # }}}
364
365 # delete temporary storage entry to make WebUI clean
366 unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
367     delete $session{'Attachments'};
368 }
369
370
371 # }}}
372
373 if ((!exists $ARGS{'AddMoreAttach'}) and ($ARGS{'id'} eq 'new')) { # new ticket?
374     if ($ValidCFs) {
375         $m->comp('Display.html', %ARGS);
376         $RT::Logger->crit("After display call; error is $@");
377         $m->abort();
378     }
379     else {
380         # Invalid CFs
381         while (my $CF = $CFs->Next) {
382             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
383             push @results, $CF->Name . ': ' . $msg;
384         }
385     }
386 }
387
388 my $actions = {
389     A => {
390         html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Show basics') . q[</a>],
391     },
392     B => {
393         html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Show details') . q[</a>],
394     },
395 };
396 </%INIT>
397
398 <%ARGS>
399 $DependsOn => undef
400 $DependedOnBy => undef
401 $MemberOf => undef
402 $QuoteTransaction => undef
403 $Queue => undef
404 $CloneTicket => undef
405 </%ARGS>