title = "Locations" url = "/setup/locations" layout = "default" is_hidden = 0 == addJs('assets/js/setup/locations.js'); } function onAddLocation() { //get the values sent from ajax $code = $_POST['code']; $description = $_POST['description']; //wrap the mysql call into a try and catch so that we can catch any errors try { Db::insert("INSERT INTO custom_locations(code, description) VALUES(?, ?)",[$code,$description]); return 'ok'; } catch (\PDOException $e) { # do something or render a custom error page //\Flash::success('flash from ajax handler'); //return ['#flashDiv' => $this->renderPartial('flashMessage')]; return 'There was an error with adding the Location to the database. Please make sure that the Code entered is not already in use.'; } } function onEditLocation() { //get the values sent from ajax $code = $_POST['code']; $description = $_POST['description']; //wrap the mysql call into a try and catch so that we can catch any errors try { Db::insert("UPDATE custom_locations SET description=:description WHERE code=:code",[$description,$code]); return 'ok'; } catch (\PDOException $e) { return 'There was an error while updating the Locations descritpion'; } } ?> ==

Locations

{% partial 'loadLocations' %}