Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / share / html / Search / Bulk.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2016 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 SavedSearchId SavedChartSearchId Token)) {
54 <input type="hidden" class="hidden" name="<%$var%>" value="<%$ARGS{$var} || ''%>" />
55 %}
56 <& /Elements/CollectionList, 
57     Query => $Query,
58     DisplayFormat => $DisplayFormat,
59     Format => $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(All)?$/', 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 <label>(<input type="checkbox" class="checkbox" name="ForceOwnerChange"
84 <% $ARGS{ForceOwnerChange} ? 'checked="checked"' : '' %> /> <&|/l&>Force change</&>)</label></td></tr>
85 <tr><td class="label"> <&|/l&>Add Requestor</&>: </td>
86 <td class="value"> <& /Elements/EmailInput, Name => "AddRequestor", Size=> 20, Default => $ARGS{AddRequestor} &> </td></tr>
87 <tr><td class="label"> <&|/l&>Remove Requestor</&>: </td>
88 <td class="value"> <& /Elements/EmailInput, Name => "DeleteRequestor", Size=> 20, Default => $ARGS{DeleteRequestor} &> </td></tr>
89 <tr><td class="label"> <&|/l&>Add Cc</&>: </td>
90 <td class="value"> <& /Elements/EmailInput, Name => "AddCc", Size=> 20, Default => $ARGS{AddCc} &> </td></tr>
91 <tr><td class="label"> <&|/l&>Remove Cc</&>: </td>
92 <td class="value"> <& /Elements/EmailInput, Name => "DeleteCc", Size=> 20, Default => $ARGS{DeleteCc} &> </td></tr>
93 <tr><td class="label"> <&|/l&>Add AdminCc</&>: </td>
94 <td class="value"> <& /Elements/EmailInput, Name => "AddAdminCc", Size=> 20, Default => $ARGS{AddAdminCc} &> </td></tr>
95 <tr><td class="label"> <&|/l&>Remove AdminCc</&>: </td>
96 <td class="value"> <& /Elements/EmailInput, Name => "DeleteAdminCc", Size=> 20, Default => $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 % my $rel = ($ARGS{Priority} =~ s/^R//);
105 <td class="value"> <& /Elements/SelectPriority, Name => "Priority", Default => $ARGS{Priority} &> 
106 <select name="Priority-Mode">
107 <option value="absolute" <% !$rel && 'selected' %>>absolute</option>
108 <option value="relative" <%  $rel && 'selected' %>>relative</option>
109 </select>
110 </td></tr>
111 <tr><td class="label"> <&|/l&>Make queue</&>: </td>
112 <td class="value"> <& /Elements/SelectQueue, Name => "Queue", Default => $ARGS{Queue} &> </td></tr>
113 <tr><td class="label"> <&|/l&>Make Status</&>: </td>
114 <td class="value"> <& /Ticket/Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}, Queues => $seen_queues &> </td></tr>
115 <tr><td class="label"> <&|/l&>Make date Starts</&>: </td>
116 <td class="value"> <& /Elements/SelectDate, Name => "Starts_Date", Default => $ARGS{Starts_Date} || '' &> </td></tr>
117 <tr><td class="label"> <&|/l&>Make date Started</&>: </td>
118 <td class="value"> <& /Elements/SelectDate, Name => "Started_Date", Default => $ARGS{Started_Date} || '' &> </td></tr>
119 <tr><td class="label"> <&|/l&>Make date Told</&>: </td>
120 <td class="value"> <& /Elements/SelectDate, Name => "Told_Date", Default => $ARGS{Told_Date} || '' &> </td></tr>
121 <tr><td class="label"> <&|/l&>Make date Due</&>: </td>
122 <td class="value"> <& /Elements/SelectDate, Name => "Due_Date", Default => $ARGS{Due_Date} || '' &> </td></tr>
123 </table>
124
125 </td>
126 </tr>
127 </table>
128 </&>
129 <&| /Widgets/TitleBox, title => loc('Add comments or replies to selected tickets') &>
130 <table>
131 <tr><td align="right"><&|/l&>Update Type</&>:</td>
132 <td><select name="UpdateType" id="UpdateType">
133   <option value="private" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'private' ? 'selected="selected"' : '' %> ><&|/l&>Comments (Not sent to requestors)</&></option>
134 <option value="response" <% $ARGS{UpdateType} && $ARGS{UpdateType} eq 'response' ? 'selected="selected"' : '' %>><&|/l&>Reply to requestors</&></option>
135 </select> 
136 </td></tr>
137 <tr>
138     <td align="right"><&|/l&>Subject</&>:</td>
139     <td>
140         <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || "" %>" />
141 % $m->callback( %ARGS, CallbackName => 'AfterUpdateSubject' );
142     </td>
143 </tr>
144 % $m->callback( CallbackName => 'BeforeTransactionCustomFields', CustomFields => $TxnCFs );
145 % while (my $CF = $TxnCFs->Next()) {
146 <tr>
147 <td align="right"><% $CF->Name %>:</td>
148 <td><& /Elements/EditCustomField,
149     CustomField => $CF,
150     Object => RT::Transaction->new( $session{'CurrentUser'} ),
151     &><em><% $CF->FriendlyType %></em></td>
152 </td></tr>
153 % } # end if while
154
155 <& /Ticket/Elements/AddAttachments, %ARGS &>
156
157  <tr><td class="labeltop"><&|/l&>Message</&>:</td>
158  <td class="messagebox-container action-<% $ARGS{UpdateType} || 'private' %>">
159 % $m->callback( %ARGS, CallbackName => 'BeforeMessageBox' );
160 %# Currently, bulk update always starts with Comment not Reply selected, so we check this unconditionally
161 % my $IncludeSignature = RT->Config->Get('MessageBoxIncludeSignatureOnComment');
162 <& /Elements/MessageBox, Name => "UpdateContent", 
163     $ARGS{UpdateContent} ? ( Default => $ARGS{UpdateContent}, IncludeSignature => 0 ) :
164                         ( IncludeSignature => $IncludeSignature ),
165         &>
166  </td></tr>
167  </table>
168
169 </&>
170
171 <%perl>
172 my $cfs = RT::CustomFields->new($session{'CurrentUser'});
173 $cfs->LimitToGlobal();
174 $cfs->LimitToQueue($_) for keys %$seen_queues;
175 $cfs->SetContextObject( values %$seen_queues ) if keys %$seen_queues == 1;
176 </%perl>
177
178 % if ( $cfs->Count ) {
179 <&|/Widgets/TitleBox, title => loc('Edit Custom Fields') &>
180 <& /Elements/BulkCustomFields, $ARGS{'AddMoreAttach'} ? %ARGS : (), CustomFields => $cfs &>
181 </&>
182 % }
183
184 <&|/Widgets/TitleBox, title => loc('Edit Links'), color => "#336633"&>
185 <em><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&></em><br />
186 <& /Elements/BulkLinks, Collection => $Tickets, $ARGS{'AddMoreAttach'} ? %ARGS : () &>
187 </&>
188
189 <&| /Widgets/TitleBox, title => loc('Merge'), color => '#336633' &>
190 <& /Ticket/Elements/EditMerge, Tickets => $Tickets, %ARGS &>
191 </&>
192
193 <& /Elements/Submit, Label => loc('Update') &>
194
195
196 </form>
197
198
199 <%INIT>
200 unless ( defined $Rows ) {
201     $Rows = $RowsPerPage;
202     $ARGS{Rows} = $RowsPerPage;
203 }
204 my $title = loc("Update multiple tickets");
205
206 #freeside
207 unless ( $session{'CurrentUser'}
208          ->HasRight( Right => 'BulkUpdateTickets', Object => RT->System) )
209 {
210     Abort('You are not allowed to bulk-update tickets.');
211 }
212
213 # Iterate through the ARGS hash and remove anything with a null value.
214 map ( $ARGS{$_} =~ /^$/ && ( delete $ARGS{$_} ), keys %ARGS );
215
216 my (@results);
217
218 ProcessAttachments(ARGSRef => \%ARGS);
219
220 $Page ||= 1;
221
222 $Format ||= RT->Config->Get('DefaultSearchResultFormat');
223
224 # inject _CHECKBOX to the first field.
225 my $DisplayFormat = "'__CheckBox.{UpdateTicket}__',". $Format;
226 $DisplayFormat =~ s/\s*,\s*('?__NEWLINE__'?)/,$1,''/gi;
227
228 $DECODED_ARGS->{'UpdateTicketAll'} = 1 unless @UpdateTicket;
229
230 my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
231 $Tickets->FromSQL($Query);
232 if ( $OrderBy =~ /\|/ ) {
233
234   # Multiple Sorts
235   my @OrderBy = split /\|/, $OrderBy;
236   my @Order   = split /\|/, $Order;
237   $Tickets->OrderByCols(
238     map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
239       ( 0 .. $#OrderBy ) );
240 }
241 else {
242   $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
243 }
244
245 $Tickets->RowsPerPage($Rows) if ($Rows);
246 $Tickets->GotoPage( $Page - 1 );    # SB uses page 0 as the first page
247
248 Abort( loc("No search to operate on.") ) unless ($Tickets);
249
250 # build up a list of all custom fields for tickets that we're displaying, so
251 # we can display sane edit widgets.
252
253 my $fields      = {};
254 my $seen_queues = {};
255 while ( my $ticket = $Tickets->Next ) {
256     next if $seen_queues->{ $ticket->Queue };
257     $seen_queues->{ $ticket->Queue } ||= $ticket->QueueObj;
258
259     my $custom_fields = $ticket->CustomFields;
260     while ( my $field = $custom_fields->Next ) {
261         $fields->{ $field->id } = $field;
262     }
263 }
264
265 #Iterate through each ticket we've been handed
266 my @linkresults;
267
268 $Tickets->RedoSearch();
269
270 if ( defined($ARGS{'Priority'})
271      and ($ARGS{'Priority-Mode'} || '') eq 'relative' ) {
272     # magic in Ticket::SetPriority
273     $ARGS{'Priority'} = 'R'.$ARGS{'Priority'};
274 }
275 delete $ARGS{'Priority-Mode'};
276
277 unless ( $ARGS{'AddMoreAttach'} ) {
278
279     while ( my $Ticket = $Tickets->Next ) {
280         my $tid = $Ticket->id;
281         next unless grep $tid == $_, @UpdateTicket;
282
283         #Update the links
284         $ARGS{'id'} = $Ticket->id;
285
286         my @updateresults = ProcessUpdateMessage(
287             TicketObj       => $Ticket,
288             ARGSRef         => \%ARGS,
289             KeepAttachments => 1,
290         );
291
292         #Update the basics.
293         my @basicresults =
294           ProcessTicketBasics( TicketObj => $Ticket, ARGSRef => \%ARGS );
295         my @dateresults =
296           ProcessTicketDates( TicketObj => $Ticket, ARGSRef => \%ARGS );
297
298         #Update the watchers
299         my @watchresults =
300           ProcessTicketWatchers( TicketObj => $Ticket, ARGSRef => \%ARGS );
301
302          @linkresults =
303             ProcessTicketLinks( TicketObj => $Ticket, TicketId => 'Ticket', ARGSRef => \%ARGS );
304
305         my @cfresults = ProcessRecordBulkCustomFields( RecordObj => $Ticket, ARGSRef => \%ARGS );
306
307         my @statusresults =
308           ProcessTicketStatus( TicketObj => $Ticket, ARGSRef => \%ARGS );
309
310           my @tempresults = (
311             @watchresults,  @basicresults, @dateresults,
312             @updateresults, @linkresults,  @cfresults,
313             @statusresults
314         );
315
316         @tempresults =
317           map { 
318               $_ =~ /^Ticket \d+:/ ?  $_ : 
319               loc( "Ticket [_1]: [_2]", $Ticket->Id, $_ ) 
320             } @tempresults;
321
322         @results = ( @results, @tempresults );
323     }
324
325     delete $session{'Attachments'}{ $ARGS{'Token'} };
326
327     $Tickets->RedoSearch();
328 }
329
330 my $TxnCFs = RT::CustomFields->new( $session{CurrentUser} );
331 $TxnCFs->LimitToLookupType( RT::Transaction->CustomFieldLookupType );
332 $TxnCFs->LimitToGlobalOrObjectId( keys %$seen_queues );
333 $TxnCFs->SetContextObject( values %$seen_queues ) if keys %$seen_queues == 1;
334
335 </%INIT>
336 <%args>
337 $Format => undef
338 $Page => 1
339 $Rows => undef
340 $RowsPerPage => undef
341 $Order => 'ASC'
342 $OrderBy => 'id'
343 $Query => undef
344 @UpdateTicket => ()
345 </%args>