
<% 	System.out.println("****In PopUp.jsp****"); %>
<%@page import="ibase.webitm.bean.*, ibase.utility.CommonConstants"%>
<%@page import="ibase.webitm.utility.ITMException"%>
<%@page import="ibase.utility.*"%>
<%@page import="ibase.utility.UserInfoBean"%>
<%@page import="java.io.*,java.util.*,java.util.zip.*"%>
<%
	response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
	response.setHeader("Cache-Control", "no-store, no-cache,must-revalidate");
	response.addHeader("Cache-Control", "post-check=0, pre-check=0");
	response.setHeader("Pragma", "no-cache");

	try
	{
		
	  System.out.println("==========CDPopUp.jsp=================");
	 // String value1 = request.getParameter("cust_code");
	//  System.out.println("value1 :"+value1); 
	 
	//  String value2 = request.getParameter("CUST_CODE");
	  
	//  System.out.println("value2 :"+value2); 

	  String objName = null;	
	  if( request.getParameter("OBJ_NAME") != null && ( request.getParameter("OBJ_NAME") != (String)session.getAttribute( "OBJ_NAME" ) ))
	  {
		  objName = request.getParameter("OBJ_NAME");
	  }
	  else
	  {
		  objName = (String)session.getAttribute( "OBJ_NAME" );
	  }
	  String pgContext = "";
	  String fieldName = request.getParameter("FIELDNAME");
	  fieldName = fieldName.trim();
	  int pos = fieldName.lastIndexOf(".");
	  fieldName = fieldName.substring(pos+1,fieldName.length());
	  StringTokenizer st = null;
	  String[] parameters = null;
	  String keyString = request.getParameter("KEYSTRING");
	  
	  System.out.println("objName :"+objName);
	  System.out.println("fieldName :"+fieldName);
	  System.out.println("keyString :"+keyString);
	  
	  
	  if(keyString != null)
	  {
		  keyString = keyString.substring( 1 ).trim();
		  System.out.println("!!!!!!!keyString :"+keyString);
		  st = new StringTokenizer(keyString, ":");
		  System.out.println("st :"+st);
	  }
	  
	  if(st != null && st.countTokens() > 1)
	  {
		  System.out.println("============IF========"); 
		  parameters = new String[ st.countTokens() ];
		  int ctr = 0;
		  boolean flag = false;
		  while( st.hasMoreTokens() )
		  {
			  String curToken = st.nextToken();
			  if(curToken.indexOf(".") != -1)
			  {
				  curToken = curToken.substring(curToken.indexOf(".")+1);
			  }
			  flag = true;
			  curToken = (curToken.indexOf(",") != -1)?curToken.substring(0,curToken.indexOf(",")):curToken;
			  System.out.println("curToken: "+curToken);
			  parameters[ctr] = request.getParameter(curToken);
			  System.out.println("parameters with :"+" :ctr :"+parameters[ctr]);
			  ctr++;
		  }
	  }
	  else
	  {
		  System.out.println("=============ELSE===========");
		  parameters = new String[1];
		  if( ( keyString != null ) && ( keyString.indexOf(".") != -1 ) )
		  {
			  keyString = keyString.substring(keyString.indexOf(".")+1);
			  parameters[0] = request.getParameter(keyString);
		  }
		  else
		  {
			  parameters[0] = request.getParameter(keyString);
		  }
	  }

	  PopUpBean popUpBean = new PopUpBean();
	  popUpBean.setObjName(objName);
	  popUpBean.setUserInfoBean( ( ibase.utility.UserInfoBean )session.getAttribute( "USER_INFO" ) );

	  
	  System.out.println("fieldName :"+fieldName);
	  System.out.println("parameters :"+parameters);
	  System.out.println("parameters.length :"+parameters.length);
	  System.out.println("fieldName@@@@@@@ :"+request.getParameter("fieldName"));
	  if(request.getParameter("fieldName").equals("ref_no"))
	  {
		  System.out.println("111"+request.getParameter("cust_code"));
		  parameters[0]= request.getParameter("site_code");
		  parameters[1]= request.getParameter("cust_code");
		  parameters[2]= request.getParameter("ref_ser");
	  }
	  
	  if(request.getParameter("fieldName").equals("ref_ser"))
	  {
		  System.out.println("site_code :"+request.getParameter("site_code"));
		  System.out.println("cust_code :"+request.getParameter("cust_code"));
		  parameters[0]= request.getParameter("site_code");
		  parameters[1]= request.getParameter("cust_code");
	  }
	  
	  for(int i = 0; i < parameters.length; i++)
	  {
		  System.out.println("@@@@ "+parameters[i]);
	  }
	  
	  String xmlString = popUpBean.getPopUpXML(fieldName, parameters);
	  
	  System.out.println("xmlString!!!!!!!!!!!!!!!!!!!! :"+xmlString);

	  byte data[] = new byte[0];	
	  if(xmlString == null)
	  {
		  xmlString = "<Root></Root>";
	  }
	  else
	  {
		  xmlString = xmlString;
	  }
	  
	  String retHTMLStr = "";
	  if (("1").equalsIgnoreCase(CommonConstants.POPUP_TRANSFORM_FLAG))//prerna 14/04/2006
	  {
		  System.out.println("Starting XML Transformation ");
		  ValidateXMLInput vxi = new ValidateXMLInput();
		  retHTMLStr =  ( new ibase.webitm.utility.GenericUtility() ).transformToString( CommonConstants.APPLICATION_CONTEXT + "webitm" + File.separator + "xsl" + File.separator + "receipt_popup.xsl", xmlString, CommonConstants.APPLICATION_CONTEXT + File.separator + "temp", "output", ".html" );
		  System.out.println("XML Transformation Completed");
	  }
	  else
	  {
		  System.out.println("NO Transformation ");
		  retHTMLStr = "<html></body><>center>NO DATA FOUND</center></body></html>";
	  }
	  out.println(retHTMLStr);
	}
	catch(Exception e)
	{
	  System.out.println(e);
	  throw new ITMException(e);
	}
%>
