title = "Other Department Emails" url = "/setup/other-department-emails" layout = "default" is_hidden = 0 == addJs('assets/js/setup/otherDepartmentEmails.js'); $this->addJs('assets/js/dataTablesSetup.js'); $custom_responsible_department = Db::select('SELECT * FROM custom_responsible_department'); $this['custom_responsible_department'] = $custom_responsible_department; $this['restaurants'] = Db::select('SELECT * FROM custom_restaurants'); //$visitFrequency = Db::connection('hssData')->select('SELECT * FROM visitFrequency'); //$this['visitFrequency'] = $visitFrequency; } function onAddOtherDepartmentEmails() { //get the values sent from ajax $email = $_POST['email']; $restaurantAccess = $_POST['restaurantAccess']; $department = $_POST['department']; foreach ($restaurantAccess as $res) { //check if the restaurant was already added by the brand //if yes then we do not add it again $restaurantExists = Db::table('custom_user_department') ->where('email', '=', $email) ->where('restaurant_id', '=', $res) ->where('resp_department_id', '=', $department) ->first(); //if true then it means this is null if(is_null($restaurantExists)){ try { Db::table('custom_user_department')->insert(['email' => $email, 'restaurant_id' => $res, 'resp_department_id' => $department]); } catch (\PDOException $e) { return 'There was an error will adding the Restaurant Access'; } } } return 'ok'; } function onDeleteUser(){ $id = $_POST['id']; try { Db::select('DELETE FROM custom_user_department WHERE id="'.$id.'"'); 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 'error'; } } function onGetAllRestaurants(){ return Db::select('select * from custom_restaurants WHERE custom_restaurants.isDeactivated="0" '); } ?> ==