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 SavedSearchId SavedChartSearchId Token)) {
54 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var} || ''%>" />
56 <& /Elements/CollectionList,
58 DisplayFormat => $DisplayFormat,
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(All)?$/', 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 <label>(<input type="checkbox" class="checkbox" name="ForceOwnerChange"
84 <% $ARGS{ForceOwnerChange} ? 'checked="checked"' : '' %> /> <&|/l&>Force change</&>)</label></td></tr>
85 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
86 <td class="value"> <& /Elements/EmailInput, Name => "AddRequestor", Size=> 20, Default => $ARGS{AddRequestor} &> </td></tr>
87 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
88 <td class="value"> <& /Elements/EmailInput, Name => "DeleteRequestor", Size=> 20, Default => $ARGS{DeleteRequestor} &> </td></tr>
89 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
90 <td class="value"> <& /Elements/EmailInput, Name => "AddCc", Size=> 20, Default => $ARGS{AddCc} &> </td></tr>
91 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
92 <td class="value"> <& /Elements/EmailInput, Name => "DeleteCc", Size=> 20, Default => $ARGS{DeleteCc} &> </td></tr>
93 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
94 <td class="value"> <& /Elements/EmailInput, Name => "AddAdminCc", Size=> 20, Default => $ARGS{AddAdminCc} &> </td></tr>
95 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
96 <td class="value"> <& /Elements/EmailInput, Name => "DeleteAdminCc", Size=> 20, Default => $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"> <& /Ticket/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>
129 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
131 <tr><td align="right"><&|/l&>Update Type</&>:</td>
132 <td><select name="UpdateType" id="UpdateType">
133 <option value="private" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'private' ? 'selected="selected"' : '' %> ><&|/l&>Comments (Not sent to requestors)</&></option>
134 <option value="response" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'response' ? 'selected="selected"' : '' %>><&|/l&>Reply to requestors</&></option>
138 <td align="right"><&|/l&>Subject</&>:</td>
140 <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || "" %>" />
141 % $m->callback( %ARGS, CallbackName => 'AfterUpdateSubject' );
144 % $m->callback( CallbackName => 'BeforeTransactionCustomFields', CustomFields => $TxnCFs );
145 % while (my $CF = $TxnCFs->Next()) {
147 <td align="right"><% $CF->Name %>:</td>
148 <td><& /Elements/EditCustomField,
150 Object => RT::Transaction->new( $session{'CurrentUser'} ),
151 &><em><% $CF->FriendlyType %></em></td>
155 <& /Ticket/Elements/AddAttachments, %ARGS &>
157 <tr><td class="labeltop"><&|/l&>Message</&>:</td>
158 <td class="messagebox-container action-<% $ARGS{UpdateType} || 'private' %>">
159 % $m->callback( %ARGS, CallbackName => 'BeforeMessageBox' );
160 %# Currently, bulk update always starts with Comment not Reply selected, so we check this unconditionally
161 % my $IncludeSignature = RT->Config->Get('MessageBoxIncludeSignatureOnComment');
162 <& /Elements/MessageBox, Name => "UpdateContent",
163 $ARGS{UpdateContent} ? ( Default => $ARGS{UpdateContent}, IncludeSignature => 0 ) :
164 ( IncludeSignature => $IncludeSignature ),
172 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
173 $cfs->LimitToGlobal();
174 $cfs->LimitToQueue($_) for keys %$seen_queues;
175 $cfs->SetContextObject( values %$seen_queues ) if keys %$seen_queues == 1;
178 % if ( $cfs->Count ) {
179 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields') &>
180 <& /Elements/BulkCustomFields, $ARGS{'AddMoreAttach'} ? %ARGS : (), CustomFields => $cfs &>
184 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
185 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
186 <& /Elements/BulkLinks, Collection => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
189 <&| /Widgets/TitleBox, title => loc('Merge'), color => '#336633' &>
190 <& /Ticket/Elements/EditMerge, Tickets => $Tickets, %ARGS &>
193 <& /Elements/Submit, Label => loc('Update') &>
200 unless ( defined $Rows ) {
201 $Rows = $RowsPerPage;
202 $ARGS{Rows} = $RowsPerPage;
204 my $title = loc("Update multiple tickets");
206 # Iterate through the ARGS hash and remove anything with a null value.
207 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
211 ProcessAttachments(ARGSRef => \%ARGS);
215 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
217 # inject _CHECKBOX to the first field.
218 my $DisplayFormat = "'__CheckBox.{UpdateTicket}__',". $Format;
219 $DisplayFormat =~ s/\s*,\s*('?__NEWLINE__'?)/,$1,''/gi;
221 $DECODED_ARGS->{'UpdateTicketAll'} = 1 unless @UpdateTicket;
223 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
224 $Tickets->FromSQL($Query);
225 if ( $OrderBy =~ /\|/ ) {
228 my @OrderBy = split /\|/, $OrderBy;
229 my @Order = split /\|/, $Order;
230 $Tickets->OrderByCols(
231 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
232 ( 0 .. $#OrderBy ) );
235 $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
238 $Tickets->RowsPerPage($Rows) if ($Rows);
239 $Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
241 Abort( loc("No search to operate on.") ) unless ($Tickets);
243 # build up a list of all custom fields for tickets that we're displaying, so
244 # we can display sane edit widgets.
247 my $seen_queues = {};
248 while ( my $ticket = $Tickets->Next ) {
249 next if $seen_queues->{ $ticket->Queue };
250 $seen_queues->{ $ticket->Queue } ||= $ticket->QueueObj;
252 my $custom_fields = $ticket->CustomFields;
253 while ( my $field = $custom_fields->Next ) {
254 $fields->{ $field->id } = $field;
258 #Iterate through each ticket we've been handed
261 $Tickets->RedoSearch();
263 if ( defined($ARGS{'Priority'})
264 and ($ARGS{'Priority-Mode'} || '') eq 'relative' ) {
265 # magic in Ticket::SetPriority
266 $ARGS{'Priority'} = 'R'.$ARGS{'Priority'};
268 delete $ARGS{'Priority-Mode'};
270 unless ( $ARGS{'AddMoreAttach'} ) {
272 while ( my $Ticket = $Tickets->Next ) {
273 my $tid = $Ticket->id;
274 next unless grep $tid == $_, @UpdateTicket;
277 $ARGS{'id'} = $Ticket->id;
279 my @updateresults = ProcessUpdateMessage(
280 TicketObj => $Ticket,
282 KeepAttachments => 1,
287 ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
289 ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
293 ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
296 ProcessTicketLinks( TicketObj => $Ticket, TicketId => 'Ticket', ARGSRef => \%ARGS );
298 my @cfresults = ProcessRecordBulkCustomFields( RecordObj => $Ticket, ARGSRef => \%ARGS );
301 ProcessTicketStatus( TicketObj => $Ticket, ARGSRef => \%ARGS );
304 @watchresults, @basicresults, @dateresults,
305 @updateresults, @linkresults, @cfresults,
311 $_ =~ /^Ticket \d+:/ ? $_ :
312 loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ )
315 @results = ( @results, @tempresults );
318 delete $session{'Attachments'}{ $ARGS{'Token'} };
320 $Tickets->RedoSearch();
323 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
324 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
325 $TxnCFs->LimitToGlobalOrObjectId( keys %$seen_queues );
326 $TxnCFs->SetContextObject( values %$seen_queues ) if keys %$seen_queues == 1;
333 $RowsPerPage => undef