Upgrade 4.0.17 clean.
[usit-rt.git] / share / html / Search / Bulk.html
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
403d7b0b 5%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
84fb5b46
MKG
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
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
16%# from www.gnu.org.
17%#
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.
22%#
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.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
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.)
37%#
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.
46%#
47%# END BPS TAGGED BLOCK }}}
48<& /Elements/Header, Title => $title &>
49<& /Elements/Tabs &>
50
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} || ''%>" />
55%}
56<& /Elements/CollectionList,
57 Query => $Query,
58 DisplayFormat => $Format,
59 Format => $ARGS{'Format'},
60 Verbatim => 1,
61 AllowSorting => 1,
62 OrderBy => $OrderBy,
63 Order => $Order,
64 Rows => $Rows,
65 Page => $Page,
66 BaseURL => RT->Config->Get('WebPath')."/Search/Bulk.html?",
67 Class => 'RT::Tickets'
68 &>
69
70% $m->callback(CallbackName => 'AfterTicketList', ARGSRef => \%ARGS);
71
72<hr />
73
74<& /Elements/Submit, Label => loc('Update'), CheckboxNameRegex => '/^UpdateTicket\d+$/', CheckAll => 1, ClearAll => 1 &>
75<br />
76<&|/Widgets/TitleBox, title => $title &>
77<table>
78<tr>
79<td valign="top">
80<table>
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>
97</table>
98</td>
99<td valign="top">
100<table>
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<td class="value"> <& /Elements/SelectPriority, Name => "Priority", Default => $ARGS{Priority} &> </td></tr>
105<tr><td class="label"> <&|/l&>Make queue</&>: </td>
106<td class="value"> <& /Elements/SelectQueue, Name => "Queue", Default => $ARGS{Queue} &> </td></tr>
107<tr><td class="label"> <&|/l&>Make Status</&>: </td>
403d7b0b 108<td class="value"> <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}, Queues => $seen_queues &> </td></tr>
84fb5b46 109<tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
403d7b0b 110<td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", Default => $ARGS{Starts_Date} || '' &> </td></tr>
84fb5b46 111<tr><td class="label"> <&|/l&>Make date Started</&>: </td>
403d7b0b 112<td class="value"> <& /Elements/SelectDate, Name => "Started_Date", Default => $ARGS{Started_Date} || '' &> </td></tr>
84fb5b46 113<tr><td class="label"> <&|/l&>Make date Told</&>: </td>
403d7b0b 114<td class="value"> <& /Elements/SelectDate, Name => "Told_Date", Default => $ARGS{Told_Date} || '' &> </td></tr>
84fb5b46 115<tr><td class="label"> <&|/l&>Make date Due</&>: </td>
403d7b0b 116<td class="value"> <& /Elements/SelectDate, Name => "Due_Date", Default => $ARGS{Due_Date} || '' &> </td></tr>
84fb5b46 117<tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
403d7b0b 118<td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", Default => $ARGS{Resolved_Date} || '' &> </td></tr>
84fb5b46
MKG
119</table>
120
121</td>
122</tr>
123</table>
124</&>
125<&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
126<table>
127<tr><td align="right"><&|/l&>Update Type</&>:</td>
128<td><select name="UpdateType">
129 <option value="private" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'private' ? 'selected="selected"' : '' %> ><&|/l&>Comments (Not sent to requestors)</&></option>
130<option value="response" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'response' ? 'selected="selected"' : '' %>><&|/l&>Reply to requestors</&></option>
131</select>
132</td></tr>
133<tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject"
134size="60" value="<% $ARGS{UpdateSubject} || "" %>" /></td></tr>
135% while (my $CF = $TxnCFs->Next()) {
136<tr>
137<td align="right"><% $CF->Name %>:</td>
138<td><& /Elements/EditCustomField,
139 CustomField => $CF,
140 NamePrefix => "Object-RT::Transaction--CustomField-",
141 Default => $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Values'} ||
142 $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Value'},
143 &><em><% $CF->FriendlyType %></em></td>
144</td></tr>
145% } # end if while
146
147<& /Ticket/Elements/AddAttachments, %ARGS &>
148
149 <tr><td class="labeltop"><&|/l&>Message</&>:</td><td>
150%# Currently, bulk update always starts with Comment not Reply selected, so we check this unconditionally
151% my $IncludeSignature = RT->Config->Get('MessageBoxIncludeSignatureOnComment');
152<& /Elements/MessageBox, Name => "UpdateContent",
153 $ARGS{UpdateContent} ? ( Default => $ARGS{UpdateContent}, IncludeSignature => 0 ) :
154 ( IncludeSignature => $IncludeSignature ),
155 &>
156 </td></tr>
157 </table>
158
159</&>
160
161<%perl>
162my $cfs = RT::CustomFields->new($session{'CurrentUser'});
163$cfs->LimitToGlobal();
164$cfs->LimitToQueue($_) for keys %$seen_queues;
165</%perl>
166
167% if ($cfs->Count) {
168<&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
169<table>
170<tr>
171<th><&|/l&>Name</&></th>
172<th><&|/l&>Add values</&></th>
173<th><&|/l&>Delete values</&></th>
174</tr>
175% while (my $cf = $cfs->Next()) {
176<tr>
177<td class="label"><% loc($cf->Name) %><br />
178<em>(<%$cf->FriendlyType%>)</em></td>
179% my $rows = 5;
180% my $cf_id = $cf->id;
181% my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows,
182% Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25,
183% Default => $ARGS{"Bulk-Add-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Add-CustomField-$cf_id-Value"}, );
184% my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf,
185% Rows => $rows, Multiple => 1, Cols => 25,
186% Default => $ARGS{"Bulk-Delete-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Delete-CustomField-$cf_id-Value"}, );
187% if ($cf->Type eq 'Select') {
188<td><& /Elements/EditCustomFieldSelect, @add &></td>
189<td><& /Elements/EditCustomFieldSelect, @del &></td>
190% } elsif ($cf->Type eq 'Combobox') {
191<td><& /Elements/EditCustomFieldCombobox, @add &></td>
192<td><& /Elements/EditCustomFieldCombobox, @del &></td>
193% } elsif ($cf->Type eq 'Freeform') {
194<td><& /Elements/EditCustomFieldFreeform, @add &></td>
195<td><& /Elements/EditCustomFieldFreeform, @del &></td>
196% } elsif ($cf->Type eq 'Text') {
197<td><& /Elements/EditCustomFieldText, @add &></td>
198<td>&nbsp;</td>
199% } else {
200% $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
201% }
202</tr>
203% }
204</table>
205</&>
206% }
207
208<&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
209<em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
210<& /Ticket/Elements/BulkLinks, Tickets => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
211</&>
212
213<& /Elements/Submit, Label => loc('Update') &>
214
215
216</form>
217
218
219<%INIT>
220unless ( defined $Rows ) {
221 $Rows = $RowsPerPage;
222 $ARGS{Rows} = $RowsPerPage;
223}
224my $title = loc("Update multiple tickets");
225
226# Iterate through the ARGS hash and remove anything with a null value.
227map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
228
229my (@results);
230
5b0d0914 231ProcessAttachments(ARGSRef => \%ARGS);
84fb5b46
MKG
232
233$Page ||= 1;
234
235$Format ||= RT->Config->Get('DefaultSearchResultFormat');
236
237# inject _CHECKBOX to the first field.
238$Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;
239
240my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
241$Tickets->FromSQL($Query);
242if ( $OrderBy =~ /\|/ ) {
243
244 # Multiple Sorts
245 my @OrderBy = split /\|/, $OrderBy;
246 my @Order = split /\|/, $Order;
247 $Tickets->OrderByCols(
248 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
249 ( 0 .. $#OrderBy ) );
250}
251else {
252 $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
253}
254
255$Tickets->RowsPerPage($Rows) if ($Rows);
256$Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
257
258Abort( loc("No search to operate on.") ) unless ($Tickets);
259
260# build up a list of all custom fields for tickets that we're displaying, so
261# we can display sane edit widgets.
262
263my $fields = {};
264my $seen_queues = {};
265while ( my $ticket = $Tickets->Next ) {
266 next if $seen_queues->{ $ticket->Queue }++;
267
268 my $custom_fields = $ticket->CustomFields;
269 while ( my $field = $custom_fields->Next ) {
270 $fields->{ $field->id } = $field;
271 }
272}
273
274#Iterate through each ticket we've been handed
275my @linkresults;
84fb5b46
MKG
276
277$Tickets->RedoSearch();
278
279# pull out the labels for any custom fields we want to update
280
281my $cf_del_keys;
282@$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
283my $cf_add_keys;
284@$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
285
286unless ( $ARGS{'AddMoreAttach'} ) {
287 # Add session attachments if any to be processed by ProcessUpdateMessage
288 $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
289
290 while ( my $Ticket = $Tickets->Next ) {
291 next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
292
293 #Update the links
294 $ARGS{'id'} = $Ticket->id;
84fb5b46
MKG
295
296 my @updateresults = ProcessUpdateMessage(
297 TicketObj => $Ticket,
298 ARGSRef => \%ARGS,
299 );
300
301 #Update the basics.
302 my @basicresults =
303 ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
304 my @dateresults =
305 ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
306
307 #Update the watchers
308 my @watchresults =
309 ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
310
311 foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) {
312 $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
313 $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
314 }
315 @linkresults =
316 ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
317 foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) {
318 delete $ARGS{ $type . "-" . $Ticket->id };
319 delete $ARGS{ $Ticket->id . "-" . $type };
320 }
321
322 my @cfresults;
323
324 foreach my $list ( $cf_add_keys, $cf_del_keys ) {
325 next unless $list->[0];
326
327
328 my $op;
329 if ( $list->[0] =~ /Add/ ) {
330 $op = 'add';
331
332 }
333 elsif ( $list->[0] =~ /Del/ ) {
334 $op = 'del';
335 }
336 else {
337 $RT::Logger->crit(
338 "Got an op that was neither add nor delete. can never happen"
339 . $list->[0] );
340 last;
341 }
342
343 foreach my $key (@$list) {
344 my ( $cfid, $cf );
345 next if $key =~ /CustomField-(\d+)-Category$/;
346 if ( $key =~ /CustomField-(\d+)-/ ) {
347 $cfid = $1;
348 $cf = RT::CustomField->new( $session{'CurrentUser'} );
349 $cf->Load($cfid);
350 }
351 else {next}
352 my @values =
353 ref( $ARGS{$key} ) eq 'ARRAY'
354 ? @{ $ARGS{$key} }
355 : ( $ARGS{$key} );
356 map { s/(\r\n|\r)/\n/g; } @values; # fix the newlines
357 # now break the multiline values into multivalues
358 @values = map { split( /\n/, $_ ) } @values
359 unless ( $cf->SingleValue );
360
361 my $current_values = $Ticket->CustomFieldValues($cfid);
362 foreach my $value (@values) {
363 if ( $op eq 'del' && $current_values->HasEntry($value) ) {
364 my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
365 Field => $cfid,
366 Value => $value
367 );
368 push @cfresults, $msg;
369 }
370
371 elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
372 my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
373 Field => $cfid,
374 Value => $value
375 );
376 push @cfresults, $msg;
377 }
378 }
379 }
380 }
381 my @tempresults = (
382 @watchresults, @basicresults, @dateresults,
383 @updateresults, @linkresults, @cfresults
384 );
385
386 @tempresults =
387 map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
388
389 @results = ( @results, @tempresults );
390 }
391
392 # Cleanup WebUI
393 delete $session{'Attachments'};
394}
395
396my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
397$TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
01e3b242 398$TxnCFs->LimitToGlobalOrObjectId( keys %$seen_queues );
84fb5b46
MKG
399
400</%INIT>
401<%args>
402$Format => undef
403$Page => 1
404$Rows => undef
405$RowsPerPage => undef
406$Order => 'ASC'
407$OrderBy => 'id'
408$Query => undef
409$SavedSearchId => undef
410$SavedChartSearchId => undef
411</%args>