. */ function setError(&$response, $message) { $response['error'] = true; $response['message'] = $message; } define("headless", true); require_once("../auth.php"); // sets $mysqli, $user $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $response = [ 'error' => false ]; switch ($action) { // action: authorize case "auth": break; // action: adduser (currently unused) case "adduser": $login = isset($_REQUEST['login']) ? $_REQUEST['login'] : NULL; $hash = isset($_REQUEST['password']) ? password_hash($_REQUEST['password'], PASSWORD_DEFAULT) : NULL; if (!empty($login) && !empty($hash)) { $newUser = new uUser(); $newId = $newUser->add($login, $hash); if ($newId !== false) { // return user id $response['userid'] = $newId; } else { setError($response, "Server error"); } } else { setError($response, "Empty login or password"); } break; // action: addtrack case "addtrack": $trackName = isset($_REQUEST['track']) ? $_REQUEST['track'] : NULL; if (empty($trackName)) { setError($response, "missing required parameter"); break; } require_once("../helpers/track.php"); $track = new uTrack(); $trackId = $track->add($user->id, $trackName); if ($trackId === false) { setError($response, "Server error"); break; } // return track id $response['trackid'] = $trackId; break; // action: addposition case "addpos": $lat = isset($_REQUEST["lat"]) ? $_REQUEST["lat"] : NULL; $lon = isset($_REQUEST["lon"]) ? $_REQUEST["lon"] : NULL; $time = isset($_REQUEST["time"]) ? $_REQUEST["time"] : NULL; $altitude = isset($_REQUEST["altitude"]) ? $_REQUEST["altitude"] : NULL; $speed = isset($_REQUEST["speed"]) ? $_REQUEST["speed"] : NULL; $bearing = isset($_REQUEST["bearing"]) ? $_REQUEST["bearing"] : NULL; $accuracy = isset($_REQUEST["accuracy"]) ? $_REQUEST["accuracy"] : NULL; $provider = isset($_REQUEST["provider"]) ? $_REQUEST["provider"] : NULL; $comment = isset($_REQUEST["comment"]) ? $_REQUEST["comment"] : NULL; $imageId = isset($_REQUEST["imageid"]) ? $_REQUEST["imageid"] : NULL; $trackId = isset($_REQUEST["trackid"]) ? $_REQUEST["trackid"] : NULL; if (is_null($lat) || is_null($lon) || is_null($time) || is_null($trackId)) { setError($response, "missing required parameter"); break; } require_once("../helpers/position.php"); $position = new uPosition(); $positionId = $position->add($user->id, $trackId, $time, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $imageId); if ($positionId === false) { setError($response, "Server error"); } break; } $mysqli->close(); header('Content-Type: application/json'); echo json_encode($response); exit(); ?>