ulogger-server/index.php

222 lines
9.6 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/>.
*/
2017-04-09 23:35:55 +02:00
2017-04-11 17:00:40 +02:00
require_once(__DIR__ . "/auth.php"); // sets $mysqli, $user
require_once(ROOT_DIR . "/helpers/position.php");
require_once(ROOT_DIR . "/helpers/track.php");
2017-04-09 23:35:55 +02:00
2017-04-10 22:46:56 +02:00
$displayUserId = NULL;
$usersArr = [];
if ($user->isAdmin || $config::$public_tracks) {
// public access or admin user
// get last position user
$lastPosition = new uPosition();
$lastPosition->getLast();
if ($lastPosition->isValid) {
// display track of last position user
$displayUserId = $lastPosition->userId;
}
2017-04-10 22:46:56 +02:00
// populate users array (for <select>)
$usersArr = $user->getAll();
} else if ($user->isValid) {
// display track of authenticated user
$displayUserId = $user->id;
2013-06-19 13:27:14 +02:00
}
2017-04-10 22:46:56 +02:00
$track = new uTrack();
$tracksArr = $track->getAll($displayUserId);
if (!empty($tracksArr)) {
// get id of the latest track
$displayTrackId = $tracksArr[0]->id;
} else {
$tracksArr = [];
$displayTrackId = NULL;
}
2017-04-10 22:46:56 +02:00
$mysqli->close();
?>
<!DOCTYPE html>
2013-06-19 13:27:14 +02:00
<html>
<head>
2017-04-10 22:46:56 +02:00
<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">
2017-04-13 08:56:30 +02:00
<link rel="apple-touch-icon" sizes="180x180" href="icons/apple-touch-icon.png">
<link rel="icon" type="image/png" href="icons/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="icons/favicon-16x16.png" sizes="16x16">
<link rel="manifest" href="manifest.json">
<link rel="mask-icon" href="icons/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="icons/favicon.ico">
<meta name="msapplication-config" content="browserconfig.xml">
2017-04-12 23:19:54 +02:00
<meta name="theme-color" content="#ffffff">
2017-04-11 17:00:40 +02:00
<link rel="stylesheet" type="text/css" href="css/main.css">
2013-06-19 13:27:14 +02:00
<script>
2017-04-10 22:46:56 +02:00
var interval = '<?= $config::$interval ?>';
var userid = '<?= ($displayUserId) ? $displayUserId : -1 ?>';
var trackid = '<?= ($displayTrackId) ? $displayTrackId : -1 ?>';
var units = '<?= $config::$units ?>';
var mapapi = '<?= $config::$mapapi ?>';
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) ?>;
2017-04-14 17:24:09 +02:00
var admin = <?= json_encode($user->isAdmin) ?>;
2017-04-12 20:16:39 +02:00
var auth = '<?= ($user->isValid) ? $user->login : "null" ?>';
var pass_regex = <?= $config->passRegex() ?>;
2013-06-19 13:27:14 +02:00
</script>
2017-04-11 17:00:40 +02:00
<script type="text/javascript" src="js/main.js"></script>
2017-04-10 22:46:56 +02:00
<?php if ($config::$mapapi == "gmaps"): ?>
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js<?= !empty($config::$gkey) ? "?key={$config::$gkey}" : "" ?>"></script>
2017-04-11 17:00:40 +02:00
<script type="text/javascript" src="js/api_gmaps.js"></script>
2017-04-10 22:46:56 +02:00
<?php else: ?>
<script type="text/javascript" src="//openlayers.org/api/OpenLayers.js"></script>
2017-04-11 17:00:40 +02:00
<script type="text/javascript" src="js/api_openlayers.js"></script>
2017-04-10 22:46:56 +02:00
<?php endif; ?>
<?php if ($user->isAdmin): ?>
2017-04-11 17:00:40 +02:00
<script type="text/javascript" src="js/admin.js"></script>
2017-04-10 22:46:56 +02:00
<?php endif; ?>
2017-04-14 17:24:09 +02:00
<?php if ($user->isValid): ?>
<script type="text/javascript" src="js/track.js"></script>
<?php endif; ?>
2017-04-11 17:00:40 +02:00
<script type="text/javascript" src="js/pass.js"></script>
2017-04-10 22:46:56 +02:00
<script type="text/javascript" src="//www.google.com/jsapi"></script>
2013-06-19 13:27:14 +02:00
<script type="text/javascript">
2017-04-10 22:46:56 +02:00
google.load('visualization', '1', { packages:['corechart'] });
2013-06-19 13:27:14 +02:00
</script>
</head>
2017-04-10 22:46:56 +02:00
<body onload="init(); loadTrack(userid, trackid, 1);">
2013-06-19 13:27:14 +02:00
<div id="menu">
<div id="menu-content">
2017-04-10 22:46:56 +02:00
<?php if ($user->isValid): ?>
<div id="user_menu">
2017-04-14 16:00:53 +02:00
<a href="javascript:void(0);" onclick="userMenu()"><img class="icon" alt="<?= $lang["user"] ?>" src="images/user.svg"> <?= htmlspecialchars($user->login) ?></a>
2017-04-10 22:46:56 +02:00
<div id="user_dropdown" class="dropdown">
<a href="javascript:void(0)" onclick="changePass()"><img class="icon" alt="<?= $lang["changepass"] ?>" src="images/lock.svg"> <?= $lang["changepass"] ?></a>
2017-04-11 17:00:40 +02:00
<a href="utils/logout.php"><img class="icon" alt="<?= $lang["logout"] ?>" src="images/poweroff.svg"> <?= $lang["logout"] ?></a>
2017-04-10 22:46:56 +02:00
</div>
</div>
<?php else: ?>
<a href="index.php?force_login=1"><img class="icon" alt="<?= $lang["login"] ?>" src="images/key.svg"> <?= $lang["login"] ?></a>
<?php endif; ?>
2013-06-19 13:27:14 +02:00
<div id="user">
2017-04-10 22:46:56 +02:00
<?php if (!empty($usersArr)): ?>
<br><u><?= $lang["user"] ?></u><br>
<form>
<select name="user" onchange="selectUser(this);">
<option value="0"><?= $lang["suser"] ?></option>
<?php foreach ($usersArr as $aUser): ?>
2017-04-14 16:00:53 +02:00
<option <?= ($aUser->id == $displayUserId) ? "selected " : "" ?>value="<?= $aUser->id ?>"><?= htmlspecialchars($aUser->login) ?></option>
2017-04-10 22:46:56 +02:00
<?php endforeach; ?>
</select>
</form>
<?php endif; ?>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
2017-01-30 21:36:44 +01:00
<div id="track">
2017-04-10 22:46:56 +02:00
<u><?= $lang["track"] ?></u><br>
<form>
<select name="track" onchange="selectTrack(this)">
<?php foreach ($tracksArr as $aTrack): ?>
2017-04-14 16:00:53 +02:00
<option value="<?= $aTrack->id ?>"><?= htmlspecialchars($aTrack->name) ?></option>
2017-04-10 22:46:56 +02:00
<?php endforeach; ?>
</select>
<input id="latest" type="checkbox" onchange="toggleLatest();"> <?= $lang["latest"] ?><br>
2017-04-14 16:00:53 +02:00
<input type="checkbox" onchange="autoReload();"> <?= $lang["autoreload"] ?> (<a href="javascript:void(0);" onclick="setTime();"><span id="auto"><?= $config::$interval ?></span></a> s)<br>
</form>
2017-04-12 20:16:39 +02:00
<a href="javascript:void(0);" onclick="loadTrack(userid, trackid, 0);"> <?= $lang["reload"] ?></a><br>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
2013-06-19 13:27:14 +02:00
<div id="summary"></div>
2017-04-10 22:46:56 +02:00
2013-06-19 13:27:14 +02:00
<div id="other">
2017-04-10 22:46:56 +02:00
<a href="javascript:void(0);" onclick="toggleChart();"><?= $lang["chart"] ?></a>
2013-06-21 11:15:09 +02:00
</div>
2017-04-10 22:46:56 +02:00
<div id="api">
2017-04-10 22:46:56 +02:00
<u><?= $lang["api"] ?></u><br>
<form>
<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>
</select>
</form>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
<div id="lang">
2017-04-10 22:46:56 +02:00
<u><?= $lang["language"] ?></u><br>
<form>
<select name="units" onchange="setLang(this.options[this.selectedIndex].value);">
<?php asort($langsArr); ?>
<?php foreach ($langsArr as $langCode => $langName): ?>
<option value="<?= $langCode ?>"<?= ($config::$lang == $langCode) ? " selected" : "" ?>><?= $langName ?></option>
<?php endforeach; ?>
</select>
</form>
2013-06-23 23:43:09 +02:00
</div>
2017-04-10 22:46:56 +02:00
<div id="units">
2017-04-10 22:46:56 +02:00
<u><?= $lang["units"] ?></u><br>
<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>
</select>
</form>
2013-06-23 23:43:09 +02:00
</div>
2017-04-10 22:46:56 +02:00
2013-06-19 13:27:14 +02:00
<div id="export">
2017-04-10 22:46:56 +02:00
<u><?= $lang["download"] ?></u><br>
2017-04-14 17:24:09 +02:00
<a class="menulink" href="javascript:void(0);" onclick="load('kml', userid, trackid);">kml</a>
<a class="menulink" href="javascript:void(0);" onclick="load('gpx', userid, trackid);">gpx</a>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
2017-04-14 17:24:09 +02:00
<?php if ($user->isValid): ?>
2017-04-10 22:46:56 +02:00
<div id="admin_menu">
<u><?= $lang["adminmenu"] ?></u><br>
2017-04-14 17:24:09 +02:00
<?php if ($user->isAdmin): ?>
<a class="menulink" href="javascript:void(0);" onclick="addUser()"><?= $lang["adduser"] ?></a>
<a class="menulink" href="javascript:void(0);" onclick="editUser()"><?= $lang["edituser"] ?></a>
<?php endif; ?>
<a class="menulink" href="javascript:void(0);" onclick="editTrack()"><?= $lang["edittrack"] ?></a>
2017-04-10 22:46:56 +02:00
</div>
<?php endif; ?>
2013-06-19 13:27:14 +02:00
</div>
2013-06-26 19:58:55 +02:00
<div id="menu-close" onclick="toggleMenu();">»</div>
2017-04-10 22:46:56 +02:00
<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>
2017-04-10 22:46:56 +02:00
2013-06-19 13:27:14 +02:00
<div id="main">
<div id="map-canvas"></div>
<div id="bottom">
<div id="chart"></div>
2017-04-10 22:46:56 +02:00
<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>
2017-04-10 22:46:56 +02:00
</body>
</html>