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/>.
|
|
|
|
*/
|
|
|
|
|
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");
|
2017-04-14 17:24:09 +02:00
|
|
|
|
2020-02-20 17:08:47 +01:00
|
|
|
$auth = new uAuth();
|
2017-08-25 13:59:19 +02:00
|
|
|
|
2020-06-10 12:40:28 +02:00
|
|
|
$action = uUtils::postString("action");
|
|
|
|
$trackId = uUtils::postInt("trackid");
|
|
|
|
$trackName = uUtils::postString("trackname");
|
2019-01-24 19:07:41 +01:00
|
|
|
|
2020-02-20 17:08:47 +01:00
|
|
|
$config = uConfig::getInstance();
|
|
|
|
$lang = (new uLang($config))->getStrings();
|
2019-02-25 10:04:09 +01:00
|
|
|
|
2020-02-20 17:08:47 +01:00
|
|
|
if (empty($action) || empty($trackId)) {
|
|
|
|
uUtils::exitWithError($lang["servererror"]);
|
|
|
|
}
|
|
|
|
$track = new uTrack($trackId);
|
2020-06-10 12:40:28 +02:00
|
|
|
if (!$track->isValid) {
|
2020-02-20 17:08:47 +01:00
|
|
|
uUtils::exitWithError($lang["servererror"]);
|
|
|
|
}
|
2020-06-10 12:40:28 +02:00
|
|
|
if (($action === "getmeta" && !$auth->hasReadAccess($track->userId)) ||
|
|
|
|
($action !== "getmeta" && !$auth->hasReadWriteAccess($track->userId))) {
|
|
|
|
uUtils::exitWithError($lang["notauthorized"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = null;
|
2017-04-14 17:24:09 +02:00
|
|
|
|
2020-02-20 17:08:47 +01:00
|
|
|
switch ($action) {
|
2017-04-14 17:24:09 +02:00
|
|
|
|
2020-06-10 12:40:28 +02:00
|
|
|
case "update":
|
2020-02-20 17:08:47 +01:00
|
|
|
if (empty($trackName) || $track->update($trackName) === false) {
|
|
|
|
uUtils::exitWithError($lang["servererror"]);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-14 17:24:09 +02:00
|
|
|
|
2020-06-10 12:40:28 +02:00
|
|
|
case "delete":
|
2020-02-20 17:08:47 +01:00
|
|
|
if ($track->delete() === false) {
|
2017-05-09 18:18:15 +02:00
|
|
|
uUtils::exitWithError($lang["servererror"]);
|
2020-02-20 17:08:47 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-06-10 12:40:28 +02:00
|
|
|
case "getmeta":
|
|
|
|
$result = [
|
|
|
|
"id" => $track->id,
|
|
|
|
"name" => $track->name,
|
|
|
|
"userId" => $track->userId,
|
|
|
|
"comment" => $track->comment
|
|
|
|
];
|
|
|
|
break;
|
|
|
|
|
2020-02-20 17:08:47 +01:00
|
|
|
default:
|
|
|
|
uUtils::exitWithError($lang["servererror"]);
|
|
|
|
break;
|
|
|
|
}
|
2017-04-14 17:24:09 +02:00
|
|
|
|
2020-06-10 12:40:28 +02:00
|
|
|
uUtils::exitWithSuccess($result);
|
2017-04-14 17:24:09 +02:00
|
|
|
|
|
|
|
?>
|