#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); use DBI; $dsn = 'DBI:mysql:dakotami_agcam_remote:localhost'; $db_user_name = 'dakotami_root'; $db_password = 'EG*7CFxp0!0o'; $dbh = DBI->connect($dsn, $db_user_name, $db_password) or die $DBI::errstr; $baseurl = 'http://dakotamicro.com'; use CGI; my $query = new CGI; my $site= $query->param('site'); my $by = $query->param('by'); my $state = $query->param('state'); my $country = $query->param('country'); my $compType = $query->param('compType'); %oems = ("Agco" , "agco.png", "Ag Leader","Ag-Leader.png", "Case","case.png", "Challenger","Challenger.png", "John Deere","John-Deere.png", "New Holland","New-Holland.png", "Outback","outback.png", "Trimble","Trimble.png", "Versatile","Versatile_Logo.png", "Agronomy Centers","agronomy-centers.png", "Short Line Dealers","short-line-dealers.png", "Radio Security","radio-security.png", "CAT","CAT-logo.png", "Kinze","Kinze.png"); %oemlinks = ("Agco" , "www.agcoagcam.com", "Ag Leader","", "Case","", "Challenger","", "John Deere","", "New Holland","", "Outback","", "Trimble","", "Versatile","", "Agronomy Centers","", "Short Line Dealers","", "Radio Security","", "CAT","", "Kinze",""); $google_api = 'AIzaSyBfzNWibeN4bYbhRdGOjl9yvWFzYCMMIRY'; print "Content-type: text/html\n\n"; &header; if ( $by eq "state" && $state ) { &show_state; } elsif ( $by eq "country" && $country ) { &show_country; } elsif ( $by eq "postal" ) { $postal = $query->param('postal'); $radius = $query->param('radius'); if ($postal) { if ($postal =~ /(\w\d\w)(\d\w\d)/) { $postal = "$1 $2"; } elsif ($postal =~/^(\d\d\d\d\d)/) { $postal = "$1"; } &find_postal; } else { print <<"EOF";
Please go back and enter a zip/postal code
EOF } } else { &state_map; } &footer; sub show_state { my $long_state = &long_state($state); $state_title = $state; print <<"EOF";Select Your State/Province:
$title | \n"; } else { print "$title | \n"; } print <<"EOF";$startDate / $endDate |
$building | EOF } print <<"EOF";$city, $state |
Search Results for $long_state: Return to US Map
$oemsrc | $company | $contact | $address | $city | $postal | $phone |
Google Map for $long_state:
Click on a marker for more information.
Map Instructions:
- to move the map around, left click and drag the map or use the arrows at the top left
- to zoom in and out use the slider controls on the left
- to see an image of the area click on the satellite button at the top
- to see both an image and the road map click on the hybrid button at the top
Search Results for $country:
$company $agco | $contact | $address | $city | $postal | $phone |
Enter your zip code/postal code to locate your closest Dakota Micro dealer:
|
|
Search Results for $postal at $radius miles:
Physical map located at bottom of page Return to US Map$oemsrc | $distance miles | $company | $contact | $address, $city, $short_state $a_postal | $phone |
Google Map for $postal at $radius miles:
Click on a marker for more information.
Map Instructions:
- to move the map around, left click and drag the map or use the arrows at the top left
- to zoom in and out use the slider controls on the left
- to see an image of the area click on the satellite button at the top
- to see both an image and the road map click on the hybrid button at the top
Sorry, the zip code you entered was not found in our database. Please try another zip code or click on the country link above to use the map to find a dealer close to you.
"; } } # given coordinates of two places in radians, compute distance in meters sub great_circle_distance { my ($lat1,$long1,$lat2,$long2) = @_; # approx radius of Earth in meters. True radius varies from # 6357km (polar) to 6378km (equatorial). my $earth_radius = 6367000; my $dlon = $long2 - $long1; my $dlat = $lat2 - $lat1; my $a = (sin($dlat / 2)) ** 2 + cos($lat1) * cos($lat2) * (sin($dlon / 2)) ** 2; my $d = 2 * atan2(sqrt($a), sqrt(1 - $a)); # This is a simpler formula, but it's subject to rounding errors # for small distances. See http://www.census.gov/cgi-bin/geo/gisfaq?Q5.1 # my $d = &acos(sin($lat1) * sin($lat2) # + cos($lat1) * cos($lat2) * cos($long1-$long2)); return $earth_radius * $d; } # round to 3 significant digits sub round_to_3 { my ($num) = @_; my ($lg,$round); if ($num == 0) { return 0; } $lg = int(log(abs($num)) / log(10.0)); # log base 10 of num $round = 10 ** ($lg - 2); return int($num / $round + 0.5) * $round; } # round to nearest integer sub round_to_int { return int(abs($_[0]) + 0.5) * ($_[0] < 0 ? -1 : 1); } # print a location in a canonical form sub loc_to_string { my($lat,$long) = @_; $lat = &radians_to_degrees($lat); $long = &radians_to_degrees($long); my $ns = "N"; my $ew = "E"; if ($lat < 0) { $lat = -$lat; $ns = "S"; } if ($long < 0) { $long = -$long; $ew = "W"; } $lat = int($lat * 3600 + 0.5); my $lat_string = sprintf("%d:%02d:%02d%s", int($lat/3600), int(($lat - 3600*int($lat / 3600))/60), $lat - 60*int($lat / 60), $ns); $long = int($long * 3600 + 0.5); my $long_string = sprintf("%d:%02d:%02d%s", int($long/3600), int(($long - 3600*int($long / 3600))/60), $long - 60*int($long / 60), $ew); return "$lat_string $long_string"; } # convert a string which looks like "34:45:12N,15:34:10W" into a pair # of degrees. Also accepts "34.233N,90.134E" etc. sub parse_location { my($str) = @_; my($lat,$long); if ($str =~ /^([0-9:.\260'"d -]*)([NS])[, ]+([0-9:.\260'"d -]*)([EW])$/i) { #" return undef if (!defined($lat = &parse_degrees($1))); $lat *= (($2 eq "N" || $2 eq "n") ? 1.0 : -1.0); return undef if (!defined($long = &parse_degrees($3))); $long *= (($4 eq "E" || $4 eq "e") ? 1.0 : -1.0); return(°rees_to_radians($lat), °rees_to_radians($long)); } else { return undef; } } # given a bearing in degrees, return a string "north", "southwest", # "east-southeast", etc. sub heading_string { my($deg) = @_; my($rounded,$s); my(@dirs) = ("north","east","south","west"); $rounded = &round_to_int($deg / 22.5) % 16; if (($rounded % 4) == 0) { $s = $dirs[$rounded/4]; } else { $s = $dirs[2 * int(((int($rounded / 4) + 1) % 4) / 2)]; $s .= $dirs[1 + 2 * int($rounded / 8)]; if ($rounded % 2 == 1) { $s = $dirs[&round_to_int($rounded/4) % 4] . "-" . $s; } } return $s; } BEGIN { $::pi = 4 * atan2(1,1); } sub degrees_to_radians { return $_[0] * $::pi / 180.0; } sub radians_to_degrees { return $_[0] * 180.0 / $::pi; } # convert a string like 34:45:12.34 or 38:40 or 34.124 or 34d45'12.34" # or 25° 02' 30" to degrees # (also handles a leading `-') sub parse_degrees { my($str) = @_; my($d,$m,$s,$sign); # yeah, this could probably be done with one regexp. if ($str =~ /^\s*(-?)([\d.]+)\s*(:|d|\260)\s*([\d.]+)\s*(:|\')\s*([\d.]+)\s*\"?\s*$/) { $sign = ($1 eq "-") ? -1.0 : 1.0; $d = $2 + 0.0; $m = $4 + 0.0; $s = $6 + 0.0; } elsif ($str =~ /^\s*(-?)([\d.]+)\s*(:|d|\260)\s*([\d.]+)(\')?\s*$/) { $sign = ($1 eq "-") ? -1.0 : 1.0; $d = $2 + 0.0; $m = $4 + 0.0; $s = 0.0; } elsif ($str =~ /^\s*(-?)([\d.]+)(d|\260)?\s*$/) { $sign = ($1 eq "-") ? -1.0 : 1.0; $d = $2 + 0.0; $m = 0.0; $s = 0.0; } else { die "parse_degrees: can't parse $str\n"; } return ($sign * ($d + ($m / 60.0) + ($s / 3600.0))); } ###################### ## END FIND POSTALS ## ###################### sub short_state { my($state) = @_; my ($short_state); if ($state eq 'Alberta') { $short_state = 'AB'; } elsif ($state eq 'British Columbia') { $short_state = 'BC'; } elsif ($state eq 'Manitoba') { $short_state = 'MB'; } elsif ($state eq 'New Brunswick') { $short_state = 'NB'; } elsif ($state eq 'Newfoundland') { $short_state = 'NF'; } elsif ($state eq 'Nova Scotia') { $short_state = 'NS'; } elsif ($state eq 'Nunavut') { $short_state = 'NU'; } elsif ($state eq 'NorthWest Territories') { $short_state = 'NT'; } elsif ($state eq 'Ontario') { $short_state = 'ON'; } elsif ($state eq 'Prince Edward Island') { $short_state = 'PEI'; } elsif ($state eq 'Quebec') { $short_state = 'PQ'; } elsif ($state eq 'Saskatchewan') { $short_state = 'SK'; } elsif ($state eq 'Yukon') { $short_state = 'YK'; } elsif ($state eq 'Alaska') { $short_state = 'AK'; } elsif ($state eq 'Alabama') { $short_state = 'AL'; } elsif ($state eq 'Arkansas') { $short_state = 'AR'; } elsif ($state eq 'Arizona') { $short_state = 'AZ'; } elsif ($state eq 'California') { $short_state = 'CA'; } elsif ($state eq 'Colorado') { $short_state = 'CO'; } elsif ($state eq 'Conneticut') { $short_state = 'CT'; } elsif ($state eq 'Delaware') { $short_state = 'DE'; } elsif ($state eq 'Florida') { $short_state = 'FL'; } elsif ($state eq 'Georgia') { $short_state = 'GA'; } elsif ($state eq 'Hawaii') { $short_state = 'HI'; } elsif ($state eq 'Iowa') { $short_state = 'IA'; } elsif ($state eq 'Idaho') { $short_state = 'ID'; } elsif ($state eq 'Illinois') { $short_state = 'IL'; } elsif ($state eq 'Indiana') { $short_state = 'IN'; } elsif ($state eq 'Kansas') { $short_state = 'KS'; } elsif ($state eq 'Kentucky') { $short_state = 'KY'; } elsif ($state eq 'Louisiana') { $short_state = 'LA'; } elsif ($state eq 'Massachusetts') { $short_state = 'MA'; } elsif ($state eq 'Maryland') { $short_state = 'MD'; } elsif ($state eq 'Maine') { $short_state = 'ME'; } elsif ($state eq 'Michigan') { $short_state = 'MI'; } elsif ($state eq 'Minnesota') { $short_state = 'MN'; } elsif ($state eq 'Missouri') { $short_state = 'MO'; } elsif ($state eq 'Mississippi') { $short_state = 'MS'; } elsif ($state eq 'Montana') { $short_state = 'MT'; } elsif ($state eq 'North Carolina') { $short_state = 'NC'; } elsif ($state eq 'North Dakota') { $short_state = 'ND'; } elsif ($state eq 'Nebraska') { $short_state = 'NE'; } elsif ($state eq 'New Hampshire') { $short_state = 'NH'; } elsif ($state eq 'New Jersey') { $short_state = 'NJ'; } elsif ($state eq 'New Mexico') { $short_state = 'NM'; } elsif ($state eq 'Nevada') { $short_state = 'NV'; } elsif ($state eq 'New York') { $short_state = 'NY'; } elsif ($state eq 'Ohio') { $short_state = 'OH'; } elsif ($state eq 'Oklahoma') { $short_state = 'OK'; } elsif ($state eq 'Oregon') { $short_state = 'OR'; } elsif ($state eq 'Pennsylvania') { $short_state = 'PA'; } elsif ($state eq 'Rhode Island') { $short_state = 'RI'; } elsif ($state eq 'South Carolina') { $short_state = 'SC'; } elsif ($state eq 'South Dakota') { $short_state = 'SD'; } elsif ($state eq 'Tennessee') { $short_state = 'Tennessee'; } elsif ($state eq 'Texas') { $short_state = 'TX'; } elsif ($state eq 'Utah') { $short_state = 'UT'; } elsif ($state eq 'Virginia') { $short_state = 'VA'; } elsif ($state eq 'Vermont') { $short_state = 'VT'; } elsif ($state eq 'Washington') { $short_state = 'WA'; } elsif ($state eq 'Wisconsin') { $short_state = 'WI'; } elsif ($state eq 'West Virginia') { $short_state = 'WV'; } elsif ($state eq 'Wyoming') { $short_state = 'WY'; } return ($short_state); } sub long_state { my($state) = @_; my ($long_state); if ($state eq 'AB') { $long_state = 'Alberta'; } elsif ($state eq 'BC') { $long_state = 'British Columbia'; } elsif ($state eq 'MB') { $long_state = 'Manitoba'; } elsif ($state eq 'NB') { $long_state = 'New Brunswick'; } elsif ($state eq 'NF') { $long_state = 'Newfoundland'; } elsif ($state eq 'NS') { $long_state = 'Nova Scotia'; } elsif ($state eq 'NU') { $long_state = 'Nunavut'; } elsif ($state eq 'NT') { $long_state = 'NorthWest Territories'; } elsif ($state eq 'ON') { $long_state = 'Ontario'; } elsif ($state eq 'PEI') { $long_state = 'Prince Edward Island'; } elsif ($state eq 'PQ') { $long_state = 'Quebec'; } elsif ($state eq 'SK') { $long_state = 'Saskatchewan'; } elsif ($state eq 'YK') { $long_state = 'Yukon'; } elsif ($state eq 'AK') { $long_state = 'Alaska'; } elsif ($state eq 'AL') { $long_state = 'Alabama'; } elsif ($state eq 'AR') { $long_state = 'Arkansas'; } elsif ($state eq 'AZ') { $long_state = 'Arizona'; } elsif ($state eq 'CA') { $long_state = 'California'; } elsif ($state eq 'CO') { $long_state = 'Colorado'; } elsif ($state eq 'CT') { $long_state = 'Conneticut'; } elsif ($state eq 'DE') { $long_state = 'Delaware'; } elsif ($state eq 'FL') { $long_state = 'Florida'; } elsif ($state eq 'GA') { $long_state = 'Georgia'; } elsif ($state eq 'HI') { $long_state = 'Hawaii'; } elsif ($state eq 'IA') { $long_state = 'Iowa'; } elsif ($state eq 'ID') { $long_state = 'Idaho'; } elsif ($state eq 'IL') { $long_state = 'Illinois'; } elsif ($state eq 'IN') { $long_state = 'Indiana'; } elsif ($state eq 'KS') { $long_state = 'Kansas'; } elsif ($state eq 'KY') { $long_state = 'Kentucky'; } elsif ($state eq 'LA') { $long_state = 'Louisiana'; } elsif ($state eq 'MA') { $long_state = 'Massachusetts'; } elsif ($state eq 'MD') { $long_state = 'Maryland'; } elsif ($state eq 'ME') { $long_state = 'Maine'; } elsif ($state eq 'MI') { $long_state = 'Michigan'; } elsif ($state eq 'MN') { $long_state = 'Minnesota'; } elsif ($state eq 'MO') { $long_state = 'Missouri'; } elsif ($state eq 'MS') { $long_state = 'Mississippi'; } elsif ($state eq 'MT') { $long_state = 'Montana'; } elsif ($state eq 'NC') { $long_state = 'North Carolina'; } elsif ($state eq 'ND') { $long_state = 'North Dakota'; } elsif ($state eq 'NE') { $long_state = 'Nebraska'; } elsif ($state eq 'NH') { $long_state = 'New Hampshire'; } elsif ($state eq 'NJ') { $long_state = 'New Jersey'; } elsif ($state eq 'NM') { $long_state = 'New Mexico'; } elsif ($state eq 'NV') { $long_state = 'Nevada'; } elsif ($state eq 'NY') { $long_state = 'New York'; } elsif ($state eq 'OH') { $long_state = 'Ohio'; } elsif ($state eq 'OK') { $long_state = 'Oklahoma'; } elsif ($state eq 'OR') { $long_state = 'Oregon'; } elsif ($state eq 'PA') { $long_state = 'Pennsylvania'; } elsif ($state eq 'RI') { $long_state = 'Rhode Island'; } elsif ($state eq 'SC') { $long_state = 'South Carolina'; } elsif ($state eq 'SD') { $long_state = 'South Dakota'; } elsif ($state eq 'TN') { $long_state = 'Tennessee'; } elsif ($state eq 'TX') { $long_state = 'Texas'; } elsif ($state eq 'UT') { $long_state = 'Utah'; } elsif ($state eq 'VA') { $long_state = 'Virginia'; } elsif ($state eq 'VT') { $long_state = 'Vermont'; } elsif ($state eq 'WA') { $long_state = 'Washington'; } elsif ($state eq 'WI') { $long_state = 'Wisconsin'; } elsif ($state eq 'WV') { $long_state = 'West Virginia'; } elsif ($state eq 'WY') { $long_state = 'Wyoming'; } elsif ($state eq 'Poland') { $long_state = 'Poland'; } elsif ($state eq 'AUS') { $long_state = 'Australia'; } return ($long_state); } # sub state_map { print <<"EOF";Enter your zip code/postal code to locate your closest Dakota Micro EOF if ($site eq 'agcam') { $mini_site = 'AgCam'; } elsif ($site eq 'overview') { $mini_site = 'OverView'; } elsif ($site eq 'innopro') { $mini_site = 'InnoPro'; } else { $mini_site = ''; } print <<"EOF"; $mini_site dealer:
Or Select Your State:
EOF } sub region_map { print <<"EOF";Select Your Region:
EOF } sub header { print <<"EOF"; EOF if ($site eq 'agcam') { $site_title = 'AgCam'; $seo_title = 'AgCam camera dealers selling the Best Camera'; $keywords = 'agcam dealers, agcam dealers, Dakota micro dealers, where to buy agcam, agcam dealer, overview dealer'; $description = 'Where can I buy an AgCam camera? Locate a Dakota Micro dealer | Features hundreds of AgCam Dealers near you'; } elsif ($site eq 'overview') { $site_title = 'OverView'; $seo_title = 'OverView camera dealers selling the Best Camera'; $keywords = 'overview dealers, agcam dealers, overview dealers, Dakota micro dealers, where to buy overview, overview dealer, agcam dealer, overview dealer'; $description = 'Where can I buy an OverView camera? Locate a Dakota Micro dealer | Features hundreds of OverView Dealers near you'; } elsif($site eq 'innopro') { $site_title = 'InnoPro'; $seo_title = 'InnoPro camera dealers selling the Best Camera'; $keywords = 'InnoPro dealers, agcam dealers, InnoPro dealers, Dakota micro dealers, where to buy overview, InnoPro dealer, agcam dealer, overview dealer'; $description = 'Where can I buy an OverView camera? Locate a Dakota Micro dealer | Features hundreds of OverView Dealers near you'; } else { $site_title = 'Dakota Micro'; $seo_title = 'Dakota Micro dealers selling the Best Camera'; $keywords = 'Agcam dealers, enduracam dealers, overview dealers, Dakota micro dealers, where to buy agcam, agcam dealer, enduracam dealer, overview dealer'; $description = 'Where can I buy an AgCam? Locate a Dakota Micro dealer | Features hundreds of AgCam Dealers near you'; } print <<"EOF";