<%init>
my %opt = @_;
my @routers;
my $conf = FS::Conf->new;
my $svc_x = $opt{'object'};
if ( $svc_x ) {
# $svc_x->ip_addr does work, even for non-svc_broadband.
$opt{$_} = $svc_x->$_
foreach qw(routernum blocknum ip_addr svcpart);
if ( $svc_x->svcnum ) {
$opt{'svcpart'} = $svc_x->cust_svc->svcpart;
}
}
my $svcpart = $opt{'svcpart'} || '';
my $ip_field = $opt{'ip_field'} || 'ip_addr';
my %fixed; # which fields are fixed
$svcpart =~ /^\d*$/ or die "invalid svcpart '$svcpart'";
if ( $svcpart ) {
my $part_svc = FS::part_svc->by_key($svcpart);
# Traditionally, columnflag 'F' on IP address means that it MUST
# be auto-assigned (or, if null IP addresses are allowed, that
# it must be null).
foreach (qw(routernum blocknum), $ip_field) {
my $psc = $part_svc->part_svc_column($_);
if ( $psc and $psc->columnflag eq 'F' ) {
$fixed{$_} = $psc->columnvalue;
}
}
if ( exists $fixed{'routernum'} ) {
@routers = (FS::router->by_key($fixed{'routernum'}))
}
else {
@routers = map { $_->router }
qsearch('part_svc_router', { svcpart => $svcpart });
}
}
else {
@routers = qsearch('router', {});
}
my %manual_addr_routernum = map { $_->routernum, $_->manual_addr } @routers;
if ( $conf->exists('auto_router') ) {
# Then show an "(automatic)" router, with no blocks. manual_addr is on
# so that the ip_addr field will be unlocked.
unshift @routers, FS::router->new({
'routernum' => '',
'routername' => '(automatic)',
'manual_addr' => 'Y',
});
$manual_addr_routernum{''} = 'Y';
}
%init>