diff --git a/helpers/position.php b/helpers/position.php index 0af1b33..b9d7149 100644 --- a/helpers/position.php +++ b/helpers/position.php @@ -202,6 +202,57 @@ return $position; } + /** + * Get last position data from database + * (for all users) + * + * @return array|bool Array of uPosition positions, false on error + */ + public static function getLastAllUsers() { + $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 + FROM + " . self::db()->table('positions') . " p + LEFT JOIN " . self::db()->table('users') . " u + ON ( p.user_id = u.id ) + WHERE p.id = ( + SELECT + p2.id + FROM + " . self::db()->table('positions') . " p2 + WHERE + p2.user_id = p.user_id + ORDER BY + p2.time DESC, + p2.id DESC + LIMIT 1 + )"; + + $result = self::db()->query($query); + if ($result === false) { + return false; + } + $positionsArr = []; + while ($row = $result->fetch_assoc()) { + $positionsArr[] = self::rowToObject($row); + } + $result->close(); + return $positionsArr; + } + /** * Get array of all positions * @@ -329,4 +380,4 @@ } } -?> \ No newline at end of file +?> diff --git a/index.php b/index.php index dabfc2b..8f135ef 100755 --- a/index.php +++ b/index.php @@ -150,7 +150,7 @@
( s)
-
+
diff --git a/js/main.js b/js/main.js index d377fb0..aa996b1 100755 --- a/js/main.js +++ b/js/main.js @@ -134,6 +134,16 @@ function getXHR() { return xmlhttp; } +function reload(userid, trackid){ + var usersSelect = document.getElementsByName('user')[0]; + if (usersSelect[usersSelect.selectedIndex].text == lang['allusers']) { + loadLastPositionAllUsers(); + } + else{ + loadTrack(userid, trackid, 0); + } +} + function loadTrack(userid, trackid, update) { var title = document.getElementById('track').getElementsByClassName('menutitle')[0]; if (trackid < 0) { return; } @@ -154,11 +164,34 @@ function loadTrack(userid, trackid, update) { removeLoader(title); } } - xhr.open('GET', 'utils/getpositions.php?trackid=' + trackid + '&userid=' + userid, true); + xhr.open('GET', 'utils/getpositions.php?trackid=' + trackid + '&userid=' + userid + '&last=' + latest, true); xhr.send(); setLoader(title); } +function loadLastPositionAllUsers() { + if (latest == 1) { trackid = 0; } + var xhr = getXHR(); + xhr.onreadystatechange = function () { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + clearMap(); + var xml = xhr.responseXML; + var positions = xml.getElementsByTagName('position'); + var posLen = positions.length; + for (var i = 0; i < posLen; i++) { + var p = parsePosition(positions[i], i); + // set marker + setMarker(p, i, posLen); + } + } + xhr = null; + } + } + xhr.open('GET', 'utils/getpositions.php?trackid=' + trackid + '&userid=' + userid + '&last=' + latest, true); + xhr.send(); +} + function parsePosition(p, id) { // read data var latitude = parseFloat(getNode(p, 'latitude')); @@ -231,6 +264,15 @@ function getPopupHtml(p, i, count) { '' + lang['tdistance'] + ' ' + (p.totalMeters.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '
' + ''; } + if (p.username == null){ + p.username = lang["nousername"]; + } + if (p.trackname == null){ + p.trackname = lang["notrackname"]; + } + if (p.comments == null){ + p.comments = lang["nocomment"]; + } var popup = '