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

<%@ page import="vkc.view.TabId" %>

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

<vkc:checkLogin />
<vkc:init/>
<html:html locale="true">
<head>
    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />

  	<vkc:cssinclude />

    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>
    
    <script type="text/javascript">
    
    window.name = "MAINVIEW";
    var associatedTabId = <%=TabId.ADMIN_ACTIVEUSERS_TAB%>;
        
    function init(){
      	var tabView = getTabView();
        var tabViewForm = tabView.document.forms[0];

        if (tabView && tabView.systemviewtype == "administrationview" && tabView.selectedTabId != associatedTabId) {
          	tabView.location.replace("<%=ctxPath%>/adminTabView.do?selectedTabId=<%=TabId.ADMIN_ACTIVEUSERS_TAB%>"
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
        }
    }

  	function openUserInfoWindow(id) {
    	var w = 800;
    	var h = 600;
    	var leftPosition = screen.width/2  - w/2;
    	var topPosition  = screen.height/2 - h/2;
    	var settings ='height=' + h + ', width=' + w + ', top=' + topPosition + ', left=' + leftPosition;
    	settings += ',scrollbars=yes,resizable';
    	settings += ',toolbar=no, location=no, directories=no, status=true, menubar=no';
    	var win = window.open('<vkc:rewrite page="/displayUserInfo.do"/>?userId=' + id, 'USERINFO_MAINVIEW', settings);
        win.focus();                              
    }

    function showSessionIds() {
        var form = document.forms[0];

        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.show.sessionids=true";
        } else {
          form.action = form.action + "&action.show.sessionids=true";
        }
        
        form.submit();
    }

    function hideSessionIds() {
        var form = document.forms[0];

        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.hide.sessionids=true";
        } else {
          form.action = form.action + "&action.hide.sessionids=true";
        }

        form.submit();
    }
    
    </script>
</head>
<body onload="init();" topmargin="0" marginheight="0">
<table width="100%" align="left" cellspacing="5" cellpadding="0" border="0">
  <html:form action="/activeUserList" method="post">  
  <bean:define id="form" name="activeUserListForm" type="vkc.administration.form.ActiveUserListForm"/>

  <html:hidden property="sessionIdsVisible"/>

  <tr><td nowrap="nowrap"><b><vkc:message key="vkc.string.number.active.users"/>:</b>&nbsp;<vkc:write name="form" property="numActiveUsers"/></td></tr>

  <logic:notEmpty name="form" property="userTrackingInfos">
  <tr>
    <td>  
	  <table width="100%" align="left" cellspacing="1" cellpadding="3" border="0" bgcolor="#808080">
	    <tr>
           <td align="left" nowrap="nowrap" class="headerUnselected">&nbsp;<b>Nr.</b>&nbsp;</td>
	       <td align="left" class="headerUnselected">&nbsp;<b><vkc:message key="activeusers.label.user"/></b>&nbsp;</td>

           <logic:equal name="form" property="sessionIdsVisible" value="false">  
           <td nowrap="nowrap" class="headerUnselected"><vkc:link href="javascript:showSessionIds();"><vkc:img page="/templates/${template.name}/gfx/plus.gif" border="0" titleKey="activeusers.label.show.sessionids" /></vkc:link></td>
           </logic:equal>

           <logic:equal name="form" property="sessionIdsVisible" value="true">  
           <td nowrap="nowrap" class="headerUnselected">&nbsp;<vkc:link href="javascript:hideSessionIds();"><vkc:img page="/templates/${template.name}/gfx/minus.gif" border="0" titleKey="activeusers.label.hide.sessionids" /></vkc:link>&nbsp;<b><vkc:message key="activeusers.label.sessionid"/></b>&nbsp;</td>
           </logic:equal>

	       <td align="left" nowrap="nowrap" class="headerUnselected">&nbsp;<b><vkc:message key="activeusers.label.ipaddress"/></b>&nbsp;</td>
	       <td align="left" nowrap="nowrap" class="headerUnselected">&nbsp;<b><vkc:message key="vkc.lastaccessed_individual"/></b>&nbsp;</td>
	    </tr>
	
	    <logic:iterate name="form" property="userTrackingInfos" indexId="ctr" id="userInfo" type="vkc.view.bean.UserTrackingInfo">
	    <tr>
	      <td align="right" nowrap="nowrap" bgcolor="white">&nbsp;<%=String.valueOf(ctr.intValue()+1)%>.&nbsp;</td>
          
          <logic:lessThan value="0" name="userInfo" property="userId">
	      <td width="100%" align="left"  nowrap="nowrap" class="columnSelected">&nbsp;<vkc:message key="vkc.administration.guestuser"/>&nbsp;</td>
          </logic:lessThan>
          
          <logic:greaterEqual value="0" name="userInfo" property="userId">
          <td width="100%" align="left"  nowrap="nowrap" class="columnSelected">&nbsp;<vkc:link href='<%="javascript:openUserInfoWindow(" + userInfo.getUserId().intValue() + ");"%>'><font color=blue><vkc:write name="userInfo" property="realName"/></font></vkc:link>&nbsp;</td>
          </logic:greaterEqual>

          <logic:equal name="form" property="sessionIdsVisible" value="false">  
          <td bgcolor="white">&nbsp;</td>
          </logic:equal>
          
          <logic:equal name="form" property="sessionIdsVisible" value="true">
          <td bgcolor="white">&nbsp;<a href="<%=ctxPath%>/templates/<%=template%>/administration/sessionInfo.jsp;jsessionid=<%=session.getId()%>?sid=<vkc:write name="userInfo" property="sessionId"/>" target="sessionInfo"><vkc:write name="userInfo" property="sessionId"/></a>&nbsp;</td>
          </logic:equal>

          <td align="right" nowrap="nowrap" bgcolor="white">&nbsp;<vkc:write name="userInfo" property="ipAddress"/>&nbsp;</td>
	      <td align="left" nowrap="nowrap" bgcolor="white">&nbsp;<vkc:write name="userInfo" property="lastAccess" formatKey="date.medium.format"/></td>
	    </tr>
	    </logic:iterate>
	  </table>
    </td>
  </tr>  
  </logic:notEmpty>
  </html:form>
</table>
</body>
</html:html>