title = "Restaurants" url = "/setup/restaurants" layout = "default" is_hidden = 0 == addJs('assets/js/setup/restaurants.js'); $this->addJs('assets/js/dataTablesSetup.js'); $brands = Db::select('SELECT * FROM custom_brands'); $this['brands'] = $brands; $cities = Db::select('SELECT * FROM custom_cities'); $this['cities'] = $cities; //$visitFrequency = Db::connection('hssData')->select('SELECT * FROM visitFrequency'); //$this['visitFrequency'] = $visitFrequency; } function onAddRestaurant() { //get the values sent from ajax $code = $_POST['code']; $name = $_POST['name']; $brandCode = $_POST['brand']; $city = $_POST['city']; //wrap the mysql call into a try and catch so that we can catch any errors try { Db::insert("INSERT INTO custom_restaurants(code, name, brandCode, city) VALUES(?, ?, ?, ?)",[$code,$name,$brandCode,$city]); 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 Restaurants to the database. Please make sure that the Code entered is not already in use.'; } } function onEditRestaurant() { //get the values sent from ajax $id = $_POST['id']; $code = $_POST['code']; $name = $_POST['name']; $brandCode = $_POST['brand']; $city = $_POST['city']; $isDeactivated = $_POST['disable']; //wrap the mysql call into a try and catch so that we can catch any errors try { Db::insert("UPDATE custom_restaurants SET code=:code, name=:name, brandCode=:brandCode, city=:city, isDeactivated=:isDeactivated WHERE id=:id",[$code,$name,$brandCode,$city,$isDeactivated,$id]); return 'ok'; } catch (\PDOException $e) { Log::info('Update Error'.$e); return 'There was an error while updating the Restaurant details'; } } ?> ==

Restaurants

{% partial 'loadRestaurants' %}