diff --git a/client/index.php b/client/index.php index dba02d4..cb0cc79 100644 --- a/client/index.php +++ b/client/index.php @@ -80,7 +80,7 @@ switch ($action) { case "addpos": $lat = isset($_REQUEST["lat"]) ? $_REQUEST["lat"] : NULL; $lon = isset($_REQUEST["lon"]) ? $_REQUEST["lon"] : NULL; - $time = isset($_REQUEST["time"]) ? $_REQUEST["time"] : NULL; + $timestamp = isset($_REQUEST["time"]) ? $_REQUEST["time"] : NULL; $altitude = isset($_REQUEST["altitude"]) ? $_REQUEST["altitude"] : NULL; $speed = isset($_REQUEST["speed"]) ? $_REQUEST["speed"] : NULL; $bearing = isset($_REQUEST["bearing"]) ? $_REQUEST["bearing"] : NULL; @@ -90,7 +90,7 @@ switch ($action) { $imageId = isset($_REQUEST["imageid"]) ? $_REQUEST["imageid"] : NULL; $trackId = isset($_REQUEST["trackid"]) ? $_REQUEST["trackid"] : NULL; - if (is_null($lat) || is_null($lon) || is_null($time) || is_null($trackId)) { + if (is_null($lat) || is_null($lon) || is_null($timestamp) || is_null($trackId)) { setError($response, "missing required parameter"); break; } @@ -98,7 +98,7 @@ switch ($action) { require_once(ROOT_DIR . "/helpers/position.php"); $position = new uPosition(); $positionId = $position->add($user->id, $trackId, - $time, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId); + $timestamp, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId); if ($positionId === false) { setError($response, "Server error"); diff --git a/css/main.css b/css/main.css index 6552d08..ed73ff8 100755 --- a/css/main.css +++ b/css/main.css @@ -109,11 +109,10 @@ select { #user, #track, #summary, #export, #import, #other, #units { padding-bottom: 10px; } -#summary span { - display: block; +#summary div { padding-top: .3em; } -#summary span img { +#summary div img { margin-bottom: -2px; } #login { @@ -170,6 +169,10 @@ select { padding-top: 5px; padding-right: 20px; } +#pbody .smaller { + color: gray; + font-size: .9em; +} #pfooter { font-size: .6rem; padding-top: 20px; diff --git a/helpers/position.php b/helpers/position.php index f67db0c..69e004c 100644 --- a/helpers/position.php +++ b/helpers/position.php @@ -25,7 +25,7 @@ */ class uPosition { public $id; - public $time; + public $timestamp; public $userId; public $userLogin; public $trackId; @@ -53,7 +53,7 @@ self::$db = uDb::getInstance(); if (!empty($positionId)) { - $query = "SELECT p.id, p.time, p.user_id, p.track_id, + $query = "SELECT p.id, UNIX_TIMESTAMP(p.time) AS tstamp, p.user_id, p.track_id, p.latitude, p.longitude, p.altitude, p.speed, p.bearing, p.accuracy, p.provider, p.comment, p.image_id, u.login, t.name FROM `" . self::$db->table('positions') . "` p @@ -82,9 +82,9 @@ * @param int $imageId * @return int|bool New position id in database, false on error */ - public function add($userId, $trackId, $time, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId) { + public function add($userId, $trackId, $timestamp, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId) { $positionId = false; - if (!is_null($lat) && !is_null($lon) && !is_null($time) && !empty($userId) && !empty($trackId)) { + if (!is_null($lat) && !is_null($lon) && !is_null($timestamp) && !empty($userId) && !empty($trackId)) { $track = new uTrack($trackId); if ($track->isValid && $track->userId == $userId) { $query = "INSERT INTO `" . self::$db->table('positions') . "` @@ -94,7 +94,7 @@ $stmt = self::$db->prepare($query); $stmt->bind_param('iisddddddssi', $userId, $trackId, - $time, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId); + $timestamp, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId); $stmt->execute(); if (!self::$db->error && !$stmt->errno) { $positionId = self::$db->insert_id; @@ -151,7 +151,7 @@ $where = ""; $params = NULL; } - $query = "SELECT p.id, p.time, p.user_id, p.track_id, + $query = "SELECT p.id, UNIX_TIMESTAMP(p.time) AS tstamp, p.user_id, p.track_id, p.latitude, p.longitude, p.altitude, p.speed, p.bearing, p.accuracy, p.provider, p.comment, p.image_id, u.login, t.name FROM `" . self::$db->table('positions') . "` p @@ -183,7 +183,7 @@ } else { $where = ""; } - $query = "SELECT p.id, p.time, p.user_id, p.track_id, + $query = "SELECT p.id, UNIX_TIMESTAMP(p.time) AS tstamp, p.user_id, p.track_id, p.latitude, p.longitude, p.altitude, p.speed, p.bearing, p.accuracy, p.provider, p.comment, p.image_id, u.login, t.name FROM `" . self::$db->table('positions') . "` p @@ -227,7 +227,7 @@ * @return int Number of seconds */ public function secondsTo($target) { - return strtotime($this->time) - strtotime($target->time); + return $this->timestamp - $target->timestamp; } /** @@ -239,7 +239,7 @@ private function rowToObject($row) { $position = new uPosition(); $position->id = $row['id']; - $position->time = $row['time']; + $position->timestamp = $row['tstamp']; $position->userId = $row['user_id']; $position->userLogin = $row['login']; $position->trackId = $row['track_id']; @@ -272,7 +272,7 @@ ); } if ($stmt->execute()) { - $stmt->bind_result($this->id, $this->time, $this->userId, $this->trackId, + $stmt->bind_result($this->id, $this->timestamp, $this->userId, $this->trackId, $this->latitude, $this->longitude, $this->altitude, $this->speed, $this->bearing, $this->accuracy, $this->provider, $this->comment, $this->imageId, $this->userLogin, $this->trackName); diff --git a/js/api_gmaps.js b/js/api_gmaps.js index 8e48953..2093bdc 100755 --- a/js/api_gmaps.js +++ b/js/api_gmaps.js @@ -81,10 +81,9 @@ function displayTrack(xml, update) { setTimeout(function () { google.maps.event.removeListener(zListener) }, 2000); } } - latestTime = p.dateoccured; polies.push(poly); - updateSummary(p.dateoccured, totalMeters, totalSeconds); + updateSummary(p.timestamp, totalMeters, totalSeconds); if (p.tid != trackid) { trackid = p.tid; setTrack(trackid); @@ -120,7 +119,7 @@ function setMarker(p, i, posLen) { var marker = new google.maps.Marker({ map: map, position: p.coordinates, - title: p.dateoccured + title: (new Date(p.timestamp * 1000)).toLocaleString() }); if (latest == 1) { marker.setIcon('//maps.google.com/mapfiles/dd-end.png') } else if (i == 0) { marker.setIcon('//maps.google.com/mapfiles/marker_greenA.png') } diff --git a/js/api_openlayers.js b/js/api_openlayers.js index cc1bf30..0f1535c 100755 --- a/js/api_openlayers.js +++ b/js/api_openlayers.js @@ -119,10 +119,8 @@ function displayTrack(xml, update) { map.zoomOut(); } } - latestTime = p.dateoccured; - //polies.push(poly); - updateSummary(p.dateoccured, totalMeters, totalSeconds); + updateSummary(p.timestamp, totalMeters, totalSeconds); if (p.tid != trackid) { trackid = p.tid; setTrack(trackid); diff --git a/js/main.js b/js/main.js index 0776daf..c899b9e 100755 --- a/js/main.js +++ b/js/main.js @@ -33,7 +33,6 @@ if (units == 'imperial') { unit_km = 'km'; } var latest = 0; -var latestTime = 0; var live = 0; var chart; var altitudes = new Array(); @@ -154,7 +153,7 @@ function parsePosition(p) { var username = getNode(p, 'username'); var trackname = getNode(p, 'trackname'); var tid = getNode(p, 'trackid'); - var dateoccured = getNode(p, 'dateoccured'); + var timestamp = getNode(p, 'timestamp'); var distance = parseInt(getNode(p, 'distance')); var seconds = parseInt(getNode(p, 'seconds')); return { @@ -169,16 +168,24 @@ function parsePosition(p) { 'username': username, 'trackname': trackname, 'tid': tid, - 'dateoccured': dateoccured, + 'timestamp': timestamp, 'distance': distance, 'seconds': seconds }; } function getPopupHtml(p, i, count) { - var dateTime = p.dateoccured.split(" "); - var date = dateTime[0]; - var time = dateTime[1]; + var date = '–––'; + var time = '–––'; + if (p.timestamp > 0) { + var d = new Date(p.timestamp * 1000); + date = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2); + time = d.toTimeString(); + var offset; + if ((offset = time.indexOf(' ')) >= 0) { + time = time.substr(0, offset) + ' ' + time.substr(offset + 1) + ''; + } + } var provider = ''; if (p.provider == 'gps') { provider = ' ()'; @@ -283,15 +290,26 @@ function removeLoader(el) { el.innerHTML = el.textContent || el.innerText; } -function updateSummary(l, d, s) { +function updateSummary(timestamp, d, s) { var t = document.getElementById('summary'); if (latest == 0) { t.innerHTML = '
' + - ' ' + (d.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '' + - ' ' + s.toHMS() + ''; - } - else { - t.innerHTML = ' ' + l; + '