{'city'}; $city = strtolower($city); $coord = $obj->{'location'}; $latitude=$coord->{'latitude'}; $longtitude = $coord->{'longitude'}; if($longtitude < 0){ $longtitude = abs($longtitude); $longtitude_str= " + ".abs($longtitude); } else $longtitude_str= " - ".$longtitude; if($latitude < 0){ $latitude = abs($latitude); $latitude_str= " + ".abs($latitude); } else $latitude_str= " - ".$latitude; $id = $_GET['id']; if(!$id) { echo "
"; } else { $sSQL="select n_Credits, n_Views, n_Clicks, n_ID from t_Users where n_ID=".stripjunk($id); $results=mysql_query($sSQL); if(mysql_num_rows($results)>0) { list($n_Credits, $n_Views, $n_Clicks, $banUserID)=mysql_fetch_row($results); $sSQL="update t_Users set n_Credits=n_Credits+(".stripjunk($ratiolow)."/".stripjunk($ratiohigh)."), n_Views=n_Views+1 where n_ID=".stripjunk($id); mysql_query($sSQL); } $sSQL="select * from t_Banners where n_UserID=".stripjunk($id)." and b_Authorised>0"; $results=mysql_query($sSQL); if($ratiohigh>$ratiolow) { $mullow=($ratiolow/$ratiohigh) * 100; } else{ $mullow=95; } if((mysql_num_rows($results)==0 && rand(0,100)>75) || (rand(0,100)>$mullow)) { echo "
"; } else { $sSQL="SELECT state,cd FROM ob_geo_grp where zip_code in (select m.zip_code from (select zip_code,latitude, longitude,state, ATAN2(SQRT(POWER(SIN((latitude ".$latitude_str.")/2),2) + COS(latitude) * COS(".$latitude.") * POWER(SIN((longitude ".$longtitude_str.")/2),2)), SQRT(1- (POWER(SIN((latitude ".$latitude_str.")/2),2) + COS(latitude) * COS(".$latitude.") * POWER(SIN((longitude ".$longtitude_str.")/2),2)))) as factor from ob_geo where city = '".$city."') as m where m.factor in (select min(factor) from (select ATAN2(SQRT(POWER(SIN((latitude ".$latitude_str.")/2),2) + COS(latitude) * COS(".$latitude.") * POWER(SIN((longitude ".$longtitude_str.")/2),2)), SQRT(1- (POWER(SIN((latitude ".$latitude_str.")/2),2) + COS(latitude) * COS(".$latitude.") * POWER(SIN((longitude ".$longtitude_str.")/2),2)))) as factor from ob_geo where city = '".$city."') as m1))"; $results=mysql_query($sSQL); if(mysql_num_rows($results)==0) { echo "
"; } else { list($state,$cd)=mysql_fetch_row($results); $subqry="SELECT bannerId FROM ob_banner_state where state='".$state."' union select bannerId from ob_banner_region where state='".$state."' and regionId=".$cd; $sSQL="select n_ID from t_Users where n_Credits>=1 and b_Authedban>0 and n_ID<>".stripjunk($id)." order by rand()"; $results=mysql_query($sSQL); if(mysql_num_rows($results)==0) { echo "
"; } else { list($remoteID)=mysql_fetch_row($results); $sSQL="select n_UserID, s_URL, s_Graphic, n_Category, n_Displays, n_ID, b_Paid, n_ExpireViews, n_ExpireClicks from t_Banners where n_ID in (".$subqry.") and (n_Category = 0) and ((b_Authorised>0 and n_UserID=".stripjunk($remoteID)." and b_Paid=0) or ((n_ExpireViews>0 or n_ExpireClicks>0) and b_Paid=1)) order by rand() limit 1"; error_log($sSQL); $results=mysql_query($sSQL); if(mysql_num_rows($results)==0) { echo "
"; } else{ list($n_UserID, $s_URL, $s_Graphic, $n_Category, $n_Displays, $banID, $b_Paid, $n_ExpireViews, $n_ExpireClicks)=mysql_fetch_row($results); echo "
"; $sSQL="update t_Banners set n_Displays=n_Displays+1 where n_ID=".stripjunk($banID); mysql_query($sSQL); if($b_Paid==0) { $sSQL="update t_Users set n_Credits=n_Credits-1 where n_ID=".stripjunk($n_UserID); mysql_query($sSQL); } else { if($n_ExpireViews>0) { $sSQL="update t_Banners set n_ExpireViews=n_ExpireViews-1 where n_ID=".stripjunk($banID); mysql_query($sSQL); $sSQL="select * from t_Banners where n_UserID=".stripjunk($n_UserID)." and (b_Authorised>0 and b_Paid<>1) or (b_Paid=1 and (n_ExpireViews>0 or n_ExpireClicks>0))"; $results=mysql_query($sSQL); if(mysql_num_rows($results)==0) { $sSQL="update t_Users set b_Authedban=0 where n_ID=".stripjunk($n_UserID); mysql_query($sSQL); } } } } } } } } $sSQL="update t_Stats set n_Value=n_Value+1 where s_Name=\"totalviews\""; mysql_query($sSQL); mysql_close(); ?>