US Example:
Enter a ZIP Code like '90210'. Canada Example:
Enter a Postal Code like 'R3Y 1T1'.
City & State
Enter a city and state (or province if in Canada).
US Example:
Enter a City and State: 'Beverly Hills', 'CA'. Canada Example
Enter a City and Province: 'Winnipeg', 'MB'.
Locate a dealer from anywhere in the world!
You don't have to be from the US or Canada to use ZIProx.
We cover the entire world with a database of over 2 million cities!
World Examples:
'Paris', 'France'.
'Hamburg', 'Germany'.
'Sydney', 'Australia'.
Select a Category Item
Select a category item or default to all items
Select a Category Item:
Select one or more
items within this category or default to all items
Select search mode:
Select how to use distance search
By distance
Display only those locations within a selected number of miles from your
current location. The resulting locations (if any) will not exceed the
selected distance.
For example: 'Within 10 miles'
By number of locations Display the selected number of locations you wish to find. ZIProx
will always display the closest locations no matter how far away they
may be.
For example: 'Nearest 3 locations'
[-
$ENV{SERVER_NAME} = 'www.bizsystems.net'; # good server name
$ptr2_License = {
'private' => 'ZIProx',
'path' => do {$_ = `/bin/pwd`; chomp;$_} . '/TestCert.license',
};
use ZIProx;
$logger = ZIProx::getLogger();
use Config::Tiny;
$configFile='download/ziprox.ini';
$c = Config::Tiny->read($configFile);
$dir = $c->{_}->{installdir};
$myFileName = $ENV{REQUEST_URI};
$myFileName =~ s/\?.*//;
@errors = () ;
$sqlCity =
"select " .
" state_name, city_name, city_lat, city_long, state_code, country_name " .
"from " .
" city, state, country " .
"where " .
" city.city_country_code = country.country_code and " .
" city.city_state_code = state.state_code and " .
" state.country_code = country.country_code and " .
" city.city_name=? and " .
" country.country_code=? ";
use DBI;
$dbh = DBI->connect("DBI:$c->{_}->{sqlengine}:$c->{_}->{sqldsn}", $c->{_}->{sqluser}, $c->{_}->{sqlpass});
if (!$DBI::errstr) {
if ($fdat{locate}) {
$logger->debug("fdat{city}=$fdat{city}");
$logger->debug("fdat{state}=$fdat{state}");
$logger->debug("fdat{zipcode}=$fdat{zipcode}");
$logger->debug("fdat{country}=$fdat{country}");
$logger->debug("fdat{rangecount}=$fdat{rangecount}");
$logger->debug("fdat{couponsOnly}=$fdat{couponsOnly}");
$logger->debug("fdat{category}=$fdat{category}");
if (!$fdat{locateWorld}) {
if (!defined($fdat{country})) {
push @errors, "**Please enter your Zipcode or your City and State"
if ( (!$fdat{zipcode} && (!$fdat{city} || !$fdat{state}))
|| (!$fdat{zipcode} && (!$fdat{city} && $fdat{state}))
|| (!$fdat{zipcode} && ($fdat{city} && !$fdat{state}))
|| ($fdat{zipcode} && ($fdat{city} || $fdat{state}))
);
if ($#errors == -1) {
# check for a valid zipcode
if ($fdat{zipcode} && !$fdat{city} && !$fdat{state}) {
$sth = $dbh->prepare("select city, state from zipcodes where zipcode = ?");
$rv = $sth->execute($fdat{zipcode});
@zipcodesRow = $sth->fetchrow_array;
$logger->debug("zipcodesRow = @zipcodesRow");
if (!defined(@zipcodesRow)) {
push @errors, "**Please enter a valid Zipcode or a City and State";
} else {
$zipcode = $fdat{zipcode};
$logger->debug("valid zipcode found: $zipcode");
$city = $zipcodesRow[0];
$state = $zipcodesRow[1];
}
}
# check for a valid city/state
if (!$fdat{zipcode} && $fdat{city} && $fdat{state}) {
$sth = $dbh->prepare("select * from zipcodes where city = '" . $fdat{city} . "' and state = '" . $fdat{state} . "'");
$rv = $sth->execute;
@zipcodesRow = $sth->fetchrow_array;
if (!defined(@zipcodesRow)) {
push @errors, "**Please enter a Zipcode or a valid City and State";
} else {
$zipcode = $zipcodesRow[0];
$city = $fdat{city};
$state = $fdat{state};
}
}
# remove leading and trailing blanks
$zipcode =~ s/^\s*(.*?)\s*$/$1/;
$logger->debug("zipcode='$zipcode'");
}
} else { #fdat{country} defined
push @errors, "**Please enter your City and Country" if (!$fdat{city});
if ($#errors == -1) {
# check for a valid or duplicate city/country combination
$sth = $dbh->prepare($sqlCity);
$rv = $sth->execute($fdat{city}, $fdat{country});
while ( @row = $sth->fetchrow_array ) {
$logger->debug("@row");
}
$rv = $sth->execute($fdat{city}, $fdat{country});
if (%dupCityHash = %{$sth->fetchall_hashref('state_name')}) {
@dupCityOrdered = sort ( { $dupCityHash{$a}->{state_name} <=> $dupCityHash{$b}->{state_name} } keys %dupCityHash) ;
} else {
push @errors, "**Please enter a valid City and Country";
}
$logger->debug("#dupCityHash = $#dupCityOrdered");
for $dupCity (@dupCityOrdered) {
$logger->debug("$dupCityHash{$dupCity}->{state_name}");
}
}
} # fdat{country}
}# fdat{locateWorld}
} else { #fdat{locate}
# build list of categories
if ($c->{_}->{categories}) {
foreach $userCategory (split ':', $c->{_}->{userCategories}) {
undef %categoryHash;
undef @categoryArray;
$sql = "select distinct $userCategory from dealers order by $userCategory";
$categoryRows = $dbh->selectcol_arrayref($sql);
foreach $categoryRow (@{$categoryRows}) {
foreach $catItem (split ',', $categoryRow) {
$catItem =~ s/^\s*(.*?)\s*$/$1/;
$categoryHash{$catItem} = 0;
}
}
@categoryArray = sort keys %categoryHash;
$logger->debug("categoryArray = " . join ',', @categoryArray);
#$categories = \@categoryArray;
# add each categoryArray to userCategoryHash
$userCategoryHash{$userCategory} = [ @categoryArray ];
}
}
if (($fdat{mode} eq "world")) {
# build list of countries
$sql = "select * from country order by country_name";
$countries = $dbh->selectall_arrayref($sql);
}
} #fdat{locate}
} #fdat{DBI::errStr}
-]
[$if !$DBI::errstr $]
[$if (!defined($fdat{locate}) || $#dupCityOrdered>0 || $#errors != -1 )$]
[$else$]
[$if (defined($fdat{locate}) and $#errors == -1)$]
[-
use ZIProx;
use WorldCityLoc;
$myLocKey = "";
$myRepLocKey = "";
# declare display modes used in priority listing
@priorityModes = ("featured", "regular");
if (defined($fdat{country})) {
($myLat, $myLong) = WorldCityLoc::getCityLoc($dbh, $fdat{city}, $fdat{state_code}, $fdat{country});
$myLocKey = $fdat{city};
($country_name) = @{$dbh->selectcol_arrayref("select country_name from country where country_code='$fdat{country}'")};
($state_name) = @{$dbh->selectcol_arrayref("select state_name from state where state_code='$fdat{state_code}' and country_code='$fdat{country}'")};
$myRepLocKey = "$fdat{city}, $state_name, $country_name";
} else {
@myLoc = ZIProx::getMyLoc($dbh, $zipcode);
($city, $state, $myLat, $myLong) = @myLoc;
$myLocKey = $zipcode;
$myRepLocKey = $zipcode;
}
ZIProx::logVisit($dbh, $myRepLocKey, $ENV{'REMOTE_ADDR'});
($optType, $count) = split / /, $fdat{rangecount};
$logger->debug("myLat=$myLat");
$logger->debug("myLong=$myLong");
# prepare to fetch all the information we need for this dealer
if (!defined($fdat{country})) {
$sql = "select * from dealers, zipcodes where dealers.dealer_zipcode=zipcodes.zipcode and dealerID=?";
} else {
$sql = "select * from dealers, city where dealers.dealer_city=city.city_name and dealerID=?";
}
$sthDealer = $dbh->prepare($sql) || die 'prepare failed: $_';
# prepare to fetch the coupon information we need for this dealer
$sthCoupon = $dbh->prepare("select coupon.couponID, coupon.coupon_name from coupon, dealers, coupdeal where coupon.couponID=coupdeal.couponID and coupdeal.dealerID=dealers.dealerID and dealers.dealerID=?")
|| die 'prepare failed: $_';
$featuredCount=0;
-]
Results for
[$ if (!$fdat{country}) $]
[$ if (!defined($fdat{city})) $]
[+ $zipcode +]
[$ else $]
[+ sprintf("%s, %s",$fdat{city}, $fdat{state}) +]
[$ endif $]
[$ else $]
[-
# lookup the state/province & country
@country_name = @{$dbh->selectcol_arrayref("select country_name from country where country_code='$fdat{country}'")};
if ($fdat{state_code}) {
@state_name = @{$dbh->selectcol_arrayref("select state_name from state where state_code='$fdat{state_code}' and country_code='$fdat{country}'")};
} else {
$sth = $dbh->prepare($sqlCity);
$rv = $sth->execute($fdat{city}, $fdat{country});
@state_name = @{$dbh->selectcol_arrayref($sth)};
}
-]
[+ sprintf("%s, %s %s",$fdat{city}, $state_name[0], $country_name[0]) +]
[$ endif $]
[$ foreach $priorityMode (@priorityModes) $]
[-
$logger->debug("priorityMode = $priorityMode");
#$logger->debug("c->{_}->{priority} = $c->{_}->{priority}");
undef @filterOrdered;
undef %dealers;
%dealers;
$territoryFound;
my $dealerCount=0;
if ($c->{_}->{territories}) {
if (($priorityMode eq "regular")) {
$logger->debug("search for dealers in territory");
# get list of dealers that cover territory
#%dealers = %{ZIProx::getDealers($dbh, $fdat{couponsOnly}, $fdat{category}, $fdat{country}, $myLocKey, undef)};
%dealers = %{ZIProx::getDealers($dbh, $myLockey, undef, %fdat)};
$dealerCount = keys %dealers;
$logger->debug("Number of territory dealers: $dealerCount");
$territoryFound='yes' if $dealerCount>0;
}
}
# if territory set and no territories, do a regular search
# or if priority search or this is a regular search
if ((!$territoryFound && $c->{_}->{territories} && $priorityMode eq "regular")
|| $c->{_}->{priority}
|| ($priorityMode eq "regular" && !$c->{_}->{territories})) {
#%dealers = %{ZIProx::getDealers($dbh, $fdat{couponsOnly}, $fdat{category}, $fdat{country}, undef, $priorityMode)};
%dealers = %{ZIProx::getDealers($dbh, undef, $priorityMode, %fdat)};
}
$dealerCount = keys %dealers;
$logger->debug("Number of dealers: $dealerCount");
$count = $count - $featuredCount;
%filterDistances = %{ZIProx::getDistances($myLat, $myLong, $optType, $count, $fdat{country}, $priorityMode, %dealers)};
@filterOrdered = sort ( { $filterDistances{$a} <=> $filterDistances{$b} } keys %filterDistances) ;
if ($priorityMode eq "featured" && $#filterOrdered != -1) {
$featuredCount = $#filterOrdered + 1;
}
$logger->debug("#filterOrdered = $#filterOrdered");
$logger->debug("count = $count");
$logger->debug("featuredCount = $featuredCount");
-]
[$ if ($#filterOrdered != -1) $]
[$ if (!($territoryFound)) $]
[$ if (($priorityMode eq "featured") && $c->{_}->{priority}) $]
[$endif$]
[$endif$]
[$ if ($c->{_}->{priority} || ($priorityMode eq "regular")) $]
[-
# set rowcount of results table (otherwise waits for error to finish)
$maxrow=$#filterOrdered+1;
-]
[-
# fetch all the information we need for this dealer
$rv = $sthDealer->bind_param(1,$filterOrdered[$row]);
$rv = $sthDealer->execute || die 'execute failed: $_';
$dealerInfoRef = $sthDealer->fetchrow_hashref;
# remove everything after the #
$addr = $dealerInfoRef->{dealer_address};
$addr =~ s/[,#].*//;
# select the source ountry
if (length($zipcode)>5) {
$srcCntCode='ca';
} else {
$srcCntCode='us';
}
# select the dest country
if (length($dealerInfoRef->{dealer_zipcode})>5) {
$dstCntCode='ca';
} else {
$dstCntCode='us';
}
$yahooURL = "http://maps.yahoo.com/py/ddResults.py?Pyt=Tmap&newcsz=$city, $state $zipcode&newcountry=$srcCntCode&taddr=$addr&newtcsz=$dealerInfoRef->{dealer_city}, $dealerInfoRef->{dealer_state} $dealerInfoRef->{dealer_zipcode}&newtcountry=$dstCntCode";
# fetch the coupon information we need for this dealer
$rvCoupon = $sthCoupon->bind_param(1,$filterOrdered[$row]);
$rvCoupon = $sthCoupon->execute || die 'execute failed: $_';
$couponInfoRef = $sthCoupon->fetchall_hashref('couponID')
|| die 'fetch failed: $_';
-]
[+$dealerInfoRef->{dealer_name}+]
[+sprintf("%d", $filterDistances{$filterOrdered[$row]})+]
miles