1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
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
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.
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.
30 %# CONTRIBUTION SUBMISSION POLICY:
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.)
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.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Elements/Header, Title => $title &>
49 <& /Ticket/Elements/Tabs,
50 current_tab => "Search/Bulk.html",
52 Format => $ARGS{'Format'}, # we don't want the locally modified one
57 SavedSearchId => $SavedSearchId,
58 SavedChartSearchId => $SavedChartSearchId,
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} || ''%>" />
66 <& /Elements/CollectionList,
68 DisplayFormat => $Format,
69 Format => $ARGS{'Format'},
76 BaseURL => RT->Config->Get('WebPath')."/Search/Bulk.html?",
77 Class => 'RT::Tickets'
80 % $m->callback(CallbackName => 'AfterTicketList', ARGSRef => \%ARGS);
84 <& /Elements/Submit, Label => loc('Update'), CheckAll => 1, ClearAll => 1 &>
86 <&|/Widgets/TitleBox, title => $title &>
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>
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>
133 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
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>
141 <tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="" /></td></tr>
142 % while (my $CF = $TxnCFs->Next()) {
144 <td align="right"><% $CF->Name %>:</td>
145 <td><& /Elements/EditCustomField,
147 NamePrefix => "Object-RT::Transaction--CustomField-"
148 &><em><% $CF->FriendlyType %></em></td>
151 % if (exists $session{'Attachments'}) {
152 <tr><td><&|/l&>Attached file</&>:</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 />
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"&>
173 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
174 $cfs->LimitToGlobal();
175 $cfs->LimitToQueue($_) for keys %$seen_queues;
179 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
182 <th><&|/l&>Name</&></th>
183 <th><&|/l&>Add values</&></th>
184 <th><&|/l&>Delete values</&></th>
186 % while (my $cf = $cfs->Next()) {
188 <td class="label"><% loc($cf->Name) %><br />
189 <em>(<%$cf->FriendlyType%>)</em></td>
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>
206 % $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
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 &>
219 <& /Elements/Submit, Label => loc('Update') &>
226 unless ( defined $Rows ) {
227 $Rows = $RowsPerPage;
228 $ARGS{Rows} = $RowsPerPage;
230 my $title = loc("Update multiple tickets");
232 # Iterate through the ARGS hash and remove anything with a null value.
233 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
237 # {{{ deal with deleting uploaded attachments
238 foreach my $key (keys %ARGS) {
239 if ($key =~ m/^DeleteAttach-(.+)$/) {
240 delete $session{'Attachments'}{$1};
242 $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
246 # {{{ store the uploaded attachment in session
247 if ($ARGS{'Attach'}) { # attachment?
248 my $attachment = MakeMIMEEntity(
249 AttachmentFieldName => 'Attach'
252 my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
253 $session{'Attachments'} = {
254 %{$session{'Attachments'} || {}},
255 $file_path => $attachment,
260 # delete temporary storage entry to make WebUI clean
261 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
262 delete $session{'Attachments'};
268 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
270 # inject _CHECKBOX to the first field.
271 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;
273 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
274 $Tickets->FromSQL($Query);
275 if ( $OrderBy =~ /\|/ ) {
278 my @OrderBy = split /\|/, $OrderBy;
279 my @Order = split /\|/, $Order;
280 $Tickets->OrderByCols(
281 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
282 ( 0 .. $#OrderBy ) );
285 $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
288 $Tickets->RowsPerPage($Rows) if ($Rows);
289 $Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
291 Abort( loc("No search to operate on.") ) unless ($Tickets);
293 # build up a list of all custom fields for tickets that we're displaying, so
294 # we can display sane edit widgets.
297 my $seen_queues = {};
298 while ( my $ticket = $Tickets->Next ) {
299 next if $seen_queues->{ $ticket->Queue }++;
301 my $custom_fields = $ticket->CustomFields;
302 while ( my $field = $custom_fields->Next ) {
303 $fields->{ $field->id } = $field;
307 #Iterate through each ticket we've been handed
311 $Tickets->RedoSearch();
313 # pull out the labels for any custom fields we want to update
316 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
318 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
320 unless ( $ARGS{'AddMoreAttach'} ) {
321 # Add session attachments if any to be processed by ProcessUpdateMessage
322 $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
324 while ( my $Ticket = $Tickets->Next ) {
325 next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
328 $ARGS{'id'} = $Ticket->id;
329 $queues{ $Ticket->QueueObj->Id }++;
331 my @updateresults = ProcessUpdateMessage(
332 TicketObj => $Ticket,
338 ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
340 ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
344 ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
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"};
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 };
359 foreach my $list ( $cf_add_keys, $cf_del_keys ) {
360 next unless $list->[0];
364 if ( $list->[0] =~ /Add/ ) {
368 elsif ( $list->[0] =~ /Del/ ) {
373 "Got an op that was neither add nor delete. can never happen"
378 foreach my $key (@$list) {
380 next if $key =~ /CustomField-(\d+)-Category$/;
381 if ( $key =~ /CustomField-(\d+)-/ ) {
383 $cf = RT::CustomField->new( $session{'CurrentUser'} );
388 ref( $ARGS{$key} ) eq 'ARRAY'
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 );
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(
403 push @cfresults, $msg;
406 elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
407 my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
411 push @cfresults, $msg;
417 @watchresults, @basicresults, @dateresults,
418 @updateresults, @linkresults, @cfresults
422 map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
424 @results = ( @results, @tempresults );
428 delete $session{'Attachments'};
431 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
432 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
433 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );
440 $RowsPerPage => undef
444 $SavedSearchId => undef
445 $SavedChartSearchId => undef