1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 %# <sales@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 &>
51 <& /Elements/ListActions, actions => \@results &>
52 <form method="post" action="<% RT->Config->Get('WebPath') %>/Search/Bulk.html" enctype="multipart/form-data" name="BulkUpdate" id="BulkUpdate">
53 % foreach my $var (qw(Query Format OrderBy Order Rows Page SavedChartSearchId)) {
54 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var} || ''%>" />
56 <& /Elements/CollectionList,
58 DisplayFormat => $Format,
59 Format => $ARGS{'Format'},
66 BaseURL => RT->Config->Get('WebPath')."/Search/Bulk.html?",
67 Class => 'RT::Tickets'
70 % $m->callback(CallbackName => 'AfterTicketList', ARGSRef => \%ARGS);
74 <& /Elements/Submit, Label => loc('Update'), CheckboxNameRegex => '/^UpdateTicket\d+$/', CheckAll => 1, ClearAll => 1 &>
76 <&|/Widgets/TitleBox, title => $title &>
81 <tr><td class="label"> <&|/l&>Make Owner</&>: </td>
82 <td class="value"> <& /Elements/SelectOwner, Name => "Owner", Default => $ARGS{Owner} || '' &>
83 (<input type="checkbox" class="checkbox" name="ForceOwnerChange"
84 <% $ARGS{ForceOwnerChange} ? 'checked="checked"' : '' %> /> <&|/l&>Force change</&>) </td></tr>
85 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
86 <td class="value"> <input name="AddRequestor" size="20" value="<% $ARGS{AddRequestor} || '' %>" /> </td></tr>
87 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
88 <td class="value"> <input name="DeleteRequestor" size="20" value="<% $ARGS{DeleteRequestor} || '' %>"/> </td></tr>
89 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
90 <td class="value"> <input name="AddCc" size="20" value="<% $ARGS{AddCc} || '' %>" /> </td></tr>
91 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
92 <td class="value"> <input name="DeleteCc" size="20" value="<% $ARGS{DeleteCc} || '' %>" /> </td></tr>
93 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
94 <td class="value"> <input name="AddAdminCc" size="20" value="<% $ARGS{AddAdminCc} || '' %>" /> </td></tr>
95 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
96 <td class="value"> <input name="DeleteAdminCc" size="20" value="<% $ARGS{DeleteAdminCc} || '' %>" /> </td></tr>
101 <tr><td class="label"> <&|/l&>Make subject</&>: </td>
102 <td class="value"> <input name="Subject" size="20" value="<% $ARGS{Subject} || '' %>"/> </td></tr>
103 <tr><td class="label"> <&|/l&>Make priority</&>: </td>
104 % my $rel = ($ARGS{Priority} =~ s/^R//);
105 <td class="value"> <& /Elements/SelectPriority, Name => "Priority", Default => $ARGS{Priority} &>
106 <select name="Priority-Mode">
107 <option value="absolute" <% !$rel && 'selected' %>>absolute</option>
108 <option value="relative" <% $rel && 'selected' %>>relative</option>
111 <tr><td class="label"> <&|/l&>Make queue</&>: </td>
112 <td class="value"> <& /Elements/SelectQueue, Name => "Queue", Default => $ARGS{Queue} &> </td></tr>
113 <tr><td class="label"> <&|/l&>Make Status</&>: </td>
114 <td class="value"> <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}, Queues => $seen_queues &> </td></tr>
115 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
116 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", Default => $ARGS{Starts_Date} || '' &> </td></tr>
117 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
118 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", Default => $ARGS{Started_Date} || '' &> </td></tr>
119 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
120 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", Default => $ARGS{Told_Date} || '' &> </td></tr>
121 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
122 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", Default => $ARGS{Due_Date} || '' &> </td></tr>
123 <tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
124 <td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", Default => $ARGS{Resolved_Date} || '' &> </td></tr>
131 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
133 <tr><td align="right"><&|/l&>Update Type</&>:</td>
134 <td><select name="UpdateType">
135 <option value="private" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'private' ? 'selected="selected"' : '' %> ><&|/l&>Comments (Not sent to requestors)</&></option>
136 <option value="response" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'response' ? 'selected="selected"' : '' %>><&|/l&>Reply to requestors</&></option>
139 <tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject"
140 size="60" value="<% $ARGS{UpdateSubject} || "" %>" /></td></tr>
141 % while (my $CF = $TxnCFs->Next()) {
143 <td align="right"><% $CF->Name %>:</td>
144 <td><& /Elements/EditCustomField,
146 NamePrefix => "Object-RT::Transaction--CustomField-",
147 Default => $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Values'} ||
148 $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Value'},
149 &><em><% $CF->FriendlyType %></em></td>
153 <& /Ticket/Elements/AddAttachments, %ARGS &>
155 <tr><td class="labeltop"><&|/l&>Message</&>:</td><td>
156 %# Currently, bulk update always starts with Comment not Reply selected, so we check this unconditionally
157 % my $IncludeSignature = RT->Config->Get('MessageBoxIncludeSignatureOnComment');
158 <& /Elements/MessageBox, Name => "UpdateContent",
159 $ARGS{UpdateContent} ? ( Default => $ARGS{UpdateContent}, IncludeSignature => 0 ) :
160 ( IncludeSignature => $IncludeSignature ),
168 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
169 $cfs->LimitToGlobal();
170 $cfs->LimitToQueue($_) for keys %$seen_queues;
174 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
177 <th><&|/l&>Name</&></th>
178 <th><&|/l&>Add values</&></th>
179 <th><&|/l&>Delete values</&></th>
181 % while (my $cf = $cfs->Next()) {
183 <td class="label"><% loc($cf->Name) %><br />
184 <em>(<%$cf->FriendlyType%>)</em></td>
186 % my $cf_id = $cf->id;
187 % my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows,
188 % Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25,
189 % Default => $ARGS{"Bulk-Add-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Add-CustomField-$cf_id-Value"}, );
190 % my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf,
191 % Rows => $rows, Multiple => 1, Cols => 25,
192 % Default => $ARGS{"Bulk-Delete-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Delete-CustomField-$cf_id-Value"}, );
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>
205 % } elsif ($cf->Type eq 'Date') {
206 <td><& /Elements/EditCustomFieldDate, @add, Default => undef &></td>
207 <td><& /Elements/EditCustomFieldDate, @del, Default => undef &></td>
208 % } elsif ($cf->Type eq 'DateTime') {
209 % # Pass datemanip format to prevent another tz date conversion
210 <td><& /Elements/EditCustomFieldDateTime, @add, Default => undef, Format => 'datemanip' &></td>
211 <td><& /Elements/EditCustomFieldDateTime, @del, Default => undef, Format => 'datemanip' &></td>
213 % $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
221 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
222 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
223 <& /Ticket/Elements/BulkLinks, Tickets => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
226 <& /Elements/Submit, Label => loc('Update') &>
233 unless ( defined $Rows ) {
234 $Rows = $RowsPerPage;
235 $ARGS{Rows} = $RowsPerPage;
237 my $title = loc("Update multiple tickets");
239 # Iterate through the ARGS hash and remove anything with a null value.
240 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
244 ProcessAttachments(ARGSRef => \%ARGS);
248 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
250 # inject _CHECKBOX to the first field.
251 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/; #'
253 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
254 $Tickets->FromSQL($Query);
255 if ( $OrderBy =~ /\|/ ) {
258 my @OrderBy = split /\|/, $OrderBy;
259 my @Order = split /\|/, $Order;
260 $Tickets->OrderByCols(
261 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
262 ( 0 .. $#OrderBy ) );
265 $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
268 $Tickets->RowsPerPage($Rows) if ($Rows);
269 $Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
271 Abort( loc("No search to operate on.") ) unless ($Tickets);
273 # build up a list of all custom fields for tickets that we're displaying, so
274 # we can display sane edit widgets.
277 my $seen_queues = {};
278 while ( my $ticket = $Tickets->Next ) {
279 next if $seen_queues->{ $ticket->Queue }++;
281 my $custom_fields = $ticket->CustomFields;
282 while ( my $field = $custom_fields->Next ) {
283 $fields->{ $field->id } = $field;
287 #Iterate through each ticket we've been handed
290 $Tickets->RedoSearch();
292 # pull out the labels for any custom fields we want to update
295 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
297 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
299 if ( defined($ARGS{'Priority'})
300 and ($ARGS{'Priority-Mode'} || '') eq 'relative' ) {
301 # magic in Ticket::SetPriority
302 $ARGS{'Priority'} = 'R'.$ARGS{'Priority'};
304 delete $ARGS{'Priority-Mode'};
306 unless ( $ARGS{'AddMoreAttach'} ) {
307 # Add session attachments if any to be processed by ProcessUpdateMessage
308 $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
310 while ( my $Ticket = $Tickets->Next ) {
311 next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
314 $ARGS{'id'} = $Ticket->id;
316 my @updateresults = ProcessUpdateMessage(
317 TicketObj => $Ticket,
323 ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
325 ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
329 ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
331 foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) {
332 $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
333 $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
336 ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
337 foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) {
338 delete $ARGS{ $type . "-" . $Ticket->id };
339 delete $ARGS{ $Ticket->id . "-" . $type };
344 foreach my $list ( $cf_add_keys, $cf_del_keys ) {
345 next unless $list->[0];
349 if ( $list->[0] =~ /Add/ ) {
353 elsif ( $list->[0] =~ /Del/ ) {
358 "Got an op that was neither add nor delete. can never happen"
363 foreach my $key (@$list) {
365 next if $key =~ /CustomField-(\d+)-Category$/;
366 if ( $key =~ /CustomField-(\d+)-/ ) {
368 $cf = RT::CustomField->new( $session{'CurrentUser'} );
373 ref( $ARGS{$key} ) eq 'ARRAY'
376 map { s/(\r\n|\r)/\n/g; } @values; # fix the newlines
377 # now break the multiline values into multivalues
378 @values = map { split( /\n/, $_ ) } @values
379 unless ( $cf->SingleValue );
381 my $current_values = $Ticket->CustomFieldValues($cfid);
383 if ( $cf->Type eq 'DateTime' || $cf->Type eq 'Date' ){
384 # Clear out empty string submissions to avoid
385 # Not set changed to Not set
386 @values = grep length, @values;
389 foreach my $value (@values) {
391 if ( $op eq 'del' ) {
392 if ( my $entry = $current_values->HasEntry($value) ) {
393 my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
395 ValueId => $entry->id,
397 push @cfresults, $msg;
401 elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
402 my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
406 push @cfresults, $msg;
412 ProcessTicketStatus( TicketObj => $Ticket, ARGSRef => \%ARGS );
415 @watchresults, @basicresults, @dateresults,
416 @updateresults, @linkresults, @cfresults,
422 $_ =~ /^Ticket \d+:/ ? $_ :
423 loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ )
426 @results = ( @results, @tempresults );
430 delete $session{'Attachments'};
432 $Tickets->RedoSearch();
435 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
436 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
437 $TxnCFs->LimitToGlobalOrObjectId( keys %$seen_queues );
444 $RowsPerPage => undef
448 $SavedSearchId => undef
449 $SavedChartSearchId => undef