<?php /* Script: vg_dropfile.php Convert a track to a JSON format License: GNU General Public License This file is part of VisuGps VisuGps is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. VisuGps is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with VisuGps; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Copyright (c) 2007-2008 Victor Berchet, <http://www.victorb.fr> */ require_once 'vg_cfg.inc.php'; require_once 'vg_tracks.php'; $content = file_get_contents("php://input"); $activity = buildActivityFromContent($content); $jsTrack = buildJsonTrack($activity->trackData); echo @json_encode($jsTrack);
function GetDatabaseTrack($trackId, $delay = 0, $utcOffset = 0) { $link = mysql_connect(dbHost, dbUser, dbPassword) or die('Could not connect: ' . mysql_error()); mysql_select_db(dbName) or die('Database does not exist'); // Track should be long enough to be valid $query = "SELECT latitude FROM point WHERE flightId = {$trackId}"; $result = mysql_query($query) or die('Query error: ' . mysql_error()); if (mysql_num_rows($result) > 5) { // Get points from the track (using UTC time) $query = "SELECT latitude, longitude, elevation, " . "HOUR(time) AS hour, " . "MINUTE(time) AS min, " . "SECOND(time) AS sec, " . "time " . "FROM point, flight " . "WHERE flightId = {$trackId} " . "AND flight.id = flightId AND utc = 1 " . ($delay > 0 ? "AND time < DATE_SUB(UTC_TIMESTAMP(), INTERVAL {$delay} MINUTE) " : "") . "ORDER BY time"; $result = mysql_query($query) or die('Query error: ' . mysql_error()); for ($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_object($result); $track['lat'][$i] = floatval($row->latitude); $track['lon'][$i] = floatval($row->longitude); $track['elev'][$i] = intval($row->elevation); $track['time']['hour'][$i] = intval($row->hour); $track['time']['min'][$i] = intval($row->min); $track['time']['sec'][$i] = intval($row->sec); } // Get points from the track (using local time) $query = "SELECT latitude, longitude, elevation, " . "HOUR(DATE_ADD(time, INTERVAL {$utcOffset} HOUR)) AS hour, " . "MINUTE(DATE_ADD(time, INTERVAL {$utcOffset} HOUR)) AS min, " . "SECOND(DATE_ADD(time, INTERVAL {$utcOffset} HOUR)) AS sec, " . "time " . "FROM point, flight " . "WHERE flightId = {$trackId} " . "AND flight.id = flightId AND utc = 0 " . ($delay > 0 ? "AND DATE_ADD(time, INTERVAL {$utcOffset} HOUR) < DATE_SUB(UTC_TIMESTAMP(), INTERVAL {$delay} MINUTE) " : "") . "ORDER BY time"; $result = mysql_query($query) or die('Query error: ' . mysql_error()); for ($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_object($result); $track['lat'][$i] = floatval($row->latitude); $track['lon'][$i] = floatval($row->longitude); $track['elev'][$i] = intval($row->elevation); $track['time']['hour'][$i] = intval($row->hour); $track['time']['min'][$i] = intval($row->min); $track['time']['sec'][$i] = intval($row->sec); } $track['date'] = array('day' => 0, 'month' => 0, 'year' => 0); $track['pilot'] = ''; $query = "SELECT DAY(start) as day,\n MONTH(start) as month,\n YEAR(start) as year,\n pilotId\n FROM flight WHERE id = {$trackId}"; $result = mysql_query($query) or die('Query error: ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_object($result); if (isset($row->day)) { $track['date']['day'] = intval($row->day); } if (isset($row->month)) { $track['date']['month'] = intval($row->month); } if (isset($row->year)) { $track['date']['year'] = intval($row->year); } } $query = "SELECT name FROM pilot WHERE id = {$row->pilotId}"; $result = mysql_query($query) or die('Query error: ' . mysql_error()); if (mysql_num_rows($result) == 1) { $row = mysql_fetch_object($result); $track['pilot'] = $row->name; } $jsTrack = buildJsonTrack($track); } else { $jsTrack['error'] = 'Invalid track'; } $data = @json_encode($jsTrack); return $data; }