From 5fe84df65a55868bbc730bbcd8a8dbb4de7a7593 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Oct 2009 00:34:34 +0000 Subject: [PATCH] selfservice per-agent skinning --- FS/FS/ClientAPI/MyAccount.pm | 75 ++++++++++++++++++++++++++++---------- FS/FS/ClientAPI/Signup.pm | 32 +++++++++++++++- FS/FS/Conf.pm | 7 +++- FS/bin/freeside-selfservice-server | 7 ++++ 4 files changed, 99 insertions(+), 22 deletions(-) diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 493cc3587..a651a8322 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -1,7 +1,7 @@ package FS::ClientAPI::MyAccount; use strict; -use vars qw( $cache $DEBUG ); +use vars qw( $cache $DEBUG $me ); use subs qw( _cache _provision ); use Data::Dumper; use Digest::MD5 qw(md5_hex); @@ -12,7 +12,8 @@ use FS::UI::Web::small_custview qw(small_custview); #less doh use FS::UI::Web; use FS::UI::bytecount qw( display_bytecount ); use FS::Conf; -use FS::Record qw(qsearch qsearchs); +#use FS::UID qw(dbh); +use FS::Record qw(qsearch qsearchs dbh); use FS::Msgcat qw(gettext); use FS::Misc qw(card_types); use FS::ClientAPI_SessionCache; @@ -29,7 +30,8 @@ use FS::payby; use FS::acct_rt_transaction; use HTML::Entities; -$DEBUG = 0; +$DEBUG = 2; +$me = '[FS::ClientAPI::MyAccount]'; #false laziness with FS::cust_main BEGIN { @@ -56,24 +58,59 @@ sub _cache { } sub skin_info { - #my $p = shift; + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + #return { 'error' => $session } if $context eq 'error'; + + my $agentnum = ''; + if ( $context eq 'customer' ) { + + 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' ) { my $conf = new FS::Conf; - use vars qw($skin_info); #cache for performance. - #agentnum eventually...? but if they're not logged in yet.. ? + #false laziness w/Signup.pm - $skin_info ||= { - 'head' => join("\n", $conf->config('selfservice-head') ), - 'body_header' => join("\n", $conf->config('selfservice-body_header') ), - 'body_footer' => join("\n", $conf->config('selfservice-body_footer') ), - 'body_bgcolor' => scalar( $conf->config('selfservice-body_bgcolor') ), - 'box_bgcolor' => scalar( $conf->config('selfservice-box_bgcolor') ), + my $skin_info_cache_agent = _cache->get("skin_info_cache_agent$agentnum"); - 'company_name' => scalar($conf->config('company_name')), - }; + if ( $skin_info_cache_agent ) { - $skin_info; + warn "$me loading cached skin info for agentnum $agentnum\n" + if $DEBUG > 1; + + } else { + + warn "$me populating skin info cache for agentnum $agentnum\n" + if $DEBUG > 1; + + $skin_info_cache_agent = { + ( map { $_ => scalar( $conf->config($_, $agentnum) ) } + qw( company_name ) ), + ( map { $_ => scalar( $conf->config("selfservice-$_", $agentnum ) ) } + qw( body_bgcolor box_bgcolor) ), + ( map { $_ => join("\n", $conf->config("selfservice-$_", $agentnum ) ) } + qw( head body_header body_footer company_address ) ), + }; + + _cache->set("skin_info_cache_agent$agentnum", $skin_info_cache_agent); + + } + + use Data::Dumper; + warn Dumper($skin_info_cache_agent); + + #{ %$skin_info_cache_agent }; + $skin_info_cache_agent; } @@ -83,7 +120,7 @@ sub login_info { my $conf = new FS::Conf; my %info = ( - %{ skin_info() }, + %{ skin_info($p) }, 'phone_login' => $conf->exists('selfservice_server-phone_login'), 'single_domain'=> scalar($conf->config('selfservice_server-single_domain')), ); @@ -176,9 +213,9 @@ sub logout { my $p = shift; if ( $p->{'session_id'} ) { _cache->remove($p->{'session_id'}); - return { %{ skin_info() }, 'error' => '' }; + return { %{ skin_info($p) }, 'error' => '' }; } else { - return { %{ skin_info() }, 'error' => "Can't resume session" }; #better error message + return { %{ skin_info($p) }, 'error' => "Can't resume session" }; #better error message } } @@ -275,8 +312,6 @@ sub customer_info { ( $session->{'pkgnum'} ? 1 : 0 ), #nobalance ); - warn $return{small_custview}; - $return{name} = $cust_main->first. ' '. $cust_main->get('last'); for (@cust_main_editable_fields) { diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index c376476c3..b9cd6c69f 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -1,7 +1,7 @@ package FS::ClientAPI::Signup; use strict; -use vars qw($DEBUG $me); +use vars qw( $DEBUG $me ); use Data::Dumper; use Tie::RefHash; use FS::Conf; @@ -338,6 +338,36 @@ sub signup_info { foreach qw( address1 city county state zip country ); } + #some of the above could probably be cached, too + + my $signup_info_cache_agent = $cache->get("signup_info_cache_agent$agentnum"); + + if ( $signup_info_cache_agent ) { + + warn "$me loading cached signup info for agentnum $agentnum\n" + if $DEBUG > 1; + + } else { + + warn "$me populating signup info cache for agentnum $agentnum\n" + if $DEBUG > 1; + + $signup_info_cache_agent = { + #( map { $_ => scalar( $conf->config($_, $agentnum) ) } + # qw( company_name ) ), + ( map { $_ => scalar( $conf->config("selfservice-$_", $agentnum ) ) } + qw( body_bgcolor box_bgcolor) ), + ( map { $_ => join("\n", $conf->config("selfservice-$_", $agentnum ) ) } + qw( head body_header body_footer ) ), + }; + + $cache->set("signup_info_cache_agent$agentnum", $signup_info_cache_agent); + + } + + $signup_info->{$_} = $signup_info_cache_agent->{$_} + foreach keys %$signup_info_cache_agent; + } # else { # delete $signup_info->{'part_pkg'}; diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 4a79131fd..fafd73837 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -146,7 +146,7 @@ sub config_binary { return $self->_usecompat('config_binary', @_) if use_confcompat; my $cv = $self->_config(@_) or return; - decode_base64($cv->value); + length($cv->value) ? decode_base64($cv->value) : ''; } =item exists KEY [ AGENTNUM [ NODEFAULT ] ] @@ -2927,6 +2927,7 @@ worry that config_items is freeside-specific and icky. 'section' => '', 'description' => 'HTML for the HEAD section of the self-service interface, typically used for LINK stylesheet tags', 'type' => 'textarea', #htmlarea? + 'per_agent' => 1, }, @@ -2935,6 +2936,7 @@ worry that config_items is freeside-specific and icky. 'section' => '', 'description' => 'HTML header for the self-service interface', 'type' => 'textarea', #htmlarea? + 'per_agent' => 1, }, { @@ -2942,6 +2944,7 @@ worry that config_items is freeside-specific and icky. 'section' => '', 'description' => 'HTML header for the self-service interface', 'type' => 'textarea', #htmlarea? + 'per_agent' => 1, }, @@ -2950,6 +2953,7 @@ worry that config_items is freeside-specific and icky. 'section' => '', 'description' => 'HTML background color for the self-service interface, for example, #FFFFFF', 'type' => 'text', + 'per_agent' => 1, }, { @@ -2957,6 +2961,7 @@ worry that config_items is freeside-specific and icky. 'section' => '', 'description' => 'HTML color for self-service interface input boxes, for example, #C0C0C0"', 'type' => 'text', + 'per_agent' => 1, }, { diff --git a/FS/bin/freeside-selfservice-server b/FS/bin/freeside-selfservice-server index 544f307ee..f72d0ab61 100644 --- a/FS/bin/freeside-selfservice-server +++ b/FS/bin/freeside-selfservice-server @@ -72,6 +72,13 @@ my $cache = new FS::ClientAPI_SessionCache( { } ); $cache->remove('signup_info_cache'); +#and also clear the selfservice skin info cache, for the same reason +my $ss_cache = new FS::ClientAPI_SessionCache( { + 'namespace' => 'FS::ClientAPI::MyAccount', +} ); +$ss_cache->remove($_) + foreach grep /^skin_info_cache_agent/, $ss_cache->get_keys(); + my $clientd = "/usr/local/sbin/freeside-selfservice-clientd"; #better name? my $warnkids=0; -- 2.11.0