1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
<%
#
# $Id: svc_forward.cgi,v 1.1 2001-08-19 15:53:35 jeff Exp $
#
# Usage: svc_forward.cgi {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
# http://server.name/path/svc_forward.cgi? {svcnum} | pkgnum{pkgnum}-svcpart{svcpart}
#
# use {svcnum} for edit, pkgnum{pkgnum}-svcpart{svcpart} for add
#
# should error out in a more CGI-friendly way, and should have more error checking (sigh).
#
# $Log: svc_forward.cgi,v $
# Revision 1.1 2001-08-19 15:53:35 jeff
# added user interface for svc_forward and vpopmail support
#
#
use strict;
use vars qw( $conf $cgi $mydomain $action $svcnum $svc_forward $pkgnum $svcpart
$part_svc $query %email $p1 $srcsvc $dstsvc $dst );
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use FS::UID qw(cgisuidsetup);
use FS::CGI qw(header popurl);
use FS::Record qw(qsearch qsearchs fields);
use FS::svc_forward;
use FS::Conf;
$cgi = new CGI;
&cgisuidsetup($cgi);
$conf = new FS::Conf;
$mydomain = $conf->config('domain');
if ( $cgi->param('error') ) {
$svc_forward = new FS::svc_forward ( {
map { $_, scalar($cgi->param($_)) } fields('svc_forward')
} );
$svcnum = $svc_forward->svcnum;
$pkgnum = $cgi->param('pkgnum');
$svcpart = $cgi->param('svcpart');
$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
die "No part_svc entry!" unless $part_svc;
} else {
my($query) = $cgi->keywords;
if ( $query =~ /^(\d+)$/ ) { #editing
$svcnum=$1;
$svc_forward=qsearchs('svc_forward',{'svcnum'=>$svcnum})
or die "Unknown (svc_forward) svcnum!";
my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum})
or die "Unknown (cust_svc) svcnum!";
$pkgnum=$cust_svc->pkgnum;
$svcpart=$cust_svc->svcpart;
$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
die "No part_svc entry!" unless $part_svc;
} else { #adding
$svc_forward = new FS::svc_forward({});
foreach $_ (split(/-/,$query)) { #get & untaint pkgnum & svcpart
$pkgnum=$1 if /^pkgnum(\d+)$/;
$svcpart=$1 if /^svcpart(\d+)$/;
}
$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
die "No part_svc entry!" unless $part_svc;
$svcnum='';
#set fixed and default fields from part_svc
my($field);
foreach $field ( fields('svc_forward') ) {
if ( $part_svc->getfield('svc_forward__'. $field. '_flag') ne '' ) {
$svc_forward->setfield($field,$part_svc->getfield('svc_forward__'. $field) );
}
}
}
}
$action = $svc_forward->svcnum ? 'Edit' : 'Add';
if ($pkgnum) {
#find all possible user svcnums (and emails)
#starting with those currently attached
my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$svc_forward->srcsvc});
$email{$svc_forward->srcsvc} = $svc_acct->email;
if ($svc_forward->dstsvc) {
$svc_acct=qsearchs('svc_acct',{'svcnum'=>$svc_forward->dstsvc});
$email{$svc_forward->dstsvc} = $svc_acct->email;
}
#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 ! )
my($i_cust_svc);
foreach $i_cust_svc ( qsearch('cust_svc',{'pkgnum'=>$cust_pkgnum,'svcpart'=>$acct_svcpart}) ) {
$svc_acct=qsearchs('svc_acct',{'svcnum'=>$i_cust_svc->getfield('svcnum')});
$email{$svc_acct->getfield('svcnum')}=$svc_acct->email;
}
}
}
} elsif ( $action eq 'Edit' ) {
my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$svc_forward->srcsvc});
$email{$svc_forward->srcsvc} = $svc_acct->email;
$svc_acct=qsearchs('svc_acct',{'svcnum'=>$svc_forward->dstsvc});
$email{$svc_forward->dstsvc} = $svc_acct->email;
} else {
die "\$action eq Add, but \$pkgnum is null!\n";
}
($srcsvc,$dstsvc,$dst)=(
$svc_forward->srcsvc,
$svc_forward->dstsvc,
$svc_forward->dst,
);
#display
$p1 = popurl(1);
print $cgi->header( '-expires' => 'now' ), header("Mail Forward $action", '',
" onLoad=\"visualize()\"");
%>
<SCRIPT>
function visualize(what){
if (document.getElementById) {
document.getElementById('dother').style.visibility = '<%= $dstsvc ? 'hidden' : 'visible' %>';
}
}
function fixup(what){
if (document.getElementById) {
if (document.getElementById('dother').style.visibility == 'hidden') {
what.dst.value='';
}
}
}
</SCRIPT>
<%
print qq!<FONT SIZE="+1" COLOR="#ff0000">Error: !, $cgi->param('error'),
"</FONT>"
if $cgi->param('error');
print qq!<FORM ACTION="${p1}process/svc_forward.cgi" onSubmit="fixup(this)" METHOD=POST>!;
#svcnum
print qq!<INPUT TYPE="hidden" NAME="svcnum" VALUE="$svcnum">!;
print qq!Service #<FONT SIZE=+1><B>!, $svcnum ? $svcnum : " (NEW)", "</B></FONT>";
print qq!<BR>!;
#pkgnum
print qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">!;
#svcpart
print qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">!;
#srcsvc
print qq!\n\nMail to <SELECT NAME="srcsvc" SIZE=1>!;
foreach $_ (keys %email) {
print "<OPTION", $_ eq $srcsvc ? " SELECTED" : "",
qq! VALUE="$_">$email{$_}!;
}
print "</SELECT>";
#dstsvc
print qq! forwards to <SELECT NAME="dstsvc" SIZE=1 onChange="changed(this)">!;
foreach $_ (keys %email) {
print "<OPTION", $_ eq $dstsvc ? " SELECTED" : "",
qq! VALUE="$_">$email{$_}!;
}
print "<OPTION", 0 eq $dstsvc ? " SELECTED" : "",
qq! VALUE="0">(other)!;
print "</SELECT> mailbox.";
%>
<SCRIPT>
var selectchoice = null;
function changed(what) {
selectchoice = what.options[what.selectedIndex].value;
if (selectchoice == "0") {
if (document.getElementById) {
document.getElementById('dother').style.visibility = "visible";
}
}else{
if (document.getElementById) {
document.getElementById('dother').style.visibility = "hidden";
}
}
}
if (document.getElementById) {
document.write("<DIV ID=\"dother\" STYLE=\"visibility: hidden\">");
}
</SCRIPT>
<%
print qq! Other destination: <INPUT TYPE="text" NAME="dst" VALUE="$dst">!;
%>
<SCRIPT>
if (document.getElementById) {
document.write("</DIV>");
}
</SCRIPT>
<CENTER><INPUT TYPE="submit" VALUE="Submit"></CENTER>
</FORM>
<TAG onLoad="
if (document.getElementById) {
document.getElementById('dother').style.visibility = '<%= $dstsvc ? 'hidden' : 'visible' %>';
document.getElementById('dlabel').style.visibility = '<%= $dstsvc ? 'hidden' : 'visible' %>';
}
">
</BODY>
</HTML>
|