Added option to see all users on map
Added an option to see last position of each user at the same time.
This commit is contained in:
parent
33a9e30625
commit
25c1b24c49
@ -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
|
||||
*
|
||||
|
@ -150,7 +150,7 @@
|
||||
<input id="latest" type="checkbox" onchange="toggleLatest();"> <?= $lang["latest"] ?><br>
|
||||
<input type="checkbox" onchange="autoReload();"> <?= $lang["autoreload"] ?> (<a href="javascript:void(0);" onclick="setTime();"><span id="auto"><?= uConfig::$interval ?></span></a> s)<br>
|
||||
</form>
|
||||
<a href="javascript:void(0);" onclick="loadTrack(userid, trackid, 0);"> <?= $lang["reload"] ?></a><br>
|
||||
<a href="javascript:void(0);" onclick="reload(userid, trackid);"> <?= $lang["reload"] ?></a><br>
|
||||
</div>
|
||||
|
||||
<div id="summary"></div>
|
||||
|
75
js/main.js
75
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) {
|
||||
'<img class="icon" alt="' + lang['tdistance'] + '" title="' + lang['tdistance'] + '" src="images/distance_blue.svg"> ' +
|
||||
(p.totalMeters.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '<br>' + '</div>';
|
||||
}
|
||||
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 =
|
||||
'<div id="popup">' +
|
||||
'<div id="pheader">' +
|
||||
@ -367,13 +409,25 @@ Number.prototype.toKmH = function() {
|
||||
|
||||
// negate value
|
||||
function toggleLatest() {
|
||||
var usersSelect = document.getElementsByName('user')[0];
|
||||
if (latest == 0) {
|
||||
if (usersSelect.options[usersSelect.length-1].text != lang['allusers']){
|
||||
var option = document.createElement("option");
|
||||
option.text = lang['allusers'];
|
||||
if (usersSelect.length >= 2){
|
||||
usersSelect.add(option);
|
||||
}
|
||||
}
|
||||
latest = 1;
|
||||
loadTrack(userid, 0, 1);
|
||||
}
|
||||
else {
|
||||
if (usersSelect.options[usersSelect.length-1].text == lang['allusers']){
|
||||
usersSelect.remove(usersSelect.length-1);
|
||||
}
|
||||
latest = 0;
|
||||
loadTrack(userid, trackid, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,15 +442,26 @@ function selectTrack(f) {
|
||||
trackid = 0;
|
||||
}
|
||||
document.getElementById('latest').checked = false;
|
||||
var usersSelect = document.getElementsByName('user')[0];
|
||||
if (latest == 1) { toggleLatest(); }
|
||||
loadTrack(userid, trackid, 1);
|
||||
}
|
||||
|
||||
function selectUser(f) {
|
||||
userid = f.options[f.selectedIndex].value;
|
||||
|
||||
if (f.options[f.selectedIndex].text == lang['allusers']){
|
||||
var trackSelect = document.getElementsByName('track')[0];
|
||||
var length = trackSelect.options.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
trackSelect.options[i] = null;
|
||||
}
|
||||
loadLastPositionAllUsers();
|
||||
}
|
||||
else{
|
||||
document.getElementById('latest').checked = false;
|
||||
if (latest == 1) { toggleLatest(); }
|
||||
getTracks(userid);
|
||||
}
|
||||
}
|
||||
|
||||
function getTracks(userid, trackid) {
|
||||
@ -452,8 +517,14 @@ function clearOptions(el) {
|
||||
function autoReload() {
|
||||
if (live == 0) {
|
||||
live = 1;
|
||||
var usersSelect = document.getElementsByName('user')[0];
|
||||
if (usersSelect[usersSelect.selectedIndex].text == lang['allusers']) {
|
||||
auto = setInterval(function () { loadLastPositionAllUsers(); }, interval * 1000);
|
||||
}
|
||||
else{
|
||||
auto = setInterval(function () { loadTrack(userid, trackid, 0); }, interval * 1000);
|
||||
}
|
||||
}
|
||||
else {
|
||||
live = 0;
|
||||
clearInterval(auto);
|
||||
|
@ -121,4 +121,9 @@ $lang["iparsefailure"] = "Parsing failed";
|
||||
$lang["idatafailure"] = "No track data in imported file";
|
||||
$lang["isizefailure"] = "The uploaded file size should not exceed %d bytes"; // substitutes number of bytes
|
||||
$lang["imultiple"] = "Notice, multiple tracks imported (%d)"; // substitutes number of imported tracks
|
||||
$lang["allusers"] = "All Users";
|
||||
$lang["notrackname"] = "No Track";
|
||||
$lang["nousername"] = "No User";
|
||||
$lang["nocomment"] = "No Comment";
|
||||
|
||||
?>
|
||||
|
@ -25,6 +25,7 @@ $auth = new uAuth();
|
||||
|
||||
$userId = uUtils::getInt('userid');
|
||||
$trackId = uUtils::getInt('trackid');
|
||||
$last = uUtils::getInt('last');
|
||||
|
||||
$positionsArr = [];
|
||||
if ($userId) {
|
||||
@ -42,6 +43,11 @@ if ($userId) {
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if ($last) {
|
||||
$positionsArr = uPosition::getLastAllUsers();
|
||||
}
|
||||
}
|
||||
|
||||
header("Content-type: text/xml");
|
||||
$xml = new XMLWriter();
|
||||
|
Loading…
x
Reference in New Issue
Block a user