#/usr/bin/perl -w use strict; use Win32::OLE; use DBI; # start IE my $ie = Win32::OLE->new('InternetExplorer.Application') or die("IE didn't start"); # create some variables that will be used in the creation of error messages my $header = qq(Map It!

Map It!

); my $usage = qq(

Usage: $0 (location #1) [location #2]
Map It! will return a map showing how to get from location #1 to location #2.
However location #2 can be omitted to receive just a destination map.

Examples:
$0 134898 will get a destination map for location 134989.
$0 0 134898 will get a route map from here to location 134898.

This example shows using 0 to represent wherre I am. It can be used as the start or end point.

); my $nodata = qq(

Location Not Found!

Check the location numbers again.

); my $footer = qq(); # get our location numbers my @loc = @ARGV; # how many were given? my $locs = @loc; # Make IE visible $ie->{Visible}=1; # If the wrong number of locations is given, show the usage message if ($locs == 0 || $locs > 2) { Error($ie,$header,$usage,$footer); } else { # setup the database stuff my $db = "database"; my $db_engine = "mysql"; my $host = "localhost"; my $user = "username"; my $password = "password"; my $dbh = DBI->connect("DBI:$db_engine:$db:$host",$user, $password,{ PrintError => 0}) || die $DBI::errstr; my $table = "locations"; my $select = "name, address1, city, state, zip"; # our arrays to hold locations' address info for later my (@street, @csz); foreach my $loc (@loc) { # if $loc is 0, it's here... so skip the database stuff if ($loc == 0) { push(@street, "123 Main St"); # your street address push(@csz, "90210"); # your zip code next; } my $where = "loc_id = $loc"; my $sql = "SELECT $select FROM $table WHERE $where;"; my $sth = $dbh->prepare($sql); if (!$sth) { die "sth error:" . $dbh->errstr . "\n"; } if (!$sth->execute) { die "sth execute error:" . $sth->errstr . "\n"; } my $ref = $sth->fetchrow_hashref; # if $$ref{address1} doesn't exist, give an error message and die if (!exists $$ref{address1}) { Error($ie,$header,$nodata,$footer); die("$loc doesn't exist"); } # add the street address push(@street, $$ref{address1}); # and zip code if known, otherwise city and state push(@csz, ($$ref{zip} || "$$ref{city},$$ref{state}")); $sth->finish(); } $dbh->disconnect(); my $url; if ($locs == 1) { # if there was only one location number given, it's a destination only map $url="http://www.mapblast.com/myblast/map.mb?CMD=GEO&CT=&IC=&LV=" ."&GMI=&GAD1=&GAD2=&GAD3=&GAD4=&AD2=$street[0]&noPrefs=&req_action=" ."crmap&skip=&serch=&PHONE=&noBRP=&remLoc=&AD4=USA&AD2_street=$street[0]" ."&AD3=$csz[0]&apmenu=&apcode=&x=67&y=11&selCategory="; } else { # otherwise, it's a route map $url = "http://www.mapblast.com/myblast/driveSilo.mb?&AD4=USA&locBoxNum=" ."&req_action=getdir&AD2=&AD3=&formnum=2&forceAddr=&CT=&GMI=" ."&multiIC=::::&locn_ckieVal=&serch=&skip=&MA=1&LV=11&CMD=FILL"; for my $i (1..2){ $url .= "&remLoc_$i=&AD4_$i=US&apmenu_$i=&apcode_$i=&GAD1_$i=&GAD2_$i=&GAD3_$i=" ."&GAD4_$i=&phone_$i=&IC_$i=&GMI_$i="; } $url .= "&AD2_street_1=$street[0]&AD2_1=$street[0]&AD3_1=$csz[0]&AD2_street_2=" ."$street[1]&AD2_2=$street[1]&AD3_2=$csz[1]"; } $ie->Navigate($url); } sub Error { my ($ie,$header,$error,$footer) = @_; $ie->Navigate(''); my $idoc = $ie->{Document}; $idoc->open("text/html","replace"); $idoc->writeln($header.$error.$footer); }