import rt 3.8.8
[freeside.git] / rt / 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
58 <& /Elements/ListActions, actions => \@results &>
59 <form method="post" action="<%$RT::WebPath%>/Search/Bulk.html" enctype="multipart/form-data">
60 % foreach my $var qw(Query Format OrderBy Order Rows Page) {
61 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var}%>" />
62 %}
63 <& /Elements/TicketList, Query => $Query,
64     DisplayFormat => $Format,
65     Format => $ARGS{'Format'},
66     Verbatim => 1,
67     AllowSorting => 1,
68     OrderBy => $OrderBy,
69     Order => $Order,
70     Rows => $Rows,
71     Page => $Page,
72     BaseURL => $RT::WebPath."/Search/Bulk.html?"
73    &>
74
75 <hr>
76
77 <& /Elements/Submit, Label => loc('Update'), CheckAll => 1, ClearAll => 1 &>
78 <br />
79 <&|/Widgets/TitleBox, title => $title &>
80 <table>
81 <tr>
82 <td valign="top">
83 <table>
84 <tr><td class="label"> <&|/l&>Make Owner</&>: </td>
85 <td class="value"> <& /Elements/SelectOwner, Name => "Owner" &> (<input type="checkbox" class="checkbox" name="ForceOwnerChange" /> <&|/l&>Force change</&>) </td></tr>
86 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
87 <td class="value"> <input name="AddRequestor" size="20" /> </td></tr>
88 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
89 <td class="value"> <input name="DeleteRequestor" size="20" /> </td></tr>
90 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
91 <td class="value"> <input name="AddCc" size="20" /> </td></tr>
92 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
93 <td class="value"> <input name="DeleteCc" size="20" /> </td></tr>
94 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
95 <td class="value"> <input name="AddAdminCc" size="20" /> </td></tr>
96 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
97 <td class="value"> <input name="DeleteAdminCc" size="20" /> </td></tr>
98 </table>
99 </td>
100 <td valign="top">
101 <table>
102 <tr><td class="label"> <&|/l&>Make subject</&>: </td>
103 <td class="value"> <input name="Subject" size="20" /> </td></tr>
104 <tr><td class="label"> <&|/l&>Make priority</&>: </td>
105 <td class="value"> <input name="Priority" size="4" /> </td></tr>
106 <tr><td class="label"> <&|/l&>Make queue</&>: </td>
107 <td class="value"> <& /Elements/SelectQueue, Name => "Queue" &> </td></tr>
108 <tr><td class="label"> <&|/l&>Make Status</&>: </td>
109 <td class="value"> <& /Elements/SelectStatus, Name => "Status" &> </td></tr>
110 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
111 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", ShowTime => 0, Default => '' &> </td></tr>
112 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
113 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", ShowTime => 0, Default => '' &> </td></tr>
114 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
115 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", ShowTime => 0, Default => '' &> </td></tr>
116 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
117 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", ShowTime => 0, Default => '' &> </td></tr>
118 <tr><td class="label"> <&|/l&>Make date Resolved</&>: </td>
119 <td class="value"> <& /Elements/SelectDate, Name => "Resolved_Date", ShowTime => 0, Default => '' &> </td></tr>
120 </table>
121
122 </td>
123 </tr>
124 </table>
125 </&>
126 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
127 <table>
128 <tr><td align="right"><&|/l&>Update Type</&>:</td>
129 <td><select name="UpdateType">
130   <option value="private" ><&|/l&>Comments (not sent to requestors)</&></option>
131 <option value="response" ><&|/l&>Reply to requestors</&></option>
132 </select> 
133 </td></tr>
134 <tr><td align="right"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="" /></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     &><em><% $CF->FriendlyType %></em></td>
142 </td></tr>
143 % } # end if while
144  <tr><td align="right"><&|/l&>Attach</&>:</td><td><input name="UpdateAttachment" type="file" /></td></tr>
145  <tr><td class="labeltop"><&|/l&>Message</&>:</td><td>
146  <& /Elements/MessageBox, Name=>"UpdateContent"&>
147  </td></tr>
148  </table>
149
150 </&>
151 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields'), color => "#336633"&>
152 <%perl>
153 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
154 $cfs->LimitToGlobal();
155 $cfs->LimitToQueue($_) for keys %$seen_queues;
156 </%perl>
157 <table>
158 <tr>
159 <th><&|/l&>Name</&></th>
160 <th><&|/l&>Add values</&></th>
161 <th><&|/l&>Delete values</&></th>
162 </tr>
163 % while (my $cf = $cfs->Next()) {
164 <tr>
165 <td class="label"><%$cf->Name%><br />
166 <em>(<%$cf->FriendlyType%>)</em></td>
167 % my $rows = 5;
168 % my @add = (NamePrefix => 'Bulk-Add-CustomField-', CustomField => $cf, Rows => $rows, Multiple => ($cf->MaxValues ==1 ? 0 : 1) , Cols => 25);
169 % my @del = (NamePrefix => 'Bulk-Delete-CustomField-', CustomField => $cf, Rows => $rows, Multiple => 1, Cols => 25);
170 % if ($cf->Type eq 'Select') {
171 <td><& /Elements/EditCustomFieldSelect, @add &></td>
172 <td><& /Elements/EditCustomFieldSelect, @del &></td>
173 % } elsif ($cf->Type eq 'Combobox') {
174 <td><& /Elements/EditCustomFieldCombobox, @add &></td>
175 <td><& /Elements/EditCustomFieldCombobox, @del &></td>
176 % } elsif ($cf->Type eq 'Freeform') {
177 <td><& /Elements/EditCustomFieldFreeform, @add &></td>
178 <td><& /Elements/EditCustomFieldFreeform, @del &></td>
179 % } elsif ($cf->Type eq 'Text') {
180 <td><& /Elements/EditCustomFieldText, @add &></td>
181 <td>&nbsp;</td>
182 % } else {
183 %   $RT::Logger->crit("Unknown CustomField type: " . $cf->Type);
184 % }
185 </tr>
186 % }
187 </table>
188 </&>
189
190 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
191 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
192 <& /Ticket/Elements/BulkLinks &>
193 </&>
194
195 <& /Elements/Submit, Label => loc('Update') &>
196
197
198 </form>
199
200
201 <%INIT>
202 my $title = loc("Update multiple tickets");
203
204 # Iterate through the ARGS hash and remove anything with a null value.
205 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
206
207 my (@results);
208
209 $Page ||= 1;
210
211 $Format ||= $RT::DefaultSearchResultFormat;
212
213 # inject _CHECKBOX to the first field.
214 $Format =~ s/'?([^']+)'?,/'___CHECKBOX__$1',/;
215
216 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
217 $Tickets->FromSQL($Query);
218 if ( $OrderBy =~ /\|/ ) {
219
220   # Multiple Sorts
221   my @OrderBy = split /\|/, $OrderBy;
222   my @Order   = split /\|/, $Order;
223   $Tickets->OrderByCols(
224     map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
225       ( 0 .. $#OrderBy ) );
226 }
227 else {
228   $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
229 }
230
231 $Tickets->RowsPerPage($Rows) if ($Rows);
232 $Tickets->GotoPage( $Page - 1 );    # SB uses page 0 as the first page
233
234 Abort( loc("No search to operate on.") ) unless ($Tickets);
235
236 # build up a list of all custom fields for tickets that we're displaying, so
237 # we can display sane edit widgets.
238
239 my $fields      = {};
240 my $seen_queues = {};
241 while ( my $ticket = $Tickets->Next ) {
242     next if $seen_queues->{ $ticket->Queue }++;
243
244     my $custom_fields = $ticket->QueueObj->TicketCustomFields;
245     while ( my $field = $custom_fields->Next ) {
246         $fields->{ $field->id } = $field;
247     }
248 }
249
250 my $do_comment_reply = 0;
251
252 # Prepare for ticket updates
253 if ($ARGS{'UpdateContent'}) {
254     $ARGS{'UpdateContent'} =~ s/\r\n/\n/g;
255     chomp( $ARGS{'UpdateContent'} );
256
257     if ($ARGS{'UpdateContent'} ne ''
258         && $ARGS{'UpdateContent'} ne "-- \n"
259         . $session{'CurrentUser'}->UserObj->Signature ) {
260         $do_comment_reply = 1;
261     }
262 }
263
264 #Iterate through each ticket we've been handed
265 my @linkresults;
266 my %queues;
267
268 $Tickets->RedoSearch();
269
270 # pull out the labels for any custom fields we want to update
271
272 my $cf_del_keys;
273 @$cf_del_keys = grep { /^Bulk-Delete-CustomField/ } keys %ARGS;
274 my $cf_add_keys;
275 @$cf_add_keys = grep { /^Bulk-Add-CustomField/ } keys %ARGS;
276
277
278 while ( my $Ticket = $Tickets->Next ) {
279     next unless ( $ARGS{ "UpdateTicket" . $Ticket->Id } );
280
281     #Update the links
282     $ARGS{'id'} = $Ticket->id;
283     $queues{ $Ticket->QueueObj->Id }++;
284
285     my @updateresults;
286     if ($do_comment_reply) {
287         ProcessUpdateMessage(
288             TicketObj => $Ticket,
289             ARGSRef   => \%ARGS,
290             Actions   => \@updateresults
291         );
292     }
293
294     #Update the basics.
295     my @basicresults =
296       ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
297     my @dateresults =
298       ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
299
300     #Update the watchers
301     my @watchresults =
302       ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
303
304     foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
305         $ARGS{ $Ticket->id . "-" . $type } = $ARGS{"Ticket-$type"};
306         $ARGS{ $type . "-" . $Ticket->id } = $ARGS{"$type-Ticket"};
307     }
308     @linkresults =
309       ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS );
310     foreach my $type qw(MergeInto DependsOn MemberOf RefersTo) {
311         delete $ARGS{ $type . "-" . $Ticket->id };
312         delete $ARGS{ $Ticket->id . "-" . $type };
313     }
314
315     my @cfresults;
316
317     foreach my $list ( $cf_add_keys, $cf_del_keys ) {
318         next unless $list->[0];
319
320
321         my $op;
322         if ( $list->[0] =~ /Add/ ) {
323             $op = 'add';
324
325         }
326         elsif ( $list->[0] =~ /Del/ ) {
327             $op = 'del';
328         }
329         else {
330             $RT::Logger->crit(
331                 "Got an op that was neither add nor delete. can never happen"
332                   . $list->[0] );
333             last;
334         }
335
336         foreach my $key (@$list) {
337             my ( $cfid, $cf );
338             next if $key =~ /CustomField-(\d+)-Category$/;
339             if ( $key =~ /CustomField-(\d+)-/ ) {
340                 $cfid = $1;
341                 $cf   = RT::CustomField->new( $session{'CurrentUser'} );
342                 $cf->Load($cfid);
343             }
344             else {next}
345             my @values =
346               ref( $ARGS{$key} ) eq 'ARRAY'
347               ? @{ $ARGS{$key} }
348               : ( $ARGS{$key} );
349             map { s/(\r\n|\r)/\n/g; } @values;    # fix the newlines
350                  # now break the multiline values into multivalues
351             @values = map { split( /\n/, $_ ) } @values
352               unless ( $cf->SingleValue );
353
354             my $current_values = $Ticket->CustomFieldValues($cfid);
355             foreach my $value (@values) {
356                 if ( $op eq 'del' && $current_values->HasEntry($value) ) {
357                     my ( $id, $msg ) = $Ticket->DeleteCustomFieldValue(
358                         Field => $cfid,
359                         Value => $value
360                     );
361                     push @cfresults, $msg;
362                 }
363
364                 elsif ( $op eq 'add' && !$current_values->HasEntry($value) ) {
365                     my ( $id, $msg ) = $Ticket->AddCustomFieldValue(
366                         Field => $cfid,
367                         Value => $value
368                     );
369                     push @cfresults, $msg;
370                 }
371             }
372         }
373     }
374     my @tempresults = (
375         @watchresults,  @basicresults, @dateresults,
376         @updateresults, @linkresults,  @cfresults
377     );
378
379     @tempresults =
380       map { loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) } @tempresults;
381
382     @results = ( @results, @tempresults );
383 }
384
385 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
386 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
387 $TxnCFs->LimitToGlobalOrObjectId( sort keys %queues );
388
389 </%INIT>
390 <%args>
391 $Format => undef
392 $Page => 1
393 $Rows => undef
394 $Order => 'ASC'
395 $OrderBy => 'id'
396 $Query => undef
397 </%args>