topical media & game development
mashup-gmaps-ch13-backend.cgi / cgi
#!/usr/bin/perl
use DBI;
use Math::Trig;
use strict;
use CGI qw/:standard/;
print header(-type => 'text/xml');
my dbh))
{
die "Couldn't open connection to database\n";
}
if (param('m') eq 'saveroute')
{
saveroute();
}
if (param('m') eq 'delroute')
{
delroute(param('routeid'));
}
elsif(param('m') eq 'listroutes')
{
listroutes();
}
elsif(param('m') eq 'getroute')
{
getroute(param('routeid'));
}
sub delroute
{
my (dbh->do(sprintf('delete from ch12_routesimple where routeid=\%s',
dbh->do(sprintf('delete from ch12_routepoints where routeid=\%s',
sth = sth->execute();
print "<routes>";
while (my sth->fetchrow_hashref())
{
printf('<route routeid="\%s" title="\%s" lat="\%s" lng="\%s"/>',
row->{title},
row->{lng}
);
}
print "</routes>";
}
sub latlngdistance
{
my (ydeg1,ydeg2) = @_;
my (y1,y2) = (deg2rad(ydeg1),
deg2rad(ydeg2));
my latdistance = x1;
my y2 - a = sin(latdistance/2) +
cos(x2) * sin(lngdistance/2);
my a), sqrt(1-d = c;
return title = param('title');
my points = param('points');
my @pointlist = split(/,/,routeid;
if (defined(param('routeid')) && param('routeid') != 0)
{
dbh->do(sprintf('update ch12_routesimple set title=\%s,description=\%s where routeid=\%s',
title),
description),
dbh->do(sprintf('delete from ch12_routepoints where routeid=\%s',
dbh->do(sprintf('insert into ch12_routesimple values(0,\%s,\%s)',
title),
description)));
dbh->{mysql_insertid};
}
foreach my seqid,y) = split(/:/,dbh->do(sprintf('insert into ch12_routepoints values(\%s,\%s,\%s,\%s)',
routeid),
x),
y),
seqid)));
}
xmlmessage('Route added',{routeid => reqrouteid) = @_;
my dbh->selectrow_hashref('select routeid,title,description from ch12_routesimple where routeid = ' .
reqrouteid));
if (reqrouteid)
{
xmlmessage('Error: route not found');
return();
}
printf('<route><routeinfo routeid="\%s" title="\%s" description="\%s"/>',
routedata->{title},
sth = dbh->quote(sth->execute();
my seq = 0;
my (lasty) = (undef,undef);
while (my sth->fetchrow_hashref())
{
row->{lat},
seq >= 2)
{
lastx,row->{lat},lastx,row->{lat},sth->finish();
printf('<distance km="%.2f" miles="%.2f"/>',distance/1.609344));
print("</route>\n");
}
sub xmlmessage
{
my (attrib) = @_;
printf('<msg><message text="\%s" \%s/></msg>',
_,_}) } keys %{
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.