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 = ' (' + lang['gps'] + ')'; @@ -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 = '' + - '' + lang['tdistance'] + ' ' + (d.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '' + - '' + lang['ttime'] + ' ' + s.toHMS() + ''; - } - else { - t.innerHTML = '' + l; + '
' + lang['tdistance'] + ' ' + (d.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '
' + + '
' + lang['ttime'] + ' ' + s.toHMS() + '
'; + } else { + var today = new Date(); + var d = new Date(timestamp * 1000); + var dateString = ''; + if (d.toDateString() != today.toDateString()) { + dateString += d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2); + dateString += '
'; + } + var timeString = d.toTimeString(); + var offset; + if ((offset = timeString.indexOf(' ')) >= 0) { + timeString = timeString.substr(0, offset) + ' ' + timeString.substr(offset + 1) + ''; + } + t.innerHTML = '' + dateString + timeString; } } diff --git a/scripts/migrate_from_phptrackme.php b/scripts/migrate_from_phptrackme.php index f23cd2d..abf2282 100644 --- a/scripts/migrate_from_phptrackme.php +++ b/scripts/migrate_from_phptrackme.php @@ -176,7 +176,7 @@ function process_user_tracks($user_id) { */ function process_track($user_id, $old_id, $new_id) { global $pt_mysqli, $mysqli; - $sql = "SELECT Latitude, Longitude, Altitude, Speed, Angle, DateOccurred, Comments FROM pt_positions WHERE FK_Users_ID = ? AND FK_Trips_ID = ? ORDER BY DateOccurred"; + $sql = "SELECT Latitude, Longitude, Altitude, Speed, Angle, UNIX_TIMESTAMP(DateOccurred), Comments FROM pt_positions WHERE FK_Users_ID = ? AND FK_Trips_ID = ? ORDER BY DateOccurred, ID"; if (!($pos_select = $pt_mysqli->prepare($sql))) { echo "Prepare failed: (" . $pt_mysqli->errno . ") " . $pt_mysqli->error . "\n"; exit(1); @@ -185,7 +185,7 @@ function process_track($user_id, $old_id, $new_id) { echo "Binding parameters failed: (" . $pos_select->errno . ") " . $pos_select->error . "\n"; exit(1); } - if (!$pos_select->bind_result($lat, $lon, $altitude, $speed, $bearing, $time, $comment)) { + if (!$pos_select->bind_result($lat, $lon, $altitude, $speed, $bearing, $timestamp, $comment)) { echo "Binding parameters failed: (" . $pos_select->errno . ") " . $pos_select->error . "\n"; exit(1); } @@ -194,17 +194,17 @@ function process_track($user_id, $old_id, $new_id) { exit(1); } $pos_select->store_result(); - if (!($pos_insert = $mysqli->prepare("INSERT INTO `$tPositions` (time, user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id) + if (!($pos_insert = $mysqli->prepare("INSERT INTO `$tPositions` (FROM_UNIXTIME(time), user_id, track_id, latitude, longitude, altitude, speed, bearing, accuracy, provider, comment, image_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))) { echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error . "\n"; exit(1); } - $provider = $comment = $time = $imageid = null; + $provider = $comment = $timestamp = $imageid = null; $lat = $lon = 0; $altitude = $speed = $bearing = $accuracy = null; if (!$pos_insert->bind_param('siiddddddssi', - $time, $user_id, $new_id, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageid)) { + $timestamp, $user_id, $new_id, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageid)) { echo "Binding parameters failed: (" . $pos_insert->errno . ") " . $pos_insert->error . "\n"; exit(1); } diff --git a/utils/export.php b/utils/export.php index 374bb23..f382954 100755 --- a/utils/export.php +++ b/utils/export.php @@ -132,7 +132,7 @@ if ($trackId && $userId) { "{$lang["user"]}: " . htmlspecialchars($position->userLogin) . "
{$lang["track"]}: " . htmlspecialchars($position->trackName) . "" . "
" . - "
{$lang["time"]}: {$position->time}
" . + "
{$lang["time"]}: " . date("Y-m-d H:i:s (e)", $position->timestamp) . "
" . (!is_null($position->speed) ? "{$lang["speed"]}: " . round($position->speed * 3.6 * $factor_kmh, 2) . " {$unit_kmh}
" : "") . (!is_null($position->altitude) ? "{$lang["altitude"]}: " . round($position->altitude * $factor_m) . " {$unit_m}
" : "") . "{$lang["ttime"]}: " . toHMS($totalSeconds) . "
" . @@ -182,7 +182,7 @@ if ($trackId && $userId) { $xml->writeAttribute("version", "1.1"); $xml->startElement("metadata"); $xml->writeElement("name", $positionsArr[0]->trackName); - $xml->writeElement("time", gmdate("Y-m-d\TH:i:s\Z", strtotime($positionsArr[0]->time))); + $xml->writeElement("time", gmdate("Y-m-d\TH:i:s\Z", $positionsArr[0]->timestamp)); $xml->endElement(); $xml->startElement("trk"); $xml->writeElement("name", $positionsArr[0]->trackName); @@ -200,11 +200,11 @@ if ($trackId && $userId) { $xml->writeAttribute("lat", $position->latitude); $xml->writeAttribute("lon", $position->longitude); if (!is_null($position->altitude)) { $xml->writeElement("ele", $position->altitude); } - $xml->writeElement("time", gmdate("Y-m-d\TH:i:s\Z", strtotime($position->time))); + $xml->writeElement("time", gmdate("Y-m-d\TH:i:s\Z", $position->timestamp)); $xml->writeElement("name", ++$i); $xml->startElement("desc"); $description = - "{$lang["user"]}: {$position->userLogin} {$lang["track"]}: {$position->trackName} {$lang["time"]}: {$position->time}" . + "{$lang["user"]}: {$position->userLogin} {$lang["track"]}: {$position->trackName} {$lang["time"]}: " . date("Y-m-d H:i:s (e)", $position->timestamp) . (!is_null($position->speed) ? " {$lang["speed"]}: " . round($position->speed * 3.6 * $factor_kmh, 2) . " {$unit_kmh}" : "") . (!is_null($position->altitude) ? " {$lang["altitude"]}: " . round($position->altitude * $factor_m) . " {$unit_m}" : "") . " {$lang["ttime"]}: " . toHMS($totalSeconds) . diff --git a/utils/getpositions.php b/utils/getpositions.php index 90ed143..cb11dd0 100755 --- a/utils/getpositions.php +++ b/utils/getpositions.php @@ -56,7 +56,7 @@ if ($userId) { $xml->writeElement("altitude", ($position->altitude) ? round($position->altitude) : $position->altitude); $xml->writeElement("speed", $position->speed); $xml->writeElement("bearing", $position->bearing); - $xml->writeElement("dateoccured", $position->time); + $xml->writeElement("timestamp", $position->timestamp); $xml->writeElement("accuracy", $position->accuracy); $xml->writeElement("provider", $position->provider); $xml->writeElement("comments", $position->comment);