public function action_delete_route($id) { $route = ORM::factory('bwfl_user_route', $id); try { $route->delete(); } catch (Exception $e) { Bwfl_Flash::write('error', $e->getMessage()); return; } $user_routes = $this->_user->routes->find_all(); $this->template->content = View::factory('blocks/content/map')->set('user', $this->_user)->set('user_routes', $user_routes); $this->template->page_title = 'Map a Route | BeeWell For Life Route Saved'; $this->template->page_desc = $this->template->page_title; Bwfl_Flash::write('success', 'Success, route has been deleted.'); }
public static function saveRoute($data) { /** Load ORM object for current user and check routes If a route with the current name exists delete and add again, otherwise just add it */ $uid = $data['user_id']; $route_name = preg_replace('/\\s/', '-', $data['name']); $check_name_sql = "SELECT id FROM user_routes WHERE name=:name AND user_id=:id"; $result = DB::query(Database::SELECT, $check_name_sql)->param(':name', $route_name)->param(':id', $uid)->execute(); if ($result->offsetExists(0)) { foreach ($result as $row) { $delete_routeID = $row['id']; } $deleteSQL = "DELETE FROM user_routes WHERE id = " . $delete_routeID . " AND user_id = " . $uid; $delete = DB::query('delete', $deleteSQL)->execute(); } try { $route = ORM::factory('bwfl_user_route'); $route->miles = $data['miles']; $route->name = $route_name; $route->user_id = $data['user_id']; $route->date_created = date('Y-m-d', time()); $route->save(); $routeID = $route->pk(); $coordinates = ORM::factory('bwfl_coordinates'); if (isset($data['lat']) && isset($data['lng'])) { if (is_array($data['lat']) && is_array($data['lng'])) { $coordinates->saveCoordinates($data['lat'], $data['lng'], $routeID); } } } catch (ORM_Validation_Exception $e) { Bwfl_Flash::write('error', $e->errors('model')); return; } catch (Exception $e) { Bwfl_Flash::write('error', $e->getMessage()); return; } $success_clean_name = Security::xss_clean(stripslashes($data['name'])); Bwfl_Flash::write('success', 'Your ' . strip_tags($data['miles']) . ' mile route "' . $success_clean_name . '" has been saved. <br /> Go back to the <a href="/">Dashboard</a> to log your miles.'); //return $routeID; }
<div class="map" role="main"> <h1 class="entry-title">» Map a Route</h1> <?php echo Bwfl_Flash::html(); ?> <p class="intro">This planning tool lets you map out your route and save it for future use. Once you’ve saved your route, and calculated your distance, go back to the <a href="/">Dashboard</a> page to log your miles.</p> <div class="saved-routes"> <!-- <h2>My Saved Routes:</h2> --> <table caption="My Saved Routes:" summary="This is a summary of my tabular data." id="mySavedRoutes"> <caption>My Saved Routes:</caption> <thead id="savedHead"> <tr> <th id="itemcolumn" scope="col"><span>Route Name</span></th> <th id="col1" scope="col"><span>Miles</span></th> <th id="col2" scope="col"><span>Delete</span></th> </tr> </thead> <tfoot> <tr> <td colspan="3"></td> </tr> </tfoot> <tbody> <?php if (sizeof($user_routes)) { ?> <?php $i = 1; ?> <?php foreach ($user_routes as $route) {