4 my $conf = new FS::Conf;
6 my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_forward);
7 if ( $cgi->param('error') ) {
8 $svc_forward = new FS::svc_forward ( {
9 map { $_, scalar($cgi->param($_)) } fields('svc_forward')
11 $svcnum = $svc_forward->svcnum;
12 $pkgnum = $cgi->param('pkgnum');
13 $svcpart = $cgi->param('svcpart');
14 $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
15 die "No part_svc entry!" unless $part_svc;
18 my($query) = $cgi->keywords;
20 if ( $query =~ /^(\d+)$/ ) { #editing
22 $svc_forward=qsearchs('svc_forward',{'svcnum'=>$svcnum})
23 or die "Unknown (svc_forward) svcnum!";
25 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum})
26 or die "Unknown (cust_svc) svcnum!";
28 $pkgnum=$cust_svc->pkgnum;
29 $svcpart=$cust_svc->svcpart;
31 $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
32 die "No part_svc entry!" unless $part_svc;
36 $svc_forward = new FS::svc_forward({});
38 foreach $_ (split(/-/,$query)) { #get & untaint pkgnum & svcpart
39 $pkgnum=$1 if /^pkgnum(\d+)$/;
40 $svcpart=$1 if /^svcpart(\d+)$/;
42 $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
43 die "No part_svc entry!" unless $part_svc;
47 #set fixed and default fields from part_svc
48 foreach my $part_svc_column (
49 grep { $_->columnflag } $part_svc->all_part_svc_column
51 $svc_forward->setfield( $part_svc_column->columnname,
52 $part_svc_column->columnvalue,
58 my $action = $svc_forward->svcnum ? 'Edit' : 'Add';
63 #find all possible user svcnums (and emails)
65 #starting with those currently attached
66 if ( $svc_forward->srcsvc ) {
67 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $svc_forward->srcsvc } );
68 $email{$svc_forward->srcsvc} = $svc_acct->email;
70 if ( $svc_forward->dstsvc ) {
71 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $svc_forward->dstsvc } );
72 $email{$svc_forward->dstsvc} = $svc_acct->email;
75 #and including the rest for this customer
76 my($u_part_svc,@u_acct_svcparts);
77 foreach $u_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_acct'}) ) {
78 push @u_acct_svcparts,$u_part_svc->getfield('svcpart');
81 my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
82 my($custnum)=$cust_pkg->getfield('custnum');
84 foreach $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) {
85 my($cust_pkgnum)=$i_cust_pkg->getfield('pkgnum');
87 foreach $acct_svcpart (@u_acct_svcparts) { #now find the corresponding
88 #record(s) in cust_svc ( for this
90 foreach my $i_cust_svc (
91 qsearch( 'cust_svc', { 'pkgnum' => $cust_pkgnum,
92 'svcpart' => $acct_svcpart } )
95 qsearchs( 'svc_acct', { 'svcnum' => $i_cust_svc->svcnum } );
96 $email{$svc_acct->svcnum} = $svc_acct->email;
101 } elsif ( $action eq 'Edit' ) {
103 my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$svc_forward->srcsvc});
104 $email{$svc_forward->srcsvc} = $svc_acct->email;
106 $svc_acct=qsearchs('svc_acct',{'svcnum'=>$svc_forward->dstsvc});
107 $email{$svc_forward->dstsvc} = $svc_acct->email;
110 die "\$action eq Add, but \$pkgnum is null!\n";
113 my($srcsvc,$dstsvc,$dst)=(
114 $svc_forward->srcsvc,
115 $svc_forward->dstsvc,
123 <%= header("Mail Forward $action") %>
125 <% if ( $cgi->param('error') ) { %>
126 <FONT SIZE="+1" COLOR="#ff0000">Error: <%= $cgi->param('error') %></FONT>
130 Service #<%= $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
131 Service: <B><%= $part_svc->svc %></B><BR><BR>
135 <%= ntable("#cccccc",2) %>
136 <TR><TD ALIGN="right">Email to</TD><TD><SELECT NAME="srcsvc" SIZE=1>
137 <% foreach $_ (keys %email) { %>
138 <OPTION<%= $_ eq $srcsvc ? " SELECTED" : "" %> VALUE="<%= $_ %>"><%= $email{$_} %></OPTION>
143 tie my %tied_email, 'Tie::IxHash',
144 '' => 'SELECT DESTINATION',
146 '0' => '(other email address)';
147 my $widget = new HTML::Widgets::SelectLayers(
148 'selected_layer' => $dstsvc,
149 'options' => \%tied_email,
150 'form_name' => 'dummy',
151 'form_action' => 'process/svc_forward.cgi',
152 'form_select' => ['srcsvc'],
153 'html_between' => '</TD></TR></TABLE>',
154 'layer_callback' => sub {
156 my $html = qq!<INPUT TYPE="hidden" NAME="svcnum" VALUE="$svcnum">!.
157 qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">!.
158 qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">!.
159 qq!<INPUT TYPE="hidden" NAME="dstsvc" VALUE="$layer">!;
160 if ( $layer eq '0' ) {
161 $html .= ntable("#cccccc",2).
162 '<TR><TD ALIGN="right">Destination email</TD>'.
163 qq!<TD><INPUT TYPE="text" NAME="dst" VALUE="$dst"></TD>!.
166 $html .= '<BR><INPUT TYPE="submit" VALUE="Submit">';
172 <TR><TD ALIGN="right">Forwards to</TD>
173 <TD><%= $widget->html %>