private static function doAddRoute($conn, &$f, $userid, $format = "geojson") { $i = 0; $stmt = $conn->prepare("INSERT INTO walkroutes(title,description,distance,the_geom," . "startlon,startlat,userid,authorised) VALUES " . "(?,?,?,GeomFromText(?,900913),?,?,?,?)"); switch ($format) { case "geojson": $stmt->bindParam(1, $f["properties"]["title"]); $stmt->bindParam(2, $f["properties"]["description"]); $stmt->bindParam(3, $f["properties"]["distance"]); $stmt->bindParam(4, Walkroute::mkgeom($f["geometry"]["coordinates"])); $stmt->bindParam(5, $f["geometry"]["coordinates"][0][0]); $stmt->bindParam(6, $f["geometry"]["coordinates"][0][1]); $stmt->bindParam(7, $userid); $status = $userid > 0 ? 1 : 0; $stmt->bindParam(8, $status); break; case "gpx": $stmt->bindParam(1, $f["name"]); $stmt->bindParam(2, $f["desc"]); $stmt->bindParam(3, $f["distance"]); $stmt->bindParam(4, Walkroute::mkgeom($f["trk"])); $stmt->bindParam(5, $f["trk"][0]["lon"]); $stmt->bindParam(6, $f["trk"][0]["lat"]); $stmt->bindParam(7, $userid); $status = $userid > 0 ? 1 : 0; $stmt->bindParam(8, $status); break; } $stmt->execute(); $result = $conn->query("SELECT currval('walkroutes_id_seq') AS lastid"); $row = $result->fetch(PDO::FETCH_ASSOC); return $row['lastid']; }
} } else { header("HTTP/1.1 400 Bad Request"); } break; case "deleteMultiWaypoints": if ($_SERVER['REQUEST_METHOD'] == 'POST') { $userid = $um->getUserIdFromCredentials(); $deleted = array(); if ($userid <= 0) { header("HTTP/1.1 401 Unauthorized"); } elseif (isset($cpost["ids"])) { $user = new User($userid, $conn); $ids = json_decode($cpost["ids"]); foreach ($ids as $id) { if (ctype_digit("{$id}")) { $wr = Walkroute::getWalkrouteFromWaypoint($conn, $id); if ($userid > 0 && ($wr->getUserId() == $userid || $user->isAdmin())) { Walkroute::deleteWaypoint($conn, $id); $deleted[] = $id; } } } header("Content-type: application/json"); echo json_encode($deleted); } else { header("HTTP/1.1 400 Bad Request"); } } break; }