1 <% include('/elements/header.html', "Mail Forward $action") %>
3 <% include('/elements/error.html') %>
5 Service #<% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
6 Service: <B><% $part_svc->svc %></B><BR><BR>
8 <FORM ACTION="process/svc_forward.cgi" METHOD="POST">
9 <INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
10 <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
11 <INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
13 <SCRIPT TYPE="text/javascript">
14 function srcchanged(what) {
15 if ( what.options[what.selectedIndex].value == 0 ) {
16 what.form.src.disabled = false;
17 what.form.src.style.backgroundColor = "white";
19 what.form.src.disabled = true;
20 what.form.src.style.backgroundColor = "lightgrey";
23 function dstchanged(what) {
24 if ( what.options[what.selectedIndex].value == 0 ) {
25 what.form.dst.disabled = false;
26 what.form.dst.style.backgroundColor = "white";
28 what.form.dst.disabled = true;
29 what.form.dst.style.backgroundColor = "lightgrey";
34 <% ntable("#cccccc",2) %>
37 <TD ALIGN="right">Email to</TD>
39 % if ( $conf->exists('svc_forward-no_srcsvc') ) {
40 <INPUT NAME="srcsrc" TYPE="hidden" VALUE="0">
42 <SELECT NAME="srcsvc" SIZE=1 onChange="srcchanged(this)">
43 % foreach $_ (keys %email) {
44 <OPTION VALUE="<% $_ %>"
45 <% $_ eq $srcsvc ? 'SELECTED' : '' %>
46 ><% $email{$_} %></OPTION>
48 <OPTION VALUE="0" <% $src ? 'SELECTED' : '' %>
49 >(other email address)</OPTION>
53 % my $src_disabled = $src
54 % || $conf->exists('svc_forward-no_srcsvc')
59 <% $src_disabled ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>
65 <TR><TD ALIGN="right">Forwards to</TD>
66 <TD><SELECT NAME="dstsvc" SIZE=1 onChange="dstchanged(this)">
67 % foreach $_ (keys %email) {
69 <OPTION<% $_ eq $dstsvc ? " SELECTED" : "" %> VALUE="<% $_ %>"><% $email{$_} %></OPTION>
72 <OPTION <% $dst ? 'SELECTED' : '' %> VALUE="0">(other email address)</OPTION>
74 <INPUT TYPE="text" NAME="dst" VALUE="<% $dst %>" <% ( $dst || !scalar(%email) ) ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>>
77 <BR><INPUT TYPE="submit" VALUE="Submit">
80 <% include('/elements/footer.html') %>
85 unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
87 my $conf = new FS::Conf;
89 my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_forward);
90 if ( $cgi->param('error') ) {
91 $svc_forward = new FS::svc_forward ( {
92 map { $_, scalar($cgi->param($_)) } fields('svc_forward')
94 $svcnum = $svc_forward->svcnum;
95 $pkgnum = $cgi->param('pkgnum');
96 $svcpart = $cgi->param('svcpart');
97 $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
98 die "No part_svc entry!" unless $part_svc;
100 } elsif ( $cgi->param('pkgnum') && $cgi->param('svcpart') ) { #adding
102 $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
104 $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
107 $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
108 die "No part_svc entry!" unless $part_svc;
110 $svc_forward = new FS::svc_forward({});
114 $svc_forward->set_default_and_fixed;
118 my($query) = $cgi->keywords;
120 $query =~ /^(\d+)$/ or die "unparsable svcnum";
122 $svc_forward=qsearchs('svc_forward',{'svcnum'=>$svcnum})
123 or die "Unknown (svc_forward) svcnum!";
125 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum})
126 or die "Unknown (cust_svc) svcnum!";
128 $pkgnum=$cust_svc->pkgnum;
129 $svcpart=$cust_svc->svcpart;
131 $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
132 die "No part_svc entry!" unless $part_svc;
135 my $action = $svc_forward->svcnum ? 'Edit' : 'Add';
139 #starting with those currently attached
140 foreach my $method (qw( srcsvc_acct dstsvc_acct )) {
141 my $svc_acct = $svc_forward->$method();
142 $email{$svc_acct->svcnum} = $svc_acct->email if $svc_acct;
147 #find all possible user svcnums (and emails)
149 #and including the rest for this customer
150 my($u_part_svc,@u_acct_svcparts);
151 foreach $u_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_acct'}) ) {
152 push @u_acct_svcparts,$u_part_svc->getfield('svcpart');
155 my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
156 my($custnum)=$cust_pkg->getfield('custnum');
158 foreach $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) {
159 my($cust_pkgnum)=$i_cust_pkg->getfield('pkgnum');
161 foreach $acct_svcpart (@u_acct_svcparts) { #now find the corresponding
162 #record(s) in cust_svc ( for this
164 foreach my $i_cust_svc (
165 qsearch( 'cust_svc', { 'pkgnum' => $cust_pkgnum,
166 'svcpart' => $acct_svcpart } )
169 qsearchs( 'svc_acct', { 'svcnum' => $i_cust_svc->svcnum } );
170 $email{$svc_acct->svcnum} = $svc_acct->email;
175 } elsif ( $action eq 'Add' ) {
176 die "\$action eq Add, but \$pkgnum is null!\n";
179 my($srcsvc,$dstsvc,$dst)=(
180 $svc_forward->srcsvc,
181 $svc_forward->dstsvc,
184 my $src = $svc_forward->dbdef_table->column('src') ? $svc_forward->src : '';