<%@ page contentType="text/html"%>
<%@ page
	import="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*"%>
<%@page import="ibase.dashboard.sfa.ejb.*"%>
<!--<%@page import="ibase.webitm.reports.utility.ResourceConstants"%>
-->
<%@page import="ibase.utility.CommonConstants"%>
<%@ page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page import="org.w3c.dom.Node"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="ibase.webitm.utility.GenericUtility"%>

<%!GenericUtility genericUtility = GenericUtility.getInstance();
	String xmlString = "";
	String objName = "";
	Document dom = null;
	NodeList dtlList = null;
	Node parentNode = null;
	NodeList childNodeList = null;
	Node currDetail = null;
	String childNodeName = "";
	String yearweek="";	
	String doctors="";
	String chemist="";
	String stockist="";
	String unlisted="";
        String rptTitle="";
	
	StringBuffer xmlData = null;
%>
<%
	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");
	int ctr = 0;
	CommonConstants.setAPPLICATION_CONTEXT(config.getServletContext().getRealPath("/"));
%>
<html>
<head>
<script type="text/javascript" src="/ibase/FusionChart/js/FusionCharts.js"> </script>

</head>
<body>


	<%
	try
	{
		
		ibase.utility.UserInfoBean userInfo = (ibase.utility.UserInfoBean) session.getAttribute("USER_INFO");
		String user = userInfo.getLoginCode();
		System.out.println("user ::" + user);

                rptTitle   = request.getParameter("rtitle");
		if (rptTitle == null || rptTitle.trim().length() == 0)
		{
			rptTitle =" " ;
		} else
		{
			if(rptTitle.equalsIgnoreCase("Y") && rptTitle.trim().length()!= 0)
			{
				rptTitle ="Customer Meeting Trends ";
		      }
			else{
				rptTitle =" " ;
			}
		}

		
		Context context = new InitialContext();
		CustomerMeetingTrendsRemote dashboardPortal = (CustomerMeetingTrendsRemote) context.lookup("ibase/CustomerMeetingTrends/remote");
		System.out.println("Ejb remote =>" + dashboardPortal);
		if (user != null && user.trim().length() != 0)
		{

			xmlString = dashboardPortal.getData(user);
			System.out.println("xmlString  length is ==>" + xmlString.length());
			System.out.println("xmlString  in jsp ==>" + xmlString);
		}
		
		xmlData = new StringBuffer("<chart caption='");
		xmlData.append(rptTitle);
		xmlData.append("' xaxisname='Week' yaxisname='Number of Visits' numdivlines='9' showSum='1' showvalues='0' useRoundEdges='1' showLabels='1'>" );
		if (xmlString != null && xmlString.trim().length() > 0)
		{
		
			dom = genericUtility.parseString(xmlString);
			if(dom !=null )
			{	
				dtlList = dom.getElementsByTagName("Detail1");
				System.out.println("Detail Node Length==" + dtlList.getLength());
				xmlData.append("<categories font='Arial' >");
				for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
				{
					parentNode = dtlList.item(cntr);
					childNodeList = parentNode.getChildNodes();
					System.out.println("child Node Length==" + childNodeList.getLength());
					for (int nodCtr = 0; nodCtr < childNodeList.getLength(); nodCtr++)
					{
						currDetail = childNodeList.item(nodCtr);
						childNodeName = currDetail.getNodeName();
						
						if (childNodeName.trim().equals("yearweek"))
						{
							//String yearweek1 = genericUtility.getColumnValueFromNode("yearweek", parentNode);
							 yearweek =currDetail.getTextContent();							
							xmlData.append("<category label='"+yearweek+"'/>");
						}
						
					}
					
			
				}
				xmlData.append("</categories>");
				
				
				dtlList = dom.getElementsByTagName("Detail2");
				System.out.println("Detail Node Length==" + dtlList.getLength());
				xmlData.append("<dataset seriesname='Doctors' color='8BBA00' showValues='0'>");
				for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
				{
					parentNode = dtlList.item(cntr);
					childNodeList = parentNode.getChildNodes();

					for (int nodCtr = 0; nodCtr < childNodeList.getLength(); nodCtr++)
					{
						currDetail = childNodeList.item(nodCtr);
						childNodeName = currDetail.getNodeName();
						if (childNodeName.trim().equals("doctor"))
						{
							//doctors = genericUtility.getColumnValueFromNode("doctor", parentNode);
							
							doctors = currDetail.getTextContent();
							
						}xmlData.append("<set value='"+doctors+"'/>");
						
					}
			
				}
				xmlData.append("</dataset>");
				
				dtlList = dom.getElementsByTagName("Detail3");
				System.out.println("Detail Node Length==" + dtlList.getLength());
				xmlData.append("<dataset seriesname='Chemist' color='F6BD0F' showValues='0'>");
				for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
				{
					parentNode = dtlList.item(cntr);
					childNodeList = parentNode.getChildNodes();

					for (int nodCtr = 0; nodCtr < childNodeList.getLength(); nodCtr++)
					{
						currDetail = childNodeList.item(nodCtr);
						childNodeName = currDetail.getNodeName();
						if (childNodeName.trim().equals("chemist"))
						{
							//chemist = genericUtility.getColumnValueFromNode("chemist", parentNode);
							chemist = currDetail.getTextContent();
							xmlData.append("<set value='"+chemist+"'/>");
						}
						
					}
			
				}
				xmlData.append("</dataset>");
				
				dtlList = dom.getElementsByTagName("Detail4");
				System.out.println("Detail Node Length==" + dtlList.getLength());
				xmlData.append("<dataset seriesname='Stockist' color='F781F3' showValues='0'>");
				for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
				{
					parentNode = dtlList.item(cntr);
					childNodeList = parentNode.getChildNodes();

					for (int nodCtr = 0; nodCtr < childNodeList.getLength(); nodCtr++)
					{
						currDetail = childNodeList.item(nodCtr);
						childNodeName = currDetail.getNodeName();
						if (childNodeName.trim().equals("stockist"))
						{
							//stockist = genericUtility.getColumnValueFromNode("stockist", parentNode);
							stockist = currDetail.getTextContent();
							xmlData.append("<set value='"+stockist+"'/>");
						}
						
					}
			
				}
				xmlData.append("</dataset>");
				
				dtlList = dom.getElementsByTagName("Detail5");
				System.out.println("Detail Node Length==" + dtlList.getLength());
				xmlData.append("<dataset seriesname='Unlisted' color='AFD8F8' showValues='0'>");
				for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
				{
					parentNode = dtlList.item(cntr);
					childNodeList = parentNode.getChildNodes();

					for (int nodCtr = 0; nodCtr < childNodeList.getLength(); nodCtr++)
					{
						currDetail = childNodeList.item(nodCtr);
						childNodeName = currDetail.getNodeName();
						if (childNodeName.trim().equals("unlisted"))
						{
							//unlisted = genericUtility.getColumnValueFromNode("unlisted", parentNode);
							unlisted =currDetail.getTextContent();
							xmlData.append("<set value='"+unlisted+"'/>");
						}
						
					}
			
				}
				xmlData.append("</dataset>");				
			}			
		}
		xmlData.append("</chart>");
		System.out.println("xmlDataString----->"+xmlData.toString());
		
%>
	<div id="chartContainer">FusionCharts XT will load here!</div>
	<script type="text/javascript">    
     
     var myChart = new FusionCharts( "/ibase/FusionChart/images/StackedColumn2D.swf", "myChartId", "250", "300","0");  
     myChart.setXMLData("<%=xmlData.toString()%>");    
     myChart.render("chartContainer");   
  
     function view2D() 
     {                    
        var chartToView2D = getChartFromId("myChartId");
        chartToView2D.view2D();
      }
   
    </script>

<%


	} catch (Exception ex)
	{
		System.out.println("Exception : ITMWizardHandlerServlet sMessageArguments(String,wizardBean) :" + ex); //$NON-NLS-1$
	}
%>

</body>
</html>
