Update phpdoc, minor formatting
This commit is contained in:
parent
4c4ca498ca
commit
c46486396c
@ -16,10 +16,10 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("auth.php"); // sets $mysqli, $user
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Exit with xml response
|
||||
* @param boolean $isError Error if true
|
||||
* @param string $errorMessage Optional error message
|
||||
|
6
admin.js
6
admin.js
@ -40,12 +40,12 @@ function submitUser() {
|
||||
return;
|
||||
}
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState==4 && xhr.status==200) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
var message = "";
|
||||
if (xml) {
|
||||
var root = xml.getElementsByTagName('root');
|
||||
var root = xml.getElementsByTagName('root');
|
||||
if (root.length && getNode(root[0], 'error') == 0) {
|
||||
removeModal();
|
||||
alert("User successfully added");
|
||||
|
92
api_gmaps.js
92
api_gmaps.js
@ -24,6 +24,7 @@ var popups = new Array();
|
||||
var polyOptions;
|
||||
var mapOptions;
|
||||
var loadedAPI = 'gmaps';
|
||||
|
||||
function init() {
|
||||
google.maps.visualRefresh = true;
|
||||
polyOptions = {
|
||||
@ -32,7 +33,7 @@ function init() {
|
||||
strokeWeight: 2
|
||||
}
|
||||
mapOptions = {
|
||||
center: new google.maps.LatLng(init_latitude,init_longitude),
|
||||
center: new google.maps.LatLng(init_latitude, init_longitude),
|
||||
zoom: 8,
|
||||
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
||||
scaleControl: true
|
||||
@ -40,7 +41,7 @@ function init() {
|
||||
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
|
||||
}
|
||||
|
||||
function displayTrack(xml,update) {
|
||||
function displayTrack(xml, update) {
|
||||
altitudes.length = 0;
|
||||
var totalMeters = 0;
|
||||
var totalSeconds = 0;
|
||||
@ -48,18 +49,18 @@ function displayTrack(xml,update) {
|
||||
var poly = new google.maps.Polyline(polyOptions);
|
||||
poly.setMap(map);
|
||||
var path = poly.getPath();
|
||||
var latlngbounds = new google.maps.LatLngBounds( );
|
||||
var latlngbounds = new google.maps.LatLngBounds();
|
||||
var positions = xml.getElementsByTagName('position');
|
||||
var posLen = positions.length;
|
||||
for (var i=0; i<posLen; i++) {
|
||||
for (var i = 0; i < posLen; i++) {
|
||||
var p = parsePosition(positions[i]);
|
||||
totalMeters += p.distance;
|
||||
totalSeconds += p.seconds;
|
||||
p['totalMeters'] = totalMeters;
|
||||
p['totalSeconds'] = totalSeconds;
|
||||
p['coordinates'] = new google.maps.LatLng(p.latitude,p.longitude);
|
||||
p['coordinates'] = new google.maps.LatLng(p.latitude, p.longitude);
|
||||
// set marker
|
||||
setMarker(p,i,posLen);
|
||||
setMarker(p, i, posLen);
|
||||
// update polyline
|
||||
path.push(p.coordinates);
|
||||
latlngbounds.extend(p.coordinates);
|
||||
@ -68,26 +69,26 @@ function displayTrack(xml,update) {
|
||||
}
|
||||
if (update) {
|
||||
map.fitBounds(latlngbounds);
|
||||
if (i==1) {
|
||||
if (i == 1) {
|
||||
// only one point, zoom out
|
||||
zListener =
|
||||
google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) {
|
||||
if (this.getZoom()){
|
||||
this.setZoom(15);
|
||||
}
|
||||
});
|
||||
setTimeout(function(){google.maps.event.removeListener(zListener)}, 2000);
|
||||
google.maps.event.addListenerOnce(map, 'bounds_changed', function (event) {
|
||||
if (this.getZoom()) {
|
||||
this.setZoom(15);
|
||||
}
|
||||
});
|
||||
setTimeout(function () { google.maps.event.removeListener(zListener) }, 2000);
|
||||
}
|
||||
}
|
||||
latestTime = p.dateoccured;
|
||||
polies.push(poly);
|
||||
|
||||
updateSummary(p.dateoccured,totalMeters,totalSeconds);
|
||||
if (p.tid!=trackid) {
|
||||
trackid=p.tid;
|
||||
updateSummary(p.dateoccured, totalMeters, totalSeconds);
|
||||
if (p.tid != trackid) {
|
||||
trackid = p.tid;
|
||||
setTrack(trackid);
|
||||
}
|
||||
if (document.getElementById('bottom').style.display=='block') {
|
||||
if (document.getElementById('bottom').style.display == 'block') {
|
||||
// update altitudes chart
|
||||
chart.clearChart();
|
||||
displayChart();
|
||||
@ -95,13 +96,13 @@ function displayTrack(xml,update) {
|
||||
}
|
||||
|
||||
function clearMap() {
|
||||
if (polies){
|
||||
for (var i=0; i<polies.length; i++){
|
||||
if (polies) {
|
||||
for (var i = 0; i < polies.length; i++) {
|
||||
polies[i].setMap(null);
|
||||
}
|
||||
}
|
||||
if (markers){
|
||||
for (var i=0; i<markers.length; i++){
|
||||
if (markers) {
|
||||
for (var i = 0; i < markers.length; i++) {
|
||||
google.maps.event.removeListener(popups[i].listener);
|
||||
popups[i].setMap(null);
|
||||
markers[i].setMap(null);
|
||||
@ -113,59 +114,60 @@ function clearMap() {
|
||||
}
|
||||
|
||||
var popup;
|
||||
function setMarker(p,i,posLen) {
|
||||
function setMarker(p, i, posLen) {
|
||||
// marker
|
||||
var marker = new google.maps.Marker( {
|
||||
var marker = new google.maps.Marker({
|
||||
map: map,
|
||||
position: p.coordinates,
|
||||
title: p.dateoccured
|
||||
});
|
||||
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') }
|
||||
else if (i==posLen-1) { marker.setIcon('//maps.google.com/mapfiles/markerB.png') }
|
||||
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') }
|
||||
else if (i == posLen - 1) { marker.setIcon('//maps.google.com/mapfiles/markerB.png') }
|
||||
else { marker.setIcon('//maps.gstatic.com/mapfiles/ridefinder-images/mm_20_gray.png') }
|
||||
// popup
|
||||
var content = getPopupHtml(p,i,posLen);
|
||||
var content = getPopupHtml(p, i, posLen);
|
||||
popup = new google.maps.InfoWindow();
|
||||
popup.listener = google.maps.event.addListener(marker, 'click', (function(marker,content) {
|
||||
return function() {
|
||||
popup.listener = google.maps.event.addListener(marker, 'click', (function (marker, content) {
|
||||
return function () {
|
||||
popup.setContent(content);
|
||||
popup.open(map, marker);
|
||||
if (document.getElementById('bottom').style.display=='block') {
|
||||
chart.setSelection([{row:i,column:null}]);
|
||||
if (document.getElementById('bottom').style.display == 'block') {
|
||||
chart.setSelection([{ row: i, column: null }]);
|
||||
}
|
||||
}
|
||||
})(marker,content));
|
||||
})(marker, content));
|
||||
markers.push(marker);
|
||||
popups.push(popup);
|
||||
}
|
||||
|
||||
function addChartEvent(chart) {
|
||||
google.visualization.events.addListener(chart, 'select', function() {
|
||||
if (popup) {popup.close(); clearTimeout(altTimeout);}
|
||||
google.visualization.events.addListener(chart, 'select', function () {
|
||||
if (popup) { popup.close(); clearTimeout(altTimeout); }
|
||||
var selection = chart.getSelection()[0];
|
||||
if (selection) {
|
||||
var id = selection.row;
|
||||
var icon = markers[id].getIcon();
|
||||
markers[id].setIcon('//maps.google.com/mapfiles/marker_orange.png');
|
||||
altTimeout = setTimeout(function() { markers[id].setIcon(icon); },2000);
|
||||
altTimeout = setTimeout(function () { markers[id].setIcon(icon); }, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//((52.20105108685229, 20.789387865580238), (52.292069558807135, 21.172192736185707))
|
||||
function getBounds() {
|
||||
var b = map.getBounds().toString();
|
||||
var bounds = b.split(',',4);
|
||||
var lat_sw = bounds[0].replace(/\(/g,'');
|
||||
var lon_sw = bounds[1].replace(/[ )]/g,'');
|
||||
var lat_ne = bounds[2].replace(/[ (]/g,'');
|
||||
var lon_ne = bounds[3].replace(/[ )]/g,'');
|
||||
return [lon_sw,lat_sw,lon_ne,lat_ne];
|
||||
var b = map.getBounds().toString();
|
||||
var bounds = b.split(',', 4);
|
||||
var lat_sw = bounds[0].replace(/\(/g, '');
|
||||
var lon_sw = bounds[1].replace(/[ )]/g, '');
|
||||
var lat_ne = bounds[2].replace(/[ (]/g, '');
|
||||
var lon_ne = bounds[3].replace(/[ )]/g, '');
|
||||
return [lon_sw, lat_sw, lon_ne, lat_ne];
|
||||
}
|
||||
|
||||
function zoomToBounds(b) {
|
||||
var sw = new google.maps.LatLng(b[1],b[0]);
|
||||
var ne = new google.maps.LatLng(b[3],b[2]);
|
||||
var bounds = new google.maps.LatLngBounds(sw,ne);
|
||||
var sw = new google.maps.LatLng(b[1], b[0]);
|
||||
var ne = new google.maps.LatLng(b[3], b[2]);
|
||||
var bounds = new google.maps.LatLngBounds(sw, ne);
|
||||
map.fitBounds(bounds);
|
||||
}
|
||||
|
@ -20,70 +20,71 @@
|
||||
var map;
|
||||
var layerTrack;
|
||||
var layerMarkers;
|
||||
var lineStyle = {strokeColor: '#FF0000', strokeOpacity: 1, strokeWidth: 2};
|
||||
var lineStyle = { strokeColor: '#FF0000', strokeOpacity: 1, strokeWidth: 2 };
|
||||
var wgs84;
|
||||
var mercator;
|
||||
var loadedAPI = 'openlayers';
|
||||
function init() {
|
||||
wgs84 = new OpenLayers.Projection('EPSG:4326'); // from WGS 1984
|
||||
mercator = new OpenLayers.Projection('EPSG:900913'); // to Mercator
|
||||
var options = { controls: [
|
||||
new OpenLayers.Control.ArgParser(), // default
|
||||
new OpenLayers.Control.Attribution(), // default
|
||||
new OpenLayers.Control.LayerSwitcher(),
|
||||
new OpenLayers.Control.Navigation(), // default
|
||||
new OpenLayers.Control.PanZoomBar(),// do we need it?
|
||||
new OpenLayers.Control.ScaleLine()
|
||||
mercator = new OpenLayers.Projection('EPSG:900913'); // to Mercator
|
||||
var options = {
|
||||
controls: [
|
||||
new OpenLayers.Control.ArgParser(), // default
|
||||
new OpenLayers.Control.Attribution(), // default
|
||||
new OpenLayers.Control.LayerSwitcher(),
|
||||
new OpenLayers.Control.Navigation(), // default
|
||||
new OpenLayers.Control.PanZoomBar(),// do we need it?
|
||||
new OpenLayers.Control.ScaleLine()
|
||||
]
|
||||
};
|
||||
map = new OpenLayers.Map('map-canvas', options);
|
||||
// default layer: OpenStreetMap
|
||||
var mapnik = new OpenLayers.Layer.OSM('OpenStreetMap',
|
||||
['//a.tile.openstreetmap.org/${z}/${x}/${y}.png',
|
||||
'//b.tile.openstreetmap.org/${z}/${x}/${y}.png',
|
||||
'//c.tile.openstreetmap.org/${z}/${x}/${y}.png']);
|
||||
['//a.tile.openstreetmap.org/${z}/${x}/${y}.png',
|
||||
'//b.tile.openstreetmap.org/${z}/${x}/${y}.png',
|
||||
'//c.tile.openstreetmap.org/${z}/${x}/${y}.png']);
|
||||
map.addLayer(mapnik);
|
||||
if (layer_ocm==1) {
|
||||
if (layer_ocm == 1) {
|
||||
// OpenCycleMap
|
||||
var ocm = new OpenLayers.Layer.OSM('OpenCycleMap',
|
||||
['//a.tile.thunderforest.com/cycle/${z}/${x}/${y}.png',
|
||||
'//b.tile.thunderforest.com/cycle/${z}/${x}/${y}.png',
|
||||
'//c.tile.thunderforest.com/cycle/${z}/${x}/${y}.png']);
|
||||
'//b.tile.thunderforest.com/cycle/${z}/${x}/${y}.png',
|
||||
'//c.tile.thunderforest.com/cycle/${z}/${x}/${y}.png']);
|
||||
map.addLayer(ocm);
|
||||
}
|
||||
if (layer_mq==1) {
|
||||
if (layer_mq == 1) {
|
||||
// MapQuest-OSM
|
||||
var mq = new OpenLayers.Layer.OSM('MapQuest-OSM',
|
||||
['//otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg',
|
||||
'//otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg',
|
||||
'//otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg',
|
||||
'//otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg']);
|
||||
'//otile2.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg',
|
||||
'//otile3.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg',
|
||||
'//otile4.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg']);
|
||||
map.addLayer(mq);
|
||||
}
|
||||
if (layer_osmapa==1) {
|
||||
if (layer_osmapa == 1) {
|
||||
// osmapa.pl
|
||||
var osmapa = new OpenLayers.Layer.OSM('osmapa.pl',
|
||||
['//a.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png',
|
||||
'//b.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png',
|
||||
'//c.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png']);
|
||||
'//b.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png',
|
||||
'//c.osm.trail.pl/osmapa.pl/${z}/${x}/${y}.png']);
|
||||
map.addLayer(osmapa);
|
||||
}
|
||||
if (layer_ump==1) {
|
||||
if (layer_ump == 1) {
|
||||
// UMP
|
||||
var ump = new OpenLayers.Layer.OSM('UMP',
|
||||
['//1.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png',
|
||||
'//2.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png',
|
||||
'//3.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png']);
|
||||
'//2.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png',
|
||||
'//3.tiles.ump.waw.pl/ump_tiles/${z}/${x}/${y}.png']);
|
||||
map.addLayer(ump);
|
||||
}
|
||||
var position = new OpenLayers.LonLat(init_longitude,init_latitude).transform(wgs84, mercator);
|
||||
var position = new OpenLayers.LonLat(init_longitude, init_latitude).transform(wgs84, mercator);
|
||||
var zoom = 8;
|
||||
map.setCenter(position, zoom);
|
||||
// init layers
|
||||
layerTrack = new OpenLayers.Layer.Vector('Track');
|
||||
layerMarkers = new OpenLayers.Layer.Markers('Markers');
|
||||
}
|
||||
function displayTrack(xml,update) {
|
||||
function displayTrack(xml, update) {
|
||||
altitudes.length = 0;
|
||||
var totalMeters = 0;
|
||||
var totalSeconds = 0;
|
||||
@ -91,16 +92,16 @@ function displayTrack(xml,update) {
|
||||
var latlngbounds = new OpenLayers.Bounds();
|
||||
var positions = xml.getElementsByTagName('position');
|
||||
var posLen = positions.length;
|
||||
for (var i=0; i<posLen; i++) {
|
||||
for (var i = 0; i < posLen; i++) {
|
||||
var p = parsePosition(positions[i]);
|
||||
totalMeters += p.distance;
|
||||
totalSeconds += p.seconds;
|
||||
p['totalMeters'] = totalMeters;
|
||||
p['totalSeconds'] = totalSeconds;
|
||||
// set marker
|
||||
setMarker(p,i,posLen);
|
||||
setMarker(p, i, posLen);
|
||||
// update polyline
|
||||
var point = new OpenLayers.Geometry.Point(p.longitude, p.latitude).transform(wgs84,mercator);
|
||||
var point = new OpenLayers.Geometry.Point(p.longitude, p.latitude).transform(wgs84, mercator);
|
||||
latlngbounds.extend(point);
|
||||
points.push(point);
|
||||
// save altitudes for chart
|
||||
@ -113,7 +114,7 @@ function displayTrack(xml,update) {
|
||||
map.addLayer(layerMarkers);
|
||||
if (update) {
|
||||
map.zoomToExtent(latlngbounds);
|
||||
if (i==1) {
|
||||
if (i == 1) {
|
||||
// only one point, zoom out
|
||||
map.zoomOut();
|
||||
}
|
||||
@ -121,12 +122,12 @@ function displayTrack(xml,update) {
|
||||
latestTime = p.dateoccured;
|
||||
//polies.push(poly);
|
||||
|
||||
updateSummary(p.dateoccured,totalMeters,totalSeconds);
|
||||
if (p.tid!=trackid) {
|
||||
trackid=p.tid;
|
||||
updateSummary(p.dateoccured, totalMeters, totalSeconds);
|
||||
if (p.tid != trackid) {
|
||||
trackid = p.tid;
|
||||
setTrack(trackid);
|
||||
}
|
||||
if (document.getElementById('bottom').style.display=='block') {
|
||||
if (document.getElementById('bottom').style.display == 'block') {
|
||||
// update altitudes chart
|
||||
chart.clearChart();
|
||||
displayChart();
|
||||
@ -134,74 +135,74 @@ function displayTrack(xml,update) {
|
||||
}
|
||||
|
||||
function clearMap() {
|
||||
if (layerTrack){
|
||||
if (layerTrack) {
|
||||
layerTrack.removeAllFeatures();
|
||||
}
|
||||
if (layerMarkers){
|
||||
if (layerMarkers) {
|
||||
layerMarkers.clearMarkers();
|
||||
}
|
||||
}
|
||||
|
||||
function setMarker(p,i,posLen) {
|
||||
function setMarker(p, i, posLen) {
|
||||
// marker
|
||||
var lonLat = new OpenLayers.LonLat(p.longitude,p.latitude).transform(wgs84,mercator);
|
||||
var lonLat = new OpenLayers.LonLat(p.longitude, p.latitude).transform(wgs84, mercator);
|
||||
var size = new OpenLayers.Size(21, 25);
|
||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
if (latest==1) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker.png',size,offset); }
|
||||
else if (i==0) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker-green.png',size,offset); }
|
||||
else if (i==posLen-1) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker.png',size,offset); }
|
||||
var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
|
||||
if (latest == 1) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker.png', size, offset); }
|
||||
else if (i == 0) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker-green.png', size, offset); }
|
||||
else if (i == posLen - 1) { var icon = new OpenLayers.Icon('//www.openstreetmap.org/openlayers/img/marker.png', size, offset); }
|
||||
else {
|
||||
size = new OpenLayers.Size(12, 20);
|
||||
offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
var icon = new OpenLayers.Icon('//maps.gstatic.com/mapfiles/ridefinder-images/mm_20_gray.png',size,offset);
|
||||
offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
|
||||
var icon = new OpenLayers.Icon('//maps.gstatic.com/mapfiles/ridefinder-images/mm_20_gray.png', size, offset);
|
||||
}
|
||||
var marker = new OpenLayers.Marker(lonLat,icon);
|
||||
var marker = new OpenLayers.Marker(lonLat, icon);
|
||||
layerMarkers.addMarker(marker);
|
||||
|
||||
// popup
|
||||
var content = getPopupHtml(p,i,posLen);
|
||||
marker.events.register("mousedown", marker, (function() {
|
||||
return function() {
|
||||
// remove popups
|
||||
if (map.popups.length>0) {
|
||||
for (var j = map.popups.length-1; j>=0; j-- ) {
|
||||
map.removePopup(map.popups[j])
|
||||
};
|
||||
var content = getPopupHtml(p, i, posLen);
|
||||
marker.events.register("mousedown", marker, (function () {
|
||||
return function () {
|
||||
// remove popups
|
||||
if (map.popups.length > 0) {
|
||||
for (var j = map.popups.length - 1; j >= 0; j--) {
|
||||
map.removePopup(map.popups[j])
|
||||
};
|
||||
}
|
||||
// show popup
|
||||
var popup = new OpenLayers.Popup.FramedCloud("popup_" + (i + 1), lonLat, null, content, icon, true);
|
||||
map.addPopup(popup);
|
||||
if (document.getElementById('bottom').style.display == 'block') {
|
||||
chart.setSelection([{ row: i, column: null }]);
|
||||
}
|
||||
}
|
||||
// show popup
|
||||
var popup = new OpenLayers.Popup.FramedCloud("popup_"+(i+1),lonLat,null,content,icon,true);
|
||||
map.addPopup(popup);
|
||||
if (document.getElementById('bottom').style.display=='block') {
|
||||
chart.setSelection([{row:i,column:null}]);
|
||||
}
|
||||
}
|
||||
})());
|
||||
}
|
||||
|
||||
function addChartEvent(chart) {
|
||||
google.visualization.events.addListener(chart, 'select', function() {
|
||||
google.visualization.events.addListener(chart, 'select', function () {
|
||||
var selection = chart.getSelection()[0];
|
||||
if (selection) {
|
||||
var id = selection.row;
|
||||
var marker = layerMarkers.markers[id];
|
||||
var url = marker.icon.url;
|
||||
marker.setUrl('//www.openstreetmap.org/openlayers/img/marker-gold.png');
|
||||
altTimeout = setTimeout(function() { marker.setUrl(url); },2000);
|
||||
altTimeout = setTimeout(function () { marker.setUrl(url); }, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
//20.597985430276808,52.15547181298076,21.363595171488573,52.33750879522563
|
||||
function getBounds() {
|
||||
var b = map.getExtent().transform(mercator,wgs84).toString();
|
||||
var bounds = b.split(',',4);
|
||||
var b = map.getExtent().transform(mercator, wgs84).toString();
|
||||
var bounds = b.split(',', 4);
|
||||
var lon_sw = bounds[0];
|
||||
var lat_sw = bounds[1];
|
||||
var lon_ne = bounds[2];
|
||||
var lat_ne = bounds[3];
|
||||
return [lon_sw,lat_sw,lon_ne,lat_ne];
|
||||
return [lon_sw, lat_sw, lon_ne, lat_ne];
|
||||
}
|
||||
|
||||
function zoomToBounds(b) {
|
||||
var bounds = new OpenLayers.Bounds(b).transform(wgs84,mercator);
|
||||
var bounds = new OpenLayers.Bounds(b).transform(wgs84, mercator);
|
||||
map.zoomToExtent(bounds);
|
||||
}
|
||||
|
4
auth.php
4
auth.php
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("helpers/config.php");
|
||||
$config = new uConfig();
|
||||
|
||||
@ -46,7 +46,7 @@ if (!$user->isValid && ($config::$require_authentication || defined('headless'))
|
||||
|
||||
if (!$login){
|
||||
// not authenticated and username not submited
|
||||
// load form
|
||||
// load form
|
||||
if (defined('headless')) {
|
||||
header('HTTP/1.1 401 Unauthorized', true, 401);
|
||||
} else {
|
||||
|
@ -16,13 +16,19 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("auth.php"); // sets $mysqli, $user
|
||||
|
||||
|
||||
/**
|
||||
* Exit with error message
|
||||
*
|
||||
* @param string $errorMessage Message
|
||||
*/
|
||||
function exitWithError($errorMessage) {
|
||||
return exitWithStatus(true, $errorMessage);
|
||||
}
|
||||
/**
|
||||
|
||||
/**
|
||||
* Exit with xml response
|
||||
* @param boolean $isError Error if true
|
||||
* @param string $errorMessage Optional error message
|
||||
@ -67,7 +73,7 @@
|
||||
if ($passUser->setPass($hash) === false) {
|
||||
exitWithError("Server error");
|
||||
}
|
||||
|
||||
|
||||
exitWithStatus();
|
||||
|
||||
|
||||
?>
|
@ -17,12 +17,18 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set response error status and message
|
||||
*
|
||||
* @param array $response Respons
|
||||
* @param string $message Message
|
||||
*/
|
||||
function setError(&$response, $message) {
|
||||
$response['error'] = true;
|
||||
$response['error'] = true;
|
||||
$response['message'] = $message;
|
||||
}
|
||||
|
||||
define("headless", true);
|
||||
define("headless", true);
|
||||
require_once("../auth.php"); // sets $mysqli, $user
|
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
|
||||
@ -92,7 +98,7 @@ switch ($action) {
|
||||
$position = new uPosition();
|
||||
$positionId = $position->add($user->id, $trackId,
|
||||
$time, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId);
|
||||
|
||||
|
||||
if ($positionId === false) {
|
||||
setError($response, "Server error");
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// This is default configuration file.
|
||||
// This is default configuration file.
|
||||
// Copy it to config.php and customize
|
||||
|
||||
// default map drawing framework
|
||||
|
15
download.php
15
download.php
@ -16,10 +16,17 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("auth.php"); // sets $mysqli, $user
|
||||
require_once("helpers/position.php");
|
||||
|
||||
/**
|
||||
* Add kml marker style element
|
||||
*
|
||||
* @param XMLWriter $xml Writer object
|
||||
* @param string $name Color name
|
||||
* @param string $url Url
|
||||
*/
|
||||
function addStyle($xml, $name, $url) {
|
||||
$xml->startElement("Style");
|
||||
$xml->writeAttribute("id", $name."Style");
|
||||
@ -32,6 +39,12 @@ function addStyle($xml, $name, $url) {
|
||||
$xml->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert seconds to [day], hour, minute, second string
|
||||
*
|
||||
* @param [type] $s Number of seconds
|
||||
* @return string [d ]hhmmss
|
||||
*/
|
||||
function toHMS($s) {
|
||||
$d = floor($s / 86400);
|
||||
$h = floor(($s % 86400) / 3600);
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("auth.php"); // sets $mysqli, $user
|
||||
require_once("helpers/position.php");
|
||||
|
||||
@ -34,7 +34,7 @@ if ($userId) {
|
||||
$position->getLast($userId);
|
||||
$positionsArr[] = $position;
|
||||
}
|
||||
|
||||
|
||||
header("Content-type: text/xml");
|
||||
$xml = new XMLWriter();
|
||||
$xml->openURI("php://output");
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("auth.php"); // sets $mysqli, $user
|
||||
require_once("helpers/track.php");
|
||||
|
||||
|
@ -17,7 +17,10 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class uConfig {
|
||||
/**
|
||||
* Handles config values
|
||||
*/
|
||||
class uConfig {
|
||||
// version number
|
||||
static $version = "0.2-beta";
|
||||
|
||||
@ -77,50 +80,60 @@ class uConfig {
|
||||
private static $fileLoaded = false;
|
||||
public static $rootDir;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
self::$rootDir = dirname(__DIR__);
|
||||
$this->setFromFile();
|
||||
$this->setFromCookies();
|
||||
}
|
||||
self::$rootDir = dirname(__DIR__);
|
||||
$this->setFromFile();
|
||||
$this->setFromCookies();
|
||||
}
|
||||
|
||||
private function setFromFile() {
|
||||
$configFile = self::$rootDir . "/config.php";
|
||||
if (self::$fileLoaded || !file_exists($configFile)) {
|
||||
return;
|
||||
}
|
||||
self::$fileLoaded = true;
|
||||
include_once($configFile);
|
||||
/**
|
||||
* Read config values from "/config.php" file
|
||||
*/
|
||||
private function setFromFile() {
|
||||
$configFile = self::$rootDir . "/config.php";
|
||||
if (self::$fileLoaded || !file_exists($configFile)) {
|
||||
return;
|
||||
}
|
||||
self::$fileLoaded = true;
|
||||
include_once($configFile);
|
||||
|
||||
if (isset($mapapi)) { self::$mapapi = $mapapi; }
|
||||
if (isset($gkey)) { self::$gkey = $gkey; }
|
||||
if (isset($layer_ocm)) { self::$layer_ocm = $layer_ocm; }
|
||||
if (isset($layer_mq)) { self::$layer_mq = $layer_mq; }
|
||||
if (isset($layer_osmapa)) { self::$layer_osmapa = $layer_osmapa; }
|
||||
if (isset($layer_ump)) { self::$layer_ump = $layer_ump; }
|
||||
if (isset($init_latitude)) { self::$init_latitude = $init_latitude; }
|
||||
if (isset($init_longitude)) { self::$init_longitude = $init_longitude; }
|
||||
if (isset($dbhost)) { self::$dbhost = $dbhost; }
|
||||
if (isset($dbuser)) { self::$dbuser = $dbuser; }
|
||||
if (isset($dbpass)) { self::$dbpass = $dbpass; }
|
||||
if (isset($dbname)) { self::$dbname = $dbname; }
|
||||
if (isset($require_authentication)) { self::$require_authentication = (bool) $require_authentication; }
|
||||
if (isset($public_tracks)) { self::$public_tracks = (bool) $public_tracks; }
|
||||
if (isset($admin_user)) { self::$admin_user = $admin_user; }
|
||||
if (isset($interval)) { self::$interval = $interval; }
|
||||
if (isset($lang)) { self::$lang = $lang; }
|
||||
if (isset($units)) { self::$units = $units; }
|
||||
if (isset($mapapi)) { self::$mapapi = $mapapi; }
|
||||
if (isset($gkey)) { self::$gkey = $gkey; }
|
||||
if (isset($layer_ocm)) { self::$layer_ocm = $layer_ocm; }
|
||||
if (isset($layer_mq)) { self::$layer_mq = $layer_mq; }
|
||||
if (isset($layer_osmapa)) { self::$layer_osmapa = $layer_osmapa; }
|
||||
if (isset($layer_ump)) { self::$layer_ump = $layer_ump; }
|
||||
if (isset($init_latitude)) { self::$init_latitude = $init_latitude; }
|
||||
if (isset($init_longitude)) { self::$init_longitude = $init_longitude; }
|
||||
if (isset($dbhost)) { self::$dbhost = $dbhost; }
|
||||
if (isset($dbuser)) { self::$dbuser = $dbuser; }
|
||||
if (isset($dbpass)) { self::$dbpass = $dbpass; }
|
||||
if (isset($dbname)) { self::$dbname = $dbname; }
|
||||
if (isset($require_authentication)) { self::$require_authentication = (bool) $require_authentication; }
|
||||
if (isset($public_tracks)) { self::$public_tracks = (bool) $public_tracks; }
|
||||
if (isset($admin_user)) { self::$admin_user = $admin_user; }
|
||||
if (isset($interval)) { self::$interval = $interval; }
|
||||
if (isset($lang)) { self::$lang = $lang; }
|
||||
if (isset($units)) { self::$units = $units; }
|
||||
|
||||
if (!self::$require_authentication) {
|
||||
// tracks must be public if we don't require authentication
|
||||
self::$public_tracks = true;
|
||||
}
|
||||
}
|
||||
private function setFromCookies() {
|
||||
if (isset($_COOKIE["ulogger_api"])) { self::$mapapi = $_COOKIE["ulogger_api"]; }
|
||||
if (isset($_COOKIE["ulogger_lang"])) { self::$lang = $_COOKIE["ulogger_lang"]; }
|
||||
if (isset($_COOKIE["ulogger_units"])) { self::$units = $_COOKIE["ulogger_units"]; }
|
||||
if (isset($_COOKIE["ulogger_interval"])) { self::$interval = $_COOKIE["ulogger_interval"]; }
|
||||
}
|
||||
}
|
||||
if (!self::$require_authentication) {
|
||||
// tracks must be public if we don't require authentication
|
||||
self::$public_tracks = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read config values stored in cookies
|
||||
*/
|
||||
private function setFromCookies() {
|
||||
if (isset($_COOKIE["ulogger_api"])) { self::$mapapi = $_COOKIE["ulogger_api"]; }
|
||||
if (isset($_COOKIE["ulogger_lang"])) { self::$lang = $_COOKIE["ulogger_lang"]; }
|
||||
if (isset($_COOKIE["ulogger_units"])) { self::$units = $_COOKIE["ulogger_units"]; }
|
||||
if (isset($_COOKIE["ulogger_interval"])) { self::$interval = $_COOKIE["ulogger_interval"]; }
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -17,31 +17,48 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
require_once (__DIR__ . "/config.php");
|
||||
class uDb extends mysqli {
|
||||
// singleton instance
|
||||
protected static $instance;
|
||||
require_once (__DIR__ . "/config.php");
|
||||
|
||||
// private constuctor
|
||||
private function __construct($host, $user, $pass, $name) {
|
||||
parent::__construct($host, $user, $pass, $name);
|
||||
if ($this->connect_error) {
|
||||
if (defined('headless')) {
|
||||
header("HTTP/1.1 503 Service Unavailable");
|
||||
exit;
|
||||
/**
|
||||
* mysqli wrapper
|
||||
*/
|
||||
class uDb extends mysqli {
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
* @var mysqli Object instance
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* Private constuctor
|
||||
*
|
||||
* @param string $host
|
||||
* @param string $user
|
||||
* @param string $pass
|
||||
* @param string $name
|
||||
*/
|
||||
private function __construct($host, $user, $pass, $name) {
|
||||
parent::__construct($host, $user, $pass, $name);
|
||||
if ($this->connect_error) {
|
||||
if (defined('headless')) {
|
||||
header("HTTP/1.1 503 Service Unavailable");
|
||||
exit;
|
||||
}
|
||||
die("Database connection error (" . $this->connect_errno . ")");
|
||||
}
|
||||
die("Database connection error (" . $this->connect_errno . ")");
|
||||
$this->set_charset('utf8');
|
||||
}
|
||||
$this->set_charset('utf8');
|
||||
}
|
||||
|
||||
// returns singleton instance
|
||||
public static function getInstance() {
|
||||
if (!self::$instance) {
|
||||
$config = new uConfig();
|
||||
self::$instance = new self($config::$dbhost, $config::$dbuser, $config::$dbpass, $config::$dbname);
|
||||
/**
|
||||
* Returns singleton instance
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (!self::$instance) {
|
||||
$config = new uConfig();
|
||||
self::$instance = new self($config::$dbhost, $config::$dbuser, $config::$dbpass, $config::$dbname);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
||||
?>
|
@ -17,9 +17,12 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . "/db.php");
|
||||
require_once(__DIR__ . "/db.php");
|
||||
|
||||
class uPosition {
|
||||
/**
|
||||
* Positions handling
|
||||
*/
|
||||
class uPosition {
|
||||
public $id;
|
||||
public $time;
|
||||
public $userId;
|
||||
@ -40,23 +43,44 @@ class uPosition {
|
||||
|
||||
private static $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param integer $positionId Position id
|
||||
*/
|
||||
public function __construct($positionId = NULL) {
|
||||
|
||||
self::$db = uDB::getInstance();
|
||||
|
||||
if (!empty($positionId)) {
|
||||
$query = "SELECT p.id, p.time, 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 positions p
|
||||
LEFT JOIN users u ON (p.user_id = u.id)
|
||||
LEFT JOIN tracks t ON (p.track_id = t.id)
|
||||
$query = "SELECT p.id, p.time, 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 positions p
|
||||
LEFT JOIN users u ON (p.user_id = u.id)
|
||||
LEFT JOIN tracks t ON (p.track_id = t.id)
|
||||
WHERE id = ? LIMIT 1";
|
||||
$params = [ 'i', $positionId ];
|
||||
$this->loadWithQuery($query, $params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add position
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $trackId
|
||||
* @param int $time Unix time stamp
|
||||
* @param double $lat
|
||||
* @param double $lon
|
||||
* @param double $altitude
|
||||
* @param double $speed
|
||||
* @param double $bearing
|
||||
* @param int $accuracy
|
||||
* @param string $provider
|
||||
* @param string $comment
|
||||
* @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) {
|
||||
$positionId = false;
|
||||
if (!is_null($lat) && !is_null($lon) && !is_null($time) && !empty($userId) && !empty($trackId)) {
|
||||
@ -77,6 +101,12 @@ class uPosition {
|
||||
return $positionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill class properties with last position data from database
|
||||
* (for given user if specified)
|
||||
*
|
||||
* @param int $userId Optional user id
|
||||
*/
|
||||
public function getLast($userId = NULL) {
|
||||
if (!empty($userId)) {
|
||||
$where = "WHERE p.user_id = ?";
|
||||
@ -85,17 +115,24 @@ class uPosition {
|
||||
$where = "";
|
||||
$params = NULL;
|
||||
}
|
||||
$query = "SELECT p.id, p.time, 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 positions p
|
||||
LEFT JOIN users u ON (p.user_id = u.id)
|
||||
LEFT JOIN tracks t ON (p.track_id = t.id)
|
||||
$query = "SELECT p.id, p.time, 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 positions p
|
||||
LEFT JOIN users u ON (p.user_id = u.id)
|
||||
LEFT JOIN tracks t ON (p.track_id = t.id)
|
||||
$where
|
||||
ORDER BY p.time DESC LIMIT 1";
|
||||
$this->loadWithQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get array of all positions
|
||||
*
|
||||
* @param int $userId Optional limit to given user id
|
||||
* @param int $trackId Optional limit to given track id
|
||||
* @return array|bool Array of uPosition positions, false on error
|
||||
*/
|
||||
public function getAll($userId = NULL, $trackId = NULL) {
|
||||
$rules = [];
|
||||
if (!empty($userId)) {
|
||||
@ -103,19 +140,19 @@ class uPosition {
|
||||
}
|
||||
if (!empty($trackId)) {
|
||||
$rules[] = "p.track_id = '" . self::$db->real_escape_string($trackId) ."'";
|
||||
}
|
||||
}
|
||||
if (!empty($rules)) {
|
||||
$where = "WHERE " . implode(" AND ", $rules);
|
||||
} else {
|
||||
} else {
|
||||
$where = "";
|
||||
}
|
||||
$query = "SELECT p.id, p.time, 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 positions p
|
||||
LEFT JOIN users u ON (p.user_id = u.id)
|
||||
LEFT JOIN tracks t ON (p.track_id = t.id)
|
||||
$where
|
||||
$query = "SELECT p.id, p.time, 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 positions p
|
||||
LEFT JOIN users u ON (p.user_id = u.id)
|
||||
LEFT JOIN tracks t ON (p.track_id = t.id)
|
||||
$where
|
||||
ORDER BY p.time";
|
||||
$result = self::$db->query($query);
|
||||
if ($result === false) {
|
||||
@ -129,7 +166,12 @@ class uPosition {
|
||||
return $positionsArr;
|
||||
}
|
||||
|
||||
// haversine distance to target point
|
||||
/**
|
||||
* Calculate distance to target point using haversine formula
|
||||
*
|
||||
* @param uPosition $target Target position
|
||||
* @return int Distance in meters
|
||||
*/
|
||||
public function distanceTo($target) {
|
||||
$lat1 = deg2rad($this->latitude);
|
||||
$lon1 = deg2rad($this->longitude);
|
||||
@ -141,10 +183,22 @@ class uPosition {
|
||||
return $bearing * 6371000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate time elapsed since target point
|
||||
*
|
||||
* @param uPosition $target Target position
|
||||
* @return int Number of seconds
|
||||
*/
|
||||
public function secondsTo($target) {
|
||||
return strtotime($this->time) - strtotime($target->time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert database row to uPosition
|
||||
*
|
||||
* @param array $row Row
|
||||
* @return uPosition Position
|
||||
*/
|
||||
private function rowToObject($row) {
|
||||
$position = new uPosition();
|
||||
$position->id = $row['id'];
|
||||
@ -166,25 +220,31 @@ class uPosition {
|
||||
return $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill class properties with database query result
|
||||
*
|
||||
* @param string $query Query
|
||||
* @param array|null $bindParams Optional array of bind parameters (types, params)
|
||||
*/
|
||||
private function loadWithQuery($query, $bindParams = NULL) {
|
||||
$stmt = self::$db->prepare($query);
|
||||
if (is_array($bindParams) && ($types = array_shift($bindParams))) {
|
||||
call_user_func_array(
|
||||
[ $stmt, 'bind_param' ],
|
||||
array_merge([ $types ], array_map(function(&$param) { return $param; }, $bindParams))
|
||||
);
|
||||
$stmt = self::$db->prepare($query);
|
||||
if (is_array($bindParams) && ($types = array_shift($bindParams))) {
|
||||
call_user_func_array(
|
||||
[ $stmt, 'bind_param' ],
|
||||
array_merge([ $types ], array_map(function(&$param) { return $param; }, $bindParams))
|
||||
);
|
||||
}
|
||||
if ($stmt->execute()) {
|
||||
$stmt->bind_result($this->id, $this->time, $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);
|
||||
if ($stmt->fetch()) {
|
||||
$this->isValid = true;
|
||||
}
|
||||
if ($stmt->execute()) {
|
||||
$stmt->bind_result($this->id, $this->time, $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);
|
||||
if ($stmt->fetch()) {
|
||||
$this->isValid = true;
|
||||
}
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -17,9 +17,12 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . "/db.php");
|
||||
require_once(__DIR__ . "/db.php");
|
||||
|
||||
class uTrack {
|
||||
/**
|
||||
* Track handling
|
||||
*/
|
||||
class uTrack {
|
||||
public $id;
|
||||
public $userId;
|
||||
public $name;
|
||||
@ -29,6 +32,11 @@ class uTrack {
|
||||
|
||||
private static $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $trackId Track id
|
||||
*/
|
||||
public function __construct($trackId = NULL) {
|
||||
|
||||
self::$db = uDB::getInstance();
|
||||
@ -46,6 +54,14 @@ class uTrack {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new track
|
||||
*
|
||||
* @param string $userId User id
|
||||
* @param string $name Name
|
||||
* @param string $comment Optional comment
|
||||
* @return int|bool New track id, false on error
|
||||
*/
|
||||
public function add($userId, $name, $comment = NULL) {
|
||||
$trackId = false;
|
||||
if (!empty($userId) && !empty($name)) {
|
||||
@ -61,6 +77,12 @@ class uTrack {
|
||||
return $trackId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all tracks
|
||||
*
|
||||
* @param int $userId Optional limit to user id
|
||||
* @return array|bool Array of uTrack tracks, false on error
|
||||
*/
|
||||
public function getAll($userId = NULL) {
|
||||
if (!empty($userId)) {
|
||||
$where = "WHERE user_id='" . self::$db->real_escape_string($userId) ."'";
|
||||
@ -80,6 +102,12 @@ class uTrack {
|
||||
return $trackArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert database row to uTrack
|
||||
*
|
||||
* @param array $row Row
|
||||
* @return uTrack Track
|
||||
*/
|
||||
private function rowToObject($row) {
|
||||
$track = new uTrack();
|
||||
$track->id = $row['id'];
|
||||
@ -89,6 +117,6 @@ class uTrack {
|
||||
$track->isValid = true;
|
||||
return $track;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -16,11 +16,13 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
require_once (__DIR__ . "/config.php");
|
||||
require_once (__DIR__ . "/db.php");
|
||||
|
||||
require_once(__DIR__ . "/config.php");
|
||||
require_once(__DIR__ . "/db.php");
|
||||
|
||||
class uUser {
|
||||
/**
|
||||
* User handling routines
|
||||
*/
|
||||
class uUser {
|
||||
public $id;
|
||||
public $login;
|
||||
public $hash;
|
||||
@ -29,6 +31,11 @@ class uUser {
|
||||
|
||||
private static $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $login Login
|
||||
*/
|
||||
public function __construct($login = NULL) {
|
||||
self::$db = uDB::getInstance();
|
||||
if (!empty($login)) {
|
||||
@ -44,6 +51,13 @@ class uUser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new user
|
||||
*
|
||||
* @param string $login Login
|
||||
* @param string $hash Password hash
|
||||
* @return int|bool New user id, false on error
|
||||
*/
|
||||
public function add($login, $hash) {
|
||||
$userid = false;
|
||||
if (!empty($login) && !empty($hash)) {
|
||||
@ -59,6 +73,12 @@ class uUser {
|
||||
return $userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set user password
|
||||
*
|
||||
* @param string $hash Hash
|
||||
* @return bool True on success, false otherwise
|
||||
*/
|
||||
public function setPass($hash) {
|
||||
$ret = false;
|
||||
$sql = "UPDATE users SET password = ? WHERE login = ?";
|
||||
@ -72,14 +92,26 @@ class uUser {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given password matches user's one
|
||||
*
|
||||
* @param String $password Password
|
||||
* @return bool True if matches, false otherwise
|
||||
*/
|
||||
public function validPassword($password) {
|
||||
return password_verify($password, $this->hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store uUser object in session
|
||||
*/
|
||||
public function storeInSession() {
|
||||
$_SESSION['user'] = $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill uUser object properties from session data
|
||||
*/
|
||||
public function getFromSession() {
|
||||
if (isset($_SESSION['user'])) {
|
||||
$sessionUser = $_SESSION['user'];
|
||||
@ -91,6 +123,11 @@ class uUser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users
|
||||
*
|
||||
* @return array|bool Array of uUser users, false on error
|
||||
*/
|
||||
public function getAll() {
|
||||
$query = "SELECT id, login, password FROM users ORDER BY login";
|
||||
$result = self::$db->query($query);
|
||||
@ -105,6 +142,12 @@ class uUser {
|
||||
return $userArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert database row to uUser
|
||||
*
|
||||
* @param array $row Row
|
||||
* @return uUser User
|
||||
*/
|
||||
private function rowToObject($row) {
|
||||
$user = new uUser();
|
||||
$user->id = $row['id'];
|
||||
@ -115,10 +158,15 @@ class uUser {
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is given login admin user
|
||||
*
|
||||
* @param string $login Login
|
||||
* @return bool True if admin, false otherwise
|
||||
*/
|
||||
private function isAdmin($login) {
|
||||
$config = new uConfig();
|
||||
return (!empty($config::$admin_user) && $config::$admin_user == $login);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
||||
?>
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
require_once("auth.php");
|
||||
require_once("helpers/position.php");
|
||||
require_once("helpers/track.php");
|
||||
@ -52,7 +52,7 @@ if ($user->isAdmin || $config::$public_tracks) {
|
||||
if ($lastPosition->isValid) {
|
||||
$lastUserId = $lastPosition->userId;
|
||||
}
|
||||
|
||||
|
||||
$usersArr = $user->getAll();
|
||||
if (!empty($usersArr)) {
|
||||
foreach ($usersArr as $aUser) {
|
||||
|
4
lang.php
4
lang.php
@ -16,9 +16,9 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
// available languages
|
||||
$langsArr = [
|
||||
$langsArr = [
|
||||
"en" => "English",
|
||||
"pl" => "Polski",
|
||||
"de" => "Deutsch",
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
$lang["title"] = "• μlogger •";
|
||||
$lang["private"] = "Sie müssen Benutzernamen und Kennwort eingeben, um auf diese Seite zuzugreifen.";
|
||||
$lang["authfail"] = "Falscher Benutzername oder Passwort";
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
// default language for translations
|
||||
|
||||
$lang["title"] = "• μlogger •";
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
$lang["title"] = "• μlogger •";
|
||||
$lang["private"] = "Necesitas un nombre de usuario y contraseña para acceder a esta página.";
|
||||
$lang["authfail"] = "Nombre de usuasrio o contraseña erroneos";
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
$lang["title"] = "• μlogger •";
|
||||
$lang["private"] = "Il faut un nom d'utilisateur et un mot de passe pour accéder à cette page.";
|
||||
$lang["authfail"] = "Nom d'utilisateur ou mot de passe erroné.";
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
$lang["title"] = "• μlogger •";
|
||||
$lang["private"] = "Felhasználónév és jelszó szükséges a belépéshez";
|
||||
$lang["authfail"] = "Hibás név vagy jelszó";
|
||||
|
@ -16,7 +16,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
$lang["title"] = "• μlogger •";
|
||||
$lang["private"] = "Aby się zalogować musisz podać login i hasło";
|
||||
|
@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
session_name('ulogger');
|
||||
session_start();
|
||||
$_SESSION = NULL;
|
||||
@ -27,4 +27,5 @@ session_destroy();
|
||||
$ssl = ((!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "" || $_SERVER['HTTPS'] == "off") ? "http" : "https");
|
||||
$url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index.php");
|
||||
header("Location: $ssl://$url");
|
||||
?>
|
||||
|
||||
?>
|
8
main.css
8
main.css
@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
@ -195,8 +195,8 @@ select {
|
||||
}
|
||||
|
||||
.mi {
|
||||
color:white;
|
||||
padding-right:0.1em;
|
||||
color:white;
|
||||
padding-right:0.1em;
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ select {
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
|
||||
button {
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
260
main.js
260
main.js
@ -16,8 +16,8 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// general stuff
|
||||
if (units=='imperial') {
|
||||
// general stuff
|
||||
if (units == 'imperial') {
|
||||
factor_kmh = 0.62; //to mph
|
||||
unit_kmh = 'mph';
|
||||
factor_m = 3.28; // to feet
|
||||
@ -45,12 +45,12 @@ function displayChart() {
|
||||
data.addColumn('number', 'id');
|
||||
data.addColumn('number', 'altitude');
|
||||
var altLen = altitudes.length;
|
||||
for (var i=0; i<altLen; i++) {
|
||||
data.addRow([(i+1),Math.round((altitudes[i]*factor_m))]);
|
||||
for (var i = 0; i < altLen; i++) {
|
||||
data.addRow([(i + 1), Math.round((altitudes[i] * factor_m))]);
|
||||
}
|
||||
|
||||
var options = {
|
||||
title: lang['altitude']+' ('+unit_m+')',
|
||||
title: lang['altitude'] + ' (' + unit_m + ')',
|
||||
hAxis: { textPosition: 'none' },
|
||||
legend: { position: 'none' }
|
||||
};
|
||||
@ -63,13 +63,13 @@ function displayChart() {
|
||||
|
||||
function toggleChart(i) {
|
||||
var altLen = altitudes.length;
|
||||
if (altLen<=1) { return; }
|
||||
if (altLen <= 1) { return; }
|
||||
var e = document.getElementById('bottom');
|
||||
if (arguments.length < 1) {
|
||||
if (e.style.display == 'block') { i = 0 }
|
||||
else { i = 1; }
|
||||
}
|
||||
if (i==0) {
|
||||
if (i == 0) {
|
||||
chart.clearChart();
|
||||
e.style.display = 'none';
|
||||
}
|
||||
@ -87,7 +87,7 @@ function toggleMenu(i) {
|
||||
if (ebutton.innerHTML == '»') { i = 0 }
|
||||
else { i = 1; }
|
||||
}
|
||||
if (i==0) {
|
||||
if (i == 0) {
|
||||
emenu.style.width = '0';
|
||||
emain.style.marginRight = '0';
|
||||
ebutton.style.right = '0';
|
||||
@ -104,52 +104,52 @@ function toggleMenu(i) {
|
||||
function getXHR() {
|
||||
var xmlhttp = null;
|
||||
if (window.XMLHttpRequest) {
|
||||
xmlhttp=new XMLHttpRequest();
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
}
|
||||
else {
|
||||
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
|
||||
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
function loadTrack(userid,trackid,update) {
|
||||
if (latest==1) { trackid=0; }
|
||||
function loadTrack(userid, trackid, update) {
|
||||
if (latest == 1) { trackid = 0; }
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState==4 && xhr.status==200) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
var positions = xml.getElementsByTagName('position');
|
||||
if (positions.length>0) {
|
||||
if (positions.length > 0) {
|
||||
clearMap();
|
||||
displayTrack(xml,update);
|
||||
displayTrack(xml, update);
|
||||
}
|
||||
xhr = null;
|
||||
}
|
||||
}
|
||||
xhr.open('GET','getpositions.php?trackid='+trackid+'&userid='+userid,true);
|
||||
xhr.open('GET', 'getpositions.php?trackid=' + trackid + '&userid=' + userid, true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function parsePosition(p) {
|
||||
// read data
|
||||
var latitude = getNode(p,'latitude');
|
||||
var longitude = getNode(p,'longitude');
|
||||
var altitude = getNode(p,'altitude'); // may be null
|
||||
// read data
|
||||
var latitude = getNode(p, 'latitude');
|
||||
var longitude = getNode(p, 'longitude');
|
||||
var altitude = getNode(p, 'altitude'); // may be null
|
||||
if (altitude != null) { altitude = parseInt(altitude); }
|
||||
var speed = getNode(p,'speed'); // may be null
|
||||
var speed = getNode(p, 'speed'); // may be null
|
||||
if (speed != null) { speed = parseInt(speed); }
|
||||
var bearing = getNode(p,'bearing'); // may be null
|
||||
var bearing = getNode(p, 'bearing'); // may be null
|
||||
if (bearing != null) { bearing = parseInt(bearing); }
|
||||
var accuracy = getNode(p,'accuracy'); // may be null
|
||||
var accuracy = getNode(p, 'accuracy'); // may be null
|
||||
if (accuracy != null) { accuracy = parseInt(accuracy); }
|
||||
var provider = getNode(p,'provider'); // may be null
|
||||
var comments = getNode(p,'comments'); // may be null
|
||||
var username = getNode(p,'username');
|
||||
var trackname = getNode(p,'trackname');
|
||||
var tid = getNode(p,'trackid');
|
||||
var dateoccured = getNode(p,'dateoccured');
|
||||
var distance = parseInt(getNode(p,'distance'));
|
||||
var seconds = parseInt(getNode(p,'seconds'));
|
||||
var provider = getNode(p, 'provider'); // may be null
|
||||
var comments = getNode(p, 'comments'); // may be null
|
||||
var username = getNode(p, 'username');
|
||||
var trackname = getNode(p, 'trackname');
|
||||
var tid = getNode(p, 'trackid');
|
||||
var dateoccured = getNode(p, 'dateoccured');
|
||||
var distance = parseInt(getNode(p, 'distance'));
|
||||
var seconds = parseInt(getNode(p, 'seconds'));
|
||||
return {
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
@ -174,88 +174,97 @@ function getPopupHtml(p, i, count) {
|
||||
var time = dateTime[1];
|
||||
var provider = '';
|
||||
if (p.provider == 'gps') {
|
||||
provider = ' (<img class="icon" alt="'+lang['gps']+'" title="'+lang['gps']+'" src="images/gps_dark.svg" />)';
|
||||
provider = ' (<img class="icon" alt="' + lang['gps'] + '" title="' + lang['gps'] + '" src="images/gps_dark.svg" />)';
|
||||
} else if (p.provider == 'network') {
|
||||
provider = ' (<img class="icon" alt="'+lang['network']+'" title="'+lang['network']+'" src="images/network_dark.svg" />)';
|
||||
provider = ' (<img class="icon" alt="' + lang['network'] + '" title="' + lang['network'] + '" src="images/network_dark.svg" />)';
|
||||
}
|
||||
popup =
|
||||
'<div id="popup">'+
|
||||
'<div id="pheader">'+
|
||||
'<div><img alt="'+lang['user']+'" title="'+lang['user']+'" src="images/user_dark.svg" /> '+p.username+'</div>'+
|
||||
'<div><img alt="'+lang['track']+'" title="'+lang['track']+'" src="images/route_dark.svg" /> '+p.trackname+'</div>'+
|
||||
'</div>'+
|
||||
'<div id="pbody">'+
|
||||
((p.comments != null)?'<div id="pcomments">'+p.comments+'</div>':'')+
|
||||
'<div id="pleft">'+
|
||||
'<img class="icon" alt="'+lang['time']+'" title="'+lang['time']+'" src="images/calendar_dark.svg" /> '+date+'<br />'+
|
||||
'<img class="icon" alt="'+lang['time']+'" title="'+lang['time']+'" src="images/clock_dark.svg" /> '+time+'<br />'+
|
||||
((p.speed != null)?'<img class="icon" alt="'+lang['speed']+'" title="'+lang['speed']+'" src="images/speed_dark.svg" /> '+(p.speed.toKmH()*factor_kmh)+' '+unit_kmh+'<br />':'')+
|
||||
((p.altitude != null)?'<img class="icon" alt="'+lang['altitude']+'" title="'+lang['altitude']+'" src="images/altitude_dark.svg" /> '+(p.altitude*factor_m).toFixed()+' '+unit_m+'<br />':'')+
|
||||
((p.accuracy != null)?'<img class="icon" alt="'+lang['accuracy']+'" title="'+lang['accuracy']+'" src="images/accuracy_dark.svg" /> '+(p.accuracy*factor_m).toFixed()+' '+unit_m+provider+'<br />':'')+
|
||||
'</div>'+
|
||||
((latest==0)?
|
||||
('<div id="pright">'+
|
||||
'<img class="icon" src="images/stats_blue.svg" style="padding-left: 3em;" /><br />'+
|
||||
'<img class="icon" alt="'+lang['ttime']+'" title="'+lang['ttime']+'" src="images/time_blue.svg" /> '+p.totalSeconds.toHMS()+'<br />'+
|
||||
'<img class="icon" alt="'+lang['aspeed']+'" title="'+lang['aspeed']+'" src="images/speed_blue.svg" /> '+((p.totalSeconds>0)?((p.totalMeters/p.totalSeconds).toKmH()*factor_kmh).toFixed():0)+' '+unit_kmh+'<br />'+
|
||||
'<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>')
|
||||
:
|
||||
'')+
|
||||
'<div id="pfooter">'+lang['point']+' '+(i + 1)+' '+lang['of']+' '+count+'</div>'+
|
||||
'</div></div>';
|
||||
var stats = '';
|
||||
if (latest == 0) {
|
||||
stats =
|
||||
'<div id="pright">' +
|
||||
'<img class="icon" src="images/stats_blue.svg" style="padding-left: 3em;" /><br />' +
|
||||
'<img class="icon" alt="' + lang['ttime'] + '" title="' + lang['ttime'] + '" src="images/time_blue.svg" /> ' +
|
||||
p.totalSeconds.toHMS() + '<br />' +
|
||||
'<img class="icon" alt="' + lang['aspeed'] + '" title="' + lang['aspeed'] + '" src="images/speed_blue.svg" /> ' +
|
||||
((p.totalSeconds > 0) ? ((p.totalMeters / p.totalSeconds).toKmH() * factor_kmh).toFixed() : 0) + ' ' + unit_kmh + '<br />' +
|
||||
'<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>';
|
||||
}
|
||||
popup =
|
||||
'<div id="popup">' +
|
||||
'<div id="pheader">' +
|
||||
'<div><img alt="' + lang['user'] + '" title="' + lang['user'] + '" src="images/user_dark.svg" /> ' + p.username + '</div>' +
|
||||
'<div><img alt="' + lang['track'] + '" title="' + lang['track'] + '" src="images/route_dark.svg" /> ' + p.trackname + '</div>' +
|
||||
'</div>' +
|
||||
'<div id="pbody">' +
|
||||
((p.comments != null) ? '<div id="pcomments">' + p.comments + '</div>' : '') +
|
||||
'<div id="pleft">' +
|
||||
'<img class="icon" alt="' + lang['time'] + '" title="' + lang['time'] + '" src="images/calendar_dark.svg" /> ' + date + '<br />' +
|
||||
'<img class="icon" alt="' + lang['time'] + '" title="' + lang['time'] + '" src="images/clock_dark.svg" /> ' + time + '<br />' +
|
||||
((p.speed != null) ? '<img class="icon" alt="' + lang['speed'] + '" title="' + lang['speed'] + '" src="images/speed_dark.svg" /> ' +
|
||||
(p.speed.toKmH() * factor_kmh) + ' ' + unit_kmh + '<br />' : '') +
|
||||
((p.altitude != null) ? '<img class="icon" alt="' + lang['altitude'] + '" title="' + lang['altitude'] + '" src="images/altitude_dark.svg" /> ' +
|
||||
(p.altitude * factor_m).toFixed() + ' ' + unit_m + '<br />' : '') +
|
||||
((p.accuracy != null) ? '<img class="icon" alt="' + lang['accuracy'] + '" title="' + lang['accuracy'] + '" src="images/accuracy_dark.svg" /> ' +
|
||||
(p.accuracy * factor_m).toFixed() + ' ' + unit_m + provider + '<br />' : '') +
|
||||
'</div>' +
|
||||
stats +
|
||||
'<div id="pfooter">' + lang['point'] + ' ' + (i + 1) + ' ' + lang['of'] + ' ' + count + '</div>' +
|
||||
'</div></div>';
|
||||
return popup;
|
||||
}
|
||||
|
||||
function load(type,userid,trackid) {
|
||||
var url = 'download.php?type='+type+'&userid='+userid+'&trackid='+trackid;
|
||||
function load(type, userid, trackid) {
|
||||
var url = 'download.php?type=' + type + '&userid=' + userid + '&trackid=' + trackid;
|
||||
window.location.assign(url);
|
||||
}
|
||||
|
||||
function updateSummary(l,d,s) {
|
||||
function updateSummary(l, d, s) {
|
||||
var t = document.getElementById('summary');
|
||||
if (latest==0){
|
||||
t.innerHTML = '<u>'+lang['summary']+'</u><br />'+
|
||||
'<span><img class="icon" alt="'+lang['tdistance']+'" title="'+lang['tdistance']+'" src="images/distance.svg" /> '+(d.toKm()*factor_km).toFixed(2)+' '+unit_km+'</span>'+
|
||||
'<span><img class="icon" alt="'+lang['ttime']+'" title="'+lang['ttime']+'" src="images/time.svg" /> '+s.toHMS()+'</span>';
|
||||
if (latest == 0) {
|
||||
t.innerHTML = '<u>' + lang['summary'] + '</u><br />' +
|
||||
'<span><img class="icon" alt="' + lang['tdistance'] + '" title="' + lang['tdistance'] + '" src="images/distance.svg" /> ' + (d.toKm() * factor_km).toFixed(2) + ' ' + unit_km + '</span>' +
|
||||
'<span><img class="icon" alt="' + lang['ttime'] + '" title="' + lang['ttime'] + '" src="images/time.svg" /> ' + s.toHMS() + '</span>';
|
||||
}
|
||||
else {
|
||||
t.innerHTML = '<u>'+lang['latest']+':</u><br />'+l;
|
||||
t.innerHTML = '<u>' + lang['latest'] + ':</u><br />' + l;
|
||||
}
|
||||
}
|
||||
|
||||
function getNode(p,name) {
|
||||
function getNode(p, name) {
|
||||
return ((p.getElementsByTagName(name)[0].childNodes[0]) ? p.getElementsByTagName(name)[0].childNodes[0].nodeValue : null);
|
||||
}
|
||||
|
||||
|
||||
// seconds to (d) H:M:S
|
||||
Number.prototype.toHMS = function(){
|
||||
Number.prototype.toHMS = function () {
|
||||
var s = this;
|
||||
var d = Math.floor(s / 86400);
|
||||
var h = Math.floor((s % 86400) / 3600);
|
||||
var m = Math.floor(((s % 86400) % 3600) / 60);
|
||||
s = ((s % 86400) % 3600) % 60;
|
||||
|
||||
return ((d>0)?(d + ' d '):'') + (('00'+h).slice(-2)) + ':' + (('00'+m).slice(-2)) + ':' + (('00'+s).slice(-2)) + '';
|
||||
return ((d > 0) ? (d + ' d ') : '') + (('00' + h).slice(-2)) + ':' + (('00' + m).slice(-2)) + ':' + (('00' + s).slice(-2)) + '';
|
||||
}
|
||||
|
||||
// meters to km
|
||||
Number.prototype.toKm = function() {
|
||||
return Math.round(this/10)/100;
|
||||
Number.prototype.toKm = function () {
|
||||
return Math.round(this / 10) / 100;
|
||||
}
|
||||
|
||||
// m/s to km/h
|
||||
Number.prototype.toKmH = function() {
|
||||
return Math.round(this*3600/10)/100;
|
||||
Number.prototype.toKmH = function () {
|
||||
return Math.round(this * 3600 / 10) / 100;
|
||||
}
|
||||
|
||||
// negate value
|
||||
function toggleLatest() {
|
||||
if (latest==0) {
|
||||
if (latest == 0) {
|
||||
latest = 1;
|
||||
loadTrack(userid,0,1);
|
||||
loadTrack(userid, 0, 1);
|
||||
}
|
||||
else {
|
||||
latest = 0;
|
||||
loadTrack(userid,trackid,1);
|
||||
loadTrack(userid, trackid, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,31 +273,31 @@ function setTrack(t) {
|
||||
}
|
||||
|
||||
function selectTrack(f) {
|
||||
trackid=f.options[f.selectedIndex].value;
|
||||
trackid = f.options[f.selectedIndex].value;
|
||||
document.getElementById('latest').checked = false;
|
||||
if (latest==1) { toggleLatest(); }
|
||||
loadTrack(userid,trackid,1);
|
||||
if (latest == 1) { toggleLatest(); }
|
||||
loadTrack(userid, trackid, 1);
|
||||
}
|
||||
|
||||
function selectUser(f) {
|
||||
userid=f.options[f.selectedIndex].value;
|
||||
if (f.options[0].disabled==false) {
|
||||
userid = f.options[f.selectedIndex].value;
|
||||
if (f.options[0].disabled == false) {
|
||||
f.options[0].disabled = true;
|
||||
}
|
||||
document.getElementById('latest').checked = false;
|
||||
if (latest==1) { toggleLatest(); }
|
||||
if (latest == 1) { toggleLatest(); }
|
||||
getTracks(userid);
|
||||
}
|
||||
|
||||
function getTracks(userid) {
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState==4 && xhr.status==200) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
var trackSelect = document.getElementsByName('track')[0];
|
||||
var trackSelect = document.getElementsByName('track')[0];
|
||||
clearOptions(trackSelect);
|
||||
var tracks = xml.getElementsByTagName('track');
|
||||
if (tracks.length>0) {
|
||||
if (tracks.length > 0) {
|
||||
fillOptions(xml);
|
||||
} else {
|
||||
clearMap();
|
||||
@ -296,27 +305,27 @@ function getTracks(userid) {
|
||||
xhr = null;
|
||||
}
|
||||
}
|
||||
xhr.open('GET','gettracks.php?userid='+userid,true);
|
||||
xhr.open('GET', 'gettracks.php?userid=' + userid, true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function fillOptions(xml) {
|
||||
var trackSelect = document.getElementsByName('track')[0];
|
||||
var trackSelect = document.getElementsByName('track')[0];
|
||||
var tracks = xml.getElementsByTagName('track');
|
||||
var trackLen = tracks.length;
|
||||
for (var i=0; i<trackLen; i++) {
|
||||
var trackid = getNode(tracks[i],'trackid');
|
||||
var trackname = getNode(tracks[i],'trackname');
|
||||
for (var i = 0; i < trackLen; i++) {
|
||||
var trackid = getNode(tracks[i], 'trackid');
|
||||
var trackname = getNode(tracks[i], 'trackname');
|
||||
var option = document.createElement("option");
|
||||
option.value = trackid;
|
||||
option.innerHTML = trackname;
|
||||
trackSelect.appendChild(option);
|
||||
}
|
||||
var defaultTrack = getNode(tracks[0],'trackid');
|
||||
loadTrack(userid,defaultTrack,1);
|
||||
var defaultTrack = getNode(tracks[0], 'trackid');
|
||||
loadTrack(userid, defaultTrack, 1);
|
||||
}
|
||||
|
||||
function clearOptions(el){
|
||||
function clearOptions(el) {
|
||||
if (el.options) {
|
||||
while (el.options.length) {
|
||||
el.remove(0);
|
||||
@ -326,9 +335,9 @@ function clearOptions(el){
|
||||
|
||||
var auto;
|
||||
function autoReload() {
|
||||
if (live==0) {
|
||||
if (live == 0) {
|
||||
live = 1;
|
||||
auto = setInterval(function() { loadTrack(userid,trackid,0); },interval*1000);
|
||||
auto = setInterval(function () { loadTrack(userid, trackid, 0); }, interval * 1000);
|
||||
}
|
||||
else {
|
||||
live = 0;
|
||||
@ -338,17 +347,17 @@ function autoReload() {
|
||||
|
||||
function setTime() {
|
||||
var i = parseInt(prompt(lang['newinterval']));
|
||||
if (!isNaN(i) && i!=interval) {
|
||||
if (!isNaN(i) && i != interval) {
|
||||
interval = i;
|
||||
document.getElementById('auto').innerHTML = interval;
|
||||
// if live tracking on, reload with new interval
|
||||
if (live==1) {
|
||||
if (live == 1) {
|
||||
live = 0;
|
||||
clearInterval(auto);
|
||||
autoReload();
|
||||
}
|
||||
// save current state as default
|
||||
setCookie('interval',interval,30);
|
||||
// save current state as default
|
||||
setCookie('interval', interval, 30);
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,26 +367,27 @@ function loadMapAPI(api) {
|
||||
savedBounds = getBounds();
|
||||
document.getElementById("map-canvas").innerHTML = '';
|
||||
var url = new Array();
|
||||
if (api=='gmaps') {
|
||||
if (api == 'gmaps') {
|
||||
url.push('api_gmaps.js');
|
||||
url.push('//maps.googleapis.com/maps/api/js?'+((gkey!==null)?('key='+gkey+'&'):'')+'callback=init');
|
||||
url.push('//maps.googleapis.com/maps/api/js?' + ((gkey !== null) ? ('key=' + gkey + '&') : '') + 'callback=init');
|
||||
}
|
||||
else {
|
||||
url.push('api_openlayers.js');
|
||||
url.push('//openlayers.org/api/OpenLayers.js');
|
||||
}
|
||||
addScript(url[0]);
|
||||
waitAndLoad(api,url);
|
||||
waitAndLoad(api, url);
|
||||
}
|
||||
|
||||
var loadTime = 0;
|
||||
function waitAndLoad(api,url) {
|
||||
function waitAndLoad(api, url) {
|
||||
// wait till first script loaded
|
||||
if (loadTime>5000) { loadTime = 0; alert('Sorry, can\'t load '+api+' API'); return; }
|
||||
if (loadedAPI!==api) {
|
||||
setTimeout(function() { loadTime += 50; waitAndLoad(api,url); }, 50);
|
||||
if (loadTime > 5000) { loadTime = 0; alert('Sorry, can\'t load ' + api + ' API'); return; }
|
||||
if (loadedAPI !== api) {
|
||||
setTimeout(function () { loadTime += 50; waitAndLoad(api, url); }, 50);
|
||||
return;
|
||||
}
|
||||
if(!isScriptLoaded(url[1])){
|
||||
if (!isScriptLoaded(url[1])) {
|
||||
addScript(url[1]);
|
||||
}
|
||||
loadTime = 0;
|
||||
@ -386,26 +396,26 @@ function waitAndLoad(api,url) {
|
||||
|
||||
function waitAndInit(api) {
|
||||
// wait till main api loads
|
||||
if (loadTime>10000) { loadTime = 0; alert('Sorry, can\'t load '+api+' API'); return; }
|
||||
if (loadTime > 10000) { loadTime = 0; alert('Sorry, can\'t load ' + api + ' API'); return; }
|
||||
try {
|
||||
init();
|
||||
}
|
||||
catch(e) {
|
||||
setTimeout(function() { loadTime += 50; waitAndInit(api); }, 50);
|
||||
catch (e) {
|
||||
setTimeout(function () { loadTime += 50; waitAndInit(api); }, 50);
|
||||
return;
|
||||
}
|
||||
loadTime = 0;
|
||||
zoomToBounds(savedBounds);
|
||||
loadTrack(userid,trackid,0);
|
||||
loadTrack(userid, trackid, 0);
|
||||
// save current api as default
|
||||
setCookie('api',api,30);
|
||||
setCookie('api', api, 30);
|
||||
}
|
||||
|
||||
function addScript(url) {
|
||||
var tag = document.createElement('script');
|
||||
tag.setAttribute('type','text/javascript');
|
||||
tag.setAttribute('type', 'text/javascript');
|
||||
tag.setAttribute('src', url);
|
||||
if (typeof tag!='undefined') {
|
||||
if (typeof tag != 'undefined') {
|
||||
document.getElementsByTagName('head')[0].appendChild(tag);
|
||||
}
|
||||
}
|
||||
@ -414,32 +424,32 @@ function isScriptLoaded(url) {
|
||||
scripts = document.getElementsByTagName('script');
|
||||
for (var i = scripts.length; i--;) {
|
||||
// check if url matches src
|
||||
var scriptUrl = scripts[i].src.replace(/https?:/,'');
|
||||
var scriptUrl = scripts[i].src.replace(/https?:/, '');
|
||||
if (scriptUrl != '' && url.indexOf(scriptUrl) !== -1) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function setCookie(name,value,days) {
|
||||
function setCookie(name, value, days) {
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime()+(days*24*60*60*1000));
|
||||
var expires = '; expires='+date.toGMTString();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
var expires = '; expires=' + date.toGMTString();
|
||||
}
|
||||
else {
|
||||
var expires = '';
|
||||
}
|
||||
document.cookie = 'ulogger_'+name+'='+value+expires+'; path=/';
|
||||
document.cookie = 'ulogger_' + name + '=' + value + expires + '; path=/';
|
||||
}
|
||||
|
||||
function setLang(lang) {
|
||||
setCookie('lang',lang,30);
|
||||
setCookie('lang', lang, 30);
|
||||
location.reload();
|
||||
}
|
||||
|
||||
function setUnits(unit) {
|
||||
units = unit;
|
||||
setCookie('units',unit,30);
|
||||
setCookie('units', unit, 30);
|
||||
location.reload();
|
||||
}
|
||||
|
||||
@ -463,7 +473,7 @@ function userMenu() {
|
||||
} else {
|
||||
dropdown.classList.add('show');
|
||||
window.addEventListener('click', removeOnClick, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeOnClick(event) {
|
||||
|
6
pass.js
6
pass.js
@ -40,12 +40,12 @@ function submitPass() {
|
||||
return;
|
||||
}
|
||||
var xhr = getXHR();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState==4 && xhr.status==200) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
var xml = xhr.responseXML;
|
||||
var message = "";
|
||||
if (xml) {
|
||||
var root = xml.getElementsByTagName('root');
|
||||
var root = xml.getElementsByTagName('root');
|
||||
if (root.length && getNode(root[0], 'error') == 0) {
|
||||
removeModal();
|
||||
alert("Password successfully changed");
|
||||
|
@ -21,10 +21,10 @@
|
||||
*
|
||||
* However, as μlogger users more secure password storage methods,
|
||||
* it is impossible to convert old password hashes to the new format.
|
||||
* Administrator will have to fill in user passwords manually.
|
||||
* Alternatively authentication code could be modify in order to
|
||||
* temporarily accept old hashes and convert it as users log in.
|
||||
* It should be pretty simple, but this is not a top priority
|
||||
* Administrator will have to fill in user passwords manually.
|
||||
* Alternatively authentication code could be modify in order to
|
||||
* temporarily accept old hashes and convert it as users log in.
|
||||
* It should be pretty simple, but this is not a top priority
|
||||
* for this small project.
|
||||
*/
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user