<%-- Document : place Created on : Jan 15, 2013, 10:36:49 PM Author : Manuel --%> <%@page import="com.check1two.places.Place"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="com.check1two.places.SessionOrderBean"%> <%@page import="java.util.List"%> <%@page errorPage="exceptionHandler.jsp" %> <% com.check1two.util.ResponseUtil.setNoCache(response); com.check1two.util.RequestUtil.logRequest(request); String sessionid = request.getSession().getId(); String jsessionid = ";jsessionid="+sessionid; com.check1two.util.DebugUtil.debug = true; String placeid = request.getParameter("placeid"); java.sql.Connection con = null; //note when this page loads session order bean is null. //we better make sure we can make multiple orders. com.check1two.places.Place place = null; //we put the dispatcher here to have access to write the redirect com.check1two.places.Dispatcher dispatcher = null; //next we check that only if we have a valid int do we try to get the connection to get the place if(com.check1two.util.RequestUtil.isValidInt(placeid)){ con = com.check1two.places.MyDatasource.createPooledDatasource2().getConnection(); place = com.check1two.places.PlaceDB.readRecord(con, Integer.parseInt(placeid)); } //if we get a valid int then we will try to get the place form the database. But is someone makes a fake id then we get null //so we check to make sure that the place is not null //first we set the place to null if(place !=null){ //only show if place is open if(place.isOpen(con)){ dispatcher = place.getAvailableDispatcher(con); //not all places have delivery companies so assume always showIt boolean showIt = true; //but if delivery required if(place.isDeliveryRequired() && dispatcher == null){ showIt = false; } if(showIt){ //always get the guest user //com.check1two.places.User guestuser = com.check1two.places.UserDB.readRecord("guest@check1two.com"); //always get the user from session com.check1two.places.User user = (com.check1two.places.User)session.getAttribute("user"); //if the user is null then replace him with the guest user if(user==null){ String usermessage = "session user null"; Cookie[] cookies = request.getCookies(); String cookieName = "user"; String cookieUserEmail = util.CookieUtil.getCookieValue(cookies, cookieName); if(util.MailUtil.isValidEmailAddress(cookieUserEmail)){ user = com.check1two.places.UserDB.readRecord(cookieUserEmail); usermessage = "loaded user "+user.getName()+" "+user.getEmail(); } //the cookie user is still null so we use guest if(user==null){ user = com.check1two.places.UserDB.readRecord("guest@check1two.com"); usermessage = "guest user "+user.getName()+" "+user.getEmail(); } //if we overwrite the gues user like we did when we were doing the fb user we're fucked //so we really need to see how to create a user. String fbemail = request.getParameter("fbemail"); String fbname = request.getParameter("fbname"); if(com.check1two.util.RequestUtil.isValid(fbemail)&&com.check1two.util.RequestUtil.isValid(fbname)){ boolean isValidEmail = util.MailUtil.isValidEmailAddress(fbemail); boolean exists = com.check1two.places.UserLoginDB.emailExists(fbemail); if(isValidEmail){ //switch to that user if(exists){ user = com.check1two.places.UserDB.readRecord(fbemail); usermessage = "switched to "+user.getName()+" "+user.getEmail(); if("Please Enter Your Name".equals(user.getName())){ user.setName(fbname); //save the real name com.check1two.places.UserDB.save(user); } }else{ //create them an iringiup account but don't send email com.check1two.places.User fbuser = new com.check1two.places.User(); fbuser.setName(fbname); fbuser.setEmail(fbemail); String uuid = java.util.UUID.randomUUID().toString(); String password = uuid.substring(0, 6); fbuser.setPassword(password); com.check1two.places.UserDB.save(con, fbuser, false); user = com.check1two.places.UserDB.readRecord(fbemail); session.setAttribute("user", user); usermessage = "created user "+user.getName()+" "+user.getEmail(); } } } session.setAttribute("user", user); if(!user.getEmail().equals("guest@check1two.com")){ //save the cookie in the response String encodedEmail = util.CookieUtil.encodeEmail(user.getEmail()); Cookie cookie = util.CookieUtil.createCookie("user", encodedEmail); response.addCookie(cookie); } out.print(usermessage+"
"); }else{ //if the user from the session is not null we will override if with the //fbname fbemail if that's available and doesn't match the current user String fbemail = request.getParameter("fbemail"); String fbname = request.getParameter("fbname"); if(com.check1two.util.RequestUtil.isValid(fbemail)&&com.check1two.util.RequestUtil.isValid(fbname)){ boolean isValidEmail = util.MailUtil.isValidEmailAddress(fbemail); if(isValidEmail){ //ok now lets check to see if it's the same user //if they are the same we don't need to do //nothing but if they are not then we act on that if(!user.getEmail().equals(fbemail)){ //create them an iringiup account but don't send email com.check1two.places.User fbuser = new com.check1two.places.User(); fbuser.setName(fbname); fbuser.setEmail(fbemail); String uuid = java.util.UUID.randomUUID().toString(); String password = uuid.substring(0, 6); fbuser.setPassword(password); com.check1two.places.UserDB.save(con, fbuser, false); user = com.check1two.places.UserDB.readRecord(fbemail); session.setAttribute("user", user); //we need to set in session order bean too. }else{ session.setAttribute("user", user); } } } } //if(user==null){ // user = com.check1two.places.UserDB.readRecord("guest@check1two.com"); // session.setAttribute("user", user); //} //always get the session order bean if it is null create it and add it to the session com.check1two.places.SessionOrderBean sessionOrderBean = (com.check1two.places.SessionOrderBean)session.getAttribute("sessionOrderBean"); if(sessionOrderBean==null){ sessionOrderBean = new com.check1two.places.SessionOrderBean(); //do the promotion stuff String cid = request.getParameter("cid"); if(com.check1two.util.RequestUtil.isValid(cid)){ java.util.Map map = new java.util.HashMap(); map.put("cid", cid); sessionOrderBean.setParameterMap(map); } //do the embed stuff String embed = request.getParameter("embed"); if(com.check1two.util.RequestUtil.isValid(embed)){ sessionOrderBean.setEmbed(true); } //do the referal stuff String ref = request.getParameter("ref"); if(com.check1two.util.RequestUtil.isValid(ref)){ sessionOrderBean.setRef(ref); } //applebees in hammond doens't have a dispactcher they are a pickup only place if(dispatcher!=null){ //add the dispatcher that is going to do the order //this allows us to use a non primary dispatcher sessionOrderBean.setDispatcherId(dispatcher.getId()); } sessionOrderBean.setUser(user); com.check1two.places.LoggerUtil.info("place.jsp setting into sessionOrderBean 100 : "+place); sessionOrderBean.setPlace(place); //this helps us eliminate the login once needed in OrderUtil and fixes showing the button in order.jsp when having 1 option String orderType = com.check1two.places.OrderTypesUtil.getPlaceDefaultOrderType(Integer.parseInt(place.getId())); sessionOrderBean.setOrderType(orderType); session.setAttribute("sessionOrderBean", sessionOrderBean); }else{ //we need this else stament because of previous sessions and previous items. Place sessionOrderBeanPlace = sessionOrderBean.getPlace(); if(!sessionOrderBeanPlace.getId().equals(place.getId())){ //different place reset the bean sessionOrderBean = new com.check1two.places.SessionOrderBean(); //do the promotion stuff String cid = request.getParameter("cid"); if(com.check1two.util.RequestUtil.isValid(cid)){ java.util.Map map = new java.util.HashMap(); map.put("cid", cid); sessionOrderBean.setParameterMap(map); } //do the embed stuff //this is great because lets say it's set on enbed but not on way back it's still there String embed = request.getParameter("embed"); if(com.check1two.util.RequestUtil.isValid(embed)){ sessionOrderBean.setEmbed(true); } //do the referal stuff String ref = request.getParameter("ref"); if(com.check1two.util.RequestUtil.isValid(ref)){ sessionOrderBean.setRef(ref); } //applebees in hammond doens't have a dispactcher they are a pickup only place if(dispatcher!=null){ //add the dispatcher that is going to do the order //this allows us to use a non primary dispatcher sessionOrderBean.setDispatcherId(dispatcher.getId()); } sessionOrderBean.setUser(user); com.check1two.places.LoggerUtil.info("places.jsp 116 resetting stale session with new data."); sessionOrderBean.setPlace(place); //this helps us eliminate the login once needed in OrderUtil and fixes showing the button in order.jsp when having 1 option String orderType = com.check1two.places.OrderTypesUtil.getPlaceDefaultOrderType(Integer.parseInt(place.getId())); sessionOrderBean.setOrderType(orderType); session.setAttribute("sessionOrderBean", sessionOrderBean); }else{ //this is just for debuggin purposes //String userEmail = user.getEmail(); //out.println("userEmail:"+userEmail+"
"); //String sessionUserEmail = ((com.check1two.places.User)session.getAttribute("user")).getEmail(); //out.println("sessionUserEmail"+sessionUserEmail+"
"); //String sessionOrderBeanUserEmail = sessionOrderBean.getUser().getEmail(); //out.println("sessionOrderBeanUserEmail"+sessionOrderBeanUserEmail+"
"); //since the logic above may have changed the user set the user into the session order bean here. sessionOrderBean.setUser(user); //do the promotion stuff String cid = request.getParameter("cid"); if(com.check1two.util.RequestUtil.isValid(cid)){ java.util.Map map = new java.util.HashMap(); map.put("cid", cid); sessionOrderBean.setParameterMap(map); } //do the referal stuff String ref = request.getParameter("ref"); if(com.check1two.util.RequestUtil.isValid(ref)){ sessionOrderBean.setRef(ref); } } } //GET THE ORDER ITEM //added this because of race condition on android where order page was showing geedunk and place page was showing shamroc /* if(sessionOrderBean!=null){ //added this because if type place?placeid=21 and add items then type place?placeid=28 view order i would see items for wrong place if(sessionOrderBean.getPlace()!=null){ int sessionorderbeanplaceid = sessionOrderBean.getPlace().getId(); int parameterplaceid = place.getId(); if(parameterplaceid!=sessionorderbeanplaceid){ sessionOrderBean = new SessionOrderBean(); } } sessionOrderBean.setPlace(place); session.setAttribute("sessionOrderBean", sessionOrderBean); } */ //HANDLE THE ORDER ITEMS String action = request.getParameter("action"); if(com.check1two.util.RequestUtil.isValid(action)&& "additemtoorder".equalsIgnoreCase(action)){ String itemid = request.getParameter("itemid"); String itemid2 = request.getParameter("itemid2"); if(com.check1two.util.RequestUtil.isValidInt(itemid)&&com.check1two.util.RequestUtil.isValidInt(itemid2)){ com.check1two.places.IItem iitem = new com.check1two.places.ItemBD(); if(place.getName().toLowerCase().contains("check1two")){ iitem = new com.check1two.places.Check1TwoAlphabetMenuItemDB(); } com.check1two.places.Item item = iitem.readRecord(itemid); /* done above //create the order add item to the order if(sessionOrderBean == null){ sessionOrderBean = new com.check1two.places.SessionOrderBean(); //if cookies are off then i wont be able to add more than 1 item //and when i click view order it will log me out. //out.print(sessionOrderBean); sessionOrderBean.setPlace(place); sessionOrderBean.setUser((com.check1two.places.User)session.getAttribute("user")); session.setAttribute("sessionOrderBean", sessionOrderBean); } */ //here we set the item price since it can be S M L etc. //careful duplicate logic in the bottom of this app String itemPrice = item.getPrice(); //here we will use logic to make x number of buttons made on item price. itemPrice = itemPrice.trim();//make sure we get rig of spaces arounf it String itemPrices [] = itemPrice.split(" "); if(itemPrices.length>1){ item.setPrice(itemPrices[Integer.parseInt(itemid2)]);//so now our item has 1 price instead of 3 //also need to set the description we must tell people this is how you do multiple items, only if item has more than1 price. String itemDescription = item.getDescription(); itemDescription = itemDescription.trim(); String itemDescriptions [] = itemDescription.split(" "); //only do this if the size matches if(itemPrices.length == itemDescriptions.length){ item.setDescription(itemDescriptions[Integer.parseInt(itemid2)]); } } sessionOrderBean.addItem(item); out.println("Adding "+item.getName()+" to order. You have "+sessionOrderBean.getOrderItems().size()+" item(s) in your order."); } } /* //get user String username = "Guest"; if(sessionOrderBean == null){ com.check1two.places.User user = (com.check1two.places.User)session.getAttribute("user"); if(user!=null){ username = user.getName(); }else{ //username = "Chuck Norris"; //we get here when we do a deep link into the place.jsp //for example https://check1two.com/places/place.jsp?placeid=21 com.check1two.places.User guestuser = com.check1two.places.UserDB.readRecord("guest@check1two.com"); username = guestuser.getName(); //save user in session session.setAttribute("user", guestuser); //save user in session order bean //sessionOrderBean.setUser(guestuser);//it's null //save sesson order bean in session //session.setAttribute("sessionOrderBean", sessionOrderBean); } }else{ com.check1two.places.User user = sessionOrderBean.getUser(); if(user!=null){ username = user.getName(); } } */ //****************************************************************************** //get menus com.check1two.places.IMenu imenu = new com.check1two.places.MenuDB(); if(place.getName().toLowerCase().contains("check1two")){ imenu = new com.check1two.places.AlphabetMenuDB(); } //this shows the menu title //if(place.getName().toLowerCase().contains("slidell")){ // imenu = new com.check1two.places.AnythingDeliveredMenu(); //} List menus = imenu.readRecords(placeid); %> <%=sessionid%> - <%=sessionOrderBean.getUser().getEmail()%> - <%=sessionOrderBean.getPlace().getName()%> @ <%=sessionOrderBean.getPlace().getAddress()%> <%=sessionOrderBean.getTotal()%>
<% if("471".equals(placeid)){ %> <%-- --%> <% } %>
<%----%>
<%-- --%> Cajun Tyme
<% //if embed is there don't show back button, otherwise show it. if(!sessionOrderBean.isEmbed()){ String url = "goplaces.jsp"; //add the lat lon to the url if they are not null //we saw when entering from 535-fast.com and pressing back they were null //we sent them not in hidden request parameters so lets check there too //String lat = (String)session.getAttribute("lat"); //String lon = (String)session.getAttribute("lon"); //if(com.check1two.util.RequestUtil.isValid(lat)&&com.check1two.util.RequestUtil.isValid(lon)){ // url = url+"?lat="+lat+"&lon="+lon; //}else{ //if it's not in the session the check the new hidden parameters sent in the menu link String lat = request.getParameter("lat"); String lon = request.getParameter("lon"); if(com.check1two.util.RequestUtil.isValid(lat)&&com.check1two.util.RequestUtil.isValid(lon)){ url = url+"?lat="+lat+"&lon="+lon; } //} //here we make the go places button go to the city of the delivery partner boolean isRemoteOrderingSystem = "REMOTE ORDERING SYSTEM".equals(place.getName().toUpperCase()); if(isRemoteOrderingSystem){ lat = place.getLat(); lon = place.getLon(); url = "goplaces.jsp"; url = url+"?lat="+lat+"&lon="+lon; } %> <% if("471".equals(placeid)){ %> <% }else{ %> <% } }//end is enbed %>
method="post">
<%=place.getName().toUpperCase()%> <% if(dispatcher!=null){ out.println(" - delivered by "+dispatcher.getName()); out.println(""); } %>
<%-- --%> <% }//end if }//end for %> <%--
--%> <% for(int i=0;i <%--
<%=menuName%>
--%> <%-- --%> <% for(int j=0;j <%-- --%> <%}//end if item.isEnabled } %>

<%=menuName%>

Name Desc Add
<%=itemName%>
<%=itemDescription%>
<%=itemPrice%> <% for(int k=0;k <%--
method="post">--%> <%----%>
<% } %>
<%--
--%>
<%-- --%> <% }else{ out.println("

no delivery drivers available on duty in our system to support delivery operations for this place at this time but you can try youdeliver.us and grow your credit.

"); } }else{ out.println("

"+place.getName()+" is currently closed

"); out.println("

Become A Driver Today So We Can Stay Open Longer Tomorrow

"); } }else{ out.println("place is null"); } if(con!=null){ con.close(); } %>