<%@ 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"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.text.SimpleDateFormat"%>

<%!GenericUtility genericUtility = GenericUtility.getInstance();
	String xmlString = "";
	String objName = "";
	Document dom = null;
	NodeList dtlList = null;
	Node parentNode = null;
	NodeList childNodeList = null;
	Node currDetailNode = null;
	String childNodeName = "";
	String visits="";
	String category="";
	String cyear="";
	String cmonth="";
	StringBuffer chartData=null;
	String xmlData= "";
	Calendar calender= Calendar.getInstance();
	java.util.Date date = new java.util.Date(calender.getTimeInMillis());
	String rptTitle="";		
%>
<%
	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");
		cyear = new SimpleDateFormat("yy").format(date);
		cmonth = new SimpleDateFormat("MMMM").format(date);

		rptTitle   = request.getParameter("rtitle");
		if (rptTitle == null || rptTitle.trim().length() == 0)
		{
			rptTitle =" " ;
		} else
		{
			if(rptTitle.equalsIgnoreCase("Y") && rptTitle.trim().length()!= 0)
			{
				rptTitle =" Doctors Meeting by Class for "+ cmonth + "-"+ cyear;
		      }
			else{
				rptTitle =" " ;
			}
		}
				
		String user = userInfo.getLoginCode();
		System.out.println("user ::" + user);
		Context context = new InitialContext();
		DoctorsMeetingByClassRemote dashboardPortal = (DoctorsMeetingByClassRemote) context.lookup("ibase/DoctorsMeetingByClass/remote");
		System.out.println("Ejb remote =>" + dashboardPortal);
		if (user != null && user.trim().length() != 0)
		{
			xmlString = dashboardPortal.getData(user);
		}
	     chartData=new StringBuffer("<chart caption='");
	     chartData.append(rptTitle);
	     chartData.append("' baseFont='Arial' xAxisName='Category' yAxisName='Visits' showLabels='0' showLegend='1'>");
	     dom = genericUtility.parseString(xmlString);
	    if(dom !=null )
	    {
	        dtlList = dom.getElementsByTagName("Detail");
	    	for (int cntr = 0; cntr < dtlList.getLength(); cntr++)
	    	{
	    		parentNode = dtlList.item(cntr);
	    		childNodeList = parentNode.getChildNodes();

	    		for (int nodCtr = 0; nodCtr < childNodeList.getLength(); nodCtr++)
	    		{
	    			currDetailNode = childNodeList.item(nodCtr);
	    			childNodeName = currDetailNode.getNodeName();
	    			
	    			if (childNodeName.trim().equals("category"))
	    			{
	    				category = genericUtility.getColumnValueFromNode("category", parentNode);
	    			}
	    			if(childNodeName.trim().equals("visits"))
	    			{
	    				visits = genericUtility.getColumnValueFromNode("visits", parentNode);
	    			}
	    		}
	    	chartData.append("<set label='").append(category+"' value='").append(visits+"'>").append("</set>");			
	    	}
	    }
	     chartData.append("</chart>");
	     
	     System.out.println("chartData "+chartData);
	     
%>
<div id="chartContainer">FusionCharts XT will load here!</div>
<script type="text/javascript">    
     
     var myChart = new FusionCharts("/ibase/FusionChart/images/Pie2D.swf", "myChartId", "250", "300","0");  
     myChart.setXMLData("<%= chartData.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); 
	}
%>

</body>
</html>
