import rt 3.8.11
[freeside.git] / rt / html / Ticket / Create.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 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/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 => 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="label">
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="label">
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 <& /Elements/Callback, _CallbackName => 'BeforeMessageBox', QueueObj => $QueueObj, %ARGS &>
156 % if (exists $ARGS{Content}) {
157 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
158 % } else {
159 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
160 %}
161
162 <br />
163 </td>
164 </tr>
165 <tr>
166 <td align="right" colspan="2">
167 </td>
168 </tr>
169 </table>
170 </&>
171 <& /Elements/Submit, Label => loc("Create")&>
172 </div>
173
174 <div id="Ticket-Create-details">
175 <a name="details"></a>
176 <table width="100%" border="0">
177 <tr>
178 <td width="50%" valign="top">
179
180           <&| /Widgets/TitleBox, title => loc('The Basics'), 
181                 title_class=> 'inverse',  
182                 color => "#993333" &>
183 <table border="0">
184 <tr><td align="right"><&|/l&>Priority</&>:</td><td><input size="3" name="InitialPriority" value="<% $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority %>" /></td></tr>
185 <tr><td align="right"><&|/l&>Final Priority</&>:</td><td><input size="3" name="FinalPriority" value="<% $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority %>" /></td></tr>
186 <tr><td align="right"><&|/l&>Time Estimated</&>:</td>
187 <td>
188 <input size="3" name="TimeEstimated" value="<%$ARGS{TimeEstimated}%>" />
189 <& /Elements/SelectTimeUnits, Name =>'TimeEstimated' &>
190
191 </td></tr>
192 <tr><td align="right"><&|/l&>Time Worked</&>:</td>
193 <td>
194 <input size="3" name="TimeWorked" value="<%$ARGS{TimeWorked}%>" />
195 <& /Elements/SelectTimeUnits, Name =>'TimeWorked' &>
196
197 </td></tr>
198 <tr>
199 <td align="right"><&|/l&>Time Left</&>:</td>
200 <td><input size="3" name="TimeLeft" value="<%$ARGS{TimeLeft}%>" />
201 <& /Elements/SelectTimeUnits, Name =>'TimeLeft' &>
202 </td></tr>
203 </table>
204 </&>
205 <br />
206 <&|/Widgets/TitleBox, title => loc("Dates"),
207                 title_class=> 'inverse',  
208                  color => "#663366" &>
209
210 <table>
211 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
212 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
213 </table>
214 </&>
215 <br />
216 </td>
217
218 <td valign="top">
219 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
220
221 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
222 <table border="0">
223 <tr><td align="right"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} %>" /></td></tr>
224 <tr><td align="right"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} %>" /></td></tr>
225 <tr><td align="right"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} %>" /></td></tr>
226 <tr><td align="right"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} %>" /></td></tr>
227 <tr><td align="right"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} %>" /></td></tr>
228 <tr><td align="right"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} %>" /></td></tr>
229
230
231 </table>
232 </&>
233 <br />
234
235 </td>
236 </tr>
237 </table>
238 <& /Elements/Submit, Label => loc("Create") &>
239 </div>
240 </form>
241
242 <%INIT>
243
244 my $CloneTicketObj;
245 if ( $CloneTicket ) {
246     $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
247     $CloneTicketObj->Load($CloneTicket) or Abort(loc("Ticket could not be loaded"));
248     
249     my $clone = {
250         Requestors       => join( ',', $CloneTicketObj->RequestorAddresses ),
251         Cc               => join( ',', $CloneTicketObj->CcAddresses),
252         AdminCc          => join( ',', $CloneTicketObj->AdminCcAddresses),
253         InitialPriority => $CloneTicketObj->Priority, 
254     };
255     
256     $clone->{$_} = $CloneTicketObj->$_() 
257         for qw/Owner Subject FinalPriority TimeEstimated TimeWorked 
258                 Status TimeLeft Starts Started Due Resolved/;
259     
260         my $members = $CloneTicketObj->Members;
261         my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
262         while ( my $member = $members->Next ) {
263             push @members, $member->LocalBase;
264         }
265         $clone->{'MemberOf-new'} = join ' ', @members;
266     
267         my $members_of = $CloneTicketObj->MemberOf;
268         while ( my $member_of = $members_of->Next ) {
269             push @members_of, $member_of->LocalTarget;
270         }
271         $clone->{'new-MemberOf'} = join ' ', @members_of;
272         
273         my $refers = $CloneTicketObj->RefersTo;
274         while ( my $refer = $refers->Next ) {
275             push @refers, $refer->LocalTarget;
276         }
277         $clone->{'new-RefersTo'} = join ' ', @refers;
278     
279         my $refers_by = $CloneTicketObj->ReferredToBy;
280         while ( my $refer_by = $refers_by->Next ) {
281             push @refers_by, $refer_by->LocalBase;
282         }
283         $clone->{'RefersTo-new'} = join ' ', @refers_by;
284     
285         my $depends = $CloneTicketObj->DependsOn;
286         while ( my $depend = $depends->Next ) {
287             push @depends, $depend->LocalTarget;
288         }
289         $clone->{'new-DependsOn'} = join ' ', @depends;
290     
291         my $depends_by = $CloneTicketObj->DependedOnBy;
292         while ( my $depend_by = $depends_by->Next ) {
293             push @depends_by, $depend_by->LocalBase;
294         }
295         $clone->{'DependsOn-new'} = join ' ', @depends_by;
296     
297     
298     
299     my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
300     while ( my $cf = $cfs->Next ) {
301         my $cf_id = $cf->id;
302         my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
303         my @cf_values;
304         while ( my $cf_value = $cf_values->Next ) {
305             push @cf_values, $cf_value->Content;
306         }
307         $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} 
308             = join "\n", @cf_values;
309     }
310     
311     for ( keys %$clone ) {
312         $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
313     }
314
315 }
316
317 my @results;
318 my $QueueObj = new RT::Queue($session{'CurrentUser'});
319 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
320 my $CFs = $QueueObj->TicketCustomFields();
321 my $TxnCFs = $QueueObj->TicketTransactionCustomFields();
322
323 my $ValidCFs = $m->comp(
324     '/Elements/ValidateCustomFields',
325     CustomFields => $CFs,
326     ARGSRef => \%ARGS
327 );
328
329 # if no due date has been set explicitly, then use the
330 # queue's default if it exists
331 if ($QueueObj->DefaultDueIn && !$ARGS{'Due'}) {
332     my $default_due = RT::Date->new($session{'CurrentUser'});
333     $default_due->SetToNow();
334     $default_due->AddDays($QueueObj->DefaultDueIn);
335     $ARGS{'Due'} = $default_due->ISO();
336 }
337
338 # {{{ deal with deleting uploaded attachments
339 foreach my $key (keys %ARGS) {
340     if ($key =~ m/^DeleteAttach-(.+)$/) {
341         delete $session{'Attachments'}{$1};
342     }
343     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
344 }
345
346 # {{{ store the uploaded attachment in session
347 if ($ARGS{'Attach'}) {                  # attachment?
348     $session{'Attachments'} = {} unless defined $session{'Attachments'};
349
350     my $subject = "$ARGS{'Attach'}";
351
352     # strip leading directories
353     $subject =~ s#^.*[\\/]##;
354
355     my $attachment = MakeMIMEEntity(
356         Subject             => $subject,
357         Body                => "",
358         AttachmentFieldName => 'Attach'
359     );
360
361     $session{'Attachments'} = { %{$session{'Attachments'} || {}},
362                                 $ARGS{'Attach'} => $attachment };
363 }
364 # }}}
365
366 # delete temporary storage entry to make WebUI clean
367 unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
368     delete $session{'Attachments'};
369 }
370
371
372 # }}}
373
374 if ((!exists $ARGS{'AddMoreAttach'}) and ($ARGS{'id'} eq 'new')) { # new ticket?
375     if ($ValidCFs) {
376         $m->comp('Display.html', %ARGS);
377         $RT::Logger->crit("After display call; error is $@");
378         $m->abort();
379     }
380     else {
381         # Invalid CFs
382         while (my $CF = $CFs->Next) {
383             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
384             push @results, $CF->Name . ': ' . $msg;
385         }
386     }
387 }
388
389 my $actions = {
390     A => {
391         html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Show basics') . q[</a>],
392     },
393     B => {
394         html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Show details') . q[</a>],
395     },
396 };
397 </%INIT>
398
399 <%ARGS>
400 $DependsOn => undef
401 $DependedOnBy => undef
402 $MemberOf => undef
403 $QuoteTransaction => undef
404 $Queue => undef
405 $CloneTicket => undef
406 </%ARGS>