<%@ page import = "java.io.*" %>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.util.Date"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "java.text.SimpleDateFormat" %>

<%@ page import = "java.text.*"%>
<%@ page import = "java.net.*"%>
<%@ page import = "java.security.*"%>
<%@ page import = "java.net.URLDecoder"%>
<%@ page import = "sun.misc.*"%>
<%@ page import = "javax.security.cert.*"%>
<%@ page import = "javax.net.*"%>
<%@ page import = "javax.net.ssl.*"%>

<%@ page import = "egurkha.EgDbAdapterUI"%>
<%@ page import = "com.eg.EgDbAdapterTypeUI"%>
<%@ page import = "com.egurkha.monitor.alarms.*"%>
<%@ page import = "com.egurkha.*"%>
<%@ page import = "com.eg.EgAlarmTable"%>
<%@ page import = "egurkha.reporter.ErUserData"%>

<%@ page import = "com.eg.*"%>
<%@ page import	= "com.egurkha.util.*" %>
<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.eg.EgInstallInfo" %>
<%@ page import = "com.egurkha.admin.mfa.GoogleAuthenticator"%>

<%@ taglib prefix = "egui" uri = "../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<style type="text/css">

	h2
	{
		font-family: verdana, sans-serif;
		font-size: 16px;
		letter-spacing: 0.6pt;
	}

	table.tDesign
	{
		border-width: 1px;
		border-spacing: 2px;
		border-style: outset;
		border-color: black;
		border-collapse: separate;
		empty-cells:hide;
	}

	table.tDesign th
	{
		border-width: 1px;
		padding: 5px;
		border-style: inset;
		border-color: gray;
		background-color: rgb(255, 255, 240);
	}

	table.tDesign td
	{
		border-width: 1px;
		padding: 5px 5px;
		border-style: inset;
		border-color: gray;
	}

	.main
	{
		padding: 5px;
		color: #010208;
	}

	.demo
	{
		height: 250px;
		padding: 5px;
	}

	.portal
	{
		padding: 5px;
	}
	.status
	{
		float: left;
		/*position: fixed;*/
		left: 0;
		bottom: 0;
		padding: 5px;
	}

	.crl{
		clear:both;margin-top:5px;
	}
</style>

<%!
	String hostName[] ={"https://egontap.eginnovations.com","https://customer.eginnovations.com/egcrm/","http://egcs11.eginnovations.com","https://egcs21.eginnovations.com","https://www.eginnovations.com"};
	String arr[]={"tick.JPG","wrong.jpg"};
	String userArray[] = {"bob","kim","mike","tom","jim","tim","jeff","sam","ken","keith","julie","mark","adam","moby","ovm","xchg","apmcode","apminfra","rum","nutanix","nutanixvdi","sharepoint","portals"};
%>

<%
	String pageCode = request.getParameter("pageCode");

	String UName1 = "";
	String Pwd1 = "";

	Cookie cookie = null;
	Cookie[] cookies = null;

	if(pageCode != null)
	{
		if(pageCode.equals("demoCode"))
		{
			UName1 = request.getParameter("username");
			Pwd1 = request.getParameter("password");
		}
	}
	else
	{
		// Get an array of Cookies associated with this domain
		cookies = request.getCookies();
		if( cookies != null )
		{
			for (int i = 0; i < cookies.length; i++)
			{
				cookie = cookies[i];
				if(cookie.getName( ).equals("user_name"))
					UName1 = cookie.getValue( );
				else if(cookie.getName( ).equals("password"))
					Pwd1 = cookie.getValue( );
			}
		}
	}

	if(UName1 == null || Pwd1 == null)
	{
		response.sendRedirect("demoAlerts.jsp");
	}
	else if (!(UName1.equals("admin")) || !(Pwd1.equals("Admin!@#")))
	{
	%>
		<script>
			window.alert("Please, Enter the Correct Credentials")
		</script>
	<%
		response.sendRedirect("demoAlerts.jsp");
	}

	int alerts = 0;
	int unknowns = 0;

	String p_status = "";
	String count = "1";
	String status = null;
	int val = -1;

	ArrayList user_list = new ArrayList();
	Hashtable user_server = new Hashtable();

	HashMap userQuery = new HashMap();
	HashMap portalStatus = new HashMap();
	HashMap errorMsg = new HashMap();
	HashMap mapAlarmCount = new HashMap();
	HashMap demoDescption = new HashMap();
	HashMap licensePortal = new HashMap();

	mapAlarmCount.put("bob","c1,mj1,mr2"); //("name","critical,major,minor")
	mapAlarmCount.put("jim","c1,mj1,mr2");
	mapAlarmCount.put("jeff","c1,mj1,mr2");
	mapAlarmCount.put("mark","c1,mj1,mr2");
	mapAlarmCount.put("kim","c1,mj2,mr2");
	mapAlarmCount.put("mike","c1,mj2,mr2");
	mapAlarmCount.put("tom","c1,mj2,mr2");
	mapAlarmCount.put("sam","c1,mj2,mr2");
	mapAlarmCount.put("ken","c1,mj2,mr2");
	mapAlarmCount.put("adam","c1,mj4,mr2");
	mapAlarmCount.put("julie","c1,mj2,mr1");
	mapAlarmCount.put("tim","c1,mj1,mr1");
	mapAlarmCount.put("keith","c1,mj1,mr0");
	mapAlarmCount.put("ovm","c1,mj2,mr4");
	mapAlarmCount.put("moby","c1,mj2,mr5");
	mapAlarmCount.put("xchg","c1,mj2,mr4");
	mapAlarmCount.put("apmcode","c2,mj2,mr1");
	mapAlarmCount.put("apminfra","c1,mj1,mr5");
	mapAlarmCount.put("rum","c1,mj3,mr0");
	mapAlarmCount.put("nutanix","c1,mj2,mr3");
	mapAlarmCount.put("nutanixvdi","c1,mj2,mr4");
	mapAlarmCount.put("sharepoint","c1,mj1,mr3");
	mapAlarmCount.put("portals","c0,mj0,mr0");


	//demoUser - Descrption
	demoDescption.put("bob","Citrix XenApp on Physical servers  - BOB"); //("name","description")
	demoDescption.put("kim","Citrix XenApp on Vmware  - KIM ");
	demoDescption.put("mike","Citrix XenApp on XenServer  - MIKE");
	demoDescption.put("tom","Web application on Vmware  - TOM");
	demoDescption.put("jim","XenDesktop with Vmware vSphere  - JIM");
	demoDescption.put("tim","XenDesktop with XenServer  - TIM");
	demoDescption.put("jeff","Vmware View with Vmware vSphere  - JEFF");
	demoDescption.put("sam","Java application with Amazon EC2  - SAM");
	demoDescption.put("ken","Java application with vmware vSphere  - KEN");
	demoDescption.put("keith","Oracle database and Microsoft SQL  - KEITH");
	demoDescption.put("julie","Java application and Microsoft SQL  - JULIE");
	demoDescption.put("adam","Citrix XD 7 Apps and vmware vSphere  - ADAM");
	demoDescption.put("mark","SAP R3 with vmware vSphere  - MARK");
	demoDescption.put("moby","Citrix XenMobile and Sharefile  - MOBY");
	demoDescption.put("ovm","Apps on Oracle VM Server  - OVM");
	demoDescption.put("xchg","Microsoft Exchange 2013 on VMware  - XCHG");
	demoDescption.put("apmcode","BTM Application issue - APMCODE");
	demoDescption.put("apminfra","BTM Infrastructure issue - APMINFRA");
	demoDescption.put("rum","Real User Monitoring  - RUM");
	demoDescption.put("nutanix","Nutanix Acropolis - NUTANIX");
	demoDescption.put("nutanixvdi","Nutanix Acropolis - VDI - NUTANIXVDI");
	demoDescption.put("sharepoint","Microsoft Sharepoint - SHAREPOINT");
	demoDescption.put("portals","Status of hosted portals");
%>

<html>
	<head>
		<title>Demo Alert - Status</title>
	</head>

<script type="text/javascript">
	function newPopup(url)
	{
		popupWindow = window.open(url,'popUpWindow','height=700,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
	}

	var xmlhttp;
	function newUserPopup(name,accessKey,encryptedSecretKey,dpe,rpe)
	{
		xmlhttp = null;
		var response;
		var spe;
		var nameDemo;

		if (window.XMLHttpRequest)
		{
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (xmlhttp != null)
		{
			var params = "uname="+encodeURIComponent(name);
			var url = "/final/admin/demoStatusHelper.jsp";
			xmlhttp.open('POST',url,false);
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					try
					{
						response=xmlhttp.responseText;
						var arr = response.split(",");
						spe = arr[0];
						nameDemo = arr[1];
					}
					catch (error){}
				}
			}
			xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
			xmlhttp.send(params);
		}
		else
		{
			alert('<egui:intnl text="admin.login.Your browser does not support XMLHTTP"/>');
		}

		var myUrl = "http://demo.eginnovations.com/final/servlet/com.egurkha.EgNewLoginServlet?uname="+encodeURIComponent(name)+"&upass="+encodeURIComponent(nameDemo)+"&ape="+encodeURIComponent(accessKey)+"&spe="+encodeURIComponent(spe)+"&kpe="+encodeURIComponent(encryptedSecretKey)+"&dpe="+encodeURIComponent(dpe)+"&rpe="+encodeURIComponent(rpe);
		popupWindow = window.open(myUrl,'popUpWindow','height=700,width=1000,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
	}
</script>

	<body>
		<div class="main"  align="justify">
			<%
			// To get list of user from DB
			
			try
			{
				if (userArray!=null && userArray.length>0)
				{
					for(int i=0; i<userArray.length; i++)	// to get servers for each user
					{
						String uname = userArray[i];
						user_list.add(uname);
						ErUserData userData = new ErUserData(uname,true);
						User user =userData.getUser(uname);
						List server_list = new ArrayList();
						server_list = user.getServers(false);

						List queryList = new ArrayList();
						String q_alarm = "select PRIORITY,count(*) from alarm where (comp_name like ";
						String strComponent = "";
						for(int j =0; j< server_list.size(); j++)
						{
							String comp_name = (String) server_list.get(j);
							if(comp_name!=null && comp_name.indexOf(":")>-1)
							{
								comp_name = comp_name.substring(comp_name.indexOf(":")+1);
								if (comp_name.indexOf(":")>-1)
								comp_name=comp_name.substring(0,comp_name.indexOf(":"));
								comp_name = "'%" + comp_name + ":%'" + " OR comp_name like ";
							}
							strComponent = strComponent + comp_name;
						}
						if (strComponent.endsWith(" OR comp_name like "))
							strComponent = strComponent + "'')";

						q_alarm = q_alarm+strComponent + " group by PRIORITY";
						queryList.add(q_alarm);

						String q_unknowns = "select count(*) u_count from report where STATE='UNKNOWN' and (comp_name like ";
						q_unknowns = q_unknowns+strComponent;

						queryList.add(q_unknowns);

						userQuery.put(uname,queryList);
					}
				}

			}catch(Exception e)
			{
				System.out.println("Exception in user db -- "+e);
				e.printStackTrace();
			}
			//----------- DB connection - user - server list ends ----------------

			//----------- DB connection - alarm & count begins ----------------

			ArrayList arryList = new ArrayList();
			EgDbAdapterUI egDb = EgDbAdapterTypeUI.getObject();
			status = egDb.setConnection();
			ResultSet rs = null;

			try
			{
				if (status != null && status.equals("CONNECTED"))
				{
					for(int i=0; i < user_list.size(); i++)
					{
						String name1 = (String) user_list.get(i);
						arryList = (ArrayList) userQuery.get(name1);

						String alertQuery = (String) arryList.get(0);
						String unknownQuery = (String) arryList.get(1);
						
						try
						{
							rs = egDb.dbselect(unknownQuery);

							// for unknownQuery
							if(rs != null)
							{
								rs.next();
								unknowns = rs.getInt(1);
							}
						}
						catch (Exception er)
						{
						}
						finally
						{
							try
							{
								if(rs!=null)
								{
									rs.close();
									rs = null;
								}
							}
							catch (Exception eer)
							{
							}
						}
						

						// for alertQuery
						int minor = 0;
						int major = 0;
						int critical = 0;
						
						try
						{
							rs = egDb.dbselect(alertQuery);
							//System.out.println("[demoStatus]rs2="+rs2);
							if(rs != null)
							{
								//System.out.println("[demoStatus]rs2.next()="+rs2.next());
								while(rs.next())
								{
									String priority = rs.getString(1);
									alerts = rs.getInt(2);
									
									//System.out.println("[demoStatus]alerts="+alerts);
									
									if(priority.equalsIgnoreCase("LOW"))
									minor += alerts;
									else if(priority.equalsIgnoreCase("INTERMEDIATE"))
									major += alerts;
									else if(priority.equalsIgnoreCase("HIGH"))
									critical += alerts;
								}
							}
						}
						catch (Exception er)
						{
						}
						finally
						{
							try
							{
								if(rs!=null)
								{
									rs.close();
									rs = null;
								}
							}catch(Exception ee){}
						}

						String defaultAlert = (String) mapAlarmCount.get(name1);

						int criticalD = Integer.parseInt(defaultAlert.substring(defaultAlert.indexOf("c")+1,defaultAlert.indexOf("c")+2));
						int majorD = Integer.parseInt(defaultAlert.substring(defaultAlert.indexOf("mj")+2,defaultAlert.indexOf("mj")+3));
						int minorD = Integer.parseInt(defaultAlert.substring(defaultAlert.indexOf("mr")+2,defaultAlert.indexOf("mr")+3));

						String msg="";
						/*System.out.println("[demoStatus]minorD="+minorD);
						System.out.println("[demoStatus]majorD="+majorD);
						System.out.println("[demoStatus]CriticalID="+criticalD);
						
						System.out.println("[demoStatus]minor="+minor);
						System.out.println("[demoStatus]major="+major);
						System.out.println("[demoStatus]critical="+critical);*/
						
						if(critical >= criticalD && major >= majorD && minor >= minorD && unknowns == 0)
						{
							count = "0"; //tick
							msg = "-";
						//	System.out.println("[demoStatus] no alert");
						}
						else
						{
							count = "1"; //wrong
						//	System.out.println("[demoStatus] wrong");
						}

						if(critical < criticalD || major < majorD || minor < minorD)
						msg = "Alerts";
						if(unknowns > 0)
						msg = "Unknowns";

						errorMsg.put(name1,msg);
						msg = "";

						user_server.put(name1,count);
						count = "1";

						
					}
				}
			}catch(Exception e)
			{
				System.out.println("Exception in user db -- "+e);
				e.printStackTrace();
			}
			finally
			{
				egDb.releaseConnection(true);
			}
			EgDbAdapterTypeUI.releaseObject(egDb); 

			//----------- DB connection - alarm & count - ends ----------------

			// Set refresh, autoload time as 5 seconds
			response.setIntHeader("Refresh", 60);

			// Current Date and Time
			SimpleDateFormat sdf_date = new SimpleDateFormat("MMMM, dd  yyyy");
			SimpleDateFormat sdf_time = new SimpleDateFormat(" HH:mm:ss z");  
			java.util.Date today = new java.util.Date();
			String date = sdf_date.format(today);
			String time = sdf_time.format(today);
			%>
			<div align="center">
				<b>DATE :<%=date%></b>
				<br>
				<b>TIME :<%=time%></b>
			</div>

			<!-- --------------table for demo status-------------------- -->
			<div class="demo">
				<table class="tDesign" border="1" style="font-size:12px" width="70%">
					<h2>Demo Status</h2>

					<tr>
				<%
					for(int i = 0; i < user_list.size(); i++)
					{
					String name = (String) user_list.get(i);
				%>
					<th><b><%=(demoDescption.get(name))%></b></th>
				<%
					}
				%>
					</tr>

					<tr>
					<%
					int c =0;
					IniFile specsIni =  new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_specs.ini");
					String accessKey = specsIni.getValue("SETTINGS","EG_SERVER");
					accessKey = EgCrypt.encrypt(accessKey);

					String secretKey = GoogleAuthenticator.getRandomSecretKey();
					String encryptedSecretKey = EgCrypt.encrypt(secretKey);
					Date currDate = new Date();
					String userDateTimeFormat = "MM/dd/yyyy HH:mm:ss";
					SimpleDateFormat sdf = new SimpleDateFormat(userDateTimeFormat);
					String userDate = sdf.format(currDate); 
					String dpe = EgCrypt.encrypt(userDate);
					String randomNumber = GoogleAuthenticator.getTOTPCode(secretKey, userDate);
					String rpe = EgCrypt.encrypt(randomNumber);

					for(int i = 0; i < user_list.size(); i++)
					{
						String name = (String) user_list.get(i);
						if(user_server.get(name) != null)
						{
							c = Integer.parseInt((String)user_server.get(name));
						}
						if( c < 2)
						{
					%>
							<td align="center"><a href ="JavaScript:newUserPopup('<%=name%>','<%=accessKey%>','<%=encryptedSecretKey%>','<%=dpe%>','<%=rpe%>');"><img src="/final/admin/eg_images/alert_icons/<%=arr[c]%>" width="40"></a></td>

					<%
						}
					}
				%>
					</tr>

					<tr>
					<%
						String message="";
						for(int i=0;i<user_list.size();i++)
						{
							String name = (String) user_list.get(i);
							if(errorMsg.get(name) != null)
							{
								message = (String) errorMsg.get(name);
							}
							%>
							<td align="center"><%=message%>
							<%
							if(message.equals("-"))
							{
							%>
								<input type="hidden" value="<%=name+"$Normal"%>"/></td>
							<%
							}
							else
							{
							%>
								<input type="hidden" value="<%=name+"$"+message%>"/></td>
							<%
							}
						}
						%>
					</tr>
				</table>
			</div>
			<br>
			<!-- --------------table for portal status-------------------- -->
			<%
			HttpsURLConnection  https_con = null;
			HttpURLConnection  http_con = null;
			for(int k=0; k< hostName.length; k++)
			{
				String hostname = hostName[k];
				boolean resp_status = false;
				URL hosturl = null;			
				
				try
				{
					if(hostname.startsWith("https"))
					{
														
						hosturl = new URL(hostname);
						https_con = (HttpsURLConnection) hosturl.openConnection();
						https_con.setInstanceFollowRedirects(true);
						int resp_code = https_con.getResponseCode();
						//out.println(resp_code);

						//resp_status = https_con.getFollowRedirects();
						if(resp_code == 200)
						p_status = "0";
						else
						p_status = "1";
					}
					else if(hostname.startsWith("http"))
					{
						hosturl = new URL(hostname);
						http_con = (HttpURLConnection) hosturl.openConnection();
						http_con.setInstanceFollowRedirects(true);
						int resp_code = http_con.getResponseCode();

						//resp_status = http_con.getFollowRedirects();
						if(resp_code == 200)
						p_status = "0";
						else
						p_status = "1";
					}
				}catch(Exception e)
				{
					//System.out.println("[Error in host url connection](demoStatus)="+e);
					//out.println(e);
					p_status = "1";
					e.printStackTrace();
				}
				portalStatus.put(hostname,p_status);
			}
			%>

			<div class="portal" style="float:left">
				<table class="tDesign" style= "border: 1px solid;font-size:12px">
				<h2>Portal Status</h2>
					<tr>
					<%
						for(int i = 0; i< hostName.length; i++)
						{
							String hName = hostName[i];
							hName = hName.substring(hName.indexOf("//")+2,hName.indexOf("."));
							%>
							<th><b><%=hName.toUpperCase()%></b></th>
							<%
						}
					%>
					</tr>
					<tr>
					<%
					for(int i = 0; i< hostName.length; i++)
					{
						String name = hostName[i];
						int s = Integer.parseInt((String) portalStatus.get(name));
						//out.println(s);
					%>
						<td align="center"><a href ="JavaScript:newPopup('<%=name%>');"><img src="/final/admin/eg_images/alert_icons/<%=arr[s]%>" width="40"></a></td>
					<%
					}
					%>
					</tr>
				</table>
			</div>
			
			<!-- --------------table for License portal status-------------------- -->

	
		<%
			URL url = null;
			try
			{	
				url = new URL(null, "https://customer.eginnovations.com/egcrm/helloWorld.action?userName=network&password=network", new sun.net.www.protocol.https.Handler());	
				//url = new URL(null, "http://www.eginnovations.com/", new sun.net.www.protocol.https.Handler());	
				https_con = (HttpsURLConnection) url.openConnection();
				https_con.setConnectTimeout(60000);
				HttpHelper helper = new HttpHelper(https_con,"none","include","Expiring");
				val = helper.contentValidity;
				//out.println("Content Validity: "+val);
				if(val != 100)
					p_status = "1";
				else
					p_status = "0";
			}
			catch(Exception e)
			{
				out.println(e);
			}
			String state = "Status";
			licensePortal.put(state,p_status);

		%>

		<div class="portal" style="float:left">
				<table class="tDesign" style= "border: 1px solid;font-size:12px">
				<h2>License Portal Status</h2>
					<tr>
					<%
						int s = Integer.parseInt((String) licensePortal.get(state));
						//out.println(s);
					%>
						<td align="center"><a href ="JavaScript:newPopup('https://customer.eginnovations.com/egcrm/helloWorld.action?userName=network&password=network');"><img src="/final/admin/eg_images/alert_icons/<%=arr[s]%>" width="40"></a></td>
					
					</tr>
				</table>
			</div> 


			<!-- --------------table for Users Currently Logged-in-------------------- -->


			<div class="crl"></div><div class="status">
				<table class="tDesign" style= "border: 1px solid; font-size:14px">
				<h2>Users Currently Logged-in</h2>
				<tr><th>Host IP</th><th>User Name</th><th>User Role</th><th>Login Time</th><th>Last Accessed Time</th></tr>
				<%
					UserRegistry userRregistry = UserRegistry.getInstance();
					Map sessGrpUser = userRregistry.getLoggedInGroupUsers();
					Map sess_info = userRregistry.getSessionMappings();
					//int count = sess_info.size(); // Total users
					Iterator sess_it= sess_info.keySet().iterator();
					Iterator val_it=sess_info.values().iterator();
					TreeSet ts=new TreeSet(sess_info.values());
					int unique_users = ts.size(); // Unique users
					String sortTypes[]={"Last Accessed Time","Login Time","User Name","Host IP"};
					String sortBy=request.getParameter("sort");
					String orderBy=request.getParameter("order");
					String number[]={"0","1"};
					if(StringUtils.isNull(orderBy))
					{
						orderBy=number[1];
					}
					if (StringUtils.isNull(sortBy))
					{
						sortBy=number[0];
					}

					SimpleDateFormat simple=null;
					String value="";
					String sortTemp=sortBy;
					boolean isLongDepend=false;
					isLongDepend=(sortTemp.equals("0")||sortTemp.equals("1")||sortTemp.equals("3"));
					String uiFile = "eg_ui.ini";
					String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
					IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
					String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
					IniFile userMappingIni =  new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_ui.ini");

					Hashtable userList = new Hashtable();

					while( sess_it.hasNext() && val_it.hasNext())
					{
						String sess_id=(String)sess_it.next();

						User userbj = userRregistry.getUser(sess_id);
						String sess_user=(String)val_it.next();
						String userType = (String)userbj.getLoginType();
						String temp_Usr = userMappingIni.getValue("DBUSER_USER_MAP",sess_user);
						if (temp_Usr != null && temp_Usr.length() > 0)
						{
							sess_user = temp_Usr;
						}
						if (sess_user != null && sess_user.indexOf("/Grp/") != -1)
						{
							String uname = sess_user;
							String grpDelimiter = "/Grp/";
							int idx = uname.indexOf(grpDelimiter);
							String str_uname_A = uname.substring(0,idx);
							int nextIdx = idx + grpDelimiter.length();
							String str_uname_B = uname.substring(nextIdx);
							uname = str_uname_A + "/" + str_uname_B + " (Group)";
							sess_user = (String)sessGrpUser.get(sess_id) + " {" + uname + "}";
						}

						Long lt =(Long)userRregistry.sessionLoginTime.get(sess_id);
						Long lat = (Long)userRregistry.sessionLastTime.get(sess_id);
						String ip = (String)User.getUserIP(sess_id);
						if (ip != null && ip.equalsIgnoreCase("N/A"))
						{
							continue;
						}

						String tempSessUser = StringUtils.replace(sess_user,"<","&lt;");
						tempSessUser = StringUtils.replace(tempSessUser,">","&gt;");

						simple=new SimpleDateFormat(currentDateFormat+" HH:mm:ss");
						value = simple.format(new Date(lat.longValue()));
						//com.egurkha.EgTimeZoneConverter egt = new com.egurkha.EgTimeZoneConverter(value, _user);
						String lastAccessedTime = value;//egt.getDateTime();

						simple = new SimpleDateFormat(currentDateFormat+" HH:mm:ss");
						value = simple.format(new Date(lt.longValue()));
						//com.egurkha.EgTimeZoneConverter egt1 = new com.egurkha.EgTimeZoneConverter(value, _user);
						String loginTime = value;//egt1.getDateTime();

						//adding the user details to Hashtable for sorting
						String displayValue = ip+"#"+tempSessUser+"#"+userType+"#"+loginTime+"#"+lastAccessedTime;
						ArrayList valueArray = new ArrayList();
						if(userList.containsKey(userType))
						{
							valueArray = (ArrayList) userList.get(userType);
						}
						valueArray.add(displayValue);
						userList.put(userType,valueArray);
					}

					//sorting the user seesion list
					if(userList != null && userList.size() > 0)
					{
						Vector v = new Vector(userList.keySet());
						Collections.sort(v);
						Iterator it = v.iterator();
						while (it.hasNext())
						{
							String element =  (String)it.next();
							ArrayList valueArray = (ArrayList) userList.get(element);
							if(valueArray != null && valueArray.size()>0)
							{
								for(int i=0; i< valueArray.size();i++)
								{
									String displayVal = (String) valueArray.get(i);
									StringTokenizer st = new StringTokenizer(displayVal,"#");
								%>
									<tr>
								<%
									while(st.hasMoreTokens())
									{
										String token = st.nextToken();
									%>
										<td><%=token%></td>
									<%
									}
									%>
									</tr>
									<%
								}
							}
						}
					}
				%>
				</table>
			</div>
		</div>
	</body>
</html>



