import rt 3.2.2
[freeside.git] / rt / html / Search / Bulk.html
1 %# {{{ BEGIN BPS TAGGED BLOCK
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2004 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# }}} END BPS TAGGED BLOCK
46 <& /Elements/Header, Title => loc("Bulk ticket update") &>
47 <& /Elements/Tabs, Title => loc("Bulk ticket update") &>
48
49 <& /Elements/ListActions, actions => \@results &>
50
51 <FORM METHOD=POST>
52 <TABLE WIDTH=100% border=0 cellpadding=3 CELLSPACING=0>
53 <TR>
54 <TH><&|/l&>Update</&></TH>
55 %foreach my $col (@cols) {
56 % my $colalias = $col;
57 % $colalias =~ s/(Obj\-\>|)(Name|AsString)//;
58
59 <TH><% loc($colalias) %>&nbsp;</TH>
60 %}
61 </TR>
62
63 <%PERL>
64
65 my $i;
66
67 $Tickets->RedoSearch();
68 while (my $Ticket = $Tickets->Next) {
69  $i++;
70  if ($i % 2) {
71      $bgcolor = "#dddddd";
72  }
73  else {
74      $bgcolor = "#ffffff";
75  }
76       </%PERL>
77 <TR bgcolor="<%$bgcolor%>">
78 <TD><input type=checkbox name="UpdateTicket<%$Ticket->Id%>" CHECKED></TD>
79 %# The ticket view is controlled by config.pm, WebOptions
80 %foreach my $col (@cols) {
81 <TD>
82 % if ($col eq 'id') {
83 <A HREF="<% $RT::WebPath%>/Ticket/Display.html?id=<%$Ticket->Id%>"><%$Ticket->Id()%></A>
84 % }
85 %else {
86 <% eval "\$Ticket->$col()" %>&nbsp;
87 %}
88 </TD>
89 %}
90 </TR>
91 %}
92
93
94
95 </TABLE>
96
97 <HR>
98
99
100 <& /Elements/TitleBoxStart, title => loc('Update selected tickets') &>
101 <TABLE>
102 <TR>
103 <TD VALIGN=TOP>
104 <table>
105 <tr><td class=label> <&|/l&>Make Owner</&>: </td>
106 <td class=value> <& /Elements/SelectOwner, Name => "Owner" &> (<input type=checkbox name="ForceOwnerChange"> <&|/l&>Force change</&>) </td></tr>
107 <tr><td class=label> <&|/l&>Add Requestor</&>: </td>
108 <td class=value> <INPUT Name="AddRequestor" SIZE=20> </td></tr>
109 <tr><td class=label> <&|/l&>Remove Requestor</&>: </td>
110 <td class=value> <INPUT Name="DeleteRequestor" SIZE=20> </td></tr>
111 <tr><td class=label> <&|/l&>Add Cc</&>: </td>
112 <td class=value> <INPUT Name="AddCc" SIZE=20> </td></tr>
113 <tr><td class=label> <&|/l&>Remove Cc</&>: </td>
114 <td class=value> <INPUT Name="DeleteCc" SIZE=20> </td></tr>
115 <tr><td class=label> <&|/l&>Add AdminCc</&>: </td>
116 <td class=value> <INPUT Name="AddAdminCc" SIZE=20> </td></tr>
117 <tr><td class=label> <&|/l&>Remove AdminCc</&>: </td>
118 <td class=value> <INPUT Name="DeleteAdminCc" SIZE=20> </td></tr>
119 </table>
120 </TD>
121 <TD VALIGN=TOP>
122 <table>
123 <tr><td class=label> <&|/l&>Make subject</&>: </td>
124 <td class=value> <INPUT Name="Subject" SIZE=20> </td></tr>
125 <tr><td class=label> <&|/l&>Make priority</&>: </td>
126 <td class=value> <INPUT Name="Priority" SIZE=4> </td></tr>
127 <tr><td class=label> <&|/l&>Make queue</&>: </td>
128 <td class=value> <& /Elements/SelectQueue, Name => "Queue" &> </td></tr>
129 <tr><td class=label> <&|/l&>Make Status</&>: </td>
130 <td class=value> <& /Elements/SelectStatus, Name => "Status" &> </td></tr>
131 <tr><td class=label> <&|/l&>Make date Starts</&>: </td>
132 <td class=value> <& /Elements/SelectDate, Name => "Starts_Date", ShowTime => 0, Default => '' &> </td></tr>
133 <tr><td class=label> <&|/l&>Make date Started</&>: </td>
134 <td class=value> <& /Elements/SelectDate, Name => "Started_Date", ShowTime => 0, Default => '' &> </td></tr>
135 <tr><td class=label> <&|/l&>Make date Told</&>: </td>
136 <td class=value> <& /Elements/SelectDate, Name => "Told_Date", ShowTime => 0, Default => '' &> </td></tr>
137 <tr><td class=label> <&|/l&>Make date Due</&>: </td>
138 <td class=value> <& /Elements/SelectDate, Name => "Due_Date", ShowTime => 0, Default => '' &> </td></tr>
139 <tr><td class=label> <&|/l&>Make date Resolved</&>: </td>
140 <td class=value> <& /Elements/SelectDate, Name => "Resolved_Date", ShowTime => 0, Default => '' &> </td></tr>
141 </table>
142
143 </TD>
144 </TR>
145 </table>
146 <& /Elements/TitleBoxEnd&>
147 <& /Elements/TitleBoxStart, title => loc('Add comments or replies to selected tickets') &>
148 <table>
149 <tr><td align=right><&|/l&>Update Type</&>:</td>
150 <td><select name="UpdateType">
151   <option value="private" ><&|/l&>Comments (not sent to requestors)</&></option>
152 <option value="response" ><&|/l&>Reply to requestors</&></option>
153 </select> 
154 </td></tr>
155 <tr><td align=right><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size=60 value=""></td></tr>
156  <tr><td align=right><&|/l&>Attach</&>:</td><td><input name="UpdateAttachment" type="file"></td></tr>
157  <tr><td class=labeltop><&|/l&>Message</&>:</td><td>
158  <& /Elements/MessageBox, Name=>"UpdateContent"&>
159  </td></tr>
160  </table>
161
162 <table>
163 % foreach (keys %allcfs) {
164 <tr><td class=label>
165 %     my $cf = $allcfs{$_};
166 %     my $pref;
167 %     if ($cf->Queue == 0) {
168 %         $pref = "[Global]";
169 %     } else {
170 %         $pref = "[Queue: " . $cfqnames{$_} . "]";
171 %     }
172 <%$pref%> <b><% $cf->Name %></b><br>
173 <% $cf->FriendlyType %>
174 </td>
175 <td>
176 % if ($cf->Type ne "FreeformMultiple") {
177 <& /Ticket/Elements/EditCustomField, CustomField => $cf &>
178 % } else {
179 Add Values<br>
180 <textarea cols=15 rows=3 name="<%$cf->Id%>-Values"></textarea>
181 </td><td>
182 Delete Values<br>
183 <textarea cols=15 rows=3 name="<%$cf->Id%>-DeleteValues"></textarea>
184 % }    
185 </td>
186 </tr>
187 % }
188 </table>
189
190 <& /Elements/TitleBoxEnd &>
191
192 <& /Elements/TitleBoxStart, title => loc('Edit Links'), color => "#336633"&>
193 <i><&|/l&>Enter tickets or URIs to link tickets to. Seperate multiple entries with spaces.</&></i><br>
194 <& /Ticket/Elements/BulkLinks &>
195 <& /Elements/TitleBoxEnd &>
196
197 <& /Elements/Submit, Label => loc('Update All') &>
198
199
200 </FORM>
201 <%INIT>
202
203 # Iterate through the ARGS hash and remove anything with a null value.
204 map ($ARGS{$_} =~ /^$/ && (delete $ARGS{$_}), keys %ARGS);
205
206 my ($bgcolor, @results);
207 my @cols = qw(id Status Priority Subject QueueObj->Name OwnerObj->Name RequestorAddresses DueAsString );
208
209
210 my $Tickets = RT::Tickets->new($session{'CurrentUser'});
211 $Tickets->FromSQL($ARGS{'Query'});
212
213 Abort(loc("No search to operate on.")) unless ($Tickets);
214
215 my %allcfs;
216 my %cfqnames;
217 my %cfqs;
218 my $count = 0;
219 while (my $Ticket = $Tickets->Next) {
220     my $cfq = $Ticket->QueueObj;
221     my $cfqid = $cfq->Id;
222     my $cfqn = $cfq->Name;
223     unless ( exists $cfqs{$cfqid} ) {
224         $cfqs{$cfqid} = 1;
225         $count++;
226         my $cfs = $cfq->CustomFields;
227         while (my $cf = $cfs->Next) {
228             $allcfs{$cf->Id} = $cf;
229             $cfqnames{$cf->Id} = $cfqn;
230         }
231     }
232 }
233
234 my $do_comment_reply=0;
235 # Prepare for ticket updates
236 $ARGS{'UpdateContent'} =~ s/\r\n/\n/g;
237 chomp ($ARGS{'UpdateContent'}) ;
238
239 if ($ARGS{'UpdateContent'} &&
240     $ARGS{'UpdateContent'} ne '' &&
241     $ARGS{'UpdateContent'} ne  "-- \n" .
242     $session{'CurrentUser'}->UserObj->Signature) {
243             $do_comment_reply=1;
244 }
245
246 #Iterate through each ticket we've been handed
247 my @linkresults;
248
249 $Tickets->RedoSearch();
250 while (my $Ticket = $Tickets->Next) {
251     $RT::Logger->debug( "Checking Ticket ".$Ticket->Id ."\n");
252     next unless ($ARGS{"UpdateTicket".$Ticket->Id});
253     $RT::Logger->debug ("Matched\n");
254     my @updateresults; 
255     if ($do_comment_reply) {
256        ProcessUpdateMessage(TicketObj => $Ticket, ARGSRef => \%ARGS, Actions => \@updateresults); 
257     }
258
259     #Update the basics.
260     my @basicresults = ProcessTicketBasics(TicketObj => $Ticket, ARGSRef => \%ARGS);
261     my @dateresults = ProcessTicketDates(TicketObj => $Ticket, ARGSRef => \%ARGS);
262     #Update the watchers
263     my @watchresults = ProcessTicketWatchers(TicketObj => $Ticket, ARGSRef => \%ARGS);    
264
265     #Update custom fields
266     my $pat = "^(\\d+)-(.*)\$";
267     foreach (keys %ARGS) {
268         $ARGS{"Ticket-" . $Ticket->Id . "-CustomField-" . $1 . "-" . $2} = $ARGS{$_} if (/$pat/o);
269     }
270     my @cfresults = ProcessTicketCustomFieldUpdates(ARGSRef => \%ARGS);
271     foreach (keys %ARGS) {
272         delete $ARGS{"Ticket-" . $Ticket->Id . "-CustomField-" . $1 . "-" . $2} if (/$pat/o);
273     }
274
275
276     #Update the links
277     $ARGS{'id'} = $Ticket;
278     $ARGS{$Ticket->Id.'-MergeInto'} = $ARGS{'Ticket-MergeInto'};
279     $ARGS{$Ticket->Id.'-DependsOn'} = $ARGS{'Ticket-DependsOn'};
280     $ARGS{'DependsOn-'.$Ticket->Id} = $ARGS{'DependsOn-Ticket'};
281     $ARGS{$Ticket->Id.'-MemberOf'} = $ARGS{'Ticket-MemberOf'};
282     $ARGS{'MemberOf-'.$Ticket->Id} = $ARGS{'MemberOf-Ticket'};
283     $ARGS{$Ticket->Id.'-RefersTo'} = $ARGS{'Ticket-RefersTo'};
284     $ARGS{'RefersTo-'.$Ticket->Id} = $ARGS{'RefersTo-Ticket'};
285     @linkresults = ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS);
286     delete $ARGS{'id'};
287     delete $ARGS{$Ticket->Id.'-MergeInto'};
288     delete $ARGS{$Ticket->Id.'-DependsOn'};
289     delete $ARGS{'DependsOn-'.$Ticket->Id};
290     delete $ARGS{$Ticket->Id.'-MemberOf'};
291     delete $ARGS{'MemberOf-'.$Ticket->Id};
292     delete $ARGS{$Ticket->Id.'-RefersTo'};
293     delete $ARGS{'RefersTo-'.$Ticket->Id};
294     
295     my @tempresults = (@watchresults, @basicresults, @dateresults, @updateresults, @linkresults, @cfresults);
296     @tempresults = map { loc("Ticket [_1]: [_2]",$Ticket->Id,$_) } @tempresults;
297
298     @results = (@results, @tempresults);
299 }
300
301 </%INIT>