<%@ page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true" %>
<%@ page isThreadSafe="true" %>
<%@ page errorPage="AdminException.jsp"
%><%@ page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@ page import="com.fujitsu.iflow.model.workflow.WFAdminSession"
%><%@ page import="com.fujitsu.iflow.model.wfcore.WFAdminSessionImpl"
%><%@ page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@ page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@ page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@ page import="com.fujitsu.iflow.server.dataobjects.ProcessDefinitionStatesEnum"
%><%@ page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@ page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@ page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@ page import="java.util.Date"
%><%@ page import="java.util.Arrays"
%><%@ page import="com.fujitsu.iflow.model.workflow.DirectoryServices"
%><%@ page import="java.util.Enumeration"
%><%@ page import="java.text.SimpleDateFormat"
%><%@ page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMAdmin"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMAdminImpl"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    BPMAdmin bpas = bps.getAdmin();
    WFAdminSessionImpl wfSession = ((BPMAdminImpl)bpas)._wfas;

    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;
    String rowColor = bcolor[nextColor];
    session.setAttribute("TabIndex","3");

    int _pageSize = 20;
    int selIdValue=1;
    long id = -1;
    String role = null;
    String selRole = null;

    String pageOption = request.getParameter("wPageId");
    if (!(pageOption != null && pageOption.length() >= 1))
    {
        pageOption = "1";
    }

    //DO NOT MERGE THE ABOVE CODE INTO THE IF-LOOP below
    int wPageValue = Integer.parseInt(pageOption);
    if (wPageValue < 1)
        wPageValue = 1;

    String password = (String) session.getAttribute("password");
    String[] roles = getRoles(wfSession,password);
    Arrays.sort(roles);
    session.setAttribute("roles",roles);

%>
<html>
<head>
<title>Interstage Business Process Manager | User Management</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="JavaScript" src="styles/clockscripts.js"></script>
<script>
function setSelection(wiForm, selPage)
{
    wiForm.wPageId.value = selPage
    wiForm.submit()
}

function setPlanId(val, id, adForm)
{
    adForm.planId.value= id
    adForm.selected.value= val
    adForm.submit()
}

function loadMembers(role, roleForm)
{
    roleForm.selRole.value= role
    roleForm.submit()
}

</script>
</head>

<body class="adminBodyClass">
<center>

<jsp:include page="AdminHeader.jsp" flush="true"/>
<form name="roleForm" method="get" action="UserMgmt1.jsp">
  <input type="hidden" name="selRole" value="-1">
  <input type="hidden" name="selected" value="Edit">

<br><br>
<table bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="25%" align="center">
<tr align="center" class="headrow">
    <td bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2">All Groups</font></td>
</tr>

<%
    for (int i = 0; i < roles.length; i++)
    {
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
        role = roles[i];
    String groupMgmtURL = "GroupMgmt.jsp?roleName="+roles[i];

%>
<tr class="<%= rowColor %>">
    <td><a href="<%= groupMgmtURL %>"><%= role %> </a></td>
</tr>
<%
   }
%>
</table>

</form>
</center>
</BODY>
</html>

<%!

    public
    String[]
    getRoles(WFAdminSession wfSession, String password)
        throws Exception
    {
    String[] roles = null;
        try {
            DirectoryServices ds = WFObjectFactory.getDirectoryServices(wfSession,wfSession.getUserName(),password);
        roles = ds.getUserGroups();
        }
        catch(Exception e)
        {
        return null;
        }
        return roles;
    }


    public WFAdminSessionImpl getiFlowSession(Object modelObject)
    {
            return (WFAdminSessionImpl)(modelObject);
    }

%>
