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