<html>

<head>
<%@ include file="nlsResource.jsp" %>
<%@ page import="java.io.*, java.util.*, jet.cs.util.*, jet.server.api.*, jet.server.api.http.*, jet.server.log.*" %>

<%@ page errorPage="errorpage.jsp" %>

<title>Run Report Form</title>
<script language="JavaScript" type="text/JavaScript">
	function paramChanged(p){
		document.form1.change_value.value = p;
		document.form1.action="";
		document.form1.submit();
	}
</script>
</head>

<%@ include file="AuthCheck.jsp" %>

<%
/**
 * This JSP shows how to call runReport2.jsp to run InvoiceReport.cls with the provided parameters.
 * Usage:
 * Copy this file and runReport2.jsp into <server_install_home>/public_html/jinfonet. 
 * Then start standalone report server and type the following URL if using standard standalone JReport Server.
 * "http://localhost:8888/jinfonet/getRptDescPage2.jsp".
 */
	HttpRptServer httpRptServer = HttpUtil.getHttpRptServer();

    String cat = "/SampleReports/SampleReports.cat"; //request.getParameter(APIConst.TAG_CATALOG);
    String rptName = "/SampleReports/InvoiceReport.cls"; //request.getParameter(APIConst.TAG_REPORT);
    String user = HttpUtil.getUser(request);
    
    String paramEngineId = request.getParameter(APIConst.TAG_ENGINE_ID);
    String change_value = request.getParameter("change_value");
    Properties ht = HttpUtil.getParameters(request);


	if(ServiceLogger.isLoggable(ServiceLogger.ACCESS, ServiceLogger.LEVEL_TRIVIAL)){
		HttpSession ssn = request.getSession(false);
		String id = ssn == null ? null : ssn.getId();
		ServiceLogger.logAccessSuccessEvent(httpRptServer.getResourceManager().getRealm(), user, id, 
											" generateSubmitReportHtml "+
											" catFullName=" + cat +
											" rptName=" + rptName,
											ServiceLogger.LEVEL_TRIVIAL);
	}
	if (paramEngineId != null && paramEngineId.length()>0) {
	    ht.put(APIConst.TAG_ENGINE_ID, request.getParameter(APIConst.TAG_ENGINE_ID));
	}
	if(change_value !=null && change_value.length()>0){
		ht.put("change_value", change_value);
	}
	
	ReportInfo rptInfo = httpRptServer.getReportInfo(user, cat, -1, rptName, -1, ht);
  String curRptSheet = rptInfo.getCurrentReportSheet().getName();
	List<String> sheets = new ArrayList();
	sheets.add(curRptSheet);
	List<ParamInfo> params = rptInfo.getParamInfos(sheets, ht);
	paramEngineId = rptInfo.getParamEngineId();
%>		
<font face="Arial">
<small>
<!-- the action should be a the URL to WebViewServlet plus string "action". 
the string is a MUST! -->
<form name="form1" method="POST" action="/jinfonet/runReport2.jsp">

<p><b>Run Report&nbsp;:&nbsp;<%= HttpUtil.decodeEsc(APIUtil.addUrlPaths(cat, rptName))%>
</b>&nbsp;&nbsp;<input type="submit" value="Submit" name="Submit_Btn">
<input type="reset" value="Reset" name="RBtn1"></p>
<%
	if(params != null && params.size() > 0) {
		StringBuffer sb = new StringBuffer();
		int sz = params.size();
		ParamInfo desc= null;%>
		<table style="font-family:Arial;font-size:10pt;" width=100%>
		<tr bgcolor="#000000"><td><b><font color="#ECECEC">
		<%= (sz == 1 ? "Parameter" : "Parameters")%>
		</font></b></td></tr></table>
        <table style="font-family:Arial;font-size:10pt;" width=100%>
		<small><font face="Arial">
<%
		for (int i = 0; i < sz; i++) {
			desc = (ParamInfo)params.get(i);
			String pmt = desc.getPrompt();
			pmt = (pmt!=null && pmt.length()>0)?pmt: desc.getName();
%>
			<tr>
				<td><%= pmt%></td>
			  <td>
					<select name="<%= APIConst.TAG_PARAM_PREFIX + desc.getName()%>" size="1" onchange="if(<%=desc.isReferedBy()%>){paramChanged('<%=desc.getName()%>');}">
<%				
						Vector v = desc.getValueOptions(Locale.getDefault());
						for (int j = 0; j < v.size(); j++) {
							String s = (String)v.get(j);
%>
					<option <%= (s.equalsIgnoreCase(desc.getDefaultValue()) ? "selected" : "")%> value="<%= s%>"><%= s%></option>
<%
				}
%>
					</select>
				</td>
			</tr>
<%
		}
%>
        </font></small></table>
<%
	}else{
%>
		<p><b>No parameter needed</b></p>
<%
	}
	int rstType = APIUtil.parseInt(request.getParameter(APIConst.TAG_RESULT_TYPE), APIConst.HTML);
