#!/usr/bin/perl

use lib "/home/simon/public_html/shartak.com/data";
use Jungle::NPC;
use Leaky::DBI;
use Jungle::Misc;
use strict;
use warnings;
use CGI;
use LWP::UserAgent;

my $qw = new CGI;
my $parrot = Jungle::NPC->new(dbh => Leaky::DBI::connect(), id => 3294);

my ($px,$py) = Jungle::Misc::xy_to_gps($parrot->{ npc }{ x }, $parrot->{ npc }{ y });

my ($ux,$uy) = ($px,$py);
$ux =~ s/\.//;
$uy =~ s/[\.\+]//g;

if ($qw->param("map")) {
    my $ua = LWP::UserAgent->new();

    my $res = $ua->get("http://www.itechsc.com/misc/shartak/ubermap/mapposgen.php?cx=$ux&cy=$uy");
    print $res->headers->as_string;
    print "\n";
    print $res->content;
    exit;
}

print <<EOF
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head><title>The Re-Pete parrot</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>The parrot known as Re-Pete is at [$px,$py]</p>

<a href="http://www.itechsc.com/misc/shartak/ubermap/mapposgen.php?cx=$ux&cy=$uy"><img src="repeteparrot.pl?map=1" alt="Map showing the location"></a>
</body>
</html>
EOF

