<%@ page language="java" buffer="100kb" errorPage="/common/error.jsp"%>
<%@ page import="vkc.view.form.DisplayAclForm"%>
<%@ page import="vkc.db.entities.VKCAclType"%>

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

<vkc:checkLogin/>

<html:html locale="true">
<head>
  <vkc:init/>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="cache" content="no-cache">
  <meta http-equiv="expires" content="1">
  <vkc:cssinclude/>
  
  <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>
  <title><vkc:message key="vkc.aclviewer.title"/></title>

  <script type="text/javascript">
  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 openGroupInfoWindow(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="/displayGroupInfo.do"/>?groupId=' + id, 'GROUPINFO_MAINVIEW', settings );
      win.focus();							  
  }
   </script>
</head>

<body>
  <html:form action="/displayAclSummaryView" method="post">
  <bean:define id="form" name="displayAclSummaryViewForm" scope="request" type="vkc.view.form.DisplayAclSummaryViewForm"/>
  <%-- Hidden fields --%>
  <html:hidden property="categoryId"/>  
  <html:hidden property="sourcePageId"/>
  <logic:notEmpty name="form" property="targetId">
    <html:hidden property="targetId"/>
  </logic:notEmpty>
  <logic:notEmpty name="form" property="subTargetId">
    <html:hidden property="subTargetId"/>
  </logic:notEmpty>

  <table class="color_dialogborder" cellspacing="0" cellpadding="3" border="0" align="center">
    <%-- Ueberschrift --%>
    <tr>
      <td class="color_default_background"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="1" height="1" border="0" alt=""/></td>
    <tr>
    <tr>
      <td class="color_titlebar" align="center">
        <font style="font-family:sans-serif; font-size:12pt; color:white;"><b><i><vkc:message key="vkc.aclsummaryviewer.title"/></i></b></font>
      </td>
    </tr>
    <%-- Umgebende Dialogtabelle --%>
    <tr>
      <td>
        <table class="color_dialogborder" cellspacing="10" border="0" width="100%">
          <%-- Anzeige des Kategorienamens --%>
          <tr>
            <td width="99%" valign="top">
              <table width="100%" cellspacing="0" cellpadding="0">
                <tr>
                  <td valign="top" width="1%">
                    <b><vkc:message key="vkc.category"/>:</b>&nbsp;
                  </td>
                  <td valign="top" width="100%" align="left" nowrap="nowrap">
                    <vkc:write name="form" property="categoryName"/>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td width="99%" valign="top">
              <%-- Haupttabelle mit Namens-Select und Liste der Berechtigungen --%>
              <table class="color_bodycontent" cellspacing="0" border="0" width="100%">
                <tr>
                  <%-- Ueberschrift des Namens-Select --%>
                  <td class="color_highlightbar">
                    &nbsp;
                  </td>
                  <td class="color_highlightbar">&nbsp;</td> 
                  <logic:iterate id="permission" name="form" property="enabledPermissions" type="vkc.db.entities.VKCPermission">
                    <td class="color_highlightbar" align="middle">
                      <b><vkc:write name="permission" property="token" /></b>
                    </td>
                  </logic:iterate> 
				  <%-- hier liste der berechtigungen --%>
		        </tr>

				<%-- acls anyother --%>
                  <bean:define id="acl" name="form" property="acl" />
                  <logic:notEmpty name="acl" property='<%="accessorPermString[" + VKCAclType.ANYOTHER_TYPE + "]"%>'>
				    <logic:iterate id="accessorPerm" name="acl" property='<%="accessorPermString[" + VKCAclType.ANYOTHER_TYPE + "]"%>' type="vkc.security.AccessorPermPair">
				      <tr valign="middle">
                        <td>
                          <i><vkc:message key="vkc.anyother"/></i>
                        </td>
                        <td>&nbsp;</td> 
                        <logic:iterate id="permission" name="form" property="enabledPermissions" type="vkc.db.entities.VKCPermission">
                           	<td align="middle" valign="middle">
                            <% if (accessorPerm.hasPermission(permission.getToken())) { %>
                            	<input type="checkbox" name="acl" checked="checked" disabled="disabled">                            
                            <% } else { %>
                                <input type="checkbox" name="acl" disabled="disabled">
                            <% } %>
                          </td>						  
                        </logic:iterate> 
				      </tr>
                    </logic:iterate>	
  				  </logic:notEmpty>
  				
  				<%-- acls users --%>
                  <bean:define id="acl" name="form" property="acl" />
                  <logic:notEmpty name="acl" property='<%="accessorPermString[" + VKCAclType.USER_TYPE + "]"%>'>
				    <tr>
				    <td><b><i><vkc:message key="vkc.users"/></i></b></td>
				    </tr>
				    <logic:iterate id="accessorPerm" name="acl" property='<%="accessorPermString[" + VKCAclType.USER_TYPE + "]"%>' type="vkc.security.AccessorPermPair">
				      <tr>
                        <td>
                          <a style="font-weight:normal;" href="javascript:openUserInfoWindow(<vkc:write name="accessorPerm" property="accessorId"/>);"><vkc:write name="accessorPerm" property="accessor"/></a>
                        </td>
                        <td>&nbsp;</td> 
                        <logic:iterate id="permission" name="form" property="enabledPermissions" type="vkc.db.entities.VKCPermission">
                          <td align="middle" valign="middle">
                            <% if (accessorPerm.hasPermission(permission.getToken())) { %>
                            	<input type="checkbox" name="acl" checked="checked" disabled="disabled">                            
                            <% } else { %>
                                <input type="checkbox" name="acl" disabled="disabled">
                            <% } %>
                          </td>						  
                        </logic:iterate> 
				      </tr>
                    </logic:iterate>	
  				  </logic:notEmpty>
  				
				  <%-- acls groups --%>
                  <bean:define id="acl" name="form" property="acl" />
                  <logic:notEmpty name="acl" property='<%="accessorPermString[" + VKCAclType.GROUP_TYPE + "]"%>'>
				    <tr>
				    <td><b><i><vkc:message key="vkc.groups"/></i></b></td>
				    </tr>
				    <logic:iterate id="accessorPerm" name="acl" property='<%="accessorPermString[" + VKCAclType.GROUP_TYPE + "]"%>' type="vkc.security.AccessorPermPair">
				      <tr>
                        <td>
                          <a style="font-weight:normal;" href="javascript:openGroupInfoWindow(<vkc:write name="accessorPerm" property="accessorId"/>);"><vkc:write name="accessorPerm" property="accessor"/></a>
                        </td>
                        <td>&nbsp;</td> 
                        <logic:iterate id="permission" name="form" property="enabledPermissions" type="vkc.db.entities.VKCPermission">
					      <td align="middle" valign="middle">
                            <% if (accessorPerm.hasPermission(permission.getToken())) { %>
                            	<input type="checkbox" name="acl" checked="checked" disabled="disabled">                            
                            <% } else { %>
                                <input type="checkbox" name="acl" disabled="disabled">
                            <% } %>
                          </td>						  
                        </logic:iterate> 
				      </tr>
                    </logic:iterate>	
  				  </logic:notEmpty>
   		      </table>
            </td>
          </tr>
          <tr>
            <td>
              <table width="100%" border="0">
                <tr>
                  <td align="middle">
                    <vkc:button property="back_action" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.back"/></vkc:button>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</html:form>
</body>
</html:html>