Exemplo n.º 1
0
 public static function addWR($conn, $txtdata, $userid, $format = "geojson")
 {
     $data = $format == "gpx" ? parseGPX($txtdata) : json_decode($txtdata, true);
     $d = $format == "gpx" ? $data : $data["features"][0];
     $id = Walkroute::doAddRoute($conn, $d, $userid, $format);
     switch ($format) {
         case "geojson":
             for ($i = 1; $i < count($data["features"]); $i++) {
                 $f = $data["features"][$i];
                 if (preg_match("/^-?[\\d\\.]+\$/", $f["geometry"]["coordinates"][0]) && preg_match("/^-?[\\d\\.]+\$/", $f["geometry"]["coordinates"][1]) && ctype_digit($f["properties"]["id"])) {
                     Walkroute::addRouteWaypoint($conn, $id, $f["geometry"]["coordinates"][0], $f["geometry"]["coordinates"][1], $f["properties"]["id"], htmlentities($f["properties"]["description"]));
                 }
             }
             break;
         case "gpx":
             for ($i = 0; $i < count($data["wp"]); $i++) {
                 $f = $data["wp"][$i];
                 if (preg_match("/^-?[\\d\\.]+\$/", $f["lat"]) && preg_match("/^-?[\\d\\.]+\$/", $f["lon"])) {
                     Walkroute::addRouteWaypoint($id, $f["lon"], $f["lat"], $i + 1, htmlentities($f["desc"]));
                 }
             }
             break;
     }
     return $id;
 }
Exemplo n.º 2
0
         header("HTTP/1.1 400 Bad Request");
         echo "Please use a POST request";
     }
     break;
 case "addWaypoint":
     $badreq = true;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $userid = $um->getUserIdFromCredentials();
         if ($userid <= 0) {
             header("HTTP/1.1 401 Unauthorized");
             $badreq = false;
         } else {
             if (isset($cpost["id"]) && ctype_digit($cpost["id"]) && isset($cpost["data"])) {
                 $f = json_decode($cpost["data"], true);
                 if (preg_match("/^-?[\\d\\.]+\$/", $f["geometry"]["coordinates"][0]) && preg_match("/^-?[\\d\\.]+\$/", $f["geometry"]["coordinates"][1])) {
                     $id = Walkroute::addRouteWaypoint($conn, $cpost["id"], $f["geometry"]["coordinates"][0], $f["geometry"]["coordinates"][1], 0, htmlentities($f["properties"]["description"]));
                     echo $id;
                     $badreq = false;
                 }
             }
         }
     }
     if ($badreq) {
         header("HTTP/1.1 400 Bad Request");
     }
     break;
 case "get":
     if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($cget["id"])) {
         $id = $cget["id"];
         if (ctype_digit($id)) {
             $wr = new Walkroute($conn, $id);