This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / rt / share / html / Search / Bulk.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, Title => $title &>
49 <& /Ticket/Elements/Tabs, 
50     current_tab => "Search/Bulk.html",
51     Title => $title,
52     Format => $ARGS{'Format'}, # we don't want the locally modified one
53     Query => $Query,
54     Rows => $Rows,
55     OrderBy => $OrderBy,
56     Order => $Order,
57     SavedSearchId => $SavedSearchId,
58     SavedChartSearchId => $SavedChartSearchId,
59     &>
60
61 <& /Elements/ListActions, actions => \@results &>
62 <form method="post" action="<% RT->Config->Get('WebPath') %>/Search/Bulk.html" enctype="multipart/form-data">
63 % foreach my $var qw(Query Format OrderBy Order Rows Page SavedChartSearchId) {
64 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var} || ''%>" />
65 %}
66 <& /Elements/CollectionList, 
67     Query => $Query,
68     DisplayFormat => $Format,
69     Format => $ARGS{'Format'},
70     Verbatim => 1,
71     AllowSorting => 1,
72     OrderBy => $OrderBy,
73     Order => $Order,
74     Rows => $Rows,
75     Page => $Page,
76     BaseURL => RT->Config->Get('WebPath')."/Search/Bulk.html?",
77     Class => 'RT::Tickets'
78    &>
79
80 % $m->callback(CallbackName => 'AfterTicketList', ARGSRef => \%ARGS);
81
82 <hr />
83
84 <& /Elements/Submit, Label => loc('Update'), CheckAll => 1, ClearAll => 1 &>
85 <br />
86 <&|/Widgets/TitleBox, title => $title &>
87 <table>
88 <tr>
89 <td valign="top">
90 <table>
91 <tr><td class="label"> <&|/l&>Make Owner</&>: </td>
92 <td class="value"> <& /Elements/SelectOwner, Name => "Owner" &> (<input type="checkbox" class="checkbox" name="ForceOwnerChange" /> <&|/l&>Force change</&>) </td></tr>
93 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
94 <td class="value"> <input name="AddRequestor" size="20" /> </td></tr>
95 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
96 <td class="value"> <input name="DeleteRequestor" size="20" /> </td></tr>
97 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
98 <td class="value"> <input name="AddCc" size="20" /> </td></tr>
99 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
100 <td class="value"> <input name="DeleteCc" size="20" /> </td></tr>
101 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
102 <td class="value"> <input name="AddAdminCc" size="20" /> </td></tr>
103 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
104 <td class="value"> <input name="DeleteAdminCc" size="20" /> </td></tr>
105 </table>
106 </td>
107 <td valign="top">
108 <table>
109 <tr><td class="label"> <&|/l&>Make subject</&>: </td>
110 <td class="value"> <input name="Subject" size="20" /> </td></tr>
111 <tr><td class="label"> <&|/l&>Make priority</&>: </td>
112 <td class="value"> <& /Elements/SelectPriority, Name => "Priority" &> </td></tr>
113 <tr><td class="label"> <&|/l&>Make queue</&>: </td>
114 <td class="value"> <& /Elements/SelectQueue, Name => "Queue" &> </td></tr>
115 <tr><td class="label"> <&|/l&>Make Status</&>: </td>
116 <td class="value"> <& /Elements/SelectStatus, Name => "Status" &> </td></tr>
117 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
118 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", ShowTime => 0, Default => '' &> </td></tr>
119 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
120 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", ShowTime => 0, Default => '' &> </td></tr>
121 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
122 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", ShowTime => 0, Default => '' &> </td></tr>
123 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
124 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", ShowTime => 0, Default => '' &> </td></tr>
125 <tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
126 <td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", ShowTime => 0, Default => '' &> </td></tr>
127 </table>
128
129 </td>
130 </tr>
131 </table>
132 </&>
133 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
134 <table>
135 <tr><td align="right"><&|/l&>Update Type</&>:</td>
136 <td><select name="UpdateType">
137   <option value="private" ><&|/l&>Comments (not sent to requestors)</&></option>
138 <option value="response" ><&|/l&>Reply to requestors</&></option>
139 </select> 
140 </td></tr>
141 <tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="" /></td></tr>
142 % while (my $CF = $TxnCFs->Next()) {
143 <tr>
144 <td align="right"><% $CF->Name %>:</td>
145 <td><& /Elements/EditCustomField, 
146     CustomField => $CF, 
147     NamePrefix => "Object-RT::Transaction--CustomField-"
148     &><em><% $CF->FriendlyType %></em></td>
149 </td></tr>
150 % } # end if while
151 % if (exists $session{'Attachments'}) {
152 <tr><td><&|/l&>Attached file</&>:</td>
153 <td>
154 <&|/l&>Check box to delete</&><br />
155 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
156 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
157 % } # end of foreach
158 </td>
159 </tr>
160 % } # end of if
161
162  <tr><td align="right"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" />
163     <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
164     <input type="hidden" class="hidden" name="UpdateAttach" value="1" /></td></tr>
165  <tr><td class="labeltop"><&|/l&>Message</&>:</td><td>
166  <& /Elements/MessageBox, Name=>"UpdateContent"&>
167  </td></tr>
168  </table>
169
170 </&>
171
172 <%perl>
173 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
174 $cfs->LimitToGlobal();
175 $cfs->LimitToQueue($_) for keys %$seen_queues;
176 </%perl>
177
178 % if ($cfs->Count) {
179 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
180 <table>
181 <tr>
182 <th><&|/l&>Name</&></th>
183 <th><&|/l&>Add values</&></th>
184 <th><&|/l&>Delete values</&></th>
185 </tr>
186 % while (my $cf = $cfs->Next()) {
187 <tr>
188 <td class="label"><% loc($cf->Name) %><br />
189 <em>(<%$cf->FriendlyType%>)</em></td>
190 % my $rows = 5;
191 % my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows, Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25);
192 % my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf, Rows => $rows, Multiple => 1, Cols => 25);
193 % if ($cf->Type eq 'Select') {
194 <td><& /Elements/EditCustomFieldSelect, @add &></td>
195 <td><& /Elements/EditCustomFieldSelect, @del &></td>
196 % } elsif ($cf->Type eq 'Combobox') {
197 <td><& /Elements/EditCustomFieldCombobox, @add &></td>
198 <td><& /Elements/EditCustomFieldCombobox, @del &></td>
199 % } elsif ($cf->Type eq 'Freeform') {
200 <td><& /Elements/EditCustomFieldFreeform, @add &></td>
201 <td><& /Elements/EditCustomFieldFreeform, @del &></td>
202 % } elsif ($cf->Type eq 'Text') {
203 <td><& /Elements/EditCustomFieldText, @add &></td>
204 <td>&nbsp;</td>
205 % } else {
206 %   $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
207 % }
208 </tr>
209 % }
210 </table>
211 </&>
212 % }
213
214 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
215 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
216 <& /Ticket/Elements/BulkLinks, Tickets => $Tickets &>
217 </&>
218
219 <& /Elements/Submit, Label => loc('Update') &>
220
221
222 </form>
223
224
225 <%INIT>
226 unless ( defined $Rows ) {
227     $Rows = $RowsPerPage;
228     $ARGS{Rows} = $RowsPerPage;
229 }
230 my $title = loc("Update multiple tickets");
231
232 # Iterate through the ARGS hash and remove anything with a null value.
233 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
234
235 my (@results);
236
237 # {{{ deal with deleting uploaded attachments
238 foreach my $key (keys %ARGS) {
239     if ($key =~ m/^DeleteAttach-(.+)$/) {
240         delete $session{'Attachments'}{$1};
241     }
242     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
243 }
244 # }}}
245
246 # {{{ store the uploaded attachment in session
247 if ($ARGS{'Attach'}) {            # attachment?
248     my $attachment = MakeMIMEEntity(
249         AttachmentFieldName => 'Attach'
250     );
251
252     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
253     $session{'Attachments'} = {
254         %{$session{'Attachments'} || {}},
255         $file_path => $attachment,
256     };
257 }
258 # }}}
259
260 # delete temporary storage entry to make WebUI clean
261 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
262     delete $session{'Attachments'};
263 }
264 # }}}
265
266 $Page ||= 1;
267
268 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
269
270 # inject _CHECKBOX to the first field.
271 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;
272
273 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
274 $Tickets->FromSQL($Query);
275 if ( $OrderBy =~ /\|/ ) {
276
277   # Multiple Sorts
278   my @OrderBy = split /\|/, $OrderBy;
279   my @Order   = split /\|/, $Order;
280   $Tickets->OrderByCols(
281     map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
282       ( 0 .. $#OrderBy ) );
283 }
284 else {
285   $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
286 }
287
288 $Tickets->RowsPerPage($Rows) if ($Rows);
289 $Tickets->GotoPage( $Page - 1 );    # SB uses page 0 as the first page
290
291 Abort( loc("No search to operate on.") ) unless ($Tickets);
292
293 # build up a list of all custom fields for tickets that we're displaying, so
294 # we can display sane edit widgets.
295
296 my $fields      = {};
297 my $seen_queues = {};
298 while ( my $ticket = $Tickets->Next ) {
299     next if $seen_queues->{ $ticket->Queue }++;
300
301     my $custom_fields = $ticket->CustomFields;
302     while ( my $field = $custom_fields->Next ) {
303         $fields->{ $field->id } = $field;
304     }
305 }
306
307 #Iterate through each ticket we've been handed
308 my @linkresults;
309 my %queues;
310
311 $Tickets->RedoSearch();
312
313 # pull out the labels for any custom fields we want to update
314
315 my $cf_del_keys;
316 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
317 my $cf_add_keys;
318 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
319
320 unless ( $ARGS{'AddMoreAttach'} ) {
321     # Add session attachments if any to be processed by ProcessUpdateMessage
322     $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
323
324     while ( my $Ticket = $Tickets->Next ) {
325         next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
326
327         #Update the links
328         $ARGS{'id'} = $Ticket->id;
329         $queues{ $Ticket->QueueObj->Id }++;
330
331         my @updateresults = ProcessUpdateMessage(
332                 TicketObj => $Ticket,
333                 ARGSRef   => \%ARGS,
334             );
335
336         #Update the basics.
337         my @basicresults =
338           ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
339         my @dateresults =
340           ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
341
342         #Update the watchers
343         my @watchresults =
344           ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
345
346         foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
347             $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
348             $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
349         }
350         @linkresults =
351           ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
352         foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
353             delete $ARGS{ $type . "-" . $Ticket->id };
354             delete $ARGS{ $Ticket->id . "-" . $type };
355         }
356
357         my @cfresults;
358
359         foreach my $list ( $cf_add_keys, $cf_del_keys ) {
360             next unless $list->[0];
361
362
363             my $op;
364             if ( $list->[0] =~ /Add/ ) {
365                 $op = 'add';
366
367             }
368             elsif ( $list->[0] =~ /Del/ ) {
369                 $op = 'del';
370             }
371             else {
372                 $RT::Logger->crit(
373                     "Got an op that was neither add nor delete. can never happen"
374                       . $list->[0] );
375                 last;
376             }
377
378             foreach my $key (@$list) {
379                 my ( $cfid, $cf );
380                 next if $key =~ /CustomField-(\d+)-Category$/;
381                 if ( $key =~ /CustomField-(\d+)-/ ) {
382                     $cfid = $1;
383                     $cf   = RT::CustomField->new( $session{'CurrentUser'} );
384                     $cf->Load($cfid);
385                 }
386                 else {next}
387                 my @values =
388                   ref( $ARGS{$key} ) eq 'ARRAY'
389                   ? @{ $ARGS{$key} }
390                   : ( $ARGS{$key} );
391                 map { s/(\r\n|\r)/\n/g; } @values;    # fix the newlines
392                      # now break the multiline values into multivalues
393                 @values = map { split( /\n/, $_ ) } @values
394                   unless ( $cf->SingleValue );
395
396                 my $current_values = $Ticket->CustomFieldValues($cfid);
397                 foreach my $value (@values) {
398                     if ( $op eq 'del' && $current_values->HasEntry($value) ) {
399                         my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
400                             Field => $cfid,
401                             Value => $value
402                         );
403                         push @cfresults, $msg;
404                     }
405
406                     elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
407                         my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
408                             Field => $cfid,
409                             Value => $value
410                         );
411                         push @cfresults, $msg;
412                     }
413                 }
414             }
415         }
416         my @tempresults = (
417             @watchresults,  @basicresults, @dateresults,
418             @updateresults, @linkresults,  @cfresults
419         );
420
421         @tempresults =
422           map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
423
424         @results = ( @results, @tempresults );
425     }
426
427     # Cleanup WebUI
428     delete $session{'Attachments'};
429 }
430
431 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
432 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
433 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );
434
435 </%INIT>
436 <%args>
437 $Format => undef
438 $Page => 1
439 $Rows => undef
440 $RowsPerPage => undef
441 $Order => 'ASC'
442 $OrderBy => 'id'
443 $Query => undef
444 $SavedSearchId => undef
445 $SavedChartSearchId => undef
446 </%args>