<?php

global $rootpath;
require_once './lib/common.inc.php';
require_once './lib/class.polylineEncoder.php';
$route_id = $_REQUEST['routeid'];
$rscp = XDb::xSql("SELECT `lat` ,`lon`\n                    FROM `route_points`\n                    WHERE `route_id`= ? ", $route_id);
$p = array();
$points = array();
for ($i = 0; false != ($record = XDb::xFetchArray($rscp)); $i++) {
    $y = $record['lon'];
    $x = $record['lat'];
    $p[0] = $x;
    $p[1] = $y;
    $points[$i] = $p;
}
$encoder = new PolylineEncoder();
$polyline = $encoder->encode($points);
?>
<script type="text/javascript" src="/lib/jsts/attache.array.min.js"></script>
<script type="text/javascript" src="/lib/jsts/javascript.util.js"></script>
<script type="text/javascript" src="/lib/jsts/jsts.0.13.2.js"></script>
<script type="text/javascript" src="/lib/js/myroutes_map.<?php 
echo date("YmdHis", filemtime($rootpath . 'lib/js/myroutes_map.js'));
?>
.js"></script>
<script type="text/javascript">
//<![CDATA[

    var currentinfowindow = null;
        $x = (int) $utm[0];
        $y = (int) $utm[1];
        $name = PLConvert('UTF-8', 'POLSKAWY', $r['name']);
        $username = PLConvert('UTF-8', 'POLSKAWY', $r['username']);
        $type = $uamType[$r['type']];
        $size = $uamSize[$r['size']];
        $difficulty = sprintf('%01.1f', $r['difficulty'] / 2);
        $terrain = sprintf('%01.1f', $r['terrain'] / 2);
        $cacheid = $r['wp_oc'];
        $descr = "{$name} by {$username} [{$difficulty}/{$terrain}]";
        $poiname = "{$cacheid} {$type}{$size}";
        $record = pack("llca64a255cca32", $x, $y, 2, $poiname, $descr, 1, 99, 'Geocaching');
        append_output($record);
        ob_flush();
    }
    XDb::xSql('DROP TABLE `wptcontent` ');
    // phpzip versenden
    if ($bUseZip == true) {
        $phpzip->add_data($sFilebasename . '.uam', $content);
        echo $phpzip->save($sFilebasename . '.zip', 'b');
    }
    exit;
}
function convert_string($str)
{
    $newstr = iconv("UTF-8", "ASCII//TRANSLIT", $str);
    if ($newstr == false) {
        return "--- charset error ---";
    } else {
        return $newstr;
    }