<%@ 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 rptTitle="";
	String event = " ", doctorsName = "", eventDate = "";%>
<%
	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>
<style type="text/css">
.reportName {
	FONT-FAMILY: Arial;
	FONT-SIZE: 12pt;
	font-weight: bold;
}

.reportTitle {
	FONT-FAMILY: Arial;
	FONT-SIZE: 10pt;
}

.reportDetail {
	FONT-FAMILY: Arial;
	FONT-SIZE: 10pt;
	width: 300px;
	border: 1px solid;
}

.reportDetail1 {
	FONT-FAMILY: Arial;
	FONT-SIZE: 10pt;
	width: 350px;
	border: 1px solid;
}

.rowColor
{
 background-color:#D3D3D3;
 text-align:left; 
 font-weight: bold;

}
</style>
<script type="text/javascript" src="FusionCharts.js"></script>
</head>
<body>

<%
	try
	{
		
		rptTitle   = request.getParameter("rtitle");
		if (rptTitle == null || rptTitle.trim().length() == 0)
		{
			rptTitle =" " ;
		} else
		{
			if(rptTitle.equalsIgnoreCase("Y") && rptTitle.trim().length()!= 0)
			{
				rptTitle ="Important Events ";
		      }
			else{
				rptTitle =" " ;
			}
		}
		
		
		ibase.utility.UserInfoBean userInfo = (ibase.utility.UserInfoBean) session.getAttribute("USER_INFO");
		String user = userInfo.getLoginCode();
		System.out.println("user ::" + user);
		//String outputFilename = objName + user + System.currentTimeMillis();
		Context context = new InitialContext();
		ImpEventsRemote impEvents = (ImpEventsRemote) context.lookup("ibase/ImpEvents/remote");
		//DashboardPortal dashboardPortal=(DashboardPortal)context.lookup("ibase.dashboard.sfa.ejb.DashboardPortal.class.getName()");
		System.out.println("Ejb remote =>" + impEvents);
		if (user != null && user.trim().length() != 0)
		{
			xmlString = impEvents.getData(user);
			System.out.println("Return xmlString====" + xmlString);
			System.out.println("xmlString  length is ==>" + xmlString.length());
		}
%>
<%
	if (xmlString != null && xmlString.trim().length() > 0)
		{
%>
<table class="reportName">
	<tr>
		<td><%=rptTitle%> </td>
	</tr>
</table>
<table class="reportDetail1" FRAME=BOX >
	<tr class="rowColor">
		<td colspan="3">Today</td>
	</tr>
	<%
		dom = genericUtility.parseString(xmlString);
				if (dom != null)
				{

					dtlList = dom.getElementsByTagName("Detail1");
					System.out.println("Detail Node Length==" + dtlList.getLength());
					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("drname"))
							{
								doctorsName = genericUtility.getColumnValueFromNode("drname", parentNode);
							}
							if (childNodeName.trim().equals("event"))
							{
								event = genericUtility.getColumnValueFromNode("event", parentNode);
							}
						}
	%>
	<tr >
		<td><%=doctorsName%></td>
		<td><%=event%></td>
	</tr>

	<%
		}
				}
	%>
	<tr class="rowColor">
		<td colspan="3">Tomorrow</td>
	</tr>

	<%
		if (dom != null)
				{
					dom = genericUtility.parseString(xmlString);
					dtlList = dom.getElementsByTagName("Detail2");
					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("drname"))
							{
								doctorsName = genericUtility.getColumnValueFromNode("drname", parentNode);
							}
							if (childNodeName.trim().equals("event"))
							{
								event = genericUtility.getColumnValueFromNode("event", parentNode);
							}
						}
	%>
	<tr>
		<td><%=doctorsName%> -</td>
		<td><%=event%></td>
	</tr>

	<%
		}
				}
	%>


	<tr class="rowColor">
		<td colspan="3">Upcoming</td>
	</tr>
	<%
		if (dom != null)
				{
					dom = genericUtility.parseString(xmlString);
					dtlList = dom.getElementsByTagName("Detail3");
					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("event_date"))
							{
								eventDate = genericUtility.getColumnValueFromNode("event_date", parentNode);
							
							
							}

							if (childNodeName.trim().equals("drname"))
							{
								doctorsName = genericUtility.getColumnValueFromNode("drname", parentNode);
							}
							if (childNodeName.trim().equals("event"))
							{
								event = genericUtility.getColumnValueFromNode("event", parentNode);
							}
						}
	%>
	<tr>
		<td><%=eventDate%></td>
		<td><%=doctorsName%> -</td>
		<td><%=event%></td>
	</tr>

	<%
		}
				}
	%>

</table>
<%
	}

	} catch (Exception ex)
	{
		System.out.println("Exception in JSP:ImpEvents:" + ex.getMessage());
	}
%>
</body>
</html>