function logAPoint($pTime, $pLat, $pLong) { $rsp = new JsonResponse_Basic("Problem logging point."); // Connect to database $conn = getDatabaseConnection(); // Now create a new trip with that user id, empty notes for now $statement = $conn->prepare('INSERT INTO waypoints (trip, time, triporderindex, latitude, longitude) VALUES(:trid, :t, :ord, :lat, :long)'); // Execute with given user id $statement->execute(array(':trid' => $_SESSION["tripid"], ':t' => $pTime, ':ord' => $_SESSION["triporderindex"], ':lat' => $pLat, ':long' => $pLong)); // Disconnect from db $conn = null; // Increment which point you're on, be done $_SESSION["triporderindex"] += 1; $rsp->setSuccessful(); $rsp->respondAndExit(); }
handleTemplateSpecifics($request, $response, $args, $templateName, $htdoc); // Return document to client echo $htdoc->saveHTML(); }); // Route for attempting to log in $app->post('/login', function () { validateAndCreateSession($_POST['username'], $_POST['password']); }); // Route for logging out $app->get('/logout', function () { endLogInSession(); }); // Middleware function to return empty error response if not logged in $RequireAuthMW = function ($request, $response, $next) { if (!hasValidSession()) { $rsp = new JsonResponse_Basic("Authentication required for route."); $rsp->respondAndExit(); } $response = $next($request, $response); return $response; }; // Route for starting a trip $app->get('/startTrip', function () { startTrippin(); })->add($RequireAuthMW); // Route for stopping a trip $app->get('/stopTrip', function () { stopTrippin(); })->add($RequireAuthMW); // Route for logging a point during a trip $app->post('/logPoint', function () {