ulogger-server/index.php

206 lines
7.9 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");
2019-02-25 10:04:09 +01:00
require_once(ROOT_DIR . "/helpers/lang.php");
2017-08-25 13:59:19 +02:00
2019-01-24 19:07:41 +01:00
$login = uUtils::postString('user');
$pass = uUtils::postPass('pass');
$action = uUtils::postString('action');
2019-02-25 10:04:09 +01:00
$lang = (new uLang(uConfig::$lang))->getStrings();
$langsArr = uLang::getLanguages();
asort($langsArr);
2017-08-25 13:59:19 +02:00
$auth = new uAuth();
2019-01-24 19:07:41 +01:00
if ($action == "auth") {
$auth->checkLogin($login, $pass);
}
2017-08-25 13:59:19 +02:00
2019-01-24 19:07:41 +01:00
if (!$auth->isAuthenticated() && $action == "auth") {
$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-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>
<html lang="<?= uConfig::$lang ?>">
2013-06-19 13:27:14 +02:00
<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"); ?>
2019-05-15 11:32:36 +02:00
<script type="module" src="js/ulogger.js"></script>
<!-- <script src="dist/ulogger.js"></script>-->
2013-06-19 13:27:14 +02:00
</head>
2017-04-10 22:46:56 +02:00
<body>
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">
<a id="menu_head"><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 id="menu_pass"><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; ?>
<div class="section">
2017-04-10 22:46:56 +02:00
<?php if (!empty($usersArr)): ?>
<label for="user" class="menutitle"><?= $lang["user"] ?></label>
2017-04-10 22:46:56 +02:00
<form>
<select id="user" name="user">
<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
<div class="section">
<label for="track" class="menutitle"><?= $lang["track"] ?></label>
2017-04-10 22:46:56 +02:00
<form>
<select id="track" name="track">
2017-04-10 22:46:56 +02:00
<?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"> <label for="latest"><?= $lang["latest"] ?></label><br>
<input id="auto_reload" type="checkbox"> <label for="auto_reload"><?= $lang["autoreload"] ?></label> (<a id="set_time"><span id="auto"><?= uConfig::$interval ?></span></a> s)<br>
2017-04-14 16:00:53 +02:00
</form>
<a id="force_reload"> <?= $lang["reload"] ?></a><br>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
<div id="summary" class="section"></div>
2017-04-10 22:46:56 +02:00
<div id="other" class="section">
<a id="altitudes"><?= $lang["chart"] ?></a>
2013-06-21 11:15:09 +02:00
</div>
2017-04-10 22:46:56 +02:00
<div>
<label for="api" class="menutitle"><?= $lang["api"] ?></label>
2017-04-10 22:46:56 +02:00
<form>
<select id="api" name="api">
<option value="gmaps"<?= (uConfig::$mapapi == "gmaps") ? " selected" : "" ?>>Google Maps</option>
2018-11-09 16:16:26 +01:00
<option value="openlayers"<?= (uConfig::$mapapi == "openlayers") ? " selected" : "" ?>>OpenLayers</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>
<label for="lang" class="menutitle"><?= $lang["language"] ?></label>
2017-04-10 22:46:56 +02:00
<form>
<select id="lang" name="lang">
2017-04-10 22:46:56 +02:00
<?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 class="section">
<label for="units" class="menutitle"><?= $lang["units"] ?></label>
2017-04-10 22:46:56 +02:00
<form>
<select id="units" name="units">
<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
<div id="export" class="section">
2017-05-10 14:54:38 +02:00
<div class="menutitle u"><?= $lang["export"] ?></div>
<a id="export_kml" class="menulink">kml</a>
<a id="export_gpx" class="menulink">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()): ?>
<div id="import" class="section">
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() ?>" />
<input type="file" id="inputFile" name="gpx" />
2017-05-09 09:06:23 +02:00
</form>
<a id="import_gpx" class="menulink">gpx</a>
2017-05-09 09:06:23 +02:00
</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()): ?>
<a id="adduser" class="menulink"><?= $lang["adduser"] ?></a>
<a id="edituser" class="menulink"><?= $lang["edituser"] ?></a>
2017-04-14 17:24:09 +02:00
<?php endif; ?>
<a id="edittrack" class="menulink"><?= $lang["edittrack"] ?></a>
2017-04-10 22:46:56 +02:00
</div>
<?php endif; ?>
2013-06-19 13:27:14 +02:00
</div>
<div id="menu-close">»</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>
<div id="chart_close"><?= $lang["close"] ?></div>
</div>
2013-06-19 13:27:14 +02:00
</div>
2017-04-10 22:46:56 +02:00
</body>
</html>