diff options
-rwxr-xr-x | README | 23 | ||||
-rw-r--r-- | README_Backitude | 42 | ||||
-rwxr-xr-x | api_gmaps.js | 15 | ||||
-rwxr-xr-x | api_openlayers.js | 4 | ||||
-rwxr-xr-x | auth.php | 7 | ||||
-rwxr-xr-x | config.php | 36 | ||||
-rwxr-xr-x | distance.php | 65 | ||||
-rwxr-xr-x | download.php | 1 | ||||
-rwxr-xr-x | export.php | 1 | ||||
-rwxr-xr-x | getpositions.php | 22 | ||||
-rwxr-xr-x | gettrips.php | 1 | ||||
-rwxr-xr-x | index.php | 24 | ||||
-rwxr-xr-x | lang.php | 3 | ||||
-rwxr-xr-x | logout.php | 1 | ||||
-rwxr-xr-x | main.css | 23 | ||||
-rwxr-xr-x | main.js | 84 | ||||
-rwxr-xr-x | requests.php | 250 | ||||
-rwxr-xr-x | runneruplive.sql (renamed from trackme.sql) | 32 |
18 files changed, 301 insertions, 333 deletions
@@ -1,11 +1,7 @@ -This is a simple web viewer for GPS tracks uploaded with mobile client. -It is designed to work with Android version of great app TrackMe (http://www.luisespinosa.com/trackme_eng.html), -but it should be easy to adjust it for other clients (other database tables). -Interface "look and feel" is based on TrackMe Display (http://forum.xda-developers.com/showthread.php?t=477394). -It is possible to switch between Google Maps API and OpenLayers API with OpenStreetMap (any other compatible base layer). +This is a simple web viewer to work with the excellent open-source fitness app RunnerUp +(https://github.com/jonasoreland/runnerup or https://play.google.com/store/apps/details?id=org.runnerup) -Live demo: -- http://flaa.fabiszewski.net/phptrackme/ +This is heavily based on the phpTrackMe (https://github.com/bfabiszewski/phpTrackme) Requirements: - PHP 5.1.2 @@ -14,21 +10,18 @@ Requirements: Features: - simple -- allows live tracking +- live tracking - track statistics -- altitudes graph +- altitudes graph (to be implemented in RunnerUp android app) - multiple users - user authentication - Google Maps API v3 -- OpenLayers v2 - ajax - server based configuration - user preferences stored in cookies -Todo -- install script -- custom icons -- write opensource client? - License - GPL + +The server address in the Android app should be set to http://<server address>/requests.php + diff --git a/README_Backitude b/README_Backitude deleted file mode 100644 index c5c1839..0000000 --- a/README_Backitude +++ /dev/null @@ -1,42 +0,0 @@ -Backitude is an Android client that is designed to capture the location -of your device at configurable time intervals or whenever a position is served -up by the operating system. You can grab it from https://play.google.com/store/apps/details?id=gaugler.backitude - -To configure Backitude to work with the custom server, you need to -set the following parameters in the custom server settings: - -Server URL: http://<your server>/requests.php -Request Type: POST -Successful Response Codes: 200,201 -Authentication options: Credentials in POST parameters -User Name: What ever you choose -Password: What ever you choose -Custom Field 1: upload -Custom Field 2: backitude - -User Name: u -Password: p -Latitude: lat -Longitude: long -Accuracy: accuracy -Speed: speed -Altitude: alt -Direction Bearing: angle -Location Timestamp: <this can be deleted> -Request Timestamp: do -Timezone Offset: <this can be deleted> -Custom Field 1: a -Custom Field 2: db - -mysql needs to be configured by running the trackme.sql sql script file. - -config.php needs to be configured. - -Within config.php: - - - Use trackme as the database name. - - Initially set allow_registration = 1 so Backitude can register and your user/pass is automatically created - - - - diff --git a/api_gmaps.js b/api_gmaps.js index 2ca65f7..52dfc61 100755 --- a/api_gmaps.js +++ b/api_gmaps.js @@ -80,7 +80,7 @@ function displayTrack(xml,update) { setTimeout(function(){google.maps.event.removeListener(zListener)}, 2000); } } - latestTime = p.dateoccured; + latestTime = p.dateAdded; polies.push(poly); updateSummary(p.dateoccured,totalMeters,totalSeconds); @@ -124,20 +124,21 @@ function setMarker(p,i,posLen) { if (latest==1) { marker.setIcon('http://maps.google.com/mapfiles/dd-end.png') } else if (i==0) { marker.setIcon('http://maps.google.com/mapfiles/marker_greenA.png') } else if (i==posLen-1) { marker.setIcon('http://maps.google.com/mapfiles/markerB.png') } - else { marker.setIcon('http://labs.google.com/ridefinder/images/mm_20_gray.png') } +// else { marker.setIcon('http://labs.google.com/ridefinder/images/mm_20_gray.png') } +// else { marker.setVisible(false) } + else { marker.setIcon('http://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle_blue.png') } // popup var content = '<div id="popup">'+ '<div id="pheader">'+lang_user+': '+p.username.toUpperCase()+'<br />'+lang_track+': '+p.trackname.toUpperCase()+ '</div>'+ '<div id="pbody">'+ ((p.comments != null)?'<div id="pcomments">'+p.comments+'</div>':'')+ - '<div id="pleft"><b>'+lang_time+':</b> '+p.dateoccured+'<br />'+ - ((p.speed != null)?'<b>'+lang_speed+':</b> '+(p.speed.toKmH()*factor_kmh)+' '+unit_kmh+'<br />':'')+ + '<div id="pleft"><b>'+lang_time+':</b> '+p.dateadded+'<br />'+ + ((p.speed != null)?'<b>'+lang_speed+':</b> '+(p.speed)+' '+unit_kmh+'<br />':'')+ ((p.altitude != null)?'<b>'+lang_altitude+':</b> '+(p.altitude*factor_m).toFixed()+' '+unit_m+'<br />':'')+'</div>'+ ((latest==0)? - ('<div id="pright"><b>'+lang_ttime+':</b> '+p.totalSeconds.toHMS()+'<br />'+ - '<b>'+lang_aspeed+':</b> '+((p.totalSeconds>0)?((p.totalMeters/p.totalSeconds).toKmH()*factor_kmh).toFixed():0)+' '+unit_kmh+'<br />'+ - '<b>'+lang_tdistance+':</b> '+(p.totalMeters.toKm()*factor_km).toFixed(2)+' '+unit_km+'<br />'+'</div>'):'')+ + ('<div id="pright"><b>'+lang_ttime+':</b> '+p.totaltime+'<br />'+ + '<b>'+lang_tdistance+':</b> '+p.totaldistance+' '+unit_m+'<br />'+'</div>'):'')+ '<div id="pfooter">'+lang_point+' '+(i+1)+' '+lang_of+' '+(posLen)+'</div>'+ '</div></div>'; popup = new google.maps.InfoWindow(); diff --git a/api_openlayers.js b/api_openlayers.js index 7795a5b..3fa08fe 100755 --- a/api_openlayers.js +++ b/api_openlayers.js @@ -116,7 +116,7 @@ function displayTrack(xml,update) { map.zoomOut(); } } - latestTime = p.dateoccured; + latestTime = p.dateAdded; //polies.push(poly); updateSummary(p.dateoccured,totalMeters,totalSeconds); @@ -163,7 +163,7 @@ function setMarker(p,i,posLen) { '</div>'+ '<div id="pbody">'+ ((p.comments != null)?'<div id="pcomments">'+p.comments+'</div>':'')+ - '<div id="pleft"><b>'+lang_time+':</b> '+p.dateoccured+'<br />'+ + '<div id="pleft"><b>'+lang_time+':</b> '+p.dateAdded+'<br />'+ ((p.speed != null)?'<b>'+lang_speed+':</b> '+(p.speed.toKmH()*factor_kmh)+' '+unit_kmh+'<br />':'')+ ((p.altitude != null)?'<b>'+lang_altitude+':</b> '+(p.altitude*factor_m).toFixed()+' '+unit_m+'<br />':'')+'</div>'+ ((latest==0)? @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -64,7 +65,7 @@ if ($require_authentication) { <div id="login"> <div id="title">'.$lang_title.'</div> <div id="subtitle">'.$lang_private.'</div> - <form action="index.php" method="post"> + <form action="index1.php" method="post"> '.$lang_username.':<br /> <input type="text" name="user"><br /> '.$lang_password.':<br /> @@ -104,7 +105,7 @@ if ($require_authentication) { else { $_SESSION['auth'] = $rec_ID; } - $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index.php"); + $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index1.php"); header("Location: $ssl://$url"); exit; } else { @@ -117,7 +118,7 @@ if ($require_authentication) { } session_destroy(); $mysqli->close(); - $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index.php"); + $url = str_replace("//", "/", $_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME'])."/index1.php"); header("Location: $ssl://$url$error"); exit; } @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -17,45 +18,32 @@ * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -$version = "2.2"; +$version = "0.1"; -// default map drawing framework -// (gmaps = google maps, openlayers = openlayers/osm) -//$mapapi = "gmaps"; -$mapapi = "openlayers"; - -// openlayers additional map layers -// OpenCycleMap (0 = no, 1 = yes) -$layer_ocm = 1; -// MapQuest-OSM (0 = no, 1 = yes) -$layer_mq = 1; -// osmapa.pl (0 = no, 1 = yes) -$layer_osmapa = 1; -// UMP (0 = no, 1 = yes) -$layer_ump = 1; +$mapapi = "gmaps"; // you may set your google maps api key // this is not obligatory by now -//$gkey = ""; +// $gkey = "AIzaSyC2CYwhwpM2NLhTm6L6ZKg9-SBpvft4P4U"; // MySQL config -$dbhost = ""; // mysql host, eg. localhost -$dbuser = ""; // database user -$dbpass = ""; // database pass -$dbname = ""; // database name +$dbhost = "127.0.0.1"; // mysql host, eg. localhost +$dbuser = "user"; // database user +$dbpass = "pass"; // database pass +$dbname = "runneruplive"; // database name $salt = ""; // fill in random string here, it will increase security of password hashes // other // require login/password authentication // (0 = no, 1 = yes) -$require_authentication = 1; +$require_authentication = 0; // admin user who has access to all users locations -$admin_user = ""; +$admin_user = " "; // allow automatic registration of new users // (0 = no, 1 = yes) -$allow_registration = 0; +$allow_registration = 1; // Default interval in seconds for live auto reload $interval = 10; @@ -67,8 +55,6 @@ $lang = "en"; //$lang = "de"; // units -// (metric, imperial) $units = "metric"; -//$units = "imperial"; ?> diff --git a/distance.php b/distance.php new file mode 100755 index 0000000..3d10de4 --- /dev/null +++ b/distance.php @@ -0,0 +1,65 @@ +<?php + +/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ +/*:: :*/ +/*:: This routine calculates the distance between two points (given the :*/ +/*:: latitude/longitude of those points). It is being used to calculate :*/ +/*:: the distance between two locations using GeoDataSource(TM) Products :*/ +/*:: :*/ +/*:: Definitions: :*/ +/*:: South latitudes are negative, east longitudes are positive :*/ +/*:: :*/ +/*:: Passed to function: :*/ +/*:: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/ +/*:: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/ +/*:: unit = the unit you desire for results :*/ +/*:: where: 'M' is statute miles :*/ +/*:: 'K' is kilometers (default) :*/ +/*:: 'N' is nautical miles :*/ +/*:: Worldwide cities and other features databases with latitude longitude :*/ +/*:: are available at http://www.geodatasource.com :*/ +/*:: :*/ +/*:: For enquiries, please contact sales@geodatasource.com :*/ +/*:: :*/ +/*:: Official Web site: http://www.geodatasource.com :*/ +/*:: :*/ +/*:: GeoDataSource.com (C) All Rights Reserved 2014 :*/ +/*:: :*/ +/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ + +//$mydistance = distance(-37.8602828,145.079616,-37.827206, 144.957393,'K'); + +//echo $mydistance; + +function distance($lat1, $lon1, $lat2, $lon2, $unit) { + + $theta = $lon1 - $lon2; + $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); + $dist = acos($dist); + $dist = rad2deg($dist); + $miles = $dist * 60 * 1.1515; + $unit = strtoupper($unit); + + if ($unit == "K") { + return ($miles * 1.609344); + } else if ($unit == "N") { + return ($miles * 0.8684); + } else { + return $miles; + } +} + +function triggerDistance($lat1, $lon1) { +$lat2 = -37.827206; +$lon2 = 144.957393; +$mydistance = distance($lat1,$lon1,$lat2, $lon2,'K'); + +error_log("distance $mydistance"); + +} + +// echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>"; +// echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>"; +// echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>"; + +?> diff --git a/download.php b/download.php index 995f190..1637978 100755 --- a/download.php +++ b/download.php @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by diff --git a/getpositions.php b/getpositions.php index 9a3acc1..578c5b5 100755 --- a/getpositions.php +++ b/getpositions.php @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -36,16 +37,16 @@ function haversine_distance($lat1, $lon1, $lat2, $lon2) { if ($userid) { if ($trackid) { // get all track data - $query = $mysqli->prepare("SELECT positions.ID,positions.Latitude,positions.Longitude,positions.Altitude,positions.Speed,positions.Angle,positions.DateOccurred,positions.Comments,users.username,trips.Name,trips.ID FROM positions LEFT JOIN users ON (positions.FK_Users_ID=users.ID) LEFT JOIN trips ON (positions.FK_Trips_ID=trips.ID) WHERE positions.FK_Users_ID=? AND positions.FK_Trips_ID=? ORDER BY positions.DateOccurred"); + $query = $mysqli->prepare("SELECT positions.ID,positions.Latitude,positions.Longitude,positions.Pace,positions.DateAdded,positions.TotalDistance,positions.TotalTime,positions.EventType,users.username,trips.Name,trips.ID FROM positions LEFT JOIN users ON (positions.FK_Users_ID=users.ID) LEFT JOIN trips ON (positions.FK_Trips_ID=trips.ID) WHERE positions.FK_Users_ID=? AND positions.FK_Trips_ID=? ORDER BY positions.DateAdded"); $query->bind_param('ii', $userid, $trackid); } else { // get data only for latest point - $query = $mysqli->prepare("SELECT positions.ID,positions.Latitude,positions.Longitude,positions.Altitude,positions.Speed,positions.Angle,positions.DateOccurred,positions.Comments,users.username,trips.Name,trips.ID FROM positions LEFT JOIN users ON (positions.FK_Users_ID=users.ID) LEFT JOIN trips ON (positions.FK_Trips_ID=trips.ID) WHERE positions.FK_Users_ID=? ORDER BY positions.DateOccurred DESC LIMIT 1"); + $query = $mysqli->prepare("SELECT positions.ID,positions.Latitude,positions.Longitude,positions.Pace,positions.DateAdded,positions.TotalDistance,positions.TotalTime,positions.EventType,users.username,trips.Name,trips.ID FROM positions LEFT JOIN users ON (positions.FK_Users_ID=users.ID) LEFT JOIN trips ON (positions.FK_Trips_ID=trips.ID) WHERE positions.FK_Users_ID=? ORDER BY positions.DateAdded DESC LIMIT 1"); $query->bind_param('i', $userid); } $query->execute(); - $query->bind_result($positionid,$latitude,$longitude,$altitude,$speed,$angle,$dateoccured,$comments,$username,$trackname,$trackid); + $query->bind_result($positionid,$latitude,$longitude,$pace,$dateadded,$totaldistance,$totaltime,$eventtype,$username,$trackname,$trackid); header("Content-type: text/xml"); $xml = new XMLWriter(); @@ -59,11 +60,12 @@ if ($userid) { $xml->writeAttribute("id", $positionid); $xml->writeElement("latitude", $latitude); $xml->writeElement("longitude", $longitude); - $xml->writeElement("altitude", ($altitude)?round($altitude):$altitude); - $xml->writeElement("speed", $speed); - $xml->writeElement("angle", $angle); - $xml->writeElement("dateoccured", $dateoccured); - $xml->writeElement("comments", $comments); + $xml->writeElement("pace", $pace); + $xml->writeElement("dateadded", $dateadded); + $xml->writeElement("TotalDistance", $totaldistance); + $xml->writeElement("TotalTime", $totaltime); + $xml->writeElement("EventType", $eventtype); + $xml->writeElement("username", $username); $xml->writeElement("trackid", $trackid); $xml->writeElement("trackname", $trackname); @@ -71,8 +73,8 @@ if ($userid) { $prev_latitude = $latitude; $prev_longitude = $longitude; $xml->writeElement("distance", round($distance)); - $seconds = (isset($prev_dateoccured))?(strtotime($dateoccured)-strtotime($prev_dateoccured)):0; - $prev_dateoccured = $dateoccured; + $seconds = (isset($prev_dateadded))?(strtotime($dateadded)-strtotime($prev_dateadded)):0; + $prev_dateadded = $dateadded; $xml->writeElement("seconds", $seconds); $xml->endElement(); } diff --git a/gettrips.php b/gettrips.php index 6883d08..601227f 100755 --- a/gettrips.php +++ b/gettrips.php @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -19,24 +20,24 @@ */ require_once("config.php"); require_once("auth.php"); +$user = ""; -if (($auth) and ($auth != $admin_user)) { +if (($auth) and ($auth != $admin_user) and ($require_authentication)) { // get username + error_log("here"); $query = "SELECT username FROM users WHERE ID='$auth' LIMIT 1"; $result = $mysqli->query($query); $row = $result->fetch_assoc(); $user = $row["username"]; - - // users - $user_form = '<u>'.$lang_user.'</u><br />'.$user.' (<a href="logout.php">'.$lang_logout.'</a>)'; } else { // free access or admin user - // prepare user select form + // prepare user select form if (($auth == $admin_user) and ($admin_user != "")) { $user = $auth; $auth = NULL; } + $user_form = ' <u>'.$lang_user.'</u><br /> <form> @@ -51,7 +52,10 @@ $user_form .= ' </select> </form> '; - $user_form .= '<u>'.$lang_user.'</u><br />'.$user.' (<a href="logout.php">'.$lang_logout.'</a>)'; +} + +if ($require_authentication) { + $user_form .= '<u>'.$lang_user.'</u><br />'.$user.' (<a href="logout.php">'.$lang_logout.'</a>)'; } // prepare track select form @@ -176,15 +180,9 @@ print ' <div id="other"> <a href="javascript:void(0);" onclick="toggleChart();">'.$lang_chart.'</a> </div> - <div id="api"> - '.$api_form.' - </div> <div id="lang"> '.$lang_form.' </div> - <div id="units"> - '.$units_form.' - </div> <div id="export"> <u>'.$lang_download.'</u><br /> <a href="javascript:void(0);" onclick="load(\'kml\',userid,trackid)">kml</a><br /> @@ -192,7 +190,7 @@ print ' </div> </div> <div id="menu-close" onclick="toggleMenu();">»</div> - <div id="footer"><a target="_blank" href="https://github.com/bfabiszewski/phpTrackme">phpTrackme</a> '.$version.'</div> + <div id="footer"><a target="_blank" href="https://github.com/markcs/RunnerUpLive">RunnerUpLive (markcs)</a> '.$version.'</div> </div> <div id="main"> <div id="map-canvas"></div> @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -20,7 +21,7 @@ switch($lang) { default: case "en": - $lang_title = "• phpTrackme •"; + $lang_title = "• RunnerUpLive •"; $lang_private = "You need login and password to access this page."; $lang_authfail = "Wrong username or password"; $lang_user = "User"; @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -1,6 +1,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -25,6 +26,25 @@ body { padding: 0; background-color: #666; } +.bgCover { background:#000; position:absolute; left:0; top:0; display:none; overflow:hidden } +.overlayBox { + border:5px solid #09F; + position:absolute; + display:none; + width:90%; + height:80%; + background:#fff; +} +.overlayContent { + padding:10px; + height:95%; + width:95% +} +.closeLink { + float:right; + color:red; +} + a { color: #bce; text-decoration: none; @@ -38,6 +58,8 @@ select { font-weight: normal; padding-top: 0.2em; } + + #menu input, #login input { width: 150px; @@ -181,3 +203,4 @@ select { #close a, #close:link, #close:visited { color: #5070af; } + @@ -1,6 +1,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -28,7 +29,7 @@ if (units=='imperial') { } else { factor_kmh = 1; - unit_kmh = 'km/h'; + unit_kmh = '/km'; factor_m = 1; unit_m = 'm'; factor_km = 1; @@ -119,7 +120,7 @@ function loadTrack(userid,trackid,update) { xhr.onreadystatechange = function() { if (xhr.readyState==4 && xhr.status==200) { var xml = xhr.responseXML; - var positions = xml.getElementsByTagName('position'); + var positions = xml.getElementsByTagName('position'); if (positions.length>0) { clearMap(); displayTrack(xml,update); @@ -135,32 +136,40 @@ function parsePosition(p) { // 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 - if (speed != null) { speed = parseInt(speed); } - var angle = getNode(p,'angle'); // may be null - if (angle != null) { angle = parseInt(angle); } - var comments = getNode(p,'comments'); // may be null + var altitude = 0; // may be null + //if (altitude != null) { altitude = parseInt(altitude); } + var speed = getNode(p,'pace'); // may be null + //speed = 1; + // var speed = 0; + //if (speed != null) { speed = parseInt(speed); } + //var angle = getNode(p,'angle'); // may be null + var angle = 0; + //if (angle != null) { angle = parseInt(angle); } + //var comments = getNode(p,'comments'); // may be null + var comments = ""; var username = getNode(p,'username'); var trackname = getNode(p,'trackname'); var tid = getNode(p,'trackid'); - var dateoccured = getNode(p,'dateoccured'); + var dateadded = getNode(p,'dateadded'); var distance = parseInt(getNode(p,'distance')); var seconds = parseInt(getNode(p,'seconds')); + var TotalDistance = parseInt(getNode(p,'TotalDistance')); + var TotalTime = getNode(p,'TotalTime'); + var EventType = getNode(p,'EventType'); return { 'latitude': latitude, 'longitude': longitude, - 'altitude': altitude, - 'speed': speed, - 'angle': angle, - 'comments': comments, + 'speed' : speed, + 'angle' : angle, 'username': username, 'trackname': trackname, 'tid': tid, - 'dateoccured': dateoccured, + 'dateadded': dateadded, 'distance': distance, - 'seconds': seconds + 'seconds': seconds, + 'totaldistance' : TotalDistance, + 'totaltime' : TotalTime, + 'EventType' : EventType, }; } @@ -397,3 +406,46 @@ function setUnits(unit) { setCookie('units',unit,30); location.reload(); } + +function showOverlayBox() { + //if box is not set to open then don't do anything + if( isOpen == false ) return; + // set the properties of the overlay box, the left and top positions + $('.overlayBox').css({ + display:'block', + left:( $(window).width() - $('.overlayBox').width() )/2, + top:( $(window).height() - $('.overlayBox').height() )/2 - 20, + position:'absolute' + }); + // set the window background for the overlay. i.e the body becomes darker + $('.bgCover').css({ + display:'block', + width: $(window).width(), + height:$(window).height(), + }); +} +function doOverlayOpen() { + //set status to open + isOpen = true; + showOverlayBox(); + $('.bgCover').css({opacity:0}).animate( {opacity:0.5, backgroundColor:'#000'} ); + // dont follow the link : so return false. + return false; +} +function doOverlayClose() { + //set status to closed + isOpen = false; + $('.overlayBox').css( 'display', 'none' ); + // now animate the background to fade out to opacity 0 + // and then hide it after the animation is complete. + $('.bgCover').animate( {opacity:0}, null, null, function() { $(this).hide(); } ); +} + +// if window is resized then reposition the overlay box +$(window).bind('resize',showOverlayBox); +// activate when the link with class launchLink is clicked +$('a.launchLink').click( doOverlayOpen ); +// close it when closeLink is clicked +$('a.closeLink').click( doOverlayClose ); + + diff --git a/requests.php b/requests.php index b112412..c9d8c59 100755 --- a/requests.php +++ b/requests.php @@ -2,6 +2,7 @@ /* phpTrackme * * Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net) + * Copyright(C) 2014 Mark Campbell-Smith (campbellsmith.me) * * This is free software; you can redistribute it and/or modify it under * the terms of the GNU Library General Public License as published by @@ -21,21 +22,35 @@ // http://forum.xda-developers.com/showpost.php?p=3250539&postcount=2 require_once("config.php"); -$user = (isset($_REQUEST['u']) ? $_REQUEST['u'] : ""); -$pass = (isset($_REQUEST['p']) ? md5($salt.$_REQUEST['p']) : ""); -$requireddb = (isset($_REQUEST['db']) ? $_REQUEST['db'] : 0); -$tripname = (isset($_REQUEST['tn']) ? $_REQUEST['tn'] : ""); -$action = (isset($_REQUEST['a']) ? $_REQUEST['a'] : ""); +$debug = 0; +$activityType = array("","Running", "Bike"); +$inputJSON = file_get_contents('php://input'); -// If the client uses Backitude then define the tripname as user-date -if ($requireddb == 'backitude') { - $tripname = $user.'-'.date("Ymd"); -} -// FIXME what is it for? -elseif ($requireddb<8) { - //Result:5 Incompatible database. - quit(5); -} + + $input= json_decode( $inputJSON, TRUE ); //convert JSON into array + $user = $input['userName']; + $pass = $input['password']; + $lat = $input['lat']; + $long = $input['long']; + $pace = $input['Pace']; + $TotalDistance = $input['TotalDistance']; + $eventType = $input['runningEventType']; + $TotalTime = $input['TotalTime']; + $dateoccurred = time(); + $tripname = $user.'-'.date("Ymd"); + $iconid = 50; +// error_log("$tripname"); +// foreach ($input as $key => $value) { +// echo "<tr>"; +// echo "<td>"; +// echo $key; +// echo "</td>"; +// echo "<td>"; +// echo $value; +// echo "</td>"; +// echo "</tr>"; +// error_log("key $key value $value"); +// } $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if ($mysqli->connect_errno) { @@ -43,11 +58,11 @@ if ($mysqli->connect_errno) { quit(4); } -if ((!$user) || (!$pass)){ +if ((!$user) || (!$pass)){ //Result:3 User or password not specified. + error_log("user or pass not specified ($user / $pass)"); quit(3); } - $query = $mysqli->prepare("SELECT ID,username,password FROM users WHERE username=? LIMIT 1"); $query->bind_param('s', $user); $query->execute(); @@ -57,9 +72,11 @@ $query->fetch(); $num = $query->num_rows; $query->free_result(); $query->close(); + if ($num) { if (($user==$rec_user) && ($pass!=$rec_pass)) { //Result:1 User correct, invalid password. + error_log("user correct, invalid password ($user / $pass <> $rec_pass)"); quit(1); } } @@ -74,141 +91,57 @@ else { if (!$userid) { //Result:2 User did not exist but after being created couldn't be found. // Or rather something went wrong while updating database - quit(2); + error_log("User not created"); + quit(2); } - } + } else { // User unknown, we don't allow autoregistration // Let's use this one: //Result:1 User correct, invalid password. - quit(1); + error_log("User unknown"); + quit(1); } } -switch($action) { - // action: noop - case "noop": - // test - quit(0); - break; - - // action: deletetrip - case "deletetrip": - if ($tripname) { - $sql = "DELETE FROM positions LEFT JOIN trips ON positions.FK_Trips_ID=trips.ID " - ."WHERE positions.FK_Users_ID=? AND trips.Name=?"; - $query = $mysqli->prepare($sql); - if ($query) { - $query->bind_param('is', $userid, $tripname); - $query->execute(); - $query->close(); - } - $sql = "DELETE FROM trips WHERE FK_Users_ID=? AND Name=?"; - $query = $mysqli->prepare($sql); - $query->bind_param('is', $userid, $tripname); - $query->execute(); - $rows = $mysqli->affected_rows; - $query->close(); - if ($rows) { - quit(0); - } - else { - //Result:7 Trip not found - quit(7); - } - } - else { - //Result:6 Trip not specified. - quit(6); - } - break; - - // action: addtrip - case "addtrip": - if ($tripname) { - $sql = "INSERT INTO trips (FK_Users_ID,Name) VALUES (?,?)"; - $query = $mysqli->prepare($sql); - $query->bind_param('is', $userid, $tripname); - $query->execute(); - $query->close(); - } - else { - //Result:6 Trip not specified. - quit(6); - } - break; - - // action: gettriplist - case "gettriplist": - $sql = "SELECT a1.Name,(SELECT MIN(a2.DateOccurred) FROM positions a2 " - ."WHERE a2.FK_Trips_ID=a1.ID) AS startdate " - ."FROM trips a1 WHERE a1.FK_Users_ID=? ORDER BY Name"; - $query = $mysqli->prepare($sql); - $query->bind_param('i', $userid); - $query->execute(); - $query->store_result(); - $query->bind_result($tripname,$startdate); - $num = $query->num_rows; - $triplist = array(); - if ($num) { - while ($query->fetch()) { - $triplist[] = $tripname."|".$startdate; - } - } - $query->free_result(); - $query->close(); - $param = implode("\n",$triplist); - quit(0,$param); - break; - - // action: upload - case "upload": - $lat = isset($_REQUEST["lat"]) ? $_REQUEST["lat"] : NULL; - $long = isset($_REQUEST["long"]) ? $_REQUEST["long"] : NULL; - // If the client uses Backitude then convert the date into handled format - $dateoccurred = isset($_REQUEST["do"]) ? $_REQUEST["do"] : NULL; - $altitude = isset($_REQUEST["alt"]) ? $_REQUEST["alt"] : NULL; - $angle = isset($_REQUEST["ang"]) ? $_REQUEST["ang"] : NULL; - $speed = isset($_REQUEST["sp"]) ? $_REQUEST["sp"] : NULL; - $iconname = isset($_REQUEST["iconname"]) ? $_REQUEST["iconname"] : NULL; - $comments = isset($_REQUEST["comments"]) ? $_REQUEST["comments"] : NULL; - $imageurl = isset($_REQUEST["imageurl"]) ? $_REQUEST["imageurl"] : NULL; - $cellid = isset($_REQUEST["cid"]) ? $_REQUEST["cid"] : NULL; - $signalstrength = isset($_REQUEST["ss"]) ? $_REQUEST["ss"] : NULL; - $signalstrengthmax = isset($_REQUEST["ssmax"]) ? $_REQUEST["ssmax"] : NULL; - $signalstrengthmin = isset($_REQUEST["ssmin"]) ? $_REQUEST["ssmin"] : NULL; - $batterystatus = isset($_REQUEST["bs"]) ? $_REQUEST["bs"] : NULL; - $uploadss = isset($_REQUEST["upss"]) ? $_REQUEST["upss"] : NULL; // FIXME is it needed? - $iconid = NULL; - if ($iconname) { - $sql = "SELECT ID FROM icons WHERE Name=? LIMIT 1"; - $query = $mysqli->prepare($sql); - $query->bind_param('s', $iconname); + if ($tripname) { + // get tripid + //$query = $mysqli->prepare("SELECT ID FROM trips WHERE FK_Users_ID=? AND Name=? LIMIT 1"); + //$query->bind_param('is', $userid, $tripname); + $query = $mysqli->prepare("SELECT ID,Name FROM trips WHERE FK_Users_ID=? AND Name LIKE '$tripname%' ORDER BY Name DESC limit 1"); + $query->bind_param('i', $userid ); $query->execute(); $query->store_result(); - $query->bind_result($id); + $query->bind_result($tripid,$tripname); $query->fetch(); $num = $query->num_rows; $query->free_result(); $query->close(); - if ($num) { - $iconid = $id; - } - } - $tripid = NULL; // FIXME: not sure what trips with null id are - if ($tripname) { - // get tripid - $query = $mysqli->prepare("SELECT ID FROM trips WHERE FK_Users_ID=? AND Name=? LIMIT 1"); - $query->bind_param('is', $userid, $tripname); + + $query = $mysqli->prepare("SELECT EventType FROM positions where FK_Users_ID=? and FK_Trips_ID=? ORDER BY ID DESC limit 1"); + $query->bind_param('ii', $userid, $tripid); $query->execute(); $query->store_result(); - $query->bind_result($tripid); + $query->bind_result($eventTypeLast); $query->fetch(); - $num = $query->num_rows; $query->free_result(); - $query->close(); - if (!$num) { + $query->close(); + + if ((!$num) || ($eventTypeLast == 3)) { // create trip + error_log("create trip"); + if (substr_count($tripname, '-') == 1) { + $tripname = $tripname."-1"; + error_log("create trip 1 $tripname"); + } + else { + $ptn = "/(.*)-(\d+$)/"; + preg_match($ptn, $tripname, $matches); + $matches[2]=$matches[2]+1; + $tripname = $matches[1]."-".$matches[2]; + error_log("create trip regex 2 $tripname"); + } + $query = $mysqli->prepare("INSERT INTO trips (FK_Users_ID,Name) VALUES (?,?)"); $query->bind_param('is', $userid, $tripname); $query->execute(); @@ -218,64 +151,33 @@ switch($action) { //Result:6 Trip didn't exist and system was unable to create it. quit(6); } - } } - if ($requireddb == 'backitude') { - $sql = "INSERT INTO positions " - ."(FK_Users_ID,FK_Trips_ID,Latitude,Longitude,DateOccurred,FK_Icons_ID," - ."Speed,Altitude,Comments,ImageURL,Angle,SignalStrength,SignalStrengthMax," - ."SignalStrengthMin,BatteryStatus) VALUES (?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?,?,?,?)"; - } else { - $sql = "INSERT INTO positions " - ."(FK_Users_ID,FK_Trips_ID,Latitude,Longitude,DateOccurred,FK_Icons_ID," - ."Speed,Altitude,Comments,ImageURL,Angle,SignalStrength,SignalStrengthMax," - ."SignalStrengthMin,BatteryStatus) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - } - + + $sql = "INSERT INTO positions " + ."(FK_Users_ID,FK_Trips_ID,Latitude,Longitude,FK_Icons_ID," + ."Pace,TotalDistance,TotalTime,EventType) VALUES (?,?,?,?,?,?,?,?,?)"; $query = $mysqli->prepare($sql); - $query->bind_param('iiddsiddssdiiii', - $userid,$tripid,$lat,$long,$dateoccurred,$iconid, - $speed,$altitude,$comments,$imageurl,$angle,$signalstrength,$signalstrengthmax, - $signalstrengthmin,$batterystatus); + $query->bind_param('iiddisisi',$userid,$tripid,$lat,$long,$iconid,$pace,$TotalDistance,$TotalTime,$eventType); + $query->execute(); $query->close(); if ($mysqli->errno) { //Result:7|SQLERROR Insert statement failed. + error_log("Mysql error on upload 1"); quit(7,$mysqli->error); } - //FIXME Are cellids used in Android client? - $upcellext = isset($_REQUEST["upcellext"]) ? $_REQUEST["upcellext"] : NULL; - if ($upcellext==1 && $cellid) { - $sql = "INSERT INTO cellids (CellID,Latitude,Longitude,SignalStrength,SignalStrengthMax,SignalStrengthMin) " - ."VALUES (?,?,?,?,?,?)"; - $query = $mysqli->prepare($sql); - $query->bind_param('sddiii',$cellid,$lat,$long,$signalstrength,$signalstrengthmax,$signalstrengthmin); - $query->execute(); - $query->close(); - if ($mysqli->errno) { - //Result:7|SQLERROR Insert statement failed. - quit(7,$mysqli->error); - } - } + error_log("finish upload"); quit(0); break; - - // action: geticonlist - // action: renametrip - // action: findclosestbuddy - // action: delete - // action: sendemail - // action: updateimageurl - // action: findclosestpositionbytime - // action: findclosestpositionbyposition - // action: gettripinfo - // action: gettriphighlights } function quit($errno,$param=""){ print "Result:".$errno.(($param)?"|$param":""); +// error_log( "Result:".$errno.(($param)?"|$param":"")); + exit(); } $mysqli->close(); ?> + diff --git a/trackme.sql b/runneruplive.sql index 5c47d24..b9b00d7 100755 --- a/trackme.sql +++ b/runneruplive.sql @@ -6,21 +6,8 @@ SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; -CREATE DATABASE IF NOT EXISTS `trackme` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; -USE `trackme`; - -CREATE TABLE IF NOT EXISTS `cellids` ( - `ID` int(11) NOT NULL auto_increment, - `CellID` varchar(255) NOT NULL, - `Latitude` double NOT NULL, - `Longitude` double NOT NULL, - `DateAdded` timestamp NOT NULL default CURRENT_TIMESTAMP, - `SignalStrength` int(11) default NULL, - `SignalStrengthMax` int(11) default NULL, - `SignalStrengthMin` int(11) default NULL, - PRIMARY KEY (`ID`), - KEY `Index_CellID` (`CellID`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +CREATE DATABASE IF NOT EXISTS `runneruplive` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; +USE `runneruplive`; CREATE TABLE IF NOT EXISTS `icons` ( `ID` int(11) NOT NULL auto_increment, @@ -29,6 +16,7 @@ CREATE TABLE IF NOT EXISTS `icons` ( PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; + CREATE TABLE IF NOT EXISTS `positions` ( `ID` int(11) NOT NULL auto_increment, `FK_Users_ID` int(11) NOT NULL, @@ -36,17 +24,11 @@ CREATE TABLE IF NOT EXISTS `positions` ( `FK_Icons_ID` int(11) default NULL, `Latitude` double NOT NULL, `Longitude` double NOT NULL, - `Altitude` double default '0', - `Speed` double default '0', - `Angle` double default NULL, + `Pace` varchar(255) default NULL, `DateAdded` timestamp NOT NULL default CURRENT_TIMESTAMP, - `DateOccurred` timestamp NULL default '0000-00-00 00:00:00', - `Comments` varchar(255) default NULL, - `ImageURL` varchar(255) default NULL, - `SignalStrength` int(11) default NULL, - `SignalStrengthMax` int(11) default NULL, - `SignalStrengthMin` int(11) default NULL, - `BatteryStatus` tinyint(4) default NULL, + `TotalDistance` int(11) default NULL, + `TotalTime` varchar(255) default NULL, + `EventType` int(11) default NULL, PRIMARY KEY (`ID`), KEY `Index_FK_Trips_ID` (`FK_Trips_ID`), KEY `Index_FK_Users_ID` (`FK_Users_ID`) |