import rt 3.8.7
[freeside.git] / rt / share / html / Ticket / Elements / PreviewScrips
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 <%args>
49 $TicketObj => undef
50
51 </%args>
52 <%init>
53 my %squelch = $m->comp('SELF:SquelchRecipients', %ARGS);
54 my $Object = $squelch{'Object'};
55 my @non_recipients = @{ $squelch{'EmailAddresses'} };
56
57 </%init>
58 <h2><&|/l&>This message will be sent to...</&></h2>
59
60 % if ( $Object and $Object->Scrips ) {
61 <i><&|/l&>(Check boxes to disable notifications to the listed recipients)</&></i><br />
62
63 % foreach my $scrip (@{$Object->Scrips->Prepared}) {
64 % next unless $scrip->ActionObj->Action->isa('RT::Action::SendEmail');
65 <b><% $scrip->Description || loc('Scrip #[_1]',$scrip->id) %></b><br />
66 <&|/l, loc($scrip->ConditionObj->Name), loc($scrip->ActionObj->Name), loc($scrip->TemplateObj->Name)&>[_1] [_2] with template [_3]</&>
67 <br />
68 %foreach my $type qw(To Cc Bcc) {
69 %my @addresses =  $scrip->ActionObj->Action->$type();
70 <ul>
71 %foreach my $addr (@addresses) {
72 <li> <b><%loc($type)%></b>: <input type="checkbox" class="checkbox" name="Ticket-<%$TicketObj->id%>-SquelchMailTo" value="<%$addr->address%>" /> <%$addr->address%>
73 % }
74 </ul>
75 % }
76 % if (RT->Config->Get('PreviewScripMessages')) {
77 <textarea cols="80" rows="5">
78 <%$scrip->ActionObj->TemplateObj->MIMEObj->as_string%>
79 </textarea>
80 % }
81 % }
82 % }
83 <br />
84
85 <h2><&|/l&>Messages about this ticket will not be sent to...</&></h2>
86 <i><&|/l&>(Check boxes to enable notifications to the listed recipients)</&></i>
87 <br />
88 <ul>
89 % foreach my $recipient (@non_recipients) {
90 <li><input type="checkbox" class="checkbox" name="Ticket-<%$TicketObj->id%>-UnsquelchMailTo" value="<%$recipient->Content%>" />
91 <% $recipient->Content %>
92 % }
93 </ul>
94 <& /Elements/Submit, Name => 'UpdatePreview', Value => 'UpdatePreview', Label => loc('Save Changes')&>
95
96 <%METHOD SquelchRecipients>
97 <%ARGS>
98 $TicketObj => undef
99 </%ARGS>
100 <%INIT>
101 my $arg = 'Ticket-'.$TicketObj->Id.'-SquelchMailTo';
102 my @squelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
103
104 foreach my $address (@squelchto) {
105         $TicketObj->SquelchMailTo($address) if ($address);
106 }
107
108
109 $arg = 'Ticket-'.$TicketObj->Id.'-UnsquelchMailTo';
110 my @unsquelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
111
112 foreach my $address (@unsquelchto) {
113         $TicketObj->UnsquelchMailTo($address) if ($address);
114 }
115
116
117 my $action;
118
119 if (($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' ) || ($ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' )) {
120     $action = 'Correspond';
121 }
122 else {
123     $action = 'Comment';
124 }
125
126 my $Message = MakeMIMEEntity(
127     Subject => $ARGS{'UpdateSubject'},
128     Body    => $ARGS{'UpdateContent'},
129 );
130
131 my ( $Transaction, $Description, $Object ) = $TicketObj->$action(
132     CcMessageTo  => $ARGS{'UpdateCc'},
133     BccMessageTo => $ARGS{'UpdateBcc'},
134     MIMEObj      => $Message,
135     TimeTaken    => $ARGS{'UpdateTimeWorked'},
136     DryRun       => 1
137 );
138 unless ( $Transaction ) {
139     $RT::Logger->error("Coulfn't fire '$action' action: $Description");
140 }
141
142
143 return (Object => $Object, EmailAddresses => [$TicketObj->SquelchMailTo]);
144 </%INIT>
145 </%METHOD>
146
147 <%METHOD GetRecipients>
148 <%ARGS>
149 $TicketObj
150 </%ARGS>
151 <%INIT>
152 my $action;
153 if ( ( $ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' )
154     || ( $ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' ) )
155 {
156     $action = 'Correspond';
157 }
158 else {
159     $action = 'Comment';
160 }
161
162 my $Message = MakeMIMEEntity(
163     Subject => $ARGS{'UpdateSubject'},
164     Body    => $ARGS{'UpdateContent'},
165 );
166
167 my ( $id, $msg, $txn ) = $TicketObj->$action(
168     CcMessageTo  => $ARGS{'UpdateCc'},
169     BccMessageTo => $ARGS{'UpdateBcc'},
170     MIMEObj      => $Message,
171     TimeTaken    => $ARGS{'UpdateTimeWorked'},
172     DryRun       => 1
173 );
174 unless ( $id && $txn ) {
175     $RT::Logger->error("Couldn't fire '$action' action: $msg");
176     return ();
177 }
178
179 my @recipients;
180 foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
181     my $action = $scrip->ActionObj->Action;
182     next unless $action->isa('RT::Action::SendEmail');
183
184     foreach my $type qw(To Cc Bcc) {
185         push @recipients, $action->$type();
186     }
187 }
188 return @recipients;
189 </%INIT>
190 </%METHOD>
191
192 <%METHOD GetRecipientsOnCreate>
193 <%INIT>
194 my $action;
195 my $Message = MakeMIMEEntity(
196     Subject => $ARGS{'Subject'},
197     Cc => $ARGS{'Cc'},
198     Body    => $ARGS{'Content'},
199 );
200
201 my $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
202 my ( $id, $txn, $msg ) = $TicketObj->Create(
203     Type            => $ARGS{'Type'} || 'ticket',
204     Queue           => $ARGS{'Queue'},
205     Owner           => $ARGS{'Owner'},
206     Requestor       => $ARGS{'Requestors'},
207     Cc              => $ARGS{'Cc'},
208     AdminCc         => $ARGS{'AdminCc'},
209     InitialPriority => $ARGS{'InitialPriority'},
210     FinalPriority   => $ARGS{'FinalPriority'},
211     TimeLeft        => $ARGS{'TimeLeft'},
212     TimeEstimated   => $ARGS{'TimeEstimated'},
213     TimeWorked      => $ARGS{'TimeWorked'},
214     Subject         => $ARGS{'Subject'},
215     Status          => $ARGS{'Status'},
216     MIMEObj      => $Message,
217     DryRun       => 1
218 );
219 unless ( $id && $txn ) {
220     $RT::Logger->error("Couldn't fire '$action' action: $msg");
221     return ();
222 }
223
224 my @recipients;
225 foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
226     my $action = $scrip->ActionObj->Action;
227     next unless $action->isa('RT::Action::SendEmail');
228
229     foreach my $type qw(To Cc Bcc) {
230         push @recipients, $action->$type();
231     }
232 }
233 return @recipients;
234 </%INIT>
235 </%METHOD>