This commit was generated by cvs2svn to compensate for changes in r12472,
[freeside.git] / rt / share / html / Search / Bulk.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2011 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 <& /Ticket/Elements/Tabs, 
50     current_tab => "Search/Bulk.html",
51     Title => $title,
52     Format => $ARGS{'Format'}, # we don't want the locally modified one
53     Query => $Query,
54     Rows => $Rows,
55     OrderBy => $OrderBy,
56     Order => $Order,
57     SavedSearchId => $SavedSearchId,
58     SavedChartSearchId => $SavedChartSearchId,
59     &>
60
61 <& /Elements/ListActions, actions => \@results &>
62 <form method="post" action="<% RT->Config->Get('WebPath') %>/Search/Bulk.html" enctype="multipart/form-data">
63 % foreach my $var qw(Query Format OrderBy Order Rows Page SavedChartSearchId) {
64 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var} || ''%>" />
65 %}
66 <& /Elements/CollectionList, 
67     Query => $Query,
68     DisplayFormat => $Format,
69     Format => $ARGS{'Format'},
70     Verbatim => 1,
71     AllowSorting => 1,
72     OrderBy => $OrderBy,
73     Order => $Order,
74     Rows => $Rows,
75     Page => $Page,
76     BaseURL => RT->Config->Get('WebPath')."/Search/Bulk.html?",
77     Class => 'RT::Tickets'
78    &>
79
80 % $m->callback(CallbackName => 'AfterTicketList', ARGSRef => \%ARGS);
81
82 <hr />
83
84 <& /Elements/Submit, Label => loc('Update'), CheckAll => 1, ClearAll => 1 &>
85 <br />
86 <&|/Widgets/TitleBox, title => $title &>
87 <table>
88 <tr>
89 <td valign="top">
90 <table>
91 <tr><td class="label"> <&|/l&>Make Owner</&>: </td>
92 <td class="value"> <& /Elements/SelectOwner, Name => "Owner", Default => $ARGS{Owner} || '' &>
93 (<input type="checkbox" class="checkbox" name="ForceOwnerChange"
94  <% $ARGS{ForceOwnerChange} ? 'checked="checked"' : '' %> /> <&|/l&>Force change</&>) </td></tr>
95 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
96 <td class="value"> <input name="AddRequestor" size="20" value="<% $ARGS{AddRequestor} || '' %>" /> </td></tr>
97 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
98 <td class="value"> <input name="DeleteRequestor" size="20" value="<% $ARGS{DeleteRequestor} || '' %>"/> </td></tr>
99 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
100 <td class="value"> <input name="AddCc" size="20" value="<% $ARGS{AddCc} || '' %>" /> </td></tr>
101 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
102 <td class="value"> <input name="DeleteCc" size="20" value="<% $ARGS{DeleteCc} || '' %>" /> </td></tr>
103 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
104 <td class="value"> <input name="AddAdminCc" size="20" value="<% $ARGS{AddAdminCc} || '' %>" /> </td></tr>
105 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
106 <td class="value"> <input name="DeleteAdminCc" size="20" value="<% $ARGS{DeleteAdminCc} || '' %>" /> </td></tr>
107 </table>
108 </td>
109 <td valign="top">
110 <table>
111 <tr><td class="label"> <&|/l&>Make subject</&>: </td>
112 <td class="value"> <input name="Subject" size="20" value="<% $ARGS{Subject} || '' %>"/> </td></tr>
113 <tr><td class="label"> <&|/l&>Make priority</&>: </td>
114 % my $rel = ($ARGS{Priority} =~ s/^R//);
115 <td class="value"> <& /Elements/SelectPriority, Name => "Priority", Default => $ARGS{Priority} &> 
116 <select name="Priority-Mode">
117 <option value="absolute" <% !$rel && 'selected' %>>absolute</option>
118 <option value="relative" <%  $rel && 'selected' %>>relative</option>
119 </select>
120 </td></tr>
121 <tr><td class="label"> <&|/l&>Make queue</&>: </td>
122 <td class="value"> <& /Elements/SelectQueue, Name => "Queue", Default => $ARGS{Queue} &> </td></tr>
123 <tr><td class="label"> <&|/l&>Make Status</&>: </td>
124 <td class="value"> <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status} &> </td></tr>
125 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
126 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", ShowTime => 0, Default => $ARGS{Starts_Date} || '' &> </td></tr>
127 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
128 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", ShowTime => 0, Default => $ARGS{Started_Date} || '' &> </td></tr>
129 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
130 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", ShowTime => 0, Default => $ARGS{Tole_Date} || '' &> </td></tr>
131 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
132 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", ShowTime => 0, Default => $ARGS{Due_Date} || '' &> </td></tr>
133 <tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
134 <td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", ShowTime => 0, Default => $ARGS{Resolved_Date} || '' &> </td></tr>
135 </table>
136
137 </td>
138 </tr>
139 </table>
140 </&>
141 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
142 <table>
143 <tr><td align="right"><&|/l&>Update Type</&>:</td>
144 <td><select name="UpdateType">
145   <option value="private" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'private' ? 'selected="selected"' : '' %> ><&|/l&>Comments (not sent to requestors)</&></option>
146 <option value="response" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'response' ? 'selected="selected"' : '' %>><&|/l&>Reply to requestors</&></option>
147 </select> 
148 </td></tr>
149 <tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject"
150 size="60" value="<% $ARGS{UpdateSubject} || "" %>" /></td></tr>
151 % while (my $CF = $TxnCFs->Next()) {
152 <tr>
153 <td align="right"><% $CF->Name %>:</td>
154 <td><& /Elements/EditCustomField, 
155     CustomField => $CF, 
156     NamePrefix => "Object-RT::Transaction--CustomField-",
157     Default => $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Values'} || 
158             $ARGS{"Object-RT::Transaction--CustomField-" . $CF->id . '-Value'},
159     &><em><% $CF->FriendlyType %></em></td>
160 </td></tr>
161 % } # end if while
162 % if (exists $session{'Attachments'}) {
163 <tr><td><&|/l&>Attached file</&>:</td>
164 <td>
165 <&|/l&>Check box to delete</&><br />
166 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
167 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
168 % } # end of foreach
169 </td>
170 </tr>
171 % } # end of if
172
173  <tr><td align="right"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" />
174     <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
175     <input type="hidden" class="hidden" name="UpdateAttach" value="1" /></td></tr>
176  <tr><td class="labeltop"><&|/l&>Message</&>:</td><td>
177 %# Currently, bulk update always starts with Comment not Reply selected, so we check this unconditionally
178 % my $IncludeSignature = RT->Config->Get('MessageBoxIncludeSignatureOnComment');
179 <& /Elements/MessageBox, Name => "UpdateContent", 
180     $ARGS{UpdateContent} ? ( Default => $ARGS{UpdateContent}, IncludeSignature => 0 ) :
181                         ( IncludeSignature => $IncludeSignature ),
182         &>
183  </td></tr>
184  </table>
185
186 </&>
187
188 <%perl>
189 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
190 $cfs->LimitToGlobal();
191 $cfs->LimitToQueue($_) for keys %$seen_queues;
192 </%perl>
193
194 % if ($cfs->Count) {
195 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
196 <table>
197 <tr>
198 <th><&|/l&>Name</&></th>
199 <th><&|/l&>Add values</&></th>
200 <th><&|/l&>Delete values</&></th>
201 </tr>
202 % while (my $cf = $cfs->Next()) {
203 <tr>
204 <td class="label"><% loc($cf->Name) %><br />
205 <em>(<%$cf->FriendlyType%>)</em></td>
206 % my $rows = 5;
207 % my $cf_id = $cf->id;
208 % my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows,
209 %   Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25, 
210 %   Default => $ARGS{"Bulk-Add-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Add-CustomField-$cf_id-Value"}, );
211 % my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf,
212 %   Rows => $rows, Multiple => 1, Cols => 25,
213 %   Default => $ARGS{"Bulk-Delete-CustomField-$cf_id-Values"} || $ARGS{"Bulk-Delete-CustomField-$cf_id-Value"}, );
214 % if ($cf->Type eq 'Select') {
215 <td><& /Elements/EditCustomFieldSelect, @add &></td>
216 <td><& /Elements/EditCustomFieldSelect, @del &></td>
217 % } elsif ($cf->Type eq 'Combobox') {
218 <td><& /Elements/EditCustomFieldCombobox, @add &></td>
219 <td><& /Elements/EditCustomFieldCombobox, @del &></td>
220 % } elsif ($cf->Type eq 'Freeform') {
221 <td><& /Elements/EditCustomFieldFreeform, @add &></td>
222 <td><& /Elements/EditCustomFieldFreeform, @del &></td>
223 % } elsif ($cf->Type eq 'Text') {
224 <td><& /Elements/EditCustomFieldText, @add &></td>
225 <td>&nbsp;</td>
226 % } else {
227 %   $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
228 % }
229 </tr>
230 % }
231 </table>
232 </&>
233 % }
234
235 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
236 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
237 <& /Ticket/Elements/BulkLinks, Tickets => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
238 </&>
239
240 <& /Elements/Submit, Label => loc('Update') &>
241
242
243 </form>
244
245
246 <%INIT>
247 unless ( defined $Rows ) {
248     $Rows = $RowsPerPage;
249     $ARGS{Rows} = $RowsPerPage;
250 }
251 my $title = loc("Update multiple tickets");
252
253 # Iterate through the ARGS hash and remove anything with a null value.
254 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
255
256 my (@results);
257
258 # {{{ deal with deleting uploaded attachments
259 foreach my $key (keys %ARGS) {
260     if ($key =~ m/^DeleteAttach-(.+)$/) {
261         delete $session{'Attachments'}{$1};
262     }
263     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
264 }
265 # }}}
266
267 # {{{ store the uploaded attachment in session
268 if ($ARGS{'Attach'}) {            # attachment?
269     my $attachment = MakeMIMEEntity(
270         AttachmentFieldName => 'Attach'
271     );
272
273     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
274     $session{'Attachments'} = {
275         %{$session{'Attachments'} || {}},
276         $file_path => $attachment,
277     };
278 }
279 # }}}
280
281 # delete temporary storage entry to make WebUI clean
282 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
283     delete $session{'Attachments'};
284 }
285 # }}}
286
287 $Page ||= 1;
288
289 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
290
291 # inject _CHECKBOX to the first field.
292 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;      #'
293
294 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
295 $Tickets->FromSQL($Query);
296 if ( $OrderBy =~ /\|/ ) {
297
298   # Multiple Sorts
299   my @OrderBy = split /\|/, $OrderBy;
300   my @Order   = split /\|/, $Order;
301   $Tickets->OrderByCols(
302     map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
303       ( 0 .. $#OrderBy ) );
304 }
305 else {
306   $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
307 }
308
309 $Tickets->RowsPerPage($Rows) if ($Rows);
310 $Tickets->GotoPage( $Page - 1 );    # SB uses page 0 as the first page
311
312 Abort( loc("No search to operate on.") ) unless ($Tickets);
313
314 # build up a list of all custom fields for tickets that we're displaying, so
315 # we can display sane edit widgets.
316
317 my $fields      = {};
318 my $seen_queues = {};
319 while ( my $ticket = $Tickets->Next ) {
320     next if $seen_queues->{ $ticket->Queue }++;
321
322     my $custom_fields = $ticket->CustomFields;
323     while ( my $field = $custom_fields->Next ) {
324         $fields->{ $field->id } = $field;
325     }
326 }
327
328 #Iterate through each ticket we've been handed
329 my @linkresults;
330 my %queues;
331
332 $Tickets->RedoSearch();
333
334 # pull out the labels for any custom fields we want to update
335
336 my $cf_del_keys;
337 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
338 my $cf_add_keys;
339 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
340
341 if ( defined($ARGS{'Priority'})
342      and ($ARGS{'Priority-Mode'} || '') eq 'relative' ) {
343     # magic in Ticket::SetPriority
344     $ARGS{'Priority'} = 'R'.$ARGS{'Priority'};
345 }
346 delete $ARGS{'Priority-Mode'};
347
348 unless ( $ARGS{'AddMoreAttach'} ) {
349     # Add session attachments if any to be processed by ProcessUpdateMessage
350     $ARGS{'UpdateAttachments'} = $session{'Attachments'} if ( $session{'Attachments'} );
351
352     while ( my $Ticket = $Tickets->Next ) {
353         next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
354
355         #Update the links
356         $ARGS{'id'} = $Ticket->id;
357         $queues{ $Ticket->QueueObj->Id }++;
358
359         my @updateresults = ProcessUpdateMessage(
360                 TicketObj => $Ticket,
361                 ARGSRef   => \%ARGS,
362             );
363
364         #Update the basics.
365         my @basicresults =
366           ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
367         my @dateresults =
368           ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
369
370         #Update the watchers
371         my @watchresults =
372           ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
373
374         foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
375             $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
376             $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
377         }
378         @linkresults =
379           ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
380         foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
381             delete $ARGS{ $type . "-" . $Ticket->id };
382             delete $ARGS{ $Ticket->id . "-" . $type };
383         }
384
385         my @cfresults;
386
387         foreach my $list ( $cf_add_keys, $cf_del_keys ) {
388             next unless $list->[0];
389
390
391             my $op;
392             if ( $list->[0] =~ /Add/ ) {
393                 $op = 'add';
394
395             }
396             elsif ( $list->[0] =~ /Del/ ) {
397                 $op = 'del';
398             }
399             else {
400                 $RT::Logger->crit(
401                     "Got an op that was neither add nor delete. can never happen"
402                       . $list->[0] );
403                 last;
404             }
405
406             foreach my $key (@$list) {
407                 my ( $cfid, $cf );
408                 next if $key =~ /CustomField-(\d+)-Category$/;
409                 if ( $key =~ /CustomField-(\d+)-/ ) {
410                     $cfid = $1;
411                     $cf   = RT::CustomField->new( $session{'CurrentUser'} );
412                     $cf->Load($cfid);
413                 }
414                 else {next}
415                 my @values =
416                   ref( $ARGS{$key} ) eq 'ARRAY'
417                   ? @{ $ARGS{$key} }
418                   : ( $ARGS{$key} );
419                 map { s/(\r\n|\r)/\n/g; } @values;    # fix the newlines
420                      # now break the multiline values into multivalues
421                 @values = map { split( /\n/, $_ ) } @values
422                   unless ( $cf->SingleValue );
423
424                 my $current_values = $Ticket->CustomFieldValues($cfid);
425                 foreach my $value (@values) {
426                     if ( $op eq 'del' && $current_values->HasEntry($value) ) {
427                         my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
428                             Field => $cfid,
429                             Value => $value
430                         );
431                         push @cfresults, $msg;
432                     }
433
434                     elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
435                         my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
436                             Field => $cfid,
437                             Value => $value
438                         );
439                         push @cfresults, $msg;
440                     }
441                 }
442             }
443         }
444         my @statusresults =
445           ProcessTicketStatus( TicketObj => $Ticket, ARGSRef => \%ARGS );
446
447           my @tempresults = (
448             @watchresults,  @basicresults, @dateresults,
449             @updateresults, @linkresults,  @cfresults,
450             @statusresults
451         );
452
453         @tempresults =
454           map { 
455               $_ =~ /^Ticket \d+:/ ?  $_ : 
456               loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) 
457             } @tempresults;
458
459         @results = ( @results, @tempresults );
460     }
461
462     # Cleanup WebUI
463     delete $session{'Attachments'};
464 }
465
466 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
467 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
468 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );
469
470 </%INIT>
471 <%args>
472 $Format => undef
473 $Page => 1
474 $Rows => undef
475 $RowsPerPage => undef
476 $Order => 'ASC'
477 $OrderBy => 'id'
478 $Query => undef
479 $SavedSearchId => undef
480 $SavedChartSearchId => undef
481 </%args>