my($context, $session, $custnum) = _custoragent_session_custnum($p);
#return { 'error' => $session } if $context eq 'error';
+ my $domain = $session->{'domain'};
+
my $agentnum = '';
if ( $context eq 'customer' && $custnum ) {
$p->{'agentnum'} = $agentnum;
my $conf = new FS::Conf;
-
+ my $timeout = $conf->config('selfservice-session_timeout') || '1 hour';
#false laziness w/Signup.pm
my $skin_info_cache_agent = _cache->get("skin_info_cache_agent$agentnum");
warn "$me populating skin info cache for agentnum $agentnum\n"
if $DEBUG > 1;
+ my $menu = $conf->config("ng_selfservice-menu", $agentnum );
+
$skin_info_cache_agent = {
'agentnum' => $agentnum,
( map { $_ => scalar( $conf->config($_, $agentnum) ) }
( map { $_ => join("\n", $conf->config("selfservice-$_", $agentnum ) ) }
qw( head body_header body_footer company_address ) ),
'money_char' => $conf->config("money_char") || '$',
- 'menu' => join("\n", $conf->config("ng_selfservice-menu", $agentnum ) ) ||
+ 'menu' => _menu($domain,$menu),
+ };
+
+ _cache->set("skin_info_cache_agent$agentnum", $skin_info_cache_agent, $timeout);
+
+ }
+
+ #{ %$skin_info_cache_agent };
+ $skin_info_cache_agent;
+
+}
+
+## checks if page is in menu listing, if not sends to main with error.
+sub check_access {
+ my $p = shift;
+ my $error;
+
+ return if $p->{'page'} eq "index.php";
+ return if $p->{'page'} eq "ip_login.php";
+
+ return if substr($p->{'page'}, 0, length("process_")) eq "process_";
+
+ my $conf = new FS::Conf;
+
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+
+ my $domain = ref($session) ? $session->{'domain'} : '';
+
+ my $agentnum = '';
+ if ( $context eq 'customer' && $custnum ) {
+
+ my $sth = dbh->prepare('SELECT agentnum FROM cust_main WHERE custnum = ?')
+ or die dbh->errstr;
+
+ $sth->execute($custnum) or die $sth->errstr;
+
+ $agentnum = $sth->fetchrow_arrayref->[0]
+ or die "no agentnum for custnum $custnum";
+
+ #} elsif ( $context eq 'agent' ) {
+ } elsif ( defined($p->{'agentnum'}) and $p->{'agentnum'} =~ /^(\d+)$/ ) {
+ $agentnum = $1;
+ }
+ $p->{'agentnum'} = $agentnum;
+
+ my $menu = $conf->config("ng_selfservice-menu", $agentnum );
+
+ my $allowed_pages = _menu($domain,$menu);
+
+ my %allowed;
+ my @lines = split /\n/, $allowed_pages;
+ foreach my $line (@lines) {
+ chomp; # remove newlines
+ $line =~ s/^\s+//; # remove leading whitespace
+ next unless length($line);
+ my (@pages) = split(/ /, $line, 2);
+ $allowed{$pages[0]} = $pages[1];
+ }
+
+ $error = "You do not have access to the page ".$allowed{$p->{page}} unless $allowed{$p->{page}};
+
+ return { 'error' => $error, };
+
+}
+
+sub _menu {
+ my $p = shift;
+ my $m = shift;
+
+ my $menu;
+
+ if ($p eq 'ip_mac') {
+ $menu = 'main.php Home
+
+ payment.php Payments
+ payment_cc.php Credit Card Payment
+ payment_ach.php Electronic Check Payment
+ payment_paypal.php PayPal Payment
+ payment_webpay.php Webpay Payments
+
+ docs.php FAQs
+
+ logout.php Logout
+ ';
+ }
+ else {
+ $menu = join("\n", $m ) ||
'main.php Home
services.php Services
docs.php FAQs
logout.php Logout
- ',
- };
+ ';
+ }
+ return $menu;
+}
- _cache->set("skin_info_cache_agent$agentnum", $skin_info_cache_agent);
+sub get_mac_address {
+ my $p = shift;
- }
+## access radius exports acct tables to get mac
+ my @part_export = ();
+ @part_export = (
+ qsearch( 'part_export', { 'exporttype' => 'sqlradius' } ),
+ qsearch( 'part_export', { 'exporttype' => 'sqlradius_withdomain' } ),
+ qsearch( 'part_export', { 'exporttype' => 'broadband_sqlradius' } ),
+ );
- #{ %$skin_info_cache_agent };
- $skin_info_cache_agent;
+ my @sessions;
+ foreach my $part_export (@part_export) {
+ push @sessions, ( @{ $part_export->usage_sessions( {
+ 'ip' => $p->{'ip'},
+ 'session_status' => 'open',
+ } ) } );
+ }
+ return { 'mac_address' => $sessions[0]->{'callingstationid'}, };
}
sub login_info {
my %info = (
%{ skin_info($p) },
- 'phone_login' => $conf->exists('selfservice_server-phone_login'),
- 'single_domain'=> scalar($conf->config('selfservice_server-single_domain')),
+ 'phone_login' => $conf->exists('selfservice_server-phone_login'),
+ 'single_domain' => scalar($conf->config('selfservice_server-single_domain')),
'banner_url' => scalar($conf->config('selfservice-login_banner_url')),
'banner_image_md5' =>
md5_hex($conf->config_binary('selfservice-login_banner_image')),
$svc_x = $svc_phone;
+ } elsif ( $p->{'domain'} eq 'ip_mac' ) {
+
+ return { error => 'MAC address empty '.$p->{'username'} }
+ unless $p->{'username'};
+
+ my $mac_address = $p->{'username'};
+ $mac_address =~ s/[\:\,\-\. ]//g;
+ $mac_address =~ tr/[a-z]/[A-Z/;
+
+ my $svc_broadband = qsearchs( 'svc_broadband', { 'mac_addr' => $mac_address } );
+ return { error => 'MAC address not found '.$p->{'username'} }
+ unless $svc_broadband;
+ $svc_x = $svc_broadband;
+
+ $session->{'domain'} = $p->{'domain'};
+
} elsif ( $p->{email}
&& (my $contact = FS::contact->by_selfservice_email($p->{email}))
)
for (@cust_main_editable_fields) {
$return{$_} = $cust_main->get($_);
}
+ $return{$_} = $cust_main->masked($_) for qw/ss stateid/;
+
#maybe a little more expensive, but it should be cached by now
for (@location_editable_fields) {
$return{$_} = $cust_main->bill_location->get($_)
my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
or return { 'error' => "unknown custnum $custnum" };
+ my $conf = new FS::Conf;
+ if (($p->{payby} eq "CHEK" || $p->{payby} eq "DCHEK") && $conf->exists('selfservice-ACH_info_readonly')) {
+ return { 'error' => "You do not have authority to add a bank account" };
+ }
+
my $new = new FS::cust_main { $cust_main->hash };
$new->set( $_ => $p->{$_} )
# but if it hasn't been passed in at all, leave ship_location alone--
# DON'T change it to match bill_location.
- my $conf = new FS::Conf;
-
my @invoicing_list;
if ( exists $p->{'invoicing_list'} || exists $p->{'postal_invoicing'} ) {
#false laziness with httemplate/edit/process/cust_main.cgi
'show_paystate' => $conf->exists('show_bankstate'),
'save_unchecked' => $conf->exists('selfservice-save_unchecked'),
+ 'ach_read_only' => $conf->exists('selfservice-ACH_info_readonly'),
};
if ($cust_payby) {
$return{payname} = $cust_payby->payname
|| ( $cust_main->first. ' '. $cust_main->get('last') );
+ $return{custpaybynum} = $cust_payby->custpaybynum;
if ( $cust_payby->payby =~ /^(CARD|DCRD)$/ ) {
$return{card_type} = cardtype($cust_payby->payinfo);
$return{paybatch} = $return{payunique}; #back compat
$return{credit_card_surcharge_percentage} = $conf->config('credit-card-surcharge-percentage', $cust_main->agentnum);
+ $return{credit_card_surcharge_flatfee} = $conf->config('credit-card-surcharge-flatfee', $cust_main->agentnum);
return { 'error' => '',
%return,
#false laziness w/process/payment.cgi
my $payinfo;
my $paycvv = '';
+ my $replace_cust_payby;
if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
$p->{'payinfo1'} =~ /^([\dx]+)$/
my $payinfo2 = $1;
$payinfo = $payinfo1. '@'. $payinfo2;
+ my $achonfile = 0;
foreach my $cust_payby ($cust_main->cust_payby('CHEK','DCHK')) {
if ( $cust_payby->paymask eq $payinfo ) {
$payinfo = $cust_payby->payinfo;
+ $replace_cust_payby = $cust_payby;
+ $achonfile = 1;
last;
}
}
+
+ if ($conf->exists('selfservice-ACH_info_readonly') && !$achonfile) {
+ return { 'error' => "You are not allowed to change your payment information." };
+ }
} elsif ( $payby eq 'CARD' || $payby eq 'DCRD' ) {
foreach my $cust_payby ($cust_main->cust_payby('CARD','DCRD')) {
if ( $cust_payby->paymask eq $payinfo ) {
$payinfo = $cust_payby->payinfo;
+ $replace_cust_payby = $cust_payby;
$onfile = 1;
last;
}
'CHEK' => [ qw( ss paytype paystate stateid stateid_state payip ) ],
);
+ my %replace = ( 'replace' => $replace_cust_payby, );
+
my $card_type = '';
$card_type = cardtype($payinfo) if $payby eq 'CARD';
'amount' => sprintf('%.2f', $amount),
'payby' => $payby,
'payinfo' => $payinfo,
- 'paymask' => $cust_main->mask_payinfo( $payby, $payinfo ),
+ 'paymask' => FS::payinfo_Mixin->mask_payinfo( $payby, $payinfo ),
'card_type' => $card_type,
'paydate' => $p->{'year'}. '-'. $p->{'month'}. '-01',
'paydate_pretty' => $p->{'month'}. ' / '. $p->{'year'},
'payname' => $payname,
'discount_term' => $discount_term,
'pkgnum' => $session->{'pkgnum'},
+ %replace,
map { $_ => $p->{$_} } ( @{ $payby2fields{$payby} },
qw( save auto ),
)
my $error = $cust_main->save_cust_payby(
'payment_payby' => $payby,
+ 'replace' => $validate->{'replace'}, # cust_payby object to replace
%saveopt
);
#XXX payinfo1 + payinfo2 for CHEK?
#or take the opportunity to use separate, more well- named fields?
- # my $payinfo;
- # $p->{'payinfo1'} =~ /^([\dx]+)$/
- # or return { 'error' => "illegal account number ". $p->{'payinfo1'} };
- # my $payinfo1 = $1;
- # $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by echeck-country CA ?
- # or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} };
- # my $payinfo2 = $1;
- # $payinfo = $payinfo1. '@'. $payinfo2;
+ if ($p->{'payby'} eq 'CHEK') {
+ $p->{'payinfo1'} =~ /^([\dx]+)$/
+ or return { 'error' => "illegal account number ". $p->{'payinfo1'} };
+ my $payinfo1 = $1;
+ $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by echeck-country CA ?
+ or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} };
+ my $payinfo2 = $1;
+ $p->{'payinfo'} = $payinfo1. '@'. $payinfo2;
+ }
my $cust_payby = new FS::cust_payby {
'custnum' => $custnum,
my($context, $session, $custnum) = _custoragent_session_custnum($p);
return { 'error' => $session } if $context eq 'error';
+ if ($p->{'payby'} eq 'CHEK') {
+ $p->{'payinfo1'} =~ /^([\dx]+)$/
+ or return { 'error' => "illegal account number ". $p->{'payinfo1'} };
+ my $payinfo1 = $1;
+ $p->{'payinfo2'} =~ /^([\dx\.]+)$/ # . turned on by echeck-country CA ?
+ or return { 'error' => "illegal ABA/routing number ". $p->{'payinfo2'} };
+ my $payinfo2 = $1;
+ $p->{'payinfo'} = $payinfo1. '@'. $payinfo2;
+ }
+
my $cust_payby = qsearchs('cust_payby', {
'custnum' => $custnum,
'custpaybynum' => $p->{'custpaybynum'},
})
or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} };
+ my $cust_main = qsearchs( 'cust_main', {custnum => $cust_payby->custnum} )
+ or return { 'error' => 'unknown custnum '.$cust_payby->custnum };
+
foreach my $field (
qw( weight payby payinfo paycvv paydate payname paystate paytype payip )
) {
next unless exists($p->{$field});
$cust_payby->set($field,$p->{$field});
}
+ $cust_payby->set( 'paymask' => $cust_payby->mask_payinfo );
- my $error = $cust_payby->replace;
- if ( $error ) {
- return { 'error' => $error };
- } else {
- return { 'custpaybynum' => $cust_payby->custpaybynum };
+ # Update column if given a value, and the given value wasn't
+ # the value generated by $cust_main->masked($column);
+ $cust_main->set( $_, $p->{$_} )
+ for grep{ $p->{$_} !~ /^x/i; }
+ grep{ exists $p->{$_} }
+ qw/ss stateid/;
+
+ # Perform updates within a transaction
+ local $FS::UID::AutoCommit = 0;
+
+ if ( my $error = $cust_payby->replace || $cust_main->replace ) {
+ dbh->rollback;
+ return { error => $error };
}
-
+
+ dbh->commit;
+ return { custpaybynum => $cust_payby->custpaybynum };
}
sub verify_payby {
})
or return { 'error' => 'unknown custpaybynum '. $p->{'custpaybynum'} };
- return { 'error' => $cust_payby->delete };
-
+ my $conf = new FS::Conf;
+ if (($cust_payby->payby eq "DCHK" || $cust_payby->payby eq "CHEK") && $conf->exists('selfservice-ACH_info_readonly')) {
+ return { 'error' => "Sorry you do not have permission to delete bank information." };
+ }
+ else {
+ return { 'error' => $cust_payby->delete };
+ }
}
sub cancel {
}
+sub pkg_info {
+ my $p = shift;
+
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
+
+ my $pkg = qsearchs({
+ 'table' => 'cust_pkg',
+ 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
+ 'hashref' => {
+ 'custnum' => $custnum,
+ 'pkgnum' => $p->{'pkgnum'},
+ },
+ })
+ or return {'error' => 'unknown pkg num $pkgnum'};
+
+ return {
+ pkg_label => $pkg->pkg,
+ pkgpart => $pkg->pkgpart,
+ classnum => $pkg->classnum,
+ };
+
+}
+
sub list_pkgs {
my $p = shift;
# unavoidable false laziness w/ httemplate/view/cust_main/tickets.html
if ( $FS::TicketSystem::system && FS::TicketSystem->selfservice_priority ) {
+
+ @tickets = grep { $_->{'_selfservice_priority'}
+ !~ /^\s*(closed?|resolved?|done)\s*/i }
+ @tickets;
+
my $conf = new FS::Conf;
my $dir = $conf->exists('ticket_system-priority_reverse') ? -1 : 1;
+{ tickets => [
}
1;
-