rt 4.0.23
[freeside.git] / rt / share / html / Search / Bulk.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
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 % 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>
109 </select>
110 </td></tr>
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>
125 </table>
126
127 </td>
128 </tr>
129 </table>
130 </&>
131 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
132 <table>
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>
137 </select> 
138 </td></tr>
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()) {
142 <tr>
143 <td align="right"><% $CF->Name %>:</td>
144 <td><& /Elements/EditCustomField, 
145     CustomField => $CF, 
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>
150 </td></tr>
151 % } # end if while
152
153 <& /Ticket/Elements/AddAttachments, %ARGS &>
154
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 ),
161         &>
162  </td></tr>
163  </table>
164
165 </&>
166
167 <%perl>
168 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
169 $cfs->LimitToGlobal();
170 $cfs->LimitToQueue($_) for keys %$seen_queues;
171 </%perl>
172
173 % if ($cfs->Count) {
174 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
175 <table>
176 <tr>
177 <th><&|/l&>Name</&></th>
178 <th><&|/l&>Add values</&></th>
179 <th><&|/l&>Delete values</&></th>
180 </tr>
181 % while (my $cf = $cfs->Next()) {
182 <tr>
183 <td class="label"><% loc($cf->Name) %><br />
184 <em>(<%$cf->FriendlyType%>)</em></td>
185 % my $rows = 5;
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>
204 <td>&nbsp;</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>
212 % } else {
213 %   $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
214 % }
215 </tr>
216 % }
217 </table>
218 </&>
219 % }
220
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 : () &>
224 </&>
225
226 <& /Elements/Submit, Label => loc('Update') &>
227
228
229 </form>
230
231
232 <%INIT>
233 unless ( defined $Rows ) {
234     $Rows = $RowsPerPage;
235     $ARGS{Rows} = $RowsPerPage;
236 }
237 my $title = loc("Update multiple tickets");
238
239 # Iterate through the ARGS hash and remove anything with a null value.
240 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
241
242 my (@results);
243
244 ProcessAttachments(ARGSRef => \%ARGS);
245
246 $Page ||= 1;
247
248 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
249
250 # inject _CHECKBOX to the first field.
251 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;      #'
252
253 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
254 $Tickets->FromSQL($Query);
255 if ( $OrderBy =~ /\|/ ) {
256
257   # Multiple Sorts
258   my @OrderBy = split /\|/, $OrderBy;
259   my @Order   = split /\|/, $Order;
260   $Tickets->OrderByCols(
261     map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
262       ( 0 .. $#OrderBy ) );
263 }
264 else {
265   $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
266 }
267
268 $Tickets->RowsPerPage($Rows) if ($Rows);
269 $Tickets->GotoPage( $Page - 1 );    # SB uses page 0 as the first page
270
271 Abort( loc("No search to operate on.") ) unless ($Tickets);
272
273 # build up a list of all custom fields for tickets that we're displaying, so
274 # we can display sane edit widgets.
275
276 my $fields      = {};
277 my $seen_queues = {};
278 while ( my $ticket = $Tickets->Next ) {
279     next if $seen_queues->{ $ticket->Queue }++;
280
281     my $custom_fields = $ticket->CustomFields;
282     while ( my $field = $custom_fields->Next ) {
283         $fields->{ $field->id } = $field;
284     }
285 }
286
287 #Iterate through each ticket we've been handed
288 my @linkresults;
289
290 $Tickets->RedoSearch();
291
292 # pull out the labels for any custom fields we want to update
293
294 my $cf_del_keys;
295 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
296 my $cf_add_keys;
297 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
298
299 if ( defined($ARGS{'Priority'})
300      and ($ARGS{'Priority-Mode'} || '') eq 'relative' ) {
301     # magic in Ticket::SetPriority
302     $ARGS{'Priority'} = 'R'.$ARGS{'Priority'};
303 }
304 delete $ARGS{'Priority-Mode'};
305
306 unless ( $ARGS{'AddMoreAttach'} ) {
307     # Add session attachments if any to be processed by ProcessUpdateMessage
308     $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
309
310     while ( my $Ticket = $Tickets->Next ) {
311         next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
312
313         #Update the links
314         $ARGS{'id'} = $Ticket->id;
315
316         my @updateresults = ProcessUpdateMessage(
317                 TicketObj => $Ticket,
318                 ARGSRef   => \%ARGS,
319             );
320
321         #Update the basics.
322         my @basicresults =
323           ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
324         my @dateresults =
325           ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
326
327         #Update the watchers
328         my @watchresults =
329           ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
330
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"};
334         }
335         @linkresults =
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 };
340         }
341
342         my @cfresults;
343
344         foreach my $list ( $cf_add_keys, $cf_del_keys ) {
345             next unless $list->[0];
346
347
348             my $op;
349             if ( $list->[0] =~ /Add/ ) {
350                 $op = 'add';
351
352             }
353             elsif ( $list->[0] =~ /Del/ ) {
354                 $op = 'del';
355             }
356             else {
357                 $RT::Logger->crit(
358                     "Got an op that was neither add nor delete. can never happen"
359                       . $list->[0] );
360                 last;
361             }
362
363             foreach my $key (@$list) {
364                 my ( $cfid, $cf );
365                 next if $key =~ /CustomField-(\d+)-Category$/;
366                 if ( $key =~ /CustomField-(\d+)-/ ) {
367                     $cfid = $1;
368                     $cf   = RT::CustomField->new( $session{'CurrentUser'} );
369                     $cf->Load($cfid);
370                 }
371                 else {next}
372                 my @values =
373                   ref( $ARGS{$key} ) eq 'ARRAY'
374                   ? @{ $ARGS{$key} }
375                   : ( $ARGS{$key} );
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 );
380
381                 my $current_values = $Ticket->CustomFieldValues($cfid);
382
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;
387                 }
388
389                 foreach my $value (@values) {
390
391                     if ( $op eq 'del' ) {
392                         if ( my $entry = $current_values->HasEntry($value) ) {
393                             my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
394                                 Field => $cfid,
395                                 ValueId => $entry->id,
396                             );
397                             push @cfresults, $msg;
398                         }
399                     }
400
401                     elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
402                         my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
403                             Field => $cfid,
404                             Value => $value
405                         );
406                         push @cfresults, $msg;
407                     }
408                 }
409             }
410         }
411         my @statusresults =
412           ProcessTicketStatus( TicketObj => $Ticket, ARGSRef => \%ARGS );
413
414           my @tempresults = (
415             @watchresults,  @basicresults, @dateresults,
416             @updateresults, @linkresults,  @cfresults,
417             @statusresults
418         );
419
420         @tempresults =
421           map { 
422               $_ =~ /^Ticket \d+:/ ?  $_ : 
423               loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) 
424             } @tempresults;
425
426         @results = ( @results, @tempresults );
427     }
428
429     # Cleanup WebUI
430     delete $session{'Attachments'};
431
432     $Tickets->RedoSearch();
433 }
434
435 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
436 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
437 $TxnCFs->LimitToGlobalOrObjectId( keys %$seen_queues );
438
439 </%INIT>
440 <%args>
441 $Format => undef
442 $Page => 1
443 $Rows => undef
444 $RowsPerPage => undef
445 $Order => 'ASC'
446 $OrderBy => 'id'
447 $Query => undef
448 $SavedSearchId => undef
449 $SavedChartSearchId => undef
450 </%args>