<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.DirectoryServices"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    WFSession wfSession = (WFSession)session.getAttribute("ModelsessionID");
    if (wfSession == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }
%>
<html>
<head><title>Interstage Business Process Manager | Reassign Task</title></head>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<script>
    function backClicked(id)
    {
        location.href("WorkItem.jsp?taskId=" + id);
    }
</script>
<body class="bodyClass" onLoad="goforit();">

    <jsp:include page="WorkItemHeader.jsp" flush="true"/> </br></br>
<%
    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;
    long taskId = Long.parseLong(request.getParameter("taskId"));
    WorkItem task = WFObjectFactory.getWorkItem(taskId, wfSession);
    String pwd = (String)session.getAttribute("password");
    DirectoryServices ds  = WFObjectFactory.getDirectoryServices(
        wfSession, wfSession.getUserName(), pwd);
    String[] groups = ds.getUserGroups();
    String selectedGroup = (String)session.getAttribute("selectedGroup");
    String[] usersToAdd = (String[])session.getAttribute("usersToAdd");

    String from="";
    String to="";
    String date="";
    String forTask="";
    String process="";
    if(task != null)
    {
        from = task.getInitiator();
        to = task.getAssignee();
        date = (new java.util.Date(task.getCreationTime())).toString();
        forTask = task.getName();
        process = task.getProcessInstanceName();
    }
%>
<center>
<form method="get" action='<%= response.encodeURL("ReassignAction.jsp") %>'>

<table width="650" class="tableClass" border="0" cellspacing="1" cellpadding="0" bgcolor="#CCCCCC">
    <input type="hidden" name="taskId" value="<%= taskId %>">
    <tr class="headrow" height="20">
        <td colspan="2">&nbsp;
            Reassigning the task: <%= task.getName() %>
        </td>
    </tr>
<%
    String rowColor = bcolor[nextColor];
    nextColor = (nextColor + 1)%2;
%>
  <tr class="<%=rowColor%>">
  <td colspan="2">
    <table class="tableClass" border="0" width="100%" cellspacing="0" cellpadding="4">
    <col width="15%"><col width="85%">
    <tr class="<%=rowColor%>">
        <td class="prompt">From</td>
        <td><% QuickForm.writeHtml(out, from); %></td>
        </tr>
<%
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
%>
    <tr class="<%=rowColor%>">
        <td class="prompt">To</td>
        <td ><% QuickForm.writeHtml(out, to); %></td>
        </tr>
<%
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
%>
    <tr class="<%=rowColor%>">
        <td class="prompt">Date</td>
        <td ><% QuickForm.writeHtml(out, date); %></td>
        </tr>
<%
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
%>
    <tr class="<%=rowColor%>">
        <td class="prompt">For</td>
        <td ><% QuickForm.writeHtml(out, forTask); %></td>
        </tr>
<%
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
%>
    <tr class="<%=rowColor%>">
        <td class="prompt">Process Instance</td>
        <td ><% QuickForm.writeHtml(out, process); %></td>
        </tr>
    </table>
    </td>
  </tr>
<%
    rowColor = bcolor[nextColor];
    nextColor = (nextColor + 1)%2;
%>
  <tr class="<%=rowColor%>"><td colspan="2" align="center">
<br/>
<table class="<%=rowColor%>" border="0" cellpacing="0" cellpadding="0" cellspacing="2">
<tr align="center">
    <td bgcolor="#EEEEEE"><font class="arialfonts"><b>Groups</b></font></td>
    <td><img src="images/clear.gif" width="25" height="10"/></td>
    <td bgcolor="#EEEEEE"><font class="arialfonts"><b>Users</b></font></td>
    <td><img src="images/clear.gif" width="10" height="10"/></td>
    <td><img src="images/clear.gif" width="25" height="10"/></td>
    <td><img src="images/clear.gif" width="10" height="10"/></td>
    <td bgcolor="#EEEEEE"><font class="arialfonts"><b>Reassign</b></font></td>
</tr>

        <tr align="center">
          <td>
            <select name="Groups" size="10" onChange="this.form.submit()" style="width:150 px;">
    <%
        if ( groups != null && groups.length > 0 )
        {
            for(int i=0; i<groups.length; i++)
            {
                if ( groups[i].equals(selectedGroup) )
                {
    %>
              <option selected value="<%= groups[i] %>"> <%= groups[i] %> </option>
    <%
                }
                else
                {
    %>
              <option value="<%= groups[i] %>"> <%= groups[i] %> </option>
    <%
                }
            }
        }
    %>
            </select>
          </td>
          <td>&nbsp;</td>
          <td>
            <select name="Users" size="10" multiple style="width:150 px;">
     <%
            if(selectedGroup != null)
            {
                String[] members = ds.getUserList(selectedGroup);
                int mlen = members.length;
                if(mlen > 0)
                {
                    for(int i=0; i<mlen; i++)
                    {
    %>
                        <option><%= members[i] %></option>
    <%
                    }
                }
                else {
    %>
                    <option>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </option>
    <%
                }
            }
            else {
    %>
                    <option>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </option>
    <%
            }
    %>
            </select>
          </td>
    <td><img src="images/clear.gif" width="10" height="10"/></td>
          <td>
            <input class="submitClass" type="submit" name="AddUsers" value=">>"><br><br>
            <input class="submitClass" type="submit" name="DeleteUsers" value="<<">
          </td>
    <td><img src="images/clear.gif" width="10" height="10"/></td>
          <td>
        <select name="Reassign" size="10" multiple style="width:150 px;">
        <%
        if (usersToAdd != null)
        {
            for(int i=0; i<usersToAdd.length; i++)
            {
            %>
            <option><%= usersToAdd[i] %></option>
            <%
            }
        }
        else
        {
        %>
            <option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
        <%
        }
        %>
        </select>
        </td>
        </tr>
    </table><br/><br/>
    </td>
    </tr>
<tr class="evenrow"><td colspan="2">
   <table class="tableClass" align="center">
    <tr>
        <td>
            <input class="submitClass" type="submit" name="ReassignButton" value="Reassign">
          </td>
          <td>&nbsp;</td> <td>&nbsp;</td>
          <td>
            <input class="submitClass" name="button" type="button" onClick="backClicked(<%= task.getId() %>)" value="Cancel">
          </td>
        </tr>
    </table>

    </td>
  </tr>
</table>
</form>
</center>
</body>
</html>

