<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8"
   import="com.novell.webaccess.common.JSPConduit,
           java.util.ArrayList" %>

<%   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources"); %>

<HTML>
<HEAD>
<TITLE><%= c.string("CustomCategoriesReport.Title") %></TITLE>
<% if (c.var("inProgress").equals("true")) { %>
   <META HTTP-EQUIV="Refresh" CONTENT="2">
<% } %>
<link   rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>

<jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
<jsp:include page='<%= c.getPath("dev/OSScripts_inc.jsp") %>' flush="true" />

<script language="JavaScript">


   /*******************
    * FUNCTION HEADER *
    *******************/
    function selectAllCollections()
    {
        var numOptions = document.GetCustomCategoriesForm.CollectionList.length;
        for(var i = 0; i < numOptions; i++)
        {
            document.GetCustomCategoriesForm.CollectionList.options[i].selected = "selected";
        }
    }

   /*******************
    * FUNCTION HEADER *
    *******************/
   function onPageSubmit()
   {
      var found = "false";
      var selected = "";
      var numOptions = document.GetCustomCategoriesForm.CollectionList.length;
      for(var i = 0; i < numOptions; i++)
      {
         if(document.GetCustomCategoriesForm.CollectionList.options[i].selected == true)
         {
            if(found == "true")
            {
               selected += ",";
            }

            selected += i;

            found = "true";
         }
      }

      if(found == "false")
      {
         alert("<%= c.string("CustomCategoriesReport.MakeSelection") %>");
         return false;
      }

      document.GetCustomCategoriesForm.selectedElements.value = selected;

      return true;
   }

</script>
</HEAD>

<BODY   TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" bgcolor="#FFFFFF"
        onLoad="returnFromOS();">

<form   name="GetCustomCategoriesForm"
        method=post
        action="webacc"
        onSubmit="return(onPageSubmit())">

        <input  type=hidden
                name="taskId"
                value="<%= c.var("taskId") %>">

        <input  type=hidden
                name="merge"
                value="fw.CustomCategoriesReport">

        <input  type=hidden
                name="error"
                value="dev.GenErr">

        <input  type=hidden
                name="nextState"
                value="getCustomCategories">

        <input  type=hidden
                name="selectedElements"
                value="">

   <% c.set("TaskHeader.title", c.string("CustomCategoriesReport.ReportHeader"));
      c.set("TaskHeader.helpFile", "fw/getcustomcategoriesformtask.html");
      c.set("TaskHeader.iconUrl", "dev/bullet_default_16.gif"); %>
   <jsp:include page='<%= c.getPath("dev/TaskHeader_inc.jsp") %>' flush="true" />

   <div class="formdescriptextml0"  style="width: 70%"><%= c.string("CustomCategoriesReport.Instructions") %></div>
   <div class="mediumtext" style="margin-top: 1em;"><%= c.string("CustomCategoriesReport.CollectionPrompt") %></div>

   <div>
      <%
         String sCollectionCount = (String)c.get("Collection.Count");
         String size = sCollectionCount;
         if(Integer.parseInt(size) > 10)
         {
            size = "10";
         }
         else if(Integer.parseInt(sCollectionCount) < 5)
         {
            size = "5";
         }
      %>
      <select name="CollectionList" multiple="multiple" size="<%=size%>">
        <%
           String sSelectedElements = (String)c.get("Selected.Elements");
           String[] sSelected = sSelectedElements.split(",");
           int[] selected = new int[sSelected.length];
           for(int j = 0; j < sSelected.length; j++)
           {
              selected[j] = Integer.parseInt(sSelected[j]);
           }
           if (sCollectionCount != null)
           {
               int iCollectionCount = Integer.parseInt(sCollectionCount);
               boolean found;
               for (int i = 0; i < iCollectionCount; i++)
               {
                  found = false;
                  String collectionFDN = (String)c.get("Collection." + i + ".FDN");

                  for(int j = 0; j < selected.length; j++)
                  {
                     if(selected[j] == i)
                     {
                        found = true;
                     }
                  }

                   if (found == true)
                   {
                       %>
                            <option value="<%=collectionFDN%>" selected="selected"><%=collectionFDN %></option>
                       <%
                   }
                   else
                   {
                       %>
                            <option value="<%=collectionFDN%>"><%=collectionFDN %></option>
                       <%
                   }
               }
           }
           %>
      </select>
    </div>
    <a href="#" onClick="javascript:selectAllCollections();return false"><%= c.string("CustomCategoriesReport.SelectAllCollections") %></a>

      <% if (c.var("inProgress").equals("true")) { %>
         <div id="generate" style="display: block">
            <div class="head4" style="margin-bottom: 0.5em;  margin-top: 2em">
               <img height="32" width="32" src="<%= c.getModulesUrl() %>/dev/images/In-progress_framed32.gif" align="absmiddle"> <span class="typegold1">"<%= c.toHTML(c.string("RolesToUserReport.Generating")) %>"</span>
                  <b>"<%= c.toHTML(c.string("CustomCategoriesReportTaskDisplayName")) %>"</b></div>
            <div class="mediumtext" style="margin-left: 3em; margin-bottom: 2em; margin-top: 2em; width: 350px"><%= c.toHTML(c.var("progressMessage")) %></div>
            <div class="mediumtext" style="margin-left: 3em; margin-bottom: 2em; width: 350px">"<%= c.toHTML(c.string("RolesToUserReport.CancelReport")) %>"</div>
         </div>
      <% } %>

      <% if (c.var("progressCancelled").equals("true")) { %>
         <div id="cancel" style="display: block">
            <div class="head4" style="margin-bottom: 0.5em;  margin-top: 2em">
               <img height="32" width="32" src="<%= c.getModulesUrl() %>/dev/images/cancelled32.gif" align="absmiddle"> <span class="typegold1">"<%= c.toHTML(c.string("RolesToUserReport.Cancelled")) %>"</span>
                  <b>"<%= c.toHTML(c.string("CustomCategoriesReportTaskDisplayName")) %>"</b></div>
            <div class="mediumtext" style="margin-left: 3em; margin-bottom: 2em; width: 350px">"<%= c.toHTML(c.string("RolesToUserReport.CancelledMessage")) %>"</div>
         </div>
      <% } %>
      <div class="margintop3">
         <jsp:include page='<%= c.getPath("dev/Bar_inc.jsp") %>' flush="true" />
         <% if (c.var("inProgress").equals("true")) { %>
         <a href="webacc?taskId=<%= c.var("taskId") %>&merge=fw.GetCustomCategoriesFormTask&nextState=cancel">
            <IMG name="Cancel" alt="<%= c.string("Button.Cancel.alt") %>" title="<%= c.string("Button.Cancel.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.Cancel.image") %>" border=0></a>
         <% } else { %>
            <input   type=image
               name="OKButton"
               alt="<%= c.string("Button.OK.alt") %>"
               src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.OK.image") %>"
               border=0>
               <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" />
         <% } %>
		</div>
</form>
<jsp:include page='<%= c.getPath("dev/OSFooter_inc.jsp") %>' flush="true" />
</BODY></HTML>
