& /elements/header.html, mt("$action [_1] account",$svc) &>
<& /elements/error.html &>
% if ( $cust_main ) {
<& /elements/small_custview.html, $cust_main, '', 1,
popurl(2) . "view/cust_main.cgi" &>
% }
<& /elements/footer.html &>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
my $conf = new FS::Conf;
my @shells = $conf->config('shells');
my $curuser = $FS::CurrentUser::CurrentUser;
my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_acct, @groups);
if ( $cgi->param('error') ) {
$svc_acct = new FS::svc_acct ( {
map { $_, scalar($cgi->param($_)) } fields('svc_acct')
} );
$svcnum = $svc_acct->svcnum;
$pkgnum = $cgi->param('pkgnum');
$svcpart = $cgi->param('svcpart');
$part_svc = qsearchs( 'part_svc', { 'svcpart' => $svcpart } );
die "No part_svc entry for svcpart $svcpart!" unless $part_svc;
@groups = $cgi->param('radius_usergroup');
} elsif ( $cgi->param('pkgnum') && $cgi->param('svcpart') ) { #adding
$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
$pkgnum = $1;
$cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
$svcpart = $1;
$part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
die "No part_svc entry!" unless $part_svc;
$svc_acct = new FS::svc_acct({svcpart => $svcpart});
$svcnum='';
$svc_acct->password_recover('Y'); #default. hmm.
} else { #editing
my($query) = $cgi->keywords;
$query =~ /^(\d+)$/ or die "unparsable svcnum";
$svcnum=$1;
$svc_acct=qsearchs('svc_acct',{'svcnum'=>$svcnum})
or die "Unknown (svc_acct) 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 for svcpart $svcpart!" unless $part_svc;
@groups = $svc_acct->radius_groups;
}
my $communigate = scalar($part_svc->part_export('communigate_pro'));
# || scalar($part_svc->part_export('communigate_pro_singledomain'));
my( $cust_pkg, $cust_main ) = ( '', '' );
if ( $pkgnum ) {
$cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum } );
$cust_main = $cust_pkg->cust_main;
}
unless ( $svcnum || $cgi->param('error') ) { #adding
#set gecos
if ($cust_main) {
unless ( $part_svc->part_svc_column('uid')->columnflag eq 'F' ) {
$svc_acct->setfield('finger',
$cust_main->getfield('first') . " " . $cust_main->getfield('last')
);
}
}
$svc_acct->set_default_and_fixed( {
#false laziness w/svc-acct::_fieldhandlers
'usergroup' => sub {
my( $self, $groups ) = @_;
if ( ref($groups) eq 'ARRAY' ) {
@groups = @$groups;
$groups;
} elsif ( length($groups) ) {
@groups = split(/\s*,\s*/, $groups);
[ @groups ];
} else {
@groups = ();
[];
}
}
} );
}
my $part_svc_usergroup = $part_svc->part_svc_column('usergroup');
#fixed radius groups always override & display
my @groupnames; # only used for display of Fixed RADIUS groups
if ( $part_svc_usergroup->columnflag eq 'F' ) {
@groups = split(',',$part_svc_usergroup->columnvalue);
@groupnames = map { $_->long_description }
qsearch({ 'table' => 'radius_group',
'extra_sql' => "where groupnum in (".$part_svc_usergroup->columnvalue.")",
}) if length($part_svc_usergroup->columnvalue);
}
my $action = $svcnum ? 'Edit' : 'Add';
my $svc = $part_svc->getfield('svc');
my $otaker = getotaker;
my $username = $svc_acct->username;
my $password = '';
if ( $cgi->param('error') ) {
$password = $cgi->param('clear_password');
} elsif ( $svcnum ) {
my $password_encryption = $svc_acct->_password_encryption;
if ( $password = $svc_acct->get_cleartext_password ) {
$password = '*HIDDEN*' unless $conf->exists('showpasswords');
} elsif( $svc_acct->_password and $password_encryption ne 'plain' ) {
$password = "(".uc($password_encryption)." encrypted)";
}
}
my $ulen =
$conf->exists('usernamemax')
? $conf->config('usernamemax')
: dbdef->table('svc_acct')->column('username')->length;
my $ulen2 = $ulen+2;
my $pmax = max($conf->config('passwordmax') || 13);
my $pmax2 = $pmax+2;
my $p1 = popurl(1);
sub max {
(sort(@_))[-1]
}
my $captcha_url;
my ($export_google) = $part_svc->part_export('acct_google');
if ( $export_google ) {
my $error = $export_google->auth_error;
if ( $error ) {
if ( $error->{'captcha_url'} ) {
$captcha_url = $error->{'captcha_url'};
}
else {
$cgi->param('error', $error->{'message'});
}
} #if $error
}
if ( $part_svc->has_router ) { # duplicates the one in elements/svc_Common
if ( $svcnum ) {
my $router = qsearchs('router', {svcnum => $svc_acct->svcnum});
if ( $router ) {
$svc_acct->set("router_$_", $router->get($_))
foreach ('routername', 'routernum');
my ($block) = $router->addr_block;
$svc_acct->set('router_blocknum', $block->blocknum) if ( $block );
}
}
foreach (qw(router_routername router_routernum router_blocknum)) {
if ( $cgi->param($_) =~ /^(\w+)$/ ) {
$svc_acct->set($_, $1);
}
}
}
%init>