/*
 * Author:Wasim Ansari
 * Date:02-FEB-15
 * Request ID:D14IKAT004 (PO Wizard)
 */
package ibase.webitm.servlet.wms;


import ibase.utility.CommonConstants;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Messages;


public class PorderForm2Servlet extends HttpServlet 
{
	private static final long serialVersionUID = 1L;

   
    public PorderForm2Servlet()
    {
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		doPost( request, response );
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("XXXXXXXXXXXXXXXXXXXXXX[ Form2Servlet ]XXXXXXXXXXXXXXXXXXXX");
		
		request.setCharacterEncoding(CommonConstants.ENCODING);
		
		String htmlData = ""; //$NON-NLS-1$

		ibase.utility.UserInfoBean userInfo = ( ibase.utility.UserInfoBean )request.getSession().getAttribute( "USER_INFO" ); //$NON-NLS-1$
		
		if(userInfo != null)
		{
			String objName 	= request.getParameter("OBJ_NAME");//Storing ObjectName //$NON-NLS-1$
			String formNo 	= request.getParameter("FORM_NO");//Storing Current FormNo //$NON-NLS-1$
			String action	= request.getParameter("action");//Which actions is performed e.g. 'Next','Previous','Finish' //$NON-NLS-1$
			String formType = request.getParameter("formType");//Type of form to implement MultipleForms //$NON-NLS-1$
			
			System.out.println("OBJ_NAME="+objName);
			System.out.println("FORMNO="+formNo);
			System.out.println("ACTION="+action);
			System.out.println("FORMTYPE="+formType);
			
			String PRE_FORM_VAL = request.getParameter("PRE_FORM_VAL");
			System.out.println(PRE_FORM_VAL);
			
			if ( request.getSession().getAttribute(  "WIZARD_BEAN_" + objName ) != null ) //$NON-NLS-1$
			{
				System.out.println(" wizard object found...."); //$NON-NLS-1$
				
				if ( "previous".equalsIgnoreCase( action ) && "2".equalsIgnoreCase( formNo )  ) //$NON-NLS-1$ //$NON-NLS-2$
				{
					request.getSession().removeAttribute( "WIZARD_BEAN_" + objName ); //$NON-NLS-1$
					request.getRequestDispatcher("/webitm/jsp/PorderPage.jsp").forward(request, response); //$NON-NLS-1$
					//response.sendRedirect("/ibase/webitm/jsp/ProdWizardPage.jsp?OBJ_NAME="+objName+"&PRE_FORM_VAL="+preFormVal);
				}
			}
		}
		else
		{
			htmlData = Messages.getString("ITMWizardHandlerServlet_notLoggedIn")+"\n"+Messages.getString("ITMWizardHandlerServlet_pleaseReLogin"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		}
		
		
	}	
	

}
