ulogger-server/utils/handleposition.php

66 lines
1.9 KiB
PHP
Raw Normal View History

2020-01-13 22:57:13 +01:00
<?php
/* μlogger
*
* Copyright(C) 2020 Bartek Fabiszewski (www.fabiszewski.net)
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 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 General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
2020-02-20 17:08:47 +01:00
require_once(dirname(__DIR__) . "/helpers/auth.php");
require_once(ROOT_DIR . "/helpers/lang.php");
require_once(ROOT_DIR . "/helpers/track.php");
require_once(ROOT_DIR . "/helpers/utils.php");
require_once(ROOT_DIR . "/helpers/config.php");
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
$auth = new uAuth();
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
$action = uUtils::postString('action');
$positionId = uUtils::postInt('posid');
$comment = uUtils::postString('comment');
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
$config = uConfig::getInstance();
$lang = (new uLang($config))->getStrings();
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
if (empty($action) || empty($positionId)) {
uUtils::exitWithError($lang["servererror"]);
}
$position = new uPosition($positionId);
if (!$position->isValid ||
(!$auth->isAuthenticated() || (!$auth->isAdmin() && $auth->user->id !== $position->userId))) {
uUtils::exitWithError($lang["servererror"]);
}
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
switch ($action) {
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
case 'update':
$position->comment = $comment;
if ($position->update() === false) {
uUtils::exitWithError($lang["servererror"]);
}
break;
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
case 'delete':
if ($position->delete() === false) {
2020-01-13 22:57:13 +01:00
uUtils::exitWithError($lang["servererror"]);
2020-02-20 17:08:47 +01:00
}
break;
default:
uUtils::exitWithError($lang["servererror"]);
break;
}
2020-01-13 22:57:13 +01:00
2020-02-20 17:08:47 +01:00
uUtils::exitWithSuccess();
2020-01-13 22:57:13 +01:00
?>