<%@ page import="com.novell.emframe.dev.*"%>
<%@ page import="com.novell.admin.ns.*"%>
<%@ page import="com.novell.webaccess.common.JSPConduit"%>
<%@ page import="com.novell.emframe.dev.eMFrameUtils" %>
<%@ page import="com.novell.emframe.fw.*" %>
<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>

<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/x.tld" prefix="x" %>

<iman:stringtable bundle="DevResources"/>
<iman:stringtable bundle="FwResources"/>
<iman:stringtable bundle="BaseResources"/>

<%
JSPConduit c = JSPConduit.getJSPConduit(request);
MContext taskContext = eMFrameFactory.getMContext(request);
String[] aclScopes = eMFrameUtils.unpack((String)FwAttr.getFwAuthAttr("aclScopesPacked", request), taskContext);
pageContext.setAttribute("aclScopes", aclScopes);

%>

<HTML>
<HEAD>
   <TITLE><iman:string key="ProductName"/></TITLE>
   <iman:stylesheet/>
   <iman:eMFrameScripts/>
   <iman:osScripts/>

   <SCRIPT>
      var returnMethodName = "<c:out value="${param.returnMethodName}"/>";
      var startingPriv = 0;
   </SCRIPT>
   <SCRIPT src="<%= session.getAttribute("ModulesPath") %>/fw/javascripts/KeplerACLEditorPopupScripts.js"></SCRIPT>
</HEAD>
<BODY>
<c:if test="${param.priv != null}">
  <c:if test="${param.attr != null}">
 	<BODY onLoad="onInit(<c:out value="${param.priv}"/>, '<iman:toScript><c:out value="${param.attr}"/></iman:toScript>' );">
  </c:if>
</c:if>
<FORM name="form" method=post action="webacc">

   <iman:taskHeader titleKey="AclEditorTitle" titleBundle="FwResources"/><BR>

   <SPAN class="mediumtext"><iman:string key="AclSubjectNameLabel"/></SPAN><BR>
   <INPUT type="text" name="subjectName" value="<c:out value="${param.subj}"/>" style="width: <iman:string key="UI.textboxPixel"/>"><iman:os typeFilter="*" control="subjectName" history="true"/>
   <BR>
   <BR>
   <SPAN class="mediumtext"><iman:string key="AclModifyNameLabel"/></SPAN><BR>
   <SELECT name="modifier" size="1" style="WIDTH: 250px;" onChange="showPrivilagesModifier()">
   <c:choose>
   	<c:when test='${param.modifier == "1"}'>
   	 <OPTION VALUE="0">Attribute ACL
     <OPTION VALUE="1" SELECTED>Entry
     <OPTION VALUE="2">Dynamic Attribute
     <OPTION VALUE="3">Dynamic Entry
    </c:when>
    <c:when test='${param.modifier == "2"}'>
     <OPTION VALUE="0">Attribute ACL
     <OPTION VALUE="1">Entry
     <OPTION VALUE="2" SELECTED>Dynamic Attribute
     <OPTION VALUE="3">Dynamic Entry
    </c:when>
    <c:when test='${param.modifier == "3"}'>
     <OPTION VALUE="0">Attribute ACL
     <OPTION VALUE="1">Entry
     <OPTION VALUE="2">Dynamic Attribute
     <OPTION VALUE="3" SELECTED>Dynamic Entry
    </c:when>
    <c:otherwise>
     <OPTION VALUE="0" SELECTED>Attribute ACL
     <OPTION VALUE="1">Entry
     <OPTION VALUE="2">Dynamic Attribute
     <OPTION VALUE="3">Dynamic Entry
    </c:otherwise>
   </c:choose>
   </SELECT>
   <br>
   <br>
   <SPAN class="mediumtext"><iman:string key="AclScopeNameLabel"/></SPAN><BR>
   <SELECT name="scopeName"  size="1" style="WIDTH: 250px;">

	<c:forEach var="thisScope" items="${aclScopes}">
		<c:choose>
			<c:when test='${param.scopeName == thisScope}'>
				<OPTION VALUE="<c:out value='${thisScope}'/>" SELECTED><c:out value="${thisScope}"/>
			</c:when>
    		<c:otherwise>
    			<OPTION VALUE="<c:out value='${thisScope}'/>"><c:out value="${thisScope}"/>
    		</c:otherwise>
    	</c:choose>
	</c:forEach>
	
	
   </SELECT>
   <BR>
   <BR>
   <DIV id="propertyDiv" class="mediumtext">
   <SPAN class="mediumtext"><iman:string key="eDirRights.PropertyNameHeading"/>:</SPAN><BR>
   <SELECT name="protectedAttributeName" size=1" onChange="showPrivilages()">

      <%
         MContext context = eMFrameFactory.getMContext(request);
         String attributeName = request.getParameter("attr");
      %>
         <%
            String[] attrs = context.getDirUtils().getSortedAttrs();
			out.println("<OPTION value=\" \"> NONE");
			
            for(int i=0; i<attrs.length; i++)
            {
               boolean selected = attributeName!=null && attrs[i].equals(attributeName);
               if(selected)
               {
                  out.println("<OPTION value=\""+ eMFrameUtils.toDisplay(attrs[i]) +"\" selected>"+attrs[i]+"");
               }
               else
               {
                  out.println("<OPTION value=\""+ eMFrameUtils.toDisplay(attrs[i]) +"\">"+attrs[i]+"");
               }
            }
         %>
   </SELECT>
   <BR>
   </DIV>
   <SPAN class="mediumtext"><iman:string key="eDirRights.AssignedRightsHeading"/>:</SPAN><BR>
   <DIV id="privilagesDiv" class="mediumtext">
   </DIV>
   <BR>
   <BR>
   <SPAN class="mediumtext"><iman:string key="AclClassFilterLabel"/></SPAN><BR>
   <SELECT name="classname" size="1">

      <%
         MContext curContext = eMFrameFactory.getMContext(request);
         String curClassName = request.getParameter("classname");
         String[] classes = curContext.getDirUtils().getSortedClasses();

		 if(curClassName!=null && curClassName.equals(" "))
		 {
		 	%>
		 	<OPTION value=" " SELECTED>None
		 	<%
		 }
		 else
		 {
		 	%>
		 	<OPTION value=" ">None
		 	<%
		 }
            for(int i=0; i<classes.length; i++)
            {
               boolean curselected = curClassName!=null && classes[i].equals(curClassName);
               if(curselected)
               {
                  out.println("<OPTION value=\""+ eMFrameUtils.toDisplay(classes[i]) +"\" selected>"+classes[i]+"");
               }
               else
               {
                  out.println("<OPTION value=\""+ eMFrameUtils.toDisplay(classes[i]) +"\">"+classes[i]+"");
               }
            }
         %>
   </SELECT>
   <BR>
   <BR>
   <SPAN class="mediumtext"><iman:string key="AclFilterNameLabel"/></SPAN><BR>
   <INPUT type="text" name="filter" value="<c:out value="${param.filter}"/>" style="width: <iman:string key="UI.textboxPixel"/>"><iman:os typeFilter="*" control="filter" history="true"/>
   <BR>
   <BR>
   <iman:bar/>
   <iman:button key="OK" onClick="onOk()"/>
   <iman:button key="Cancel" onClick="window.close()" />

</FORM>
<iman:osFooter/>
</BODY>
</HTML>
