diff --git a/js/main.js b/js/main.js index 54dba6a..81d18e7 100755 --- a/js/main.js +++ b/js/main.js @@ -232,8 +232,12 @@ function importFile(input){ var root = xml.getElementsByTagName('root'); if (root.length && getNode(root[0], 'error') == 0) { trackId = getNode(root[0], 'trackid'); + trackCnt = getNode(root[0], 'trackcnt'); getTracks(userid); loadTrack(userid, trackId, 1); + if (trackCnt > 1) { + alert(sprintf(lang['imultiple'], trackCnt)); + } return; } errorMsg = getNode(root[0], 'message'); diff --git a/lang/en.php b/lang/en.php index 4e63834..98a5aa5 100644 --- a/lang/en.php +++ b/lang/en.php @@ -118,4 +118,5 @@ $lang["import"] = "Import track"; $lang["iuploadfailure"] = "Uploading failed"; $lang["iparsefailure"] = "Parsing failed"; $lang["idatafailure"] = "No track data in imported file"; +$lang["imultiple"] = "Notice, multiple tracks imported (%d)"; // substitutes number of imported tracks ?> diff --git a/lang/pl.php b/lang/pl.php index 4ea2049..2824596 100644 --- a/lang/pl.php +++ b/lang/pl.php @@ -113,5 +113,5 @@ $lang["import"] = "Importuj trasę"; $lang["iuploadfailure"] = "Błąd przesyłania pliku"; $lang["iparsefailure"] = "Błąd parsowania pliku"; $lang["idatafailure"] = "Brak trasy w importowanym pliku"; - +$lang["imultiple"] = "Uwaga, zaimportowano kilka tras (%d)"; ?> diff --git a/utils/import.php b/utils/import.php index 0179e89..ca3e783 100755 --- a/utils/import.php +++ b/utils/import.php @@ -35,8 +35,9 @@ $uploadErrors[UPLOAD_ERR_EXTENSION] = "A PHP extension stopped the file upload"; * Exit with xml response * @param boolean $isError Error if true * @param string $errorMessage Optional error message + * @param array|null $extra Optional array of extra parameters */ -function exitWithStatus($isError, $errorMessage = NULL, $trackId = NULL) { +function exitWithStatus($isError, $errorMessage = NULL, $extra = NULL) { header("Content-type: text/xml"); $xml = new XMLWriter(); $xml->openURI("php://output"); @@ -46,9 +47,14 @@ function exitWithStatus($isError, $errorMessage = NULL, $trackId = NULL) { $xml->writeElement("error", (int) $isError); if ($isError) { $xml->writeElement("message", $errorMessage); - } else { - $xml->writeElement("trackid", $trackId); } + + if (!empty($extra)) { + foreach ($extra as $key => $value) { + $xml->writeElement($key, $value); + } + } + $xml->endElement(); $xml->endDocument(); $xml->flush(); @@ -108,28 +114,32 @@ else if (empty($gpx->trk)) { exitWithStatus(true, $lang["idatafailure"]); } -$trackName = empty($gpx->trk->name) ? $gpxName : $gpx->trk->name->__toString(); -$metaName = empty($gpx->metadata->name) ? NULL : $gpx->metadata->name->__toString(); -$track = new uTrack(); -$trackId = $track->add($user->id, $trackName, $metaName); -if ($trackId === false) { - exitWithStatus(true, $lang["servererror"]); - break; -} +$trackCnt = 0; +foreach ($gpx->trk as $trk) { + $trackName = empty($trk->name) ? $gpxName : $trk->name->__toString(); + $metaName = empty($gpx->metadata->name) ? NULL : $gpx->metadata->name->__toString(); + $track = new uTrack(); + $trackId = $track->add($user->id, $trackName, $metaName); + if ($trackId === false) { + exitWithStatus(true, $lang["servererror"]); + break; + } -$position = new uPosition(); -foreach($gpx->trk->trkseg as $segment) { - foreach($segment->trkpt as $point) { - $ret = $position->add($user->id, $trackId, - strtotime($point->time), $point["lat"], $point["lon"], $point->ele, - NULL, NULL, NULL, "gps", NULL, NULL); - if ($ret === false) { - exitWithStatus(true, $lang["servererror"]); + $position = new uPosition(); + foreach($trk->trkseg as $segment) { + foreach($segment->trkpt as $point) { + $ret = $position->add($user->id, $trackId, + strtotime($point->time), $point["lat"], $point["lon"], $point->ele, + NULL, NULL, NULL, "gps", NULL, NULL); + if ($ret === false) { + exitWithStatus(true, $lang["servererror"]); + } } } + $trackCnt++; } -// return track id -exitWithStatus(false, NULL, $trackId); +// return track id and tracks count +exitWithStatus(false, NULL, [ "trackid" => $trackId, "trackcnt" => $trackCnt ]); ?> \ No newline at end of file