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

<%@ page import="vkc.view.WebShare" %>
<%@ page import="vkc.view.TabId" %>
<%@ page import="org.apache.struts.Globals" %>

<%@ 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>
  	<vkc:cssinclude />

    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>

    <script type="text/javascript">

    window.name = "MAINVIEW";
    var associatedTabId = <%=TabId.ADMIN_USERMANAGEMENT_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_USERMANAGEMENT_TAB%>"
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
        }

        <logic:present name="<%=WebShare.INFO_KEY%>" scope="request">
          <bean:define id="msg" type="java.lang.String" scope="request" name="<%=WebShare.INFO_KEY%>"/>
          alert('<vkc:message javascript="true" filter="false" key="<%=msg%>"/>');
        </logic:present>

        setAnchor();
    }

    function setAnchor() {
        <logic:present parameter="anchor">
          <bean:parameter id="anchor2" name="anchor"/>
          this.location.hash = '<%=anchor2%>';
        </logic:present>
    }

    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();
    }

    </script>

</head>
<body onload="init();" topmargin="0" marginheight="0">
<html:form action="/deleteUsers" method="post">
<bean:define id="form" name="deleteUsersForm" scope="request" type="vkc.administration.form.DeleteUsersForm"/>

<html:hidden name="form" property="redirect"/>

<logic:notEmpty name="form" property="loggedUserId">
  <html:hidden name="form" property="loggedUserId"/>
</logic:notEmpty>

<logic:iterate id="did" name="form" property="deletedUserIds" type="java.lang.Integer">
  <html:hidden name="form" property="deletedUserIds" value='<%=String.valueOf(did.toString())%>'/>
</logic:iterate>

<logic:iterate id="lid" name="form" property="lockedUserIds" type="java.lang.Integer">
  <html:hidden name="form" property="lockedUserIds" value='<%=String.valueOf(lid.toString())%>'/>
</logic:iterate>

<table width="1%" align="center" cellspacing="3" cellpadding="0" border="0">
  <logic:present name="<%=Globals.ERROR_KEY%>">
  <tr><td align="left" nowrap="nowrap" colspan="5"><font color="red"><b><vkc:errors/></b></font></td></tr>
  <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="3" bottomSpace="3"/>
  </logic:present>

  <logic:notEmpty name="form" property="loggedUserId">
  <tr>
    <td align="left" nowrap="nowrap" colspan="5"><vkc:message key="vkc.administration.userList.deleteUser.loggedUser"/></td>
  </tr>
  <tr>
	<td colspan="5">&nbsp;</td>
  </tr>
  </logic:notEmpty>

  <logic:greaterThan name="form" property="deletedUserIdsCount" value="0">
  <tr>
    <td align="center" colspan="5">
      <table align="left" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td align="left" valign="top" nowrap="nowrap"><b><vkc:message key="vkc.administration.userList.deleteUsers.ready"/></b></td>
        </tr>
        <logic:iterate id="userInfo" name="form" property="deletedUserInfos" type="vkc.view.bean.UserInfo">
        <tr>
          <td align="left" valign="top" nowrap="nowrap">
            <vkc:link href='<%="javascript:openUserInfoWindow(" + userInfo.getUserId() + ");"%>' style="font-weight:normal;">
              <span style="text-decoration:none"><vkc:write name="userInfo" property="lastnameLabel"/></span>
            </vkc:link>
          </td>
        </tr>
        </logic:iterate>
      </table>
    </td>
  </tr>
  <tr>
	<td colspan="5">&nbsp;</td>
  </tr>
  </logic:greaterThan>
  
  <logic:greaterThan name="form" property="lockedUserIdsCount" value="0">
  <tr>
    <td align="left" valign="top"><b><vkc:message key="vkc.administration.userList.deleteUsers.prepare"/></b></td>
  </tr>
  <tr>
    <td align="center" colspan="5">
	  <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0">
        <logic:iterate id="userInfo" name="form" property="lockedUserInfos" type="vkc.view.bean.UserInfo">
        <bean:define id="userQuota" name="form" property='<%="userQuota(" + userInfo.getUserId() + ")"%>' type="vkc.view.bean.VKCQuotaInfo"/>
        <bean:define id="userStatistics" name="form" property='<%="userStatistics(" + userInfo.getUserId() + ")"%>' type="vkc.view.bean.UserStatistics"/>
		<vkc:hline colspan="2" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>
		
		<tr>
		  <td nowrap="nowrap"><b><vkc:message key="vkc.administration.changecreatorpublishership.old" />:&nbsp;</b></td>
		  <td nowrap="nowrap">
            <vkc:link href='<%="javascript:openUserInfoWindow(" + userInfo.getUserId() + ");"%>' style="font-weight:normal;">
              <span style="text-decoration:none"><vkc:write name="userInfo" property="lastnameLabel"/></span>
            </vkc:link>
		  </td>
		</tr>		
		
		<tr>
		  <td colspan="2">&nbsp;</td>
		</tr>

		<tr>
	      <td><b><vkc:message key="vkc.administration.used.quota" />:&nbsp;</b></td>
	      <td><vkc:write name="userQuota" property="usedQuotaInMegaByteString"/>MB
	        <logic:notEmpty name="userQuota" property="usedQuotaInPercentString">
	        [ <vkc:write name="userQuota" property="usedQuotaInPercentString"/> ]
	        </logic:notEmpty>
	      </td>
		</tr>

		<tr>
		  <td nowrap="nowrap"><b><vkc:message key="vkc.administration.quota.published.docs" />:&nbsp;</b></td>
		  <td nowrap="nowrap"><vkc:write name="userStatistics" property="numPublishedDocuments" /></td>
		</tr>		

		<tr>
		  <td nowrap="nowrap"><b><vkc:message key="vkc.administration.quota.published.cats" />:&nbsp;</b></td>
		  <td nowrap="nowrap"><vkc:write name="userStatistics" property="numCreatedCategories" /></td>
		</tr>		

        <tr>
		  <td nowrap="nowrap"><b><vkc:message key="vkc.administration.changecreatorpublishership.new" />:&nbsp;</b></td>
		  <td>
            <bean:define id="publisherInfos" name="form" property="publisherInfos" type="java.util.List"/>
  			<html:hidden name="form" property='<%="newPublisher[" + userInfo.getUserId() + "].userId"%>'/>
            <html:select name="form" property='<%="newPublisher[" + userInfo.getUserId() + "].id"%>' size="1">
              <vkc:options collection="publisherInfos" property="userId" labelProperty="lastnameLabel"/>
            </html:select>          
          </td>        
        </tr>
        
		<vkc:hline colspan="2" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="10"/>
        </logic:iterate>
	  </table>
    </td>
  </tr>
  </logic:greaterThan>

  <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>

  <tr>
    <td align="center" colspan="5">
      <logic:equal name="form" property="deleteUsers" value="true">
      <vkc:button property="action.execute" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.execute"/></vkc:button>
	  </logic:equal>
	  <vkc:button property="action.cancel" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.cancel"/></vkc:button>
    </td>
  </tr>
</table>
</html:form>
</body>
</html:html>