Last active
April 3, 2017 02:11
-
-
Save ImagoTrigger/2e4ba2b0036ad4ae3ce7d5d748b6e2f7 to your computer and use it in GitHub Desktop.
Serves up some XML for markers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use Storable; | |
use CGI qw(:standard -nph); | |
no warnings 'utf8'; | |
$| = 1; | |
sub safe_encode | |
{ | |
my $str = shift; | |
$str =~ s{ | |
([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...) | |
}{ | |
XmlUtf8Decode($1) | |
}xegs; | |
$str =~ s/\</\</g; | |
$str =~ s/\>/\>/g; | |
$str =~ s/\&/\&/g; | |
$str | |
} | |
sub XmlUtf8Decode | |
{ | |
my( $str, $hex ) = @_; | |
my $len = length $str; | |
my $n; | |
if ( $len == 4 ) | |
{ | |
my @n = unpack "C4", $str; | |
$n = (($n[0] & 0x0f) << 18) + (($n[1] & 0x3f) << 12) + (($n[2] & 0x3f) << 6) + ($n[3] & 0x3f); | |
} | |
elsif ( $len == 3 ) | |
{ | |
my @n = unpack "C3", $str; | |
$n = (($n[0] & 0x1f) << 12) + (($n[1] & 0x3f) << 6) + ($n[2] & 0x3f); | |
} | |
elsif ( $len == 2 ) | |
{ | |
my @n = unpack "C2", $str; | |
$n = (($n[0] & 0x3f) << 6) + ($n[1] & 0x3f); | |
} | |
elsif ( $len == 1 ) | |
{ | |
$n = ord $str; | |
} | |
else | |
{ | |
die "bad value '$str' for XmlUtf8Decode"; | |
} | |
$hex ? sprintf( "&#x%x;", $n ) : "&#$n;" | |
} | |
my $q = CGI->new; | |
my $params = $q->Vars; | |
my %hash = %{retrieve('C:\\wwwroot\\maphash2.txt')}; | |
print $q->header(-type => 'text/xml', -nph=>1); | |
print qq{<?xml version="1.0" encoding="UTF-8"?><markers>}; | |
foreach my $root (keys(%hash)) { | |
next if $root eq 'runcount'; | |
if (!$params->{'root'} || $params->{'root'} eq $root || $params->{'root'} eq 'everyone') { | |
foreach my $cust (keys(%{$hash{$root}{customers}})) { | |
my ($id, $name, $addr, $lat, $lng); | |
$id = $cust; | |
$addr = safe_encode $hash{$root}{customers}{$cust}{addr}; | |
$addr =~ s/\"/\'/g; | |
$lat = safe_encode $hash{$root}{customers}{$cust}{lat}; | |
$lng = safe_encode $hash{$root}{customers}{$cust}{long}; | |
$name = safe_encode $hash{$root}{customers}{$cust}{name}; | |
$name =~ s/\"/\'/g; | |
my $route = $hash{$root}{customers}{$cust}{route}; | |
$route =~ s/MIN//; | |
my $task = $hash{$root}{customers}{$cust}{task}; | |
my $dt = $hash{$root}{customers}{$cust}{dt}; | |
my $subdomain = ($root eq 'emutah' || $root eq 'emstlouis' || $root eq 'emdenver') ? 1 : 0; | |
print qq{<marker name="$name" seen="$addr" active="$id" lat="$lat" lng="$lng" route="$route" task="$task" dt="$dt" root="$root" subdomain="$subdomain"> | |
}; | |
foreach my $invoice (keys(%{$hash{$root}{customers}{$cust}{invoices}})) { | |
my ($items,$num,$date,$notes); | |
$num = $hash{$root}{customers}{$cust}{invoices}{$invoice}{num}; | |
$date = $hash{$root}{customers}{$cust}{invoices}{$invoice}{date}; | |
$notes = safe_encode $hash{$root}{customers}{$cust}{invoices}{$invoice}{notes}; | |
$notes =~ s/\"/\'/g; | |
print qq{<invoice id="$invoice" num="$num" date="$date" notes="$notes" items="$items"/>}; | |
} | |
print qq{</marker>}; | |
} | |
} | |
} | |
print qq{</markers>}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment