. */ 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"); $auth = new uAuth(); $action = uUtils::postString("action"); $positionId = uUtils::postInt("posid"); $comment = uUtils::postString("comment"); $config = uConfig::getInstance(); $lang = (new uLang($config))->getStrings(); if (empty($action) || empty($positionId)) { uUtils::exitWithError($lang["servererror"]); } $position = new uPosition($positionId); if (!$position->isValid || !$auth->hasReadWriteAccess($position->userId)) { uUtils::exitWithError($lang["notauthorized"]); } $data = null; switch ($action) { case "update": $position->comment = $comment; if ($position->update() === false) { uUtils::exitWithError($lang["servererror"]); } break; case "delete": if ($position->delete() === false) { uUtils::exitWithError($lang["servererror"]); } break; case "imageadd": try { $fileMeta = uUtils::requireFile("image"); if ($position->setImage($fileMeta) === false) { uUtils::exitWithError($lang["servererror"]); } $data = [ "image" => $position->image ]; } catch (ErrorException $ee) { $message = $lang["servererror"]; $message .= ": {$ee->getMessage()}"; uUtils::exitWithError($message); } catch (Exception $e) { $message = $lang["iuploadfailure"]; $message .= ": {$e->getMessage()}"; uUtils::exitWithError($message); } break; case "imagedel": if ($position->removeImage() === false) { uUtils::exitWithError($lang["servererror"]); } break; default: uUtils::exitWithError($lang["servererror"]); break; } uUtils::exitWithSuccess($data); ?>