ulogger-server/utils/handletrack.php

64 lines
1.9 KiB
PHP
Raw Normal View History

2017-04-14 17:24:09 +02:00
<?php
/* μlogger
*
* Copyright(C) 2017 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/>.
*/
2017-08-25 13:59:19 +02:00
require_once(dirname(__DIR__) . "/helpers/auth.php");
2019-02-25 10:04:09 +01:00
require_once(ROOT_DIR . "/helpers/lang.php");
2017-04-14 17:24:09 +02:00
require_once(ROOT_DIR . "/helpers/track.php");
2017-05-09 18:18:15 +02:00
require_once(ROOT_DIR . "/helpers/utils.php");
2019-02-25 10:04:09 +01:00
require_once(ROOT_DIR . "/helpers/config.php");
2017-04-14 17:24:09 +02:00
2017-08-25 13:59:19 +02:00
$auth = new uAuth();
2019-01-24 19:07:41 +01:00
$action = uUtils::postString('action');
$trackId = uUtils::postInt('trackid');
$trackName = uUtils::postString('trackname');
2019-02-25 10:04:09 +01:00
$lang = (new uLang(uConfig::$lang))->getStrings();
2017-04-14 17:24:09 +02:00
if (empty($action) || empty($trackId)) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-14 17:24:09 +02:00
}
$track = new uTrack($trackId);
2017-08-25 13:59:19 +02:00
if (!$track->isValid ||
(!$auth->isAuthenticated() || (!$auth->isAdmin() && $auth->user->id !== $track->userId))) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-14 17:24:09 +02:00
}
switch ($action) {
case 'update':
if (empty($trackName) || $track->update($trackName) === false) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-14 17:24:09 +02:00
}
break;
case 'delete':
if ($track->delete() === false) {
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-14 17:24:09 +02:00
}
break;
default:
2017-05-09 18:18:15 +02:00
uUtils::exitWithError($lang["servererror"]);
2017-04-14 17:24:09 +02:00
break;
}
2017-05-09 18:18:15 +02:00
uUtils::exitWithSuccess();
2017-04-14 17:24:09 +02:00
?>