ulogger-server/index.php

229 lines
8.1 KiB
PHP
Raw Normal View History

2013-06-19 13:27:14 +02:00
<?php
2017-01-30 21:36:44 +01:00
/* μlogger
2013-06-19 13:27:14 +02:00
*
2017-01-30 21:36:44 +01:00
* Copyright(C) 2017 Bartek Fabiszewski (www.fabiszewski.net)
2013-06-19 13:27:14 +02:00
*
* This is free software; you can redistribute it and/or modify it under
2017-04-07 00:05:28 +02:00
* the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
2013-06-19 13:27:14 +02:00
* (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.
*
2017-04-07 00:05:28 +02:00
* 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");
if ($user->isValid) {
2017-04-07 22:26:47 +02:00
$itemPass = '<a href="javascript:void(0)" onclick="changePass()"><img class="icon" src="images/lock.svg" \> ' . $lang["changepass"] . '</a>';
$itemLogout = '<a href="logout.php"><img class="icon" src="images/poweroff.svg" \> ' . $lang["logout"] . '</a>';
2017-04-06 23:23:25 +02:00
$userHeader = '
<div id="user_menu">
2017-04-07 22:26:47 +02:00
<a href="javascript:void(0);" onclick="userMenu()"><img class="icon" src="images/user.svg" \> ' . $user->login . '</a>
2017-04-06 23:23:25 +02:00
<div id="user_dropdown" class="dropdown">
' . $itemPass . '
' . $itemLogout . '
</div>
</div>';
} else {
2017-04-07 22:26:47 +02:00
$userHeader = '<a href="index.php?force_login=1"><img class="icon" src="images/key.svg" \> ' . $lang["login"] . '</a>';
}
$lastUserId = NULL;
$userForm = '';
if ($user->isAdmin || $config::$public_tracks) {
// public access or admin user
2013-06-19 13:27:14 +02:00
// prepare user select form
$userForm = '
<br /><u>' . $lang["user"] . '</u>
2014-09-07 21:19:43 +02:00
<br />
2013-06-19 13:27:14 +02:00
<form>
<select name="user" onchange="selectUser(this)">
<option value="0">' . $lang["suser"] . '</option>';
2014-09-07 21:19:43 +02:00
// get last position user
$lastPosition = new uPosition();
$lastPosition->getLast();
if ($lastPosition->isValid) {
$lastUserId = $lastPosition->userId;
2014-09-07 21:19:43 +02:00
}
$usersArr = $user->getAll();
if (!empty($usersArr)) {
foreach ($usersArr as $aUser) {
$userForm.= sprintf("<option %svalue=\"%s\">%s</option>\n", (($aUser->id == $lastUserId) ? "selected " : ""), $aUser->id, $aUser->login);
}
2013-06-19 13:27:14 +02:00
}
$userForm.= '
2014-09-07 21:19:43 +02:00
</select>
</form>
';
2013-06-19 13:27:14 +02:00
}
// prepare track select form
$trackForm = '
<u>' . $lang["track"] . '</u><br />
2013-06-19 13:27:14 +02:00
<form>
<select name="track" onchange="selectTrack(this)">';
$displayId = NULL;
if ($lastUserId) {
2014-09-07 21:19:43 +02:00
// or user who did last move
$displayId = $lastUserId;
} else if ($user->isValid) {
// display track of authenticated user
$displayId = $user->id;
}
$track = new uTrack();
$tracksArr = $track->getAll($displayId);
$trackId = NULL;
if (!empty($tracksArr)) {
$trackId = $tracksArr[0]->id; // get id of the latest track
foreach ($tracksArr as $aTrack) {
$trackForm.= sprintf("<option value=\"%s\">%s</option>\n", $aTrack->id, $aTrack->name);
}
2013-06-19 13:27:14 +02:00
}
$trackForm.= '
2013-06-19 13:27:14 +02:00
</select>
<input id="latest" type="checkbox" onchange="toggleLatest();"> ' . $lang["latest"] . '<br />
2013-06-19 13:27:14 +02:00
</form>
';
2013-06-21 11:15:09 +02:00
// map api select form
$apiForm = '
<u>' . $lang["api"] . '</u><br />
2013-06-21 11:15:09 +02:00
<form>
2013-06-23 23:43:09 +02:00
<select name="api" onchange="loadMapAPI(this.options[this.selectedIndex].value);">
<option value="gmaps"' . (($config::$mapapi == "gmaps") ? ' selected' : '') . '>Google Maps</option>
<option value="openlayers"' . (($config::$mapapi == "openlayers") ? ' selected' : '') . '>OpenLayers</option>
2013-06-21 11:15:09 +02:00
</select>
</form>
';
2013-06-23 23:43:09 +02:00
// language select form
$langForm = '
<u>' . $lang["language"] . '</u><br />
2013-06-23 23:43:09 +02:00
<form>
<select name="units" onchange="setLang(this.options[this.selectedIndex].value);">';
2017-04-07 19:19:15 +02:00
asort($langsArr);
foreach ($langsArr as $langCode => $langName) {
$langForm .= '<option value="' . $langCode . '"' . (($config::$lang == $langCode) ? ' selected' : '') . '>' . $langName . '</option>';
}
$langForm .= '
2013-06-23 23:43:09 +02:00
</select>
</form>
';
// units select form
$unitsForm = '
<u>' . $lang["units"] . '</u><br />
2013-06-23 23:43:09 +02:00
<form>
<select name="units" onchange="setUnits(this.options[this.selectedIndex].value);">
<option value="metric"' . (($config::$units == "metric") ? ' selected' : '') . '>' . $lang["metric"] . '</option>
<option value="imperial"' . (($config::$units == "imperial") ? ' selected' : '') . '>' . $lang["imperial"] . '</option>
2013-06-23 23:43:09 +02:00
</select>
</form>
';
// admin menu
$adminMenu = '';
$adminScript = '';
if ($user->isAdmin) {
$adminMenu = '
<div id="admin_menu">
<u>' . $lang["adminmenu"] . '</u><br />
<a href="javascript:void(0);" onclick="addUser()">' . $lang["adduser"] . '</a><br />
</div>
';
$adminScript = '<script type="text/javascript" src="admin.js"></script>';
}
print '<!DOCTYPE html>
2013-06-19 13:27:14 +02:00
<html>
<head>
<title>' . $lang["title"] . '</title>
2013-06-19 13:27:14 +02:00
<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 = ' . $config::$interval . ';
var userid = ' . (($displayId) ? $displayId : -1) . ';
var trackid = ' . (($trackId) ? $trackId : -1) . ';
var units = "' . $config::$units . '";
var mapapi = "' . $config::$mapapi . '";
2017-04-07 16:06:05 +02:00
var gkey = ' . (!empty($config::$gkey) ? '"' . $config::$gkey . '"' : 'null') . ';
var layer_ocm = "' . $config::$layer_ocm . '";
var layer_mq = "' . $config::$layer_mq . '";
var layer_osmapa = "' . $config::$layer_osmapa . '";
var layer_ump = "' . $config::$layer_ump . '";
var init_latitude = "' . $config::$init_latitude . '";
var init_longitude = "' . $config::$init_longitude . '";
var lang = ' . json_encode($lang) . ';
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 ($config::$mapapi == "gmaps") {
2017-04-07 16:06:05 +02:00
print ' <script type="text/javascript" src="//maps.googleapis.com/maps/api/js' . (!empty($config::$gkey) ? '?key=' . $config::$gkey : '') . '"></script>
<script type="text/javascript" src="api_gmaps.js"></script>
2013-06-19 13:27:14 +02:00
';
} else {
print ' <script type="text/javascript" src="//openlayers.org/api/OpenLayers.js"></script>
2013-06-21 11:15:09 +02:00
<script type="text/javascript" src="api_openlayers.js"></script>
2013-06-19 13:27:14 +02:00
';
}
print '
' . $adminScript . '
<script type="text/javascript" src="pass.js"></script>
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>
2013-06-19 13:27:14 +02:00
</head>
<body onload="init();loadTrack(userid,trackid,1);">
<div id="menu">
<div id="menu-content">
' . $userHeader . '
2013-06-19 13:27:14 +02:00
<div id="user">
' . $userForm . '
2013-06-19 13:27:14 +02:00
</div>
2017-01-30 21:36:44 +01:00
<div id="track">
' . $trackForm . '
<input type="checkbox" onchange="autoReload();"> ' . $lang["autoreload"] . ' (<a href="javascript:void(0);" onclick="setTime()"><span id="auto">' . $config::$interval . '</span></a> s)<br />
<a href="javascript:void(0);" onclick="loadTrack(userid,trackid,0)">' . $lang["reload"] . '</a><br />
2013-06-19 13:27:14 +02:00
</div>
<div id="summary"></div>
<div id="other">
<a href="javascript:void(0);" onclick="toggleChart();">' . $lang["chart"] . '</a>
2013-06-21 11:15:09 +02:00
</div>
<div id="api">
' . $apiForm . '
2013-06-19 13:27:14 +02:00
</div>
<div id="lang">
' . $langForm . '
2013-06-23 23:43:09 +02:00
</div>
<div id="units">
' . $unitsForm . '
2013-06-23 23:43:09 +02:00
</div>
2013-06-19 13:27:14 +02:00
<div id="export">
<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>
' . $adminMenu . '
2013-06-19 13:27:14 +02:00
</div>
2013-06-26 19:58:55 +02:00
<div id="menu-close" onclick="toggleMenu();">»</div>
<div id="footer"><a target="_blank" href="https://github.com/bfabiszewski/ulogger-server"><span class="mi">μ</span>logger</a> ' . $config::$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>
2013-06-19 13:27:14 +02:00
</div>
</body>
</html>';
2013-06-19 13:27:14 +02:00
$mysqli->close();
?>