import rt 3.8.11
[freeside.git] / rt / share / html / Ticket / Elements / PreviewScrips
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2011 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 <%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>
73     <b><%loc($type)%></b>: <input type="checkbox" class="checkbox" name="Ticket-<%$TicketObj->id%>-SquelchMailTo" value="<%$addr->address%>" /> <%$addr->address%>
74
75 % $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => $addr, Type => $type);
76 </li>
77 % }
78 </ul>
79 % }
80 % if (RT->Config->Get('PreviewScripMessages')) {
81 <textarea cols="80" rows="5">
82 <%$scrip->ActionObj->TemplateObj->MIMEObj->as_string%>
83 </textarea>
84 % }
85 % }
86 % }
87
88 % if ( $Object and $Object->Rules ) {
89 % for my $rule (@{$Object->Rules}) {
90 %    next unless $rule->{hints} && $rule->{hints}{class} eq 'SendEmail';
91 <b><% $rule->Describe %></b>
92 %    my $data = $rule->{hints}{recipients};
93 %    foreach my $type (qw(To Cc Bcc)) {
94 <ul>
95 %        foreach my $address (@{$data->{$type}}) {
96 <li>
97     <b><%loc($type)%></b>: <input type="checkbox" class="checkbox" name="Ticket-<%$TicketObj->id%>-SquelchMailTo" value="<%$address%>" /> <%$address%>
98
99 %            $m->callback(CallbackName => 'AfterAddress', Ticket => $TicketObj, Address => Email::Address->parse($address), Type => $type);
100 </li>
101 %        }
102 </ul>
103
104 %   }
105 % }
106 % }
107 <br />
108
109 <h2><&|/l&>Messages about this ticket will not be sent to...</&></h2>
110 <i><&|/l&>(Check boxes to enable notifications to the listed recipients)</&></i>
111 <br />
112 <ul>
113 % foreach my $recipient (@non_recipients) {
114 <li><input type="checkbox" class="checkbox" name="Ticket-<%$TicketObj->id%>-UnsquelchMailTo" value="<%$recipient->Content%>" />
115 <% $recipient->Content %>
116 % }
117 </ul>
118 <& /Elements/Submit, Name => 'UpdatePreview', Value => 'UpdatePreview', Label => loc('Save Changes')&>
119
120 <%METHOD SquelchRecipients>
121 <%ARGS>
122 $TicketObj => undef
123 </%ARGS>
124 <%INIT>
125 my $arg = 'Ticket-'.$TicketObj->Id.'-SquelchMailTo';
126 my @squelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
127
128 foreach my $address (@squelchto) {
129         $TicketObj->SquelchMailTo($address) if ($address);
130 }
131
132
133 $arg = 'Ticket-'.$TicketObj->Id.'-UnsquelchMailTo';
134 my @unsquelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
135
136 foreach my $address (@unsquelchto) {
137         $TicketObj->UnsquelchMailTo($address) if ($address);
138 }
139
140
141 my $action;
142
143 if (($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' ) || ($ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' )) {
144     $action = 'Correspond';
145 }
146 else {
147     $action = 'Comment';
148 }
149
150 my $Message = MakeMIMEEntity(
151     Subject => $ARGS{'UpdateSubject'},
152     Body    => $ARGS{'UpdateContent'},
153 );
154
155 my ( $Transaction, $Description, $Object ) = $TicketObj->$action(
156     CcMessageTo  => $ARGS{'UpdateCc'},
157     BccMessageTo => $ARGS{'UpdateBcc'},
158     MIMEObj      => $Message,
159     TimeTaken    => $ARGS{'UpdateTimeWorked'},
160     DryRun       => 1
161 );
162 unless ( $Transaction ) {
163     $RT::Logger->error("Coulfn't fire '$action' action: $Description");
164 }
165
166
167 return (Object => $Object, EmailAddresses => [$TicketObj->SquelchMailTo]);
168 </%INIT>
169 </%METHOD>
170
171 <%METHOD GetRecipients>
172 <%ARGS>
173 $TicketObj
174 </%ARGS>
175 <%INIT>
176 my $action;
177 if ( ( $ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' )
178     || ( $ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' ) )
179 {
180     $action = 'Correspond';
181 }
182 else {
183     $action = 'Comment';
184 }
185
186 my $Message = MakeMIMEEntity(
187     Subject => $ARGS{'UpdateSubject'},
188     Body    => $ARGS{'UpdateContent'},
189 );
190
191 my ( $id, $msg, $txn ) = $TicketObj->$action(
192     CcMessageTo  => $ARGS{'UpdateCc'},
193     BccMessageTo => $ARGS{'UpdateBcc'},
194     MIMEObj      => $Message,
195     TimeTaken    => $ARGS{'UpdateTimeWorked'},
196     DryRun       => 1
197 );
198 unless ( $id && $txn ) {
199     $RT::Logger->error("Couldn't fire '$action' action: $msg");
200     return ();
201 }
202
203 my @recipients;
204 foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
205     my $action = $scrip->ActionObj->Action;
206     next unless $action->isa('RT::Action::SendEmail');
207
208     foreach my $type (qw(To Cc Bcc)) {
209         push @recipients, $action->$type();
210     }
211 }
212 return @recipients;
213 </%INIT>
214 </%METHOD>
215
216 <%METHOD GetRecipientsOnCreate>
217 <%INIT>
218 my $action;
219 my $Message = MakeMIMEEntity(
220     Subject => $ARGS{'Subject'},
221     Cc => $ARGS{'Cc'},
222     Body    => $ARGS{'Content'},
223 );
224
225 my $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
226 my ( $id, $txn, $msg ) = $TicketObj->Create(
227     Type            => $ARGS{'Type'} || 'ticket',
228     Queue           => $ARGS{'Queue'},
229     Owner           => $ARGS{'Owner'},
230     Requestor       => $ARGS{'Requestors'},
231     Cc              => $ARGS{'Cc'},
232     AdminCc         => $ARGS{'AdminCc'},
233     InitialPriority => $ARGS{'InitialPriority'},
234     FinalPriority   => $ARGS{'FinalPriority'},
235     TimeLeft        => $ARGS{'TimeLeft'},
236     TimeEstimated   => $ARGS{'TimeEstimated'},
237     TimeWorked      => $ARGS{'TimeWorked'},
238     Subject         => $ARGS{'Subject'},
239     Status          => $ARGS{'Status'},
240     MIMEObj      => $Message,
241     DryRun       => 1
242 );
243 unless ( $id && $txn ) {
244     $RT::Logger->error("Couldn't fire '$action' action: $msg");
245     return ();
246 }
247
248 my @recipients;
249 foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
250     my $action = $scrip->ActionObj->Action;
251     next unless $action->isa('RT::Action::SendEmail');
252
253     foreach my $type (qw(To Cc Bcc)) {
254         push @recipients, $action->$type();
255     }
256 }
257 return @recipients;
258 </%INIT>
259 </%METHOD>