Service: <B><% $part_svc->svc %></B><BR><BR>
<FORM ACTION="process/svc_forward.cgi" METHOD="POST">
-<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
-<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
-<INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
-
-<SCRIPT TYPE="text/javascript">
-function srcchanged(what) {
- if ( what.options[what.selectedIndex].value == 0 ) {
- what.form.src.disabled = false;
- what.form.src.style.backgroundColor = "white";
- } else {
- what.form.src.disabled = true;
- what.form.src.style.backgroundColor = "lightgrey";
- }
-}
-function dstchanged(what) {
- if ( what.options[what.selectedIndex].value == 0 ) {
- what.form.dst.disabled = false;
- what.form.dst.style.backgroundColor = "white";
- } else {
- what.form.dst.disabled = true;
- what.form.dst.style.backgroundColor = "lightgrey";
- }
-}
-</SCRIPT>
-
-<% ntable("#cccccc",2) %>
-<TR><TD ALIGN="right">Email to</TD>
-<TD><SELECT NAME="srcsvc" SIZE=1 onChange="srcchanged(this)">
-% foreach $_ (keys %email) {
-
- <OPTION<% $_ eq $srcsvc ? " SELECTED" : "" %> VALUE="<% $_ %>"><% $email{$_} %></OPTION>
-% }
-% if ( $svc_forward->dbdef_table->column('src') ) {
-
- <OPTION <% $src ? 'SELECTED' : '' %> VALUE="0">(other email address)</OPTION>
-% }
-
-</SELECT>
-% if ( $svc_forward->dbdef_table->column('src') ) {
-
-<INPUT TYPE="text" NAME="src" VALUE="<% $src %>" <% ( $src || !scalar(%email) ) ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>>
-% }
-
-</TD></TR>
-<TR><TD ALIGN="right">Forwards to</TD>
-<TD><SELECT NAME="dstsvc" SIZE=1 onChange="dstchanged(this)">
-% foreach $_ (keys %email) {
+<% include('elements/svc_forward.html',
+ 'conf' => $conf,
+ 'svcnum' => $svcnum,
+ 'pkgnum' => $pkgnum,
+ 'svcpart' => $svcpart,
+ 'srcsvc' => $srcsvc,
+ 'dstsvc' => $dstsvc,
+ 'src' => $src,
+ 'dst' => $dst,
+ 'email' => \%email,
+ ) %>
- <OPTION<% $_ eq $dstsvc ? " SELECTED" : "" %> VALUE="<% $_ %>"><% $email{$_} %></OPTION>
-% }
-
-<OPTION <% $dst ? 'SELECTED' : '' %> VALUE="0">(other email address)</OPTION>
-</SELECT>
-<INPUT TYPE="text" NAME="dst" VALUE="<% $dst %>" <% ( $dst || !scalar(%email) ) ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>>
-</TD></TR>
- </TABLE>
<BR><INPUT TYPE="submit" VALUE="Submit">
</FORM>
my %email;
-#starting with those currently attached
-foreach my $method (qw( srcsvc_acct dstsvc_acct )) {
- my $svc_acct = $svc_forward->$method();
- $email{$svc_acct->svcnum} = $svc_acct->email if $svc_acct;
-}
-
if ($pkgnum) {
#find all possible user svcnums (and emails)
- #and including the rest for this customer
- my($u_part_svc,@u_acct_svcparts);
- foreach $u_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_acct'}) ) {
- push @u_acct_svcparts,$u_part_svc->getfield('svcpart');
- }
-
- my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
- my($custnum)=$cust_pkg->getfield('custnum');
- my($i_cust_pkg);
- foreach $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) {
- my($cust_pkgnum)=$i_cust_pkg->getfield('pkgnum');
- my($acct_svcpart);
- foreach $acct_svcpart (@u_acct_svcparts) { #now find the corresponding
- #record(s) in cust_svc ( for this
- #pkgnum ! )
- foreach my $i_cust_svc (
- qsearch( 'cust_svc', { 'pkgnum' => $cust_pkgnum,
- 'svcpart' => $acct_svcpart } )
- ) {
- my $svc_acct =
- qsearchs( 'svc_acct', { 'svcnum' => $i_cust_svc->svcnum } );
- $email{$svc_acct->svcnum} = $svc_acct->email;
- }
- }
- }
+ my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
+ die "Specified package not found" unless $cust_pkg;
+ %email = $cust_pkg->forward_emails('svc_forward' => $svc_forward);
} elsif ( $action eq 'Add' ) {
+
die "\$action eq Add, but \$pkgnum is null!\n";
+
+} else {
+
+ use FS::cust_pkg;
+ %email = FS::cust_pkg->forward_emails('svc_forward' => $svc_forward);
+
}
my($srcsvc,$dstsvc,$dst)=(