This commit was generated by cvs2svn to compensate for changes in r9232,
[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>
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 <br />
88
89 <h2><&|/l&>Messages about this ticket will not be sent to...</&></h2>
90 <i><&|/l&>(Check boxes to enable notifications to the listed recipients)</&></i>
91 <br />
92 <ul>
93 % foreach my $recipient (@non_recipients) {
94 <li><input type="checkbox" class="checkbox" name="Ticket-<%$TicketObj->id%>-UnsquelchMailTo" value="<%$recipient->Content%>" />
95 <% $recipient->Content %>
96 % }
97 </ul>
98 <& /Elements/Submit, Name => 'UpdatePreview', Value => 'UpdatePreview', Label => loc('Save Changes')&>
99
100 <%METHOD SquelchRecipients>
101 <%ARGS>
102 $TicketObj => undef
103 </%ARGS>
104 <%INIT>
105 my $arg = 'Ticket-'.$TicketObj->Id.'-SquelchMailTo';
106 my @squelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
107
108 foreach my $address (@squelchto) {
109         $TicketObj->SquelchMailTo($address) if ($address);
110 }
111
112
113 $arg = 'Ticket-'.$TicketObj->Id.'-UnsquelchMailTo';
114 my @unsquelchto = ref($ARGS{$arg}) eq 'ARRAY' ? @{$ARGS{$arg}} : ($ARGS{$arg});
115
116 foreach my $address (@unsquelchto) {
117         $TicketObj->UnsquelchMailTo($address) if ($address);
118 }
119
120
121 my $action;
122
123 if (($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' ) || ($ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' )) {
124     $action = 'Correspond';
125 }
126 else {
127     $action = 'Comment';
128 }
129
130 my $Message = MakeMIMEEntity(
131     Subject => $ARGS{'UpdateSubject'},
132     Body    => $ARGS{'UpdateContent'},
133 );
134
135 my ( $Transaction, $Description, $Object ) = $TicketObj->$action(
136     CcMessageTo  => $ARGS{'UpdateCc'},
137     BccMessageTo => $ARGS{'UpdateBcc'},
138     MIMEObj      => $Message,
139     TimeTaken    => $ARGS{'UpdateTimeWorked'},
140     DryRun       => 1
141 );
142 unless ( $Transaction ) {
143     $RT::Logger->error("Coulfn't fire '$action' action: $Description");
144 }
145
146
147 return (Object => $Object, EmailAddresses => [$TicketObj->SquelchMailTo]);
148 </%INIT>
149 </%METHOD>
150
151 <%METHOD GetRecipients>
152 <%ARGS>
153 $TicketObj
154 </%ARGS>
155 <%INIT>
156 my $action;
157 if ( ( $ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq 'response' )
158     || ( $ARGS{'Action'} && $ARGS{'Action'} eq 'Respond' ) )
159 {
160     $action = 'Correspond';
161 }
162 else {
163     $action = 'Comment';
164 }
165
166 my $Message = MakeMIMEEntity(
167     Subject => $ARGS{'UpdateSubject'},
168     Body    => $ARGS{'UpdateContent'},
169 );
170
171 my ( $id, $msg, $txn ) = $TicketObj->$action(
172     CcMessageTo  => $ARGS{'UpdateCc'},
173     BccMessageTo => $ARGS{'UpdateBcc'},
174     MIMEObj      => $Message,
175     TimeTaken    => $ARGS{'UpdateTimeWorked'},
176     DryRun       => 1
177 );
178 unless ( $id && $txn ) {
179     $RT::Logger->error("Couldn't fire '$action' action: $msg");
180     return ();
181 }
182
183 my @recipients;
184 foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
185     my $action = $scrip->ActionObj->Action;
186     next unless $action->isa('RT::Action::SendEmail');
187
188     foreach my $type qw(To Cc Bcc) {
189         push @recipients, $action->$type();
190     }
191 }
192 return @recipients;
193 </%INIT>
194 </%METHOD>
195
196 <%METHOD GetRecipientsOnCreate>
197 <%INIT>
198 my $action;
199 my $Message = MakeMIMEEntity(
200     Subject => $ARGS{'Subject'},
201     Cc => $ARGS{'Cc'},
202     Body    => $ARGS{'Content'},
203 );
204
205 my $TicketObj = RT::Ticket->new( $session{'CurrentUser'} );
206 my ( $id, $txn, $msg ) = $TicketObj->Create(
207     Type            => $ARGS{'Type'} || 'ticket',
208     Queue           => $ARGS{'Queue'},
209     Owner           => $ARGS{'Owner'},
210     Requestor       => $ARGS{'Requestors'},
211     Cc              => $ARGS{'Cc'},
212     AdminCc         => $ARGS{'AdminCc'},
213     InitialPriority => $ARGS{'InitialPriority'},
214     FinalPriority   => $ARGS{'FinalPriority'},
215     TimeLeft        => $ARGS{'TimeLeft'},
216     TimeEstimated   => $ARGS{'TimeEstimated'},
217     TimeWorked      => $ARGS{'TimeWorked'},
218     Subject         => $ARGS{'Subject'},
219     Status          => $ARGS{'Status'},
220     MIMEObj      => $Message,
221     DryRun       => 1
222 );
223 unless ( $id && $txn ) {
224     $RT::Logger->error("Couldn't fire '$action' action: $msg");
225     return ();
226 }
227
228 my @recipients;
229 foreach my $scrip ( @{ $txn->Scrips->Prepared } ) {
230     my $action = $scrip->ActionObj->Action;
231     next unless $action->isa('RT::Action::SendEmail');
232
233     foreach my $type qw(To Cc Bcc) {
234         push @recipients, $action->$type();
235     }
236 }
237 return @recipients;
238 </%INIT>
239 </%METHOD>