%
# If it's stupid but it works, it's still stupid.
# -Kristian
use HTML::Widgets::SelectLayers;
use Tie::IxHash;
my( $svcnum, $pkgnum, $svcpart, $part_svc, $svc_broadband );
if ( $cgi->param('error') ) {
$svc_broadband = new FS::svc_broadband ( {
map { $_, scalar($cgi->param($_)) } fields('svc_broadband')
} );
$svcnum = $svc_broadband->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_broadband=qsearchs('svc_broadband',{'svcnum'=>$svcnum})
or die "Unknown (svc_broadband) 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_broadband = new FS::svc_broadband({});
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;
$svc_broadband->setfield('svcpart', $svcpart);
$svcnum='';
#set fixed and default fields from part_svc
foreach my $part_svc_column (
grep { $_->columnflag } $part_svc->all_part_svc_column
) {
$svc_broadband->setfield( $part_svc_column->columnname,
$part_svc_column->columnvalue,
);
}
}
}
my $action = $svc_broadband->svcnum ? 'Edit' : 'Add';
if ($pkgnum) {
#Nothing?
} elsif ( $action eq 'Edit' ) {
#Nothing?
} else {
die "\$action eq Add, but \$pkgnum is null!\n";
}
my $p1 = popurl(1);
my ($ip_addr, $speed_up, $speed_down, $blocknum) =
($svc_broadband->ip_addr,
$svc_broadband->speed_up,
$svc_broadband->speed_down,
$svc_broadband->blocknum);
%>
<%=header("Broadband Service $action", '')%>
<% if ($cgi->param('error')) { %>
Error: <%=$cgi->param('error')%>
<% } %>
Service #<%=$svcnum ? $svcnum : "(NEW)"%>