]> git.uio.no Git - usit-rt.git/blob - share/html/Search/Bulk.html
Upgrade to 4.0.13
[usit-rt.git] / share / html / Search / Bulk.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2013 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 <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>
108 <td class="value"> <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}, Queues => $seen_queues &> </td></tr>
109 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
110 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", Default => $ARGS{Starts_Date} || '' &> </td></tr>
111 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
112 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", Default => $ARGS{Started_Date} || '' &> </td></tr>
113 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
114 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", Default => $ARGS{Told_Date} || '' &> </td></tr>
115 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
116 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", Default => $ARGS{Due_Date} || '' &> </td></tr>
117 <tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
118 <td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", Default => $ARGS{Resolved_Date} || '' &> </td></tr>
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"
134 size="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>
162 my $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>
220 unless ( defined $Rows ) {
221     $Rows = $RowsPerPage;
222     $ARGS{Rows} = $RowsPerPage;
223 }
224 my $title = loc("Update multiple tickets");
225
226 # Iterate through the ARGS hash and remove anything with a null value.
227 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
228
229 my (@results);
230
231 ProcessAttachments(ARGSRef => \%ARGS);
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
240 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
241 $Tickets->FromSQL($Query);
242 if ( $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 }
251 else {
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
258 Abort( 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
263 my $fields      = {};
264 my $seen_queues = {};
265 while ( 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
275 my @linkresults;
276 my %queues;
277
278 $Tickets->RedoSearch();
279
280 # pull out the labels for any custom fields we want to update
281
282 my $cf_del_keys;
283 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
284 my $cf_add_keys;
285 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
286
287 unless ( $ARGS{'AddMoreAttach'} ) {
288     # Add session attachments if any to be processed by ProcessUpdateMessage
289     $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
290
291     while ( my $Ticket = $Tickets->Next ) {
292         next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
293
294         #Update the links
295         $ARGS{'id'} = $Ticket->id;
296         $queues{ $Ticket->QueueObj->Id }++;
297
298         my @updateresults = ProcessUpdateMessage(
299                 TicketObj => $Ticket,
300                 ARGSRef   => \%ARGS,
301             );
302
303         #Update the basics.
304         my @basicresults =
305           ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
306         my @dateresults =
307           ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
308
309         #Update the watchers
310         my @watchresults =
311           ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
312
313         foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) {
314             $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
315             $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
316         }
317         @linkresults =
318           ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
319         foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) {
320             delete $ARGS{ $type . "-" . $Ticket->id };
321             delete $ARGS{ $Ticket->id . "-" . $type };
322         }
323
324         my @cfresults;
325
326         foreach my $list ( $cf_add_keys, $cf_del_keys ) {
327             next unless $list->[0];
328
329
330             my $op;
331             if ( $list->[0] =~ /Add/ ) {
332                 $op = 'add';
333
334             }
335             elsif ( $list->[0] =~ /Del/ ) {
336                 $op = 'del';
337             }
338             else {
339                 $RT::Logger->crit(
340                     "Got an op that was neither add nor delete. can never happen"
341                       . $list->[0] );
342                 last;
343             }
344
345             foreach my $key (@$list) {
346                 my ( $cfid, $cf );
347                 next if $key =~ /CustomField-(\d+)-Category$/;
348                 if ( $key =~ /CustomField-(\d+)-/ ) {
349                     $cfid = $1;
350                     $cf   = RT::CustomField->new( $session{'CurrentUser'} );
351                     $cf->Load($cfid);
352                 }
353                 else {next}
354                 my @values =
355                   ref( $ARGS{$key} ) eq 'ARRAY'
356                   ? @{ $ARGS{$key} }
357                   : ( $ARGS{$key} );
358                 map { s/(\r\n|\r)/\n/g; } @values;    # fix the newlines
359                      # now break the multiline values into multivalues
360                 @values = map { split( /\n/, $_ ) } @values
361                   unless ( $cf->SingleValue );
362
363                 my $current_values = $Ticket->CustomFieldValues($cfid);
364                 foreach my $value (@values) {
365                     if ( $op eq 'del' && $current_values->HasEntry($value) ) {
366                         my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
367                             Field => $cfid,
368                             Value => $value
369                         );
370                         push @cfresults, $msg;
371                     }
372
373                     elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
374                         my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
375                             Field => $cfid,
376                             Value => $value
377                         );
378                         push @cfresults, $msg;
379                     }
380                 }
381             }
382         }
383         my @tempresults = (
384             @watchresults,  @basicresults, @dateresults,
385             @updateresults, @linkresults,  @cfresults
386         );
387
388         @tempresults =
389           map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
390
391         @results = ( @results, @tempresults );
392     }
393
394     # Cleanup WebUI
395     delete $session{'Attachments'};
396 }
397
398 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
399 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
400 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );
401
402 </%INIT>
403 <%args>
404 $Format => undef
405 $Page => 1
406 $Rows => undef
407 $RowsPerPage => undef
408 $Order => 'ASC'
409 $OrderBy => 'id'
410 $Query => undef
411 $SavedSearchId => undef
412 $SavedChartSearchId => undef
413 </%args>