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

<%@ page import="vkc.db.entities.VKCAclType"%>
<%@ page import="vkc.view.form.AddAccessorAclForm"%>
<%@ page import="vkc.view.form.EditDefaultCatAclForm"%>
<%@ page import="org.apache.struts.Globals"%>

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

<html:html locale="true">
<head>
    <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">

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

    <vkc:cssinclude />

    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>
	
    <script type="text/javascript">
	window.name = "MAINVIEW";

  	var windowOpen = null;

	function init() {
		window.focus();
	}

	function saveAcl(elem) {
	    var form = document.forms[0];
	    form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_SAVE %>;
	    disableAllButtons(elem);
        form.submit();
	}

	function inheritFromParent(elem) {
	    var form = document.forms[0];
	    form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_INHERIT_FROM_PARENT %>;
        disableAllButtons(elem);
	    form.submit();
	}

	function newAnyother(elem) {
	    var form = document.forms[0];
	    form.addAccessorType.value = <%= VKCAclType.ANYOTHER_TYPE %>;
	    form.addAccessorId.value = 0;
	    form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_ADDACCESSOR %>;
        disableAllButtons(elem);
	    form.submit();
	}

	function newOwner(elem) {
	    var form = document.forms[0];
	    form.addAccessorType.value = <%= VKCAclType.OWNER_TYPE %>;
	    form.addAccessorId.value = 0;
	    form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_ADDACCESSOR %>;
        disableAllButtons(elem);
	    form.submit();
	}

	function newUser(elem) {
	    var w = 400;
	    var h = 150;
	    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=no,resizable=yes,status=no';
	    windowOpen = window.open( '<vkc:rewrite page="/addAccessorAcl.do"/>?<%= AddAccessorAclForm.PARAM_ATYPE %>=<%=VKCAclType.USER_TYPE %>', 'add', settings );
	    windowOpen.focus();
	}

	function newGroup(elem) {
	    var w = 400;
	    var h = 150;
	    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=no,resizable=yes,status=no';
	    windowOpen = window.open( '<vkc:rewrite page="/addAccessorAcl.do"/>?<%= AddAccessorAclForm.PARAM_ATYPE %>=<%=VKCAclType.GROUP_TYPE %>', 'add', settings );
	    windowOpen.focus();
	}

	function deleteAccessor(elem) {
	    var form = document.forms[0];
	    bestaetigt = confirm( '<vkc:message javascript="true" filter="false" key="vkc.acl.confirm_deletation"/>' );
	    
	    if (bestaetigt == true) {
	      form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_DELETE %>;
          disableAllButtons(elem);
	      form.submit();
	    }
	}

	function selectChanged() {
	    var form = document.forms[0];
	    form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_CHANGE_SELECT %>;
	    form.submit();
	}

	function onul() {
	    if (windowOpen != null) {
	        windowOpen.close();
	    }
	}

	function addAccessor(accessorType, accessorId) {
	  	var form = document.forms[0];
	    form.addAccessorId.value = accessorId;
	    form.addAccessorType.value = accessorType;
	    form.ctrlAction.value = <%= EditDefaultCatAclForm.ACTION_ADDACCESSOR %>
	    form.submit();
	}

    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 onload="init();" onunload="onul();">
