]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | %# BEGIN BPS TAGGED BLOCK {{{ |
2 | %# | |
3 | %# COPYRIGHT: | |
4 | %# | |
5 | %# This software is Copyright (c) 1996-2012 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} &> </td></tr> | |
109 | <tr><td class="label"> <&|/l&>Make date Starts</&>: </td> | |
110 | <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", ShowTime => 0, 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", ShowTime => 0, 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", ShowTime => 0, Default => $ARGS{Tole_Date} || '' &> </td></tr> | |
115 | <tr><td class="label"> <&|/l&>Make date Due</&>: </td> | |
116 | <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", ShowTime => 0, 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", ShowTime => 0, 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> </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 | # deal with deleting uploaded attachments | |
232 | foreach my $key (keys %ARGS) { | |
233 | if ($key =~ m/^DeleteAttach-(.+)$/) { | |
234 | delete $session{'Attachments'}{$1}; | |
235 | } | |
236 | $session{'Attachments'} = { %{$session{'Attachments'} || {}} }; | |
237 | } | |
238 | ||
239 | # store the uploaded attachment in session | |
240 | if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment? | |
241 | my $attachment = MakeMIMEEntity( | |
242 | AttachmentFieldName => 'Attach' | |
243 | ); | |
244 | ||
245 | my $file_path = Encode::decode_utf8("$ARGS{'Attach'}"); | |
246 | $session{'Attachments'} = { | |
247 | %{$session{'Attachments'} || {}}, | |
248 | $file_path => $attachment, | |
249 | }; | |
250 | } | |
251 | ||
252 | # delete temporary storage entry to make WebUI clean | |
253 | unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) { | |
254 | delete $session{'Attachments'}; | |
255 | } | |
256 | ||
257 | $Page ||= 1; | |
258 | ||
259 | $Format ||= RT->Config->Get('DefaultSearchResultFormat'); | |
260 | ||
261 | # inject _CHECKBOX to the first field. | |
262 | $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/; | |
263 | ||
264 | my $Tickets = RT::Tickets->new( $session{'CurrentUser'} ); | |
265 | $Tickets->FromSQL($Query); | |
266 | if ( $OrderBy =~ /\|/ ) { | |
267 | ||
268 | # Multiple Sorts | |
269 | my @OrderBy = split /\|/, $OrderBy; | |
270 | my @Order = split /\|/, $Order; | |
271 | $Tickets->OrderByCols( | |
272 | map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } | |
273 | ( 0 .. $#OrderBy ) ); | |
274 | } | |
275 | else { | |
276 | $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order ); | |
277 | } | |
278 | ||
279 | $Tickets->RowsPerPage($Rows) if ($Rows); | |
280 | $Tickets->GotoPage( $Page - 1 ); # SB uses page 0 as the first page | |
281 | ||
282 | Abort( loc("No search to operate on.") ) unless ($Tickets); | |
283 | ||
284 | # build up a list of all custom fields for tickets that we're displaying, so | |
285 | # we can display sane edit widgets. | |
286 | ||
287 | my $fields = {}; | |
288 | my $seen_queues = {}; | |
289 | while ( my $ticket = $Tickets->Next ) { | |
290 | next if $seen_queues->{ $ticket->Queue }++; | |
291 | ||
292 | my $custom_fields = $ticket->CustomFields; | |
293 | while ( my $field = $custom_fields->Next ) { | |
294 | $fields->{ $field->id } = $field; | |
295 | } | |
296 | } | |
297 | ||
298 | #Iterate through each ticket we've been handed | |
299 | my @linkresults; | |
300 | my %queues; | |
301 | ||
302 | $Tickets->RedoSearch(); | |
303 | ||
304 | # pull out the labels for any custom fields we want to update | |
305 | ||
306 | my $cf_del_keys; | |
307 | @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS; | |
308 | my $cf_add_keys; | |
309 | @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS; | |
310 | ||
311 | unless ( $ARGS{'AddMoreAttach'} ) { | |
312 | # Add session attachments if any to be processed by ProcessUpdateMessage | |
313 | $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} ); | |
314 | ||
315 | while ( my $Ticket = $Tickets->Next ) { | |
316 | next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } ); | |
317 | ||
318 | #Update the links | |
319 | $ARGS{'id'} = $Ticket->id; | |
320 | $queues{ $Ticket->QueueObj->Id }++; | |
321 | ||
322 | my @updateresults = ProcessUpdateMessage( | |
323 | TicketObj => $Ticket, | |
324 | ARGSRef => \%ARGS, | |
325 | ); | |
326 | ||
327 | #Update the basics. | |
328 | my @basicresults = | |
329 | ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS ); | |
330 | my @dateresults = | |
331 | ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS ); | |
332 | ||
333 | #Update the watchers | |
334 | my @watchresults = | |
335 | ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS ); | |
336 | ||
337 | foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) { | |
338 | $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"}; | |
339 | $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"}; | |
340 | } | |
341 | @linkresults = | |
342 | ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS ); | |
343 | foreach my $type (qw(MergeInto DependsOn MemberOf RefersTo)) { | |
344 | delete $ARGS{ $type . "-" . $Ticket->id }; | |
345 | delete $ARGS{ $Ticket->id . "-" . $type }; | |
346 | } | |
347 | ||
348 | my @cfresults; | |
349 | ||
350 | foreach my $list ( $cf_add_keys, $cf_del_keys ) { | |
351 | next unless $list->[0]; | |
352 | ||
353 | ||
354 | my $op; | |
355 | if ( $list->[0] =~ /Add/ ) { | |
356 | $op = 'add'; | |
357 | ||
358 | } | |
359 | elsif ( $list->[0] =~ /Del/ ) { | |
360 | $op = 'del'; | |
361 | } | |
362 | else { | |
363 | $RT::Logger->crit( | |
364 | "Got an op that was neither add nor delete. can never happen" | |
365 | . $list->[0] ); | |
366 | last; | |
367 | } | |
368 | ||
369 | foreach my $key (@$list) { | |
370 | my ( $cfid, $cf ); | |
371 | next if $key =~ /CustomField-(\d+)-Category$/; | |
372 | if ( $key =~ /CustomField-(\d+)-/ ) { | |
373 | $cfid = $1; | |
374 | $cf = RT::CustomField->new( $session{'CurrentUser'} ); | |
375 | $cf->Load($cfid); | |
376 | } | |
377 | else {next} | |
378 | my @values = | |
379 | ref( $ARGS{$key} ) eq 'ARRAY' | |
380 | ? @{ $ARGS{$key} } | |
381 | : ( $ARGS{$key} ); | |
382 | map { s/(\r\n|\r)/\n/g; } @values; # fix the newlines | |
383 | # now break the multiline values into multivalues | |
384 | @values = map { split( /\n/, $_ ) } @values | |
385 | unless ( $cf->SingleValue ); | |
386 | ||
387 | my $current_values = $Ticket->CustomFieldValues($cfid); | |
388 | foreach my $value (@values) { | |
389 | if ( $op eq 'del' && $current_values->HasEntry($value) ) { | |
390 | my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue( | |
391 | Field => $cfid, | |
392 | Value => $value | |
393 | ); | |
394 | push @cfresults, $msg; | |
395 | } | |
396 | ||
397 | elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) { | |
398 | my ( $id, $msg ) = $Ticket->AddCustomFieldValue( | |
399 | Field => $cfid, | |
400 | Value => $value | |
401 | ); | |
402 | push @cfresults, $msg; | |
403 | } | |
404 | } | |
405 | } | |
406 | } | |
407 | my @tempresults = ( | |
408 | @watchresults, @basicresults, @dateresults, | |
409 | @updateresults, @linkresults, @cfresults | |
410 | ); | |
411 | ||
412 | @tempresults = | |
413 | map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults; | |
414 | ||
415 | @results = ( @results, @tempresults ); | |
416 | } | |
417 | ||
418 | # Cleanup WebUI | |
419 | delete $session{'Attachments'}; | |
420 | } | |
421 | ||
422 | my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} ); | |
423 | $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType ); | |
424 | $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues ); | |
425 | ||
426 | </%INIT> | |
427 | <%args> | |
428 | $Format => undef | |
429 | $Page => 1 | |
430 | $Rows => undef | |
431 | $RowsPerPage => undef | |
432 | $Order => 'ASC' | |
433 | $OrderBy => 'id' | |
434 | $Query => undef | |
435 | $SavedSearchId => undef | |
436 | $SavedChartSearchId => undef | |
437 | </%args> |