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');
|
||||
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');
|
||||
|
@ -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
|
||||
?>
|
||||
|
@ -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)";
|
||||
?>
|
||||
|
@ -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 ]);
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user