ulogger-server/index.php

228 lines
7.6 KiB
PHP
Raw Normal View History

2013-06-19 13:27:14 +02:00
<?php
/* phpTrackme
*
* Copyright(C) 2013 Bartek Fabiszewski (www.fabiszewski.net)
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
2014-04-01 17:28:27 +11:00
require_once("config.php");
2013-06-19 13:27:14 +02:00
require_once("auth.php");
2014-04-01 17:28:27 +11:00
2014-09-07 21:19:43 +02:00
if ($auth && !$admin) {
2013-06-19 13:27:14 +02:00
// get username
$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 {
2014-04-01 17:28:27 +11:00
// free access or admin user
2013-06-19 13:27:14 +02:00
// prepare user select form
2014-09-07 21:19:43 +02:00
if ($admin) {
$user = $admin_user;
2014-04-01 17:28:27 +11:00
}
2013-06-19 13:27:14 +02:00
$user_form = '
2014-09-07 21:19:43 +02:00
<u>'.$lang_user.'</u> ';
if ($auth) {
$user_form .= '&nbsp;'.$user.' (<a href="logout.php">'.$lang_logout.'</a>)';
}
$user_form .= '
<br />
2013-06-19 13:27:14 +02:00
<form>
<select name="user" onchange="selectUser(this)">
2013-07-25 23:34:13 +02:00
<option value="0">'.$lang_suser.'</option>';
2014-09-07 21:19:43 +02:00
// get last position user
$query = "SELECT FK_Users_ID FROM positions ORDER BY DateOccurred LIMIT 1";
$result = $mysqli->query($query);
if ($result->num_rows) {
$last = $result->fetch_row();
$last_id = $last[0];
} else {
$last_id = "";
}
2013-06-19 13:27:14 +02:00
$query = "SELECT ID,username FROM users ORDER BY username";
$result = $mysqli->query($query);
while ($row = $result->fetch_assoc()) {
2014-09-07 21:19:43 +02:00
$user_form .= sprintf("<option %svalue=\"%s\">%s</option>\n", ($row["ID"] == $last_id)?"selected ":"",$row["ID"], $row["username"]);
2013-06-19 13:27:14 +02:00
}
2014-09-07 21:19:43 +02:00
$user_form .= '
</select>
</form>
';
2013-06-19 13:27:14 +02:00
}
// prepare track select form
$track_form = '
<u>'.$lang_track.'</u><br />
<form>
<select name="track" onchange="selectTrack(this)">';
2014-09-07 21:19:43 +02:00
$userid = "";
if ($auth && !$admin) {
// display track of authenticated user
$userid = $auth;
} elseif ($last_id) {
// or user who did last move
$userid = $last_id;
}
$query = "SELECT * FROM trips WHERE FK_Users_ID='$userid' ORDER BY ID DESC";
2013-06-19 13:27:14 +02:00
$result = $mysqli->query($query);
2014-04-01 17:28:27 +11:00
2013-06-19 13:27:14 +02:00
$trackid = "";
while ($row = $result->fetch_assoc()) {
if ($trackid == "") { $trackid = $row["ID"]; } // get first row
$track_form .= sprintf("<option value=\"%s\">%s</option>\n", $row["ID"], $row["Name"]);
}
$track_form .= '
</select>
<input id="latest" type="checkbox" onchange="toggleLatest();"> '.$lang_latest.'<br />
</form>
';
2013-06-21 11:15:09 +02:00
// map api select form
$api_form = '
<u>'.$lang_api.'</u><br />
<form>
2013-06-23 23:43:09 +02:00
<select name="api" onchange="loadMapAPI(this.options[this.selectedIndex].value);">
2013-06-21 11:15:09 +02:00
<option value="gmaps"'.(($mapapi=="gmaps")?' selected':'').'>Google Maps</option>
<option value="openlayers"'.(($mapapi=="openlayers")?' selected':'').'>OpenLayers</option>
</select>
</form>
';
2013-06-23 23:43:09 +02:00
// language select form
$lang_form = '
<u>'.$lang_language.'</u><br />
<form>
<select name="units" onchange="setLang(this.options[this.selectedIndex].value);">
<option value="en"'.(($lang=="en")?' selected':'').'>English</option>
<option value="pl"'.(($lang=="pl")?' selected':'').'>Polski</option>
<option value="de"'.(($lang=="de")?' selected':'').'>Deutsch</option>
</select>
</form>
';
// units select form
$units_form = '
<u>'.$lang_units.'</u><br />
<form>
<select name="units" onchange="setUnits(this.options[this.selectedIndex].value);">
<option value="metric"'.(($units=="metric")?' selected':'').'>'.$lang_metric.'</option>
<option value="imperial"'.(($units=="imperial")?' selected':'').'>'.$lang_imperial.'</option>
</select>
</form>
';
2013-06-19 13:27:14 +02:00
print
'<!DOCTYPE html>
<html>
<head>
<title>'.$lang_title.'</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
2013-06-21 11:15:09 +02:00
<link rel="stylesheet" type="text/css" href="main.css" />
2013-06-19 13:27:14 +02:00
<script>
var interval = '.$interval.';
2014-09-07 21:19:43 +02:00
var userid = '.(($userid)?$userid:-1).';
2013-06-19 13:27:14 +02:00
var trackid = '.(($trackid)?$trackid:-1).';
var lang_user = "'.$lang_user.'";
var lang_time = "'.$lang_time.'";
var lang_speed = "'.$lang_speed.'";
var lang_altitude = "'.$lang_altitude.'";
var lang_ttime = "'.$lang_ttime.'";
var lang_aspeed = "'.$lang_aspeed.'";
var lang_tdistance = "'.$lang_tdistance.'";
var lang_point = "'.$lang_point.'";
var lang_of = "'.$lang_of.'";
var lang_summary = "'.$lang_summary.'";
var lang_latest = "'.$lang_latest.'";
var lang_track = "'.$lang_track.'";
var lang_newinterval = "'.$lang_newinterval.'";
var units = "'.$units.'";
2013-06-21 11:15:09 +02:00
var mapapi = "'.$mapapi.'";
2013-06-21 12:44:57 +02:00
var gkey = '.(isset($gkey)?'"'.$gkey.'"':'null').';
2013-06-23 00:17:28 +02:00
var layer_ocm = "'.$layer_ocm.'";
var layer_mq = "'.$layer_mq.'";
var layer_osmapa = "'.$layer_osmapa.'";
2013-06-23 23:43:09 +02:00
var layer_ump = "'.$layer_ump.'";
var init_latitude = "'.$init_latitude.'";
var init_longitude = "'.$init_longitude.'";
2013-06-19 13:27:14 +02:00
</script>
<script type="text/javascript" src="main.js"></script>
2013-06-19 13:27:14 +02:00
';
if ($mapapi == "gmaps") {
print
2013-06-23 00:17:28 +02:00
' <script type="text/javascript" src="//maps.googleapis.com/maps/api/js?'.(isset($gkey)?'key='.$gkey.'&':'').'sensor=false"></script>
2013-06-21 11:15:09 +02:00
<script type="text/javascript" src="api_gmaps.js"></script>
2013-06-19 13:27:14 +02:00
';
}
else {
print
2013-06-21 11:15:09 +02:00
' <script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript" src="api_openlayers.js"></script>
2013-06-19 13:27:14 +02:00
';
}
print '
2013-06-23 00:17:28 +02:00
<script type="text/javascript" src="//www.google.com/jsapi"></script>
2013-06-19 13:27:14 +02:00
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
</script>
</head>
<body onload="init();loadTrack(userid,trackid,1);">
<div id="menu">
<div id="menu-content">
<div id="user">
'.$user_form.'
</div>
<div id="trip">
'.$track_form.'
2013-06-23 00:17:28 +02:00
<input type="checkbox" onchange="autoReload();"> '.$lang_autoreload.' (<a href="javascript:void(0);" onclick="setTime()"><span id="auto">'.$interval.'</span></a> s)<br />
2013-06-19 13:27:14 +02:00
<a href="javascript:void(0);" onclick="loadTrack(userid,trackid,0)">'.$lang_reload.'</a><br />
</div>
<div id="summary"></div>
<div id="other">
2013-06-21 11:15:09 +02:00
<a href="javascript:void(0);" onclick="toggleChart();">'.$lang_chart.'</a>
</div>
<div id="api">
'.$api_form.'
2013-06-19 13:27:14 +02:00
</div>
2013-06-23 23:43:09 +02:00
<div id="lang">
'.$lang_form.'
</div>
<div id="units">
'.$units_form.'
</div>
2013-06-19 13:27:14 +02:00
<div id="export">
2013-06-23 23:43:09 +02:00
<u>'.$lang_download.'</u><br />
2013-06-19 13:27:14 +02:00
<a href="javascript:void(0);" onclick="load(\'kml\',userid,trackid)">kml</a><br />
<a href="javascript:void(0);" onclick="load(\'gpx\',userid,trackid)">gpx</a><br />
</div>
</div>
2013-06-26 19:58:55 +02:00
<div id="menu-close" onclick="toggleMenu();">»</div>
2013-06-23 00:17:28 +02:00
<div id="footer"><a target="_blank" href="https://github.com/bfabiszewski/phpTrackme">phpTrackme</a> '.$version.'</div>
2013-06-19 13:27:14 +02:00
</div>
<div id="main">
<div id="map-canvas"></div>
<div id="bottom">
<div id="chart"></div>
<div id="close"><a href="javascript:void(0);" onclick="toggleChart(0);">'.$lang_close.'</a></div>
</div>
</div>
</body>
</html>';
$mysqli->close();
?>