ulogger-server/index.php

226 lines
9.8 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-08-25 13:59:19 +02:00
require_once(__DIR__ . "/helpers/auth.php");
require_once(ROOT_DIR . "/helpers/config.php");
2017-04-11 17:00:40 +02:00
require_once(ROOT_DIR . "/helpers/position.php");
require_once(ROOT_DIR . "/helpers/track.php");
2017-05-09 15:25:16 +02:00
require_once(ROOT_DIR . "/helpers/utils.php");
2017-08-25 13:59:19 +02:00
require_once(ROOT_DIR . "/lang.php");
$auth = new uAuth();
if (!$auth->isAuthenticated() && $auth->isLoginAttempt()) {
$auth->exitWithRedirect("login.php?auth_error=1");
2017-08-25 13:59:19 +02:00
}
if (!$auth->isAuthenticated() && uConfig::$require_authentication) {
$auth->exitWithRedirect("login.php");
2017-08-25 13:59:19 +02:00
}
2017-04-09 23:35:55 +02:00
2017-04-10 22:46:56 +02:00
$displayUserId = NULL;
$usersArr = [];
2017-08-25 13:59:19 +02:00
if ($auth->isAdmin() || uConfig::$public_tracks) {
2017-04-10 22:46:56 +02:00
// public access or admin user
// get last position user
$lastPosition = uPosition::getLast();
2017-04-10 22:46:56 +02:00
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 = uUser::getAll();
2017-08-25 13:59:19 +02:00
} else if ($auth->isAuthenticated()) {
2017-04-10 22:46:56 +02:00
// display track of authenticated user
2017-08-25 13:59:19 +02:00
$displayUserId = $auth->user->id;
2013-06-19 13:27:14 +02:00
}
2017-04-10 22:46:56 +02:00
$tracksArr = uTrack::getAll($displayUserId);
2017-04-10 22:46:56 +02:00
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
?>
<!DOCTYPE html>
2013-06-19 13:27:14 +02:00
<html>
<head>
2017-04-10 22:46:56 +02:00
<title><?= $lang["title"] ?></title>
2017-08-25 13:59:19 +02:00
<?php include("meta.php"); ?>
2013-06-19 13:27:14 +02:00
<script>
var interval = '<?= uConfig::$interval ?>';
2017-04-10 22:46:56 +02:00
var userid = '<?= ($displayUserId) ? $displayUserId : -1 ?>';
var trackid = '<?= ($displayTrackId) ? $displayTrackId : -1 ?>';
var units = '<?= uConfig::$units ?>';
var mapapi = '<?= uConfig::$mapapi ?>';
var gkey = '<?= !empty(uConfig::$gkey) ? uConfig::$gkey : "null" ?>';
var ol_layers = <?= json_encode(uConfig::$ol_layers) ?>;
var init_latitude = <?= uConfig::$init_latitude ?>;
var init_longitude = <?= uConfig::$init_longitude ?>;
2017-04-10 22:46:56 +02:00
var lang = <?= json_encode($lang) ?>;
2017-08-25 13:59:19 +02:00
var admin = <?= json_encode($auth->isAdmin()) ?>;
var auth = '<?= ($auth->isAuthenticated()) ? $auth->user->login : "null" ?>';
var pass_regex = <?= uConfig::passRegex() ?>;
var strokeWeight = <?= uConfig::$strokeWeight ?>;
var strokeColor = '<?= uConfig::$strokeColor ?>';
var strokeOpacity = <?= uConfig::$strokeOpacity ?>;
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-08-25 13:59:19 +02:00
<?php if ($auth->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-08-25 13:59:19 +02:00
<?php if ($auth->isAuthenticated()): ?>
2017-04-14 17:24:09 +02:00
<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="loadMapAPI();">
2013-06-19 13:27:14 +02:00
<div id="menu">
<div id="menu-content">
2017-04-10 22:46:56 +02:00
2017-08-25 13:59:19 +02:00
<?php if ($auth->isAuthenticated()): ?>
2017-04-10 22:46:56 +02:00
<div id="user_menu">
2017-08-25 13:59:19 +02:00
<a href="javascript:void(0);" onclick="userMenu()"><img class="icon" alt="<?= $lang["user"] ?>" src="images/user.svg"> <?= htmlspecialchars($auth->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: ?>
2017-08-25 13:59:19 +02:00
<a href="login.php"><img class="icon" alt="<?= $lang["login"] ?>" src="images/key.svg"> <?= $lang["login"] ?></a>
2017-04-10 22:46:56 +02:00
<?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)): ?>
2017-05-10 14:54:38 +02:00
<div class="menutitle" style="padding-top: 1em"><?= $lang["user"] ?></div>
2017-04-10 22:46:56 +02:00
<form>
<select name="user" onchange="selectUser(this);">
<option value="0" disabled><?= $lang["suser"] ?></option>
2017-04-10 22:46:56 +02:00
<?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-05-10 14:54:38 +02:00
<div class="menutitle"><?= $lang["track"] ?></div>
2017-04-10 22:46:56 +02:00
<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>
<input type="checkbox" onchange="autoReload();"> <?= $lang["autoreload"] ?> (<a href="javascript:void(0);" onclick="setTime();"><span id="auto"><?= uConfig::$interval ?></span></a> s)<br>
2017-04-14 16:00:53 +02:00
</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">
<a id="altitudes" 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-05-10 14:54:38 +02:00
<div class="menutitle"><?= $lang["api"] ?></div>
2017-04-10 22:46:56 +02:00
<form>
<select name="api" onchange="loadMapAPI(this.options[this.selectedIndex].value);">
<option value="gmaps"<?= (uConfig::$mapapi == "gmaps") ? " selected" : "" ?>>Google Maps</option>
<option value="openlayers"<?= (uConfig::$mapapi == "openlayers") ? " selected" : "" ?>>OpenLayers 2</option>
<option value="openlayers3"<?= (uConfig::$mapapi == "openlayers3") ? " selected" : "" ?>>OpenLayers 3+</option>
2017-04-10 22:46:56 +02:00
</select>
</form>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
<div id="lang">
2017-05-10 14:54:38 +02:00
<div class="menutitle"><?= $lang["language"] ?></div>
2017-04-10 22:46:56 +02:00
<form>
<select name="units" onchange="setLang(this.options[this.selectedIndex].value);">
<?php asort($langsArr); ?>
<?php foreach ($langsArr as $langCode => $langName): ?>
<option value="<?= $langCode ?>"<?= (uConfig::$lang == $langCode) ? " selected" : "" ?>><?= $langName ?></option>
2017-04-10 22:46:56 +02:00
<?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-05-10 14:54:38 +02:00
<div class="menutitle"><?= $lang["units"] ?></div>
2017-04-10 22:46:56 +02:00
<form>
<select name="units" onchange="setUnits(this.options[this.selectedIndex].value);">
<option value="metric"<?= (uConfig::$units == "metric") ? " selected" : "" ?>><?= $lang["metric"] ?></option>
<option value="imperial"<?= (uConfig::$units == "imperial") ? " selected" : "" ?>><?= $lang["imperial"] ?></option>
2018-07-09 21:04:28 +02:00
<option value="nautical"<?= (uConfig::$units == "nautical") ? " selected" : "" ?>><?= $lang["nautical"] ?></option>
2017-04-10 22:46:56 +02:00
</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-05-10 14:54:38 +02:00
<div class="menutitle u"><?= $lang["export"] ?></div>
2017-05-09 09:06:23 +02:00
<a class="menulink" href="javascript:void(0);" onclick="exportFile('kml', userid, trackid);">kml</a>
<a class="menulink" href="javascript:void(0);" onclick="exportFile('gpx', userid, trackid);">gpx</a>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
2017-08-25 13:59:19 +02:00
<?php if ($auth->isAuthenticated()): ?>
2017-05-09 09:06:23 +02:00
<div id="import">
2017-05-10 14:54:38 +02:00
<div class="menutitle u"><?= $lang["import"] ?></div>
2017-05-09 15:25:16 +02:00
<form id="importForm" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="<?= uUtils::getUploadMaxSize() ?>" />
2017-05-09 09:06:23 +02:00
<input type="file" id="inputFile" name="gpx" style="display:none" onchange="importFile(this)" />
</form>
<a class="menulink" href="javascript:void(0);" onclick="document.getElementById('inputFile').click();">gpx</a>
</div>
2017-04-10 22:46:56 +02:00
<div id="admin_menu">
2017-05-10 14:54:38 +02:00
<div class="menutitle u"><?= $lang["adminmenu"] ?></div>
2017-08-25 13:59:19 +02:00
<?php if ($auth->isAdmin()): ?>
2017-04-14 17:24:09 +02:00
<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>
<div id="footer"><a target="_blank" href="https://github.com/bfabiszewski/ulogger-server"><span class="mi">μ</span>logger</a> <?= uConfig::$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>