1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2007 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/copyleft/gpl.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
58 <& /Elements/ListActions, actions => \@results &>
59 <form method="post" action="<%$RT::WebPath%>/Search/Bulk.html" enctype="multipart/form-data">
60 % foreach my $var qw(Query Format OrderBy Order Rows Page) {
61 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var}%>" />
63 <& /Elements/TicketList, Query => $Query,
64 DisplayFormat => $Format,
65 Format => $ARGS{'Format'},
72 BaseURL => $RT::WebPath."/Search/Bulk.html?"
77 <& /Elements/Submit, Label => loc('Update'), CheckAll => 1, ClearAll => 1 &>
79 <&|/Widgets/TitleBox, title => $title &>
84 <tr><td class="label"> <&|/l&>Make Owner</&>: </td>
85 <td class="value"> <& /Elements/SelectOwner, Name => "Owner" &> (<input type="checkbox" class="checkbox" name="ForceOwnerChange" /> <&|/l&>Force change</&>) </td></tr>
86 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
87 <td class="value"> <input name="AddRequestor" size="20" /> </td></tr>
88 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
89 <td class="value"> <input name="DeleteRequestor" size="20" /> </td></tr>
90 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
91 <td class="value"> <input name="AddCc" size="20" /> </td></tr>
92 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
93 <td class="value"> <input name="DeleteCc" size="20" /> </td></tr>
94 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
95 <td class="value"> <input name="AddAdminCc" size="20" /> </td></tr>
96 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
97 <td class="value"> <input name="DeleteAdminCc" size="20" /> </td></tr>
102 <tr><td class="label"> <&|/l&>Make subject</&>: </td>
103 <td class="value"> <input name="Subject" size="20" /> </td></tr>
104 <tr><td class="label"> <&|/l&>Make priority</&>: </td>
105 <td class="value"> <input name="Priority" size="4" /> </td></tr>
106 <tr><td class="label"> <&|/l&>Make queue</&>: </td>
107 <td class="value"> <& /Elements/SelectQueue, Name => "Queue" &> </td></tr>
108 <tr><td class="label"> <&|/l&>Make Status</&>: </td>
109 <td class="value"> <& /Elements/SelectStatus, Name => "Status" &> </td></tr>
110 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
111 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", ShowTime => 0, Default => '' &> </td></tr>
112 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
113 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", ShowTime => 0, Default => '' &> </td></tr>
114 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
115 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", ShowTime => 0, Default => '' &> </td></tr>
116 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
117 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", ShowTime => 0, Default => '' &> </td></tr>
118 <tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
119 <td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", ShowTime => 0, Default => '' &> </td></tr>
126 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
128 <tr><td align="right"><&|/l&>Update Type</&>:</td>
129 <td><select name="UpdateType">
130 <option value="private" ><&|/l&>Comments (not sent to requestors)</&></option>
131 <option value="response" ><&|/l&>Reply to requestors</&></option>
134 <tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="" /></td></tr>
135 % while (my $CF = $TxnCFs->Next()) {
137 <td align="right"><% $CF->Name %>:</td>
138 <td><& /Elements/EditCustomField,
140 NamePrefix => "Object-RT::Transaction--CustomField-"
141 &><em><% $CF->FriendlyType %></em></td>
144 <tr><td align="right"><&|/l&>Attach</&>:</td><td><input name="UpdateAttachment" type="file" /></td></tr>
145 <tr><td class="labeltop"><&|/l&>Message</&>:</td><td>
146 <& /Elements/MessageBox, Name=>"UpdateContent"&>
151 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
153 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
154 $cfs->LimitToGlobal();
155 $cfs->LimitToQueue($_) for keys %$seen_queues;
159 <th><&|/l&>Name</&></th>
160 <th><&|/l&>Add values</&></th>
161 <th><&|/l&>Delete values</&></th>
163 % while (my $cf = $cfs->Next()) {
165 <td class="label"><%$cf->Name%><br />
166 <em>(<%$cf->FriendlyType%>)</em></td>
168 % my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows, Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25);
169 % my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf, Rows => $rows, Multiple => 1, Cols => 25);
170 % if ($cf->Type eq 'Select') {
171 <td><& /Elements/EditCustomFieldSelect, @add &></td>
172 <td><& /Elements/EditCustomFieldSelect, @del &></td>
173 % } elsif ($cf->Type eq 'Combobox') {
174 <td><& /Elements/EditCustomFieldCombobox, @add &></td>
175 <td><& /Elements/EditCustomFieldCombobox, @del &></td>
176 % } elsif ($cf->Type eq 'Freeform') {
177 <td><& /Elements/EditCustomFieldFreeform, @add &></td>
178 <td><& /Elements/EditCustomFieldFreeform, @del &></td>
179 % } elsif ($cf->Type eq 'Text') {
180 <td><& /Elements/EditCustomFieldText, @add &></td>
183 % $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
190 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
191 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
192 <& /Ticket/Elements/BulkLinks &>
195 <& /Elements/Submit, Label => loc('Update') &>
202 my $title = loc("Update multiple tickets");
204 # Iterate through the ARGS hash and remove anything with a null value.
205 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
211 $Format ||= $RT::DefaultSearchResultFormat;
213 # inject _CHECKBOX to the first field.
214 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;
216 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
217 $Tickets->FromSQL($Query);
218 if ( $OrderBy =~ /\|/ ) {
221 my @OrderBy = split /\|/, $OrderBy;
222 my @Order = split /\|/, $Order;
223 $Tickets->OrderByCols(
224 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
225 ( 0 .. $#OrderBy ) );
228 $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
231 $Tickets->RowsPerPage($Rows) if ($Rows);
232 $Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
234 Abort( loc("No search to operate on.") ) unless ($Tickets);
236 # build up a list of all custom fields for tickets that we're displaying, so
237 # we can display sane edit widgets.
240 my $seen_queues = {};
241 while ( my $ticket = $Tickets->Next ) {
242 next if $seen_queues->{ $ticket->Queue }++;
244 my $custom_fields = $ticket->QueueObj->TicketCustomFields;
245 while ( my $field = $custom_fields->Next ) {
246 $fields->{ $field->id } = $field;
250 my $do_comment_reply = 0;
252 # Prepare for ticket updates
253 if ($ARGS{'UpdateContent'}) {
254 $ARGS{'UpdateContent'} =~ s/\r\n/\n/g;
255 chomp( $ARGS{'UpdateContent'} );
257 if ($ARGS{'UpdateContent'} ne ''
258 && $ARGS{'UpdateContent'} ne "-- \n"
259 . $session{'CurrentUser'}->UserObj->Signature ) {
260 $do_comment_reply = 1;
264 #Iterate through each ticket we've been handed
268 $Tickets->RedoSearch();
270 # pull out the labels for any custom fields we want to update
273 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
275 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
278 while ( my $Ticket = $Tickets->Next ) {
279 next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
282 $ARGS{'id'} = $Ticket->id;
283 $queues{ $Ticket->QueueObj->Id }++;
286 if ($do_comment_reply) {
287 ProcessUpdateMessage(
288 TicketObj => $Ticket,
290 Actions => \@updateresults
296 ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
298 ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
302 ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
304 foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
305 $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
306 $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
309 ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
310 foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
311 delete $ARGS{ $type . "-" . $Ticket->id };
312 delete $ARGS{ $Ticket->id . "-" . $type };
317 foreach my $list ( $cf_add_keys, $cf_del_keys ) {
318 next unless $list->[0];
322 if ( $list->[0] =~ /Add/ ) {
326 elsif ( $list->[0] =~ /Del/ ) {
331 "Got an op that was neither add nor delete. can never happen"
336 foreach my $key (@$list) {
338 if ( $key =~ /CustomField-(\d+)-/ ) {
340 $cf = RT::CustomField->new( $session{'CurrentUser'} );
345 ref( $ARGS{$key} ) eq 'ARRAY'
348 map { s/(\r\n|\r)/\n/g; } @values; # fix the newlines
349 # now break the multiline values into multivalues
350 @values = map { split( /\n/, $_ ) } @values
351 unless ( $cf->SingleValue );
353 my $current_values = $Ticket->CustomFieldValues($cfid);
354 foreach my $value (@values) {
355 if ( $op eq 'del' && $current_values->HasEntry($value) ) {
356 my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
360 push @cfresults, $msg;
363 elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
364 my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
368 push @cfresults, $msg;
374 @watchresults, @basicresults, @dateresults,
375 @updateresults, @linkresults, @cfresults
379 map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
381 @results = ( @results, @tempresults );
384 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
385 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
386 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );