<%@ page language="java" buffer="32kb" errorPage="/common/error.jsp"%>

<%@ taglib uri="struts-html"     prefix="html"  %>
<%@ taglib uri="struts-bean"     prefix="bean"  %>
<%@ taglib uri="struts-logic"    prefix="logic" %>
<%@ taglib uri="vkc-taglib"      prefix="vkc"   %>

<%@ page import="vkc.db.entities.VKCUser" %>
<%@ page import="vkc.view.WebShare"       %>
<%@ page import="vkc.util.StringUtils"    %>
<%@ page import="java.util.Date"          %>

<%
    VKCUser user = (VKCUser)request.getSession().getAttribute(WebShare.USER_KEY);
    
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        
        return;
    } else if (!user.hasAdminPrivileges()) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        
        return;
    }
    
    String id = StringUtils.normalize(request.getParameter("sid"));
    HttpSession userSession = WebShare.getSession(id);
    
    if (userSession != null) {
	    request.setAttribute("userSession", userSession);
	    Date d = new Date(userSession.getLastAccessedTime());
	    request.setAttribute("lastAccessedTime", d);
	    Date b = new Date(userSession.getCreationTime());
	    request.setAttribute("creationTime", b);
    }
%>

<html:html locale="true">
<head>
  <vkc:cssinclude/>

  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

  <title><vkc:message key="vkc"/></title>

  <script type="text/javascript">
    self.focus();
  </script>
</head>

<body vlink="#000000" link="#000000" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
  <logic:present name="userSession" scope="request">
  <table width="100%" height="100%" bgcolor="#808080" cellSpacing="1" cellPadding="3" border="0">
    <tr>
	  <td align="left" nowrap="nowrap" bgcolor="#f0f0f0"><b><vkc:message key="activeusers.label.sessionid"/>:</b></td>
	  <td width="100%" align="left" bgcolor="white"><vkc:write name="userSession" property="id"/></td>
    </tr>

    <tr>
      <td align="left" nowrap="nowrap" bgcolor="#f0f0f0"><b><vkc:message key="vkc.administration.sessiontimeout"/>:</b></td>
      <td width="100%" align="left" bgcolor="white"><%=userSession.getMaxInactiveInterval() / 60%>&nbsp;<vkc:message key="vkc.administration.sessiontimeout.minutes"/></td>
    </tr>

    <tr>
      <td align="left" nowrap="nowrap" bgcolor="#f0f0f0"><b><vkc:message key="vkc.lastaccessed_individual"/></b></td>
      <td width="100%" align="left" bgcolor="white"><vkc:write name="lastAccessedTime" formatKey="date.medium.format"/></td>
    </tr>

	<tr>
      <td align="left" nowrap="nowrap" bgcolor="#f0f0f0"><b><vkc:message key="activeusers.label.login.date"/></b></td>
      <td width="100%" align="left" bgcolor="white"><vkc:write name="creationTime" formatKey="date.medium.format"/></td>
    </tr>

    <tr>
      <td height="100%" align="left" valign="top" nowrap="nowrap" bgcolor="#f0f0f0"><b><vkc:message key="vkc.attributes"/>:</b></td>
      <td width="100%" align="left" valign="top" bgcolor="white">
        <table cellspacing="0" cellpadding="0">
          <logic:iterate id="name" name="userSession" property="attributeNames" type="java.lang.String">
          <bean:define id="obj" name="userSession" property='<%="attribute(" + name + ")"%>'/>
          <tr><td valign="top"><vkc:write name="name"/>:&nbsp;</td><td valign="top"><vkc:write name="obj"/></td></tr>
          <tr><td valign="top"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="3" border="0"/></td></tr>
          </logic:iterate>
        </table>
      </td>
    </tr>
  </table>
  </logic:present>
  
  <logic:notPresent name="userSession" scope="request">
  <bean:parameter id="sid" name="sid" value="null"/>
  <table width="100%" cellSpacing="1" cellPadding="3" border="0">
    <tr>
      <td align="center"><br><br><b><vkc:message key="error.sessionobject.unavailable" arg0='<%=sid%>'/></b></td>
	</tr>
  </table>
  </logic:notPresent>
</body>
</html:html>