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 %# Currently, bulk update always starts with Comment not Reply selected, so we check this unconditionally
167 % my $IncludeSignature = RT->Config->Get('MessageBoxIncludeSignatureOnComment');
168 <& /Elements/MessageBox, Name => "UpdateContent", IncludeSignature => $IncludeSignature &>
175 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
176 $cfs->LimitToGlobal();
177 $cfs->LimitToQueue($_) for keys %$seen_queues;
181 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
184 <th><&|/l&>Name</&></th>
185 <th><&|/l&>Add values</&></th>
186 <th><&|/l&>Delete values</&></th>
188 % while (my $cf = $cfs->Next()) {
190 <td class="label"><% loc($cf->Name) %><br />
191 <em>(<%$cf->FriendlyType%>)</em></td>
193 % my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows, Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25);
194 % my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf, Rows => $rows, Multiple => 1, Cols => 25);
195 % if ($cf->Type eq 'Select') {
196 <td><& /Elements/EditCustomFieldSelect, @add &></td>
197 <td><& /Elements/EditCustomFieldSelect, @del &></td>
198 % } elsif ($cf->Type eq 'Combobox') {
199 <td><& /Elements/EditCustomFieldCombobox, @add &></td>
200 <td><& /Elements/EditCustomFieldCombobox, @del &></td>
201 % } elsif ($cf->Type eq 'Freeform') {
202 <td><& /Elements/EditCustomFieldFreeform, @add &></td>
203 <td><& /Elements/EditCustomFieldFreeform, @del &></td>
204 % } elsif ($cf->Type eq 'Text') {
205 <td><& /Elements/EditCustomFieldText, @add &></td>
208 % $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
216 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
217 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
218 <& /Ticket/Elements/BulkLinks, Tickets => $Tickets &>
221 <& /Elements/Submit, Label => loc('Update') &>
228 unless ( defined $Rows ) {
229 $Rows = $RowsPerPage;
230 $ARGS{Rows} = $RowsPerPage;
232 my $title = loc("Update multiple tickets");
234 # Iterate through the ARGS hash and remove anything with a null value.
235 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
239 # {{{ deal with deleting uploaded attachments
240 foreach my $key (keys %ARGS) {
241 if ($key =~ m/^DeleteAttach-(.+)$/) {
242 delete $session{'Attachments'}{$1};
244 $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
248 # {{{ store the uploaded attachment in session
249 if ($ARGS{'Attach'}) { # attachment?
250 my $attachment = MakeMIMEEntity(
251 AttachmentFieldName => 'Attach'
254 my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
255 $session{'Attachments'} = {
256 %{$session{'Attachments'} || {}},
257 $file_path => $attachment,
262 # delete temporary storage entry to make WebUI clean
263 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
264 delete $session{'Attachments'};
270 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
272 # inject _CHECKBOX to the first field.
273 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;
275 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
276 $Tickets->FromSQL($Query);
277 if ( $OrderBy =~ /\|/ ) {
280 my @OrderBy = split /\|/, $OrderBy;
281 my @Order = split /\|/, $Order;
282 $Tickets->OrderByCols(
283 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
284 ( 0 .. $#OrderBy ) );
287 $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
290 $Tickets->RowsPerPage($Rows) if ($Rows);
291 $Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
293 Abort( loc("No search to operate on.") ) unless ($Tickets);
295 # build up a list of all custom fields for tickets that we're displaying, so
296 # we can display sane edit widgets.
299 my $seen_queues = {};
300 while ( my $ticket = $Tickets->Next ) {
301 next if $seen_queues->{ $ticket->Queue }++;
303 my $custom_fields = $ticket->CustomFields;
304 while ( my $field = $custom_fields->Next ) {
305 $fields->{ $field->id } = $field;
309 #Iterate through each ticket we've been handed
313 $Tickets->RedoSearch();
315 # pull out the labels for any custom fields we want to update
318 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
320 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
322 unless ( $ARGS{'AddMoreAttach'} ) {
323 # Add session attachments if any to be processed by ProcessUpdateMessage
324 $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
326 while ( my $Ticket = $Tickets->Next ) {
327 next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
330 $ARGS{'id'} = $Ticket->id;
331 $queues{ $Ticket->QueueObj->Id }++;
333 my @updateresults = ProcessUpdateMessage(
334 TicketObj => $Ticket,
340 ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
342 ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
346 ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
348 foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
349 $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
350 $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
353 ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
354 foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
355 delete $ARGS{ $type . "-" . $Ticket->id };
356 delete $ARGS{ $Ticket->id . "-" . $type };
361 foreach my $list ( $cf_add_keys, $cf_del_keys ) {
362 next unless $list->[0];
366 if ( $list->[0] =~ /Add/ ) {
370 elsif ( $list->[0] =~ /Del/ ) {
375 "Got an op that was neither add nor delete. can never happen"
380 foreach my $key (@$list) {
382 next if $key =~ /CustomField-(\d+)-Category$/;
383 if ( $key =~ /CustomField-(\d+)-/ ) {
385 $cf = RT::CustomField->new( $session{'CurrentUser'} );
390 ref( $ARGS{$key} ) eq 'ARRAY'
393 map { s/(\r\n|\r)/\n/g; } @values; # fix the newlines
394 # now break the multiline values into multivalues
395 @values = map { split( /\n/, $_ ) } @values
396 unless ( $cf->SingleValue );
398 my $current_values = $Ticket->CustomFieldValues($cfid);
399 foreach my $value (@values) {
400 if ( $op eq 'del' && $current_values->HasEntry($value) ) {
401 my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
405 push @cfresults, $msg;
408 elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
409 my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
413 push @cfresults, $msg;
419 @watchresults, @basicresults, @dateresults,
420 @updateresults, @linkresults, @cfresults
424 map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
426 @results = ( @results, @tempresults );
430 delete $session{'Attachments'};
433 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
434 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
435 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );
442 $RowsPerPage => undef
446 $SavedSearchId => undef
447 $SavedChartSearchId => undef