<html:form action="/editDefaultCatAcl" method="post">
  <bean:define id="form" name="defaultCatAclForm" scope="request" type="vkc.view.form.EditDefaultCatAclForm"/>

  <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>

  <bean:define id="cat" property="category" name="form" type="vkc.db.entities.VKCCategory"/>

  <table class="color_dialogborder" cellspacing="0" cellpadding="3" border="0" width="560" align="center">
    <%-- Schatten --%>
    <tr>
      <td class="color_default_background" width="4" align="left"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="1" height="1" border="0" alt=""/></td>
      <td class="color_default_background"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="1" height="1" border="0" alt=""/></td>
      <td class="color_default_background" width="4" align="right"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="1" height="1" border="0" alt=""/></td>
    </tr>
    <tr>
      <td class="color_titlebar_inactive" colspan="1"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="4" border="0" alt=""/></td>
      <td class="color_titlebar_inactive" align="middle"><font style="font-family:sans-serif; font-size:12pt; color:gray;"><b><i><vkc:message key="vkc.edit_cat_acls"/></i></b></font></td>    
      <td class="color_default_background" width="1%"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="4" border="0" alt=""/></td>
    </tr>
    <%-- Ueberschrift --%>
    <tr>
      <td class="color_titlebar_inactive" width="1%"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="10" border="0" alt=""/></td>
      <td class="color_titlebar" align="center" colspan="2" rowspan="2">
        <font style="font-family:sans-serif; font-size:12pt; color:white;"><b><i><vkc:message key="vkc.edit_default_cat_acls"/></i></b></font>
      </td>
    </tr>
    <tr>
      <td class="color_dialogborder_inactive"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="4" border="0" alt=""/></td>
    </tr>
    <%-- Umgebende Dialogtabelle --%>
    <tr>
      <td class="color_dialogborder_inactive"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="4" border="0" alt=""/></td>
      <td colspan="2">
        <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" nowrap="nowrap"><b><vkc:message key="vkc.acl.valid_from_category"/>:</b>&nbsp;</td>
                  <td valign="top" width="100%" align="left" nowrap="nowrap"><vkc:write name="cat" property="name"/></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%">
                <%-- Hidden fields --%>
                <html:hidden property="ctrlAction"/>
                <html:hidden property="addAccessorId"/>
                <html:hidden property="addAccessorType"/>
                <tr>
                  <%-- Ueberschrift des Namens-Select --%>
                  <td class="color_highlightbar">
                    <b><vkc:message key="vkc.acl.users_and_groups"/></b>
                  </td>
                  <td class="color_dialogborder">&nbsp;
                  </td>
                </tr>
                <tr>
                  <td width="99%">
                    <bean:define property="users" name="form" id ="usersCollection"/>
                    <bean:define property="groups" name="form" id="groupsCollection"/>
                    <bean:define property="anyothers" name="form" id="anyotherCollection"/>
                    <html:select property="accessorSelect" size="8" style="width:100%" onchange="javascript:selectChanged();" styleClass="color_bodycontent">
                      <vkc:options collection="anyotherCollection" property="selectIdString" labelProperty="accessorName"/>
                      <logic:notEmpty name="usersCollection">
                        <optgroup label="<vkc:message key='vkc.users'/>">
                          <vkc:options collection="usersCollection" property="selectIdString" labelProperty="accessorName"/>
                        </optgroup>
                      </logic:notEmpty>
                      <logic:notEmpty name="groupsCollection">
                        <optgroup label="<vkc:message key='vkc.groups'/>">
                          <vkc:options collection="groupsCollection" property="selectIdString" labelProperty="accessorName"/>
                        </optgroup>
                      </logic:notEmpty>
                    </html:select>
                  </td>
                  <td width="1%" class="color_dialogborder" valign="top">
                    <table width="100%" height="100%"cellspacing="2" cellpadding="0" border="0">
                      <tr>
                        <td>&nbsp;</td>
                        <td valign="top" width="120" align="center">
                          <vkc:button property="delete" style="width:120" onclick="javascript:deleteAccessor(this);">
                            <vkc:message key="vkc.acl.delete"/>
                          </vkc:button>
                        </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td width="120" align="center">
                          <vkc:button property="addAnyother" style="width:120" onclick="javascript:newAnyother(this);">
                            <vkc:message key="vkc.acl.new_anyother"/>
                          </vkc:button>
                        </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td width="120" align="center">
                          <vkc:button property="addOwner" style="width:120" onclick="javascript:newOwner(this);">
                            <vkc:message key="vkc.acl.new_owner"/>
                          </vkc:button>
                        </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td width="120" align="center" valign="top">
                          <vkc:button property="addUser" style="width:120" onclick="javascript:newUser(this);">
                            <vkc:message key="vkc.acl.new_user"/>
                          </vkc:button>
                        </td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td width="120" align="center">
                          <vkc:button property="addGroup" style="width:120" onclick="javascript:newGroup(this);">
                            <vkc:message key="vkc.acl.new_group"/>
                          </vkc:button>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td>
              <%-- Berechtigungen --%>
              <table class="color_bodycontent" cellspacing="0" border="0" width="100%">
                <tr>
                  <%-- Ueberschrift Berechtigungstabelle --%>
                  <td class="color_highlightbar">
                    <b><vkc:message key="vkc.acl.perms_for"/></b>
                    <logic:notEmpty name="form" property="actualAi">
                      <bean:define property="actualAi" name="form" id ="accessorInfo" type="vkc.security.AccessorInfo"/>
                      <logic:equal name="form" property="actualAccessorType" value="vkc.acl.for_this_user">
                        <vkc:message key="vkc.acl.for_this_user"/> : <a style="font-weight:normal;" href="javascript:openUserInfoWindow(<vkc:write name="accessorInfo" property="accessorId"/>);"><vkc:write name="accessorInfo" property="accessorName"/></a>
                      </logic:equal>
                      <logic:equal name="form" property="actualAccessorType" value="vkc.acl.for_this_group">
                        <vkc:message key="vkc.acl.for_this_group"/> : <a style="font-weight:normal;" href="javascript:openGroupInfoWindow(<vkc:write name="accessorInfo" property="accessorId"/>);"><vkc:write name="accessorInfo" property="accessorName"/></a>
                      </logic:equal>
                      <logic:equal name="form" property="actualAccessorType" value="vkc.acl.for_anyother">
                        <vkc:message key="vkc.acl.for_anyother"/>
                      </logic:equal>
                      <logic:equal name="form" property="actualAccessorType" value="vkc.acl.for_owner">
                        <vkc:message key="vkc.acl.for_owner"/>
                      </logic:equal>
                    </logic:notEmpty>
                  </td>
                  <td class="color_highlightbar" width="100" align="middle">
                    <b><vkc:message key="vkc.acl.allow"/></b>
                  </td>
                </tr>
                <!-- Einzelne Berechtigungen -->
                <logic:equal name="form" property="changeAclEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_c"/>
                    </td>
                    <td align="middle">
                     <html:checkbox property="changeAcl"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="readCategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_r"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="readCategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="writeCategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_w"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="writeCategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="deleteDocumentsEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_d"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="deleteDocuments"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="deleteCategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_D"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="deleteCategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="archiveCategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_a"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="archiveCategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="editQueryVirtualDocsEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_q"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="editQueryVirtualDocs"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="createSubcategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_C"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="createSubcategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="createLinkToCategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_L"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="createLinkToCategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="followLinkToCategoryEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_F"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="followLinkToCategory"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="createLinkToDocumentEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_l"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="createLinkToDocument"/>
                    </td>
                  </tr>
                </logic:equal>
                <logic:equal name="form" property="followLinkToDocumentEnabled" value="true">
                  <tr>
                    <td>
                      <vkc:message key="vkc.acl.category.perm_f"/>
                    </td>
                    <td align="middle">
                      <html:checkbox property="followLinkToDocument"/>
                    </td>
                  </tr>
                </logic:equal>
              </table>
            </td>
          </tr>
          <%-- Buttons Speichern und Fenster schließen --%>
          <tr>
            <td align="middle">
              <vkc:button property="inheritfromparent" onclick="javascript:inheritFromParent(this);">
                <vkc:message key="button.inheritfromparent"/>
              </vkc:button>
              &nbsp;&nbsp;&nbsp;
              <vkc:button property="save" onclick="javascript:saveAcl(this);">
                <vkc:message key="button.save"/>
              </vkc:button>
              &nbsp;&nbsp;&nbsp;
              <vkc:button property="close_action" onclick="javascript:disableAllButtonsAndSubmit(this);">
                <vkc:message key="button.exit"/>
              </vkc:button>
            </td>
          </tr>
          <%-- ggf. Ausgabe von Erfolgs / Fehlermeldungen --%>
          <logic:present name="vkc.acl.succeeded">
            <tr>
	          <td bgcolor="#77D369" align="center">
	            <font color="white"><b><vkc:message name="vkc.acl.succeeded"/></b></font>
	          </td>
	        </tr>
	      </logic:present>
	      <logic:present name="vkc.acl.failed">
	        <tr>
	          <td bgcolor="#FF0000" align="center">
	            <font color="white"><b><vkc:message name="vkc.acl.failed"/></b></font>
	          </td>
	        </tr>
	      </logic:present>
        </table>
      </td>
    </tr>
    <tr>
      <td class="color_default_background"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="4" border="0" alt=""/></td>
      <td class="color_dialogborder" colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="4" height="4" border="0" alt=""/></td>
    </tr>
  </table>

</html:form>
</body>
</html:html>