%>

<p>
<table style="font-family:Arial;font-size:10pt;" width=100%><tr bgcolor="#000000"><td><b><font color="#ECECEC">
Select type of report presentation:</font></b></td></tr></table>
<BR>
        
<INPUT TYPE="radio" NAME="<%= APIConst.TAG_RESULT_TYPE %>" VALUE="1" CHECKED> To HTML &nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_IS_MULTI_FILES %>" VALUE="false" > Single File &nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_IS_CHART_APPLET %>" VALUE="true" CHECKED> Applet Chart
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_HAS_HYPERLINK %>" VALUE="false"> No Hyperlink
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_HAS_PAGE_NUMBER %>" VALUE="false"> No Page Number &nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_DRILLDOWN %>" VALUE="true"> Drilldown 
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_USE_TABLE %>" VALUE="true"> Use Table 
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_RELATIVE_FONT_SIZE %>" VALUE="true"> Relative font size 
<%
	int brws = APIConst.WEB_BROWSERS.length;
	if (brws > 0) {
%>
		&nbsp;&nbsp;Web Browser: <select name="<%= APIConst.TAG_WEB_BROWSER%>" size="1">
<%			for (int i = 0; i < brws; i++) {
%>
			<option value="<%= i%>"><%= APIConst.WEB_BROWSERS[i]%></option>
<%			}
%>
		</select>
<%
	}
%>
<BR><BR>
<INPUT TYPE="radio" NAME="<%= APIConst.TAG_RESULT_TYPE %>" VALUE="2"> To PDF <BR>
<BR>
<INPUT TYPE="radio" NAME="<%= APIConst.TAG_RESULT_TYPE %>" VALUE="3"> To TEXT &nbsp;&nbsp;
<INPUT TYPE="CHECKBOX" NAME="<%= APIConst.TAG_IS_NORMAL_TEXT %>" VALUE="false"> Standard Data Format
&nbsp;&nbsp;&nbsp;&nbsp;Delimiter:<input type="text" NAME="<%= APIConst.TAG_DELIMITER %>" size="4"><BR>
<BR>
<INPUT TYPE="radio" NAME="<%= APIConst.TAG_RESULT_TYPE %>" VALUE="<%= APIConst.EXCEL %>"> To Excel <BR>
<BR>
<INPUT TYPE="radio" NAME="<%= APIConst.TAG_RESULT_TYPE %>" VALUE="<%= APIConst.PS %>"> To PS <BR>
<BR>
<INPUT TYPE="radio" NAME="<%= APIConst.TAG_RESULT_TYPE %>" VALUE="<%= APIConst.RTF %>"> To Rich Text Format <BR>
<BR>
</p>

<hr>

<table style="font-family:Arial;font-size:10pt;" border="0" width="100%">
  <tr>
    <td>
      <INPUT TYPE="radio" NAME="<%= APIConst.TAG_USE_DEF_DB_USER %>" VALUE="true" CHECKED> Use the default DB user and password defined in catalog 
    </td>
  </tr>
  <tr>
    <td>
      <INPUT TYPE="radio" NAME="<%= APIConst.TAG_USE_DEF_DB_USER %>" VALUE="false"> Use the DB user:
        <input type="text" name="<%= APIConst.TAG_DB_USER %>" size="10">
    </td>
    <td>
      password:<input type="password" name="<%= APIConst.TAG_DB_PSWD %>" size="10">
    </td>
  </tr>
</table>
</p>


<input type=hidden name="<%= APIConst.TAG_CMD %>" value="<%= APIConst.CMD_WEB_VIEW %>">
<input type=hidden name="<%= APIConst.TAG_CATALOG %>" value="<%= cat %>">
<input type=hidden name="<%= APIConst.TAG_REPORT %>" value="<%= rptName %>">
<input type=hidden name="<%= APIConst.TAG_PATH %>" value="<%= rptName %>">
<input type=hidden name="<%= APIConst.TAG_ENGINE_ID %>" value="<%= paramEngineId %>">
<input type=hidden name="change_value" value="">
<input type=hidden name="<%= APIConst.TAG_REPORT_SHEET+"$"+curRptSheet%>" value="true">

<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</p>
</form>
</small></font>
</body>
</html>
