Import: handle multiple tracks
This commit is contained in:
parent
97cfd8a723
commit
a7f52aa215
@ -232,8 +232,12 @@ function importFile(input){
|
|||||||
var root = xml.getElementsByTagName('root');
|
var root = xml.getElementsByTagName('root');
|
||||||
if (root.length && getNode(root[0], 'error') == 0) {
|
if (root.length && getNode(root[0], 'error') == 0) {
|
||||||
trackId = getNode(root[0], 'trackid');
|
trackId = getNode(root[0], 'trackid');
|
||||||
|
trackCnt = getNode(root[0], 'trackcnt');
|
||||||
getTracks(userid);
|
getTracks(userid);
|
||||||
loadTrack(userid, trackId, 1);
|
loadTrack(userid, trackId, 1);
|
||||||
|
if (trackCnt > 1) {
|
||||||
|
alert(sprintf(lang['imultiple'], trackCnt));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
errorMsg = getNode(root[0], 'message');
|
errorMsg = getNode(root[0], 'message');
|
||||||
|
@ -118,4 +118,5 @@ $lang["import"] = "Import track";
|
|||||||
$lang["iuploadfailure"] = "Uploading failed";
|
$lang["iuploadfailure"] = "Uploading failed";
|
||||||
$lang["iparsefailure"] = "Parsing failed";
|
$lang["iparsefailure"] = "Parsing failed";
|
||||||
$lang["idatafailure"] = "No track data in imported file";
|
$lang["idatafailure"] = "No track data in imported file";
|
||||||
|
$lang["imultiple"] = "Notice, multiple tracks imported (%d)"; // substitutes number of imported tracks
|
||||||
?>
|
?>
|
||||||
|
@ -113,5 +113,5 @@ $lang["import"] = "Importuj trasę";
|
|||||||
$lang["iuploadfailure"] = "Błąd przesyłania pliku";
|
$lang["iuploadfailure"] = "Błąd przesyłania pliku";
|
||||||
$lang["iparsefailure"] = "Błąd parsowania pliku";
|
$lang["iparsefailure"] = "Błąd parsowania pliku";
|
||||||
$lang["idatafailure"] = "Brak trasy w importowanym pliku";
|
$lang["idatafailure"] = "Brak trasy w importowanym pliku";
|
||||||
|
$lang["imultiple"] = "Uwaga, zaimportowano kilka tras (%d)";
|
||||||
?>
|
?>
|
||||||
|
@ -35,8 +35,9 @@ $uploadErrors[UPLOAD_ERR_EXTENSION] = "A PHP extension stopped the file upload";
|
|||||||
* Exit with xml response
|
* Exit with xml response
|
||||||
* @param boolean $isError Error if true
|
* @param boolean $isError Error if true
|
||||||
* @param string $errorMessage Optional error message
|
* @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");
|
header("Content-type: text/xml");
|
||||||
$xml = new XMLWriter();
|
$xml = new XMLWriter();
|
||||||
$xml->openURI("php://output");
|
$xml->openURI("php://output");
|
||||||
@ -46,9 +47,14 @@ function exitWithStatus($isError, $errorMessage = NULL, $trackId = NULL) {
|
|||||||
$xml->writeElement("error", (int) $isError);
|
$xml->writeElement("error", (int) $isError);
|
||||||
if ($isError) {
|
if ($isError) {
|
||||||
$xml->writeElement("message", $errorMessage);
|
$xml->writeElement("message", $errorMessage);
|
||||||
} else {
|
|
||||||
$xml->writeElement("trackid", $trackId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($extra)) {
|
||||||
|
foreach ($extra as $key => $value) {
|
||||||
|
$xml->writeElement($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$xml->endElement();
|
$xml->endElement();
|
||||||
$xml->endDocument();
|
$xml->endDocument();
|
||||||
$xml->flush();
|
$xml->flush();
|
||||||
@ -108,7 +114,9 @@ else if (empty($gpx->trk)) {
|
|||||||
exitWithStatus(true, $lang["idatafailure"]);
|
exitWithStatus(true, $lang["idatafailure"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$trackName = empty($gpx->trk->name) ? $gpxName : $gpx->trk->name->__toString();
|
$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();
|
$metaName = empty($gpx->metadata->name) ? NULL : $gpx->metadata->name->__toString();
|
||||||
$track = new uTrack();
|
$track = new uTrack();
|
||||||
$trackId = $track->add($user->id, $trackName, $metaName);
|
$trackId = $track->add($user->id, $trackName, $metaName);
|
||||||
@ -118,7 +126,7 @@ if ($trackId === false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$position = new uPosition();
|
$position = new uPosition();
|
||||||
foreach($gpx->trk->trkseg as $segment) {
|
foreach($trk->trkseg as $segment) {
|
||||||
foreach($segment->trkpt as $point) {
|
foreach($segment->trkpt as $point) {
|
||||||
$ret = $position->add($user->id, $trackId,
|
$ret = $position->add($user->id, $trackId,
|
||||||
strtotime($point->time), $point["lat"], $point["lon"], $point->ele,
|
strtotime($point->time), $point["lat"], $point["lon"], $point->ele,
|
||||||
@ -128,8 +136,10 @@ foreach($gpx->trk->trkseg as $segment) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$trackCnt++;
|
||||||
|
}
|
||||||
|
|
||||||
// return track id
|
// return track id and tracks count
|
||||||
exitWithStatus(false, NULL, $trackId);
|
exitWithStatus(false, NULL, [ "trackid" => $trackId, "trackcnt" => $trackCnt ]);
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user