####################
# 04022012 BHT add geoip country logic
##############
##############
# handle click on background
# we need to get a random active background entry
# but we have to match the page we're on to the do_where constraint
# if this is the homepage that can be 1 or 3
# on any other page it is 1 or 2
# any page
$match = " and ((do_where='1') or (do_where='2')) ";
# adjust if this is a home page
$cval = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if ( $cval == $this->{'System/BaseURL'} ) {
# this is homepage
$match = " and ((do_where='1') or (do_where='3')) ";
}
# we want to extend match by checking the country via geoip
require_once "Net/GeoIP.php";
$geoip = Net_GeoIP::getInstance("/var/www/html/recipebridge.com/html/geo/GeoIP.dat");
try {
$cc = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
#echo $geoip->lookupCountryCode('71.0.170.218');
} catch (Exception $e) {
// Handle exception
}
# do we have some defined country?
if ($cc != '') {
# apply it to the match
$match = $match." and ((country='ANY') or (country='".$cc."')) ";
}
$Query = " SELECT * FROM backgrounds where status='1' $match order by rand() limit 1;";
#echo '
Q:'.$Query;
$rbg = $DatabaseObj->fetchAll($Query);
foreach ($rbg as $Result) {
#################
# we need to deal with the new background options
# if they are set we will apply them
if ($Result->do_background_color != '-1') {
# we have some background color
$the_color = $Result->do_background_color;
# background color -- this is a css modification
?>
} # end background options color
# TOP LEFT and POSITION
$position = $Result->do_position;
$top = $Result->do_top;
# we have to modify the top based on the home page or other page
# what is our page?
#echo "
".$this->{'System/BaseURL'}."
";
#print_r($_SERVER);
# adjust positon if FIXED to offset header (and zero top)
$cval = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if ($position == 'absolute')
if ( $cval == $this->{'System/BaseURL'} ) {
$top = 44;
} else {
$top = 111;
}
$left = $Result->do_left;
?>
# WIDTH -- if zero do not set!
$width = $Result->do_width;
if ($width != '0') {
# we have some set width
?>
} # end width set
if ($Result->new_window == '0') {
$nw = '';
} else {
$nw = ' target="_blank" ';
}
$t_file = '/var/www/html/recipebridge.com/html/backgrounds/'.$Result->file_name;
$t_url = $this->{'System/BaseURL'}.'backgrounds/'.$Result->file_name;
if (file_exists($t_file)) {
# yes show it
# we are showing the image directly...and activating the click logic
#echo ' ';
echo '';
############
# script to activate click
?>
# end script
############
} else {
# no such background file?
# use default
echo '';
}
} # end foreach (should be only 1)
?>