<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.common.UdaNameSanitizer"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItem"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItemRef"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="java.lang.Long"
%><%@page import="java.io.Writer"
%><%@page import="java.net.URL"
%><%@page import="java.net.URLEncoder"
%><%@page import="java.text.DateFormat"
%><%@page import="java.text.ParseException"
%><%@page import="java.util.ArrayList"
%><%@page import="java.util.Date"
%><%@page import="java.util.List"
%><%@page import="java.util.Locale"
%><%request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
%><%
    WFSession wfSession = (WFSession)session.getAttribute("ModelsessionID");
    if (wfSession == null) {
        response.sendRedirect("Login.jsp");
        return;
    }

    WorkItem task = (WorkItem)request.getAttribute("task");
    ProcessInstance pi = task.getProcessInstance();
    Plan plan = pi.getPlan();

    List attributes = new ArrayList();
    if(task != null){
        DataItemRef[] items = plan.getDataItemRefs();
        for(int i=0; i<items.length; i++) {
            attributes.add(items[i].getName());
        }
    }

    String udaIdentifier = null;
%>
    <table width="650" class="tableClass" border="0" cellpadding="4" cellspacing="1" align="center">
<%
    int last = attributes.size();
    for (int i = 0; i<last; i++ ) {
        String attributeName = (String)attributes.get(i);
        udaIdentifier = UdaNameSanitizer.getSanitizedString(attributeName);
        if (attributeName.trim().startsWith("_")) {
            continue;
        }
        String udaValue = task.getDataItemValue(attributeName);
        String udaType = task.getDataItemType(attributeName);
%>
        <tr class="oddrow">
            <td class="prompt">
                <% QuickForm.writeHtmlWithNBSPs(out, attributeName); %>
            </td>
            <td align="left">
<%
            showInputBox(out, attributeName, udaValue, udaType);
%>
            </td>
        </tr>
<%
    }
%>
        <tr class="oddrow">
            <td colspan="2"></td>
        </tr>
     </table>


<%!

public void showInputBox(Writer out, String udaName, String udaValue, String udaType)
    throws Exception
{
    try {
        String udaIdentifier = UdaNameSanitizer.getSanitizedString(udaName);
        if(udaType.equals(DataItem.TYPE_DATE)) {
            // first rationalize the date into a long value
            // because apparently people do it different ways.
            long lval = 0;
            try {
                lval = Long.parseLong(udaValue);
            }
            catch (Exception e2) {
                // parse the date
                // assign lval
            }
            //add hidden uda for value
            out.write("\n<input type=\"hidden\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"14\" value=\"");
            QuickForm.writeHtml(out, Long.toString(lval));
            out.write("\" />");
            //add input box
            out.write("\n<input type=\"text\" name=\"xxx_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"40\" onChange=\"validateDate(wiForm.uda_"+udaIdentifier+",wiForm.xxx_"+udaIdentifier+");\"/>");
            //Add image button
            out.write("\n<input type=\"image\" name=\"button_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" src=\"calendar/cal.gif\" width=\"16\" height=\"15\"/>");
            //Add Script
            out.write("\n<script type=\"text/javascript\">");
            out.write("\nwiForm.xxx_"+udaIdentifier+".value = formatDate(wiForm.uda_"+udaIdentifier+".value); ");
            out.write("\nCalendar.setup({inputField  : \"xxx_"+udaIdentifier+"\", button      : \"button_"+udaIdentifier+"\"});");
            out.write("\nshowTimeZone();");
            out.write("\n</script>");
        } else if (udaType.equals(DataItem.TYPE_STRING)) {
            //add input box
            out.write("<textarea name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" cols=\"68\" rows=\"2\">");
            QuickForm.writeHtml(out, udaValue);
            out.write("</textarea>");
        } else if (udaType.equals(DataItem.TYPE_INTEGER)) {
            //add input box
            out.write("<input type=\"text\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"30\" value=\"");
            QuickForm.writeHtml(out, udaValue);
            out.write("\" onChange=\"validateInt(wiForm.uda_"+udaIdentifier+");\"/>");
        } else if (udaType.equals(DataItem.TYPE_LONG)) {
            //add input box
            out.write("<input type=\"text\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"30\" value=\"");
            QuickForm.writeHtml(out, udaValue);
            out.write("\" onChange=\"validateLong(wiForm.uda_"+udaIdentifier+");\"/>");
        } else if (udaType.equals(DataItem.TYPE_FLOAT)) {
            //add input box
            out.write("<input type=\"text\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"30\" value=\"");
            QuickForm.writeHtml(out, udaValue);
            out.write("\" onChange=\"validateFloat(wiForm.uda_"+udaIdentifier+");\"/>");
        } else if (udaType.equals(DataItem.TYPE_BIGDECIMAL)) {
            //add input box
            out.write("<input type=\"text\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"30\" value=\"");
            QuickForm.writeHtml(out, udaValue);
            out.write("\" onChange=\"validateBig(wiForm.uda_"+udaIdentifier+");\"/>");
        } else if (udaType.equals(DataItem.TYPE_BOOLEAN)) {
            //add input box
            boolean isTrue = udaValue.equals("true");
            out.write("<input type=\"radio\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" ");
            if (isTrue) {
                out.write("checked ");
            }
            out.write("value=\"true\" /> true ");
            out.write("<input type=\"radio\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" ");
            if (!isTrue) {
                out.write("checked ");
            }
            out.write("value=\"false\" /> false ");
        } else {
            //add input box
            out.write("<input type=\"text\" name=\"uda_");
            QuickForm.writeHtml(out, udaIdentifier);
            out.write("\" size=\"30\" value=\"");
            QuickForm.writeHtml(out, udaValue);
            out.write("\"/>");
        }
    }
    catch (Exception e) {
        out.write("Unable to understand '");
        QuickForm.writeHtml(out, udaValue);
        out.write("' because: ");
        QuickForm.writeHtml(out, e.toString());
    }
}

%>
