<% try {
		SessionCheck sessionCheck=new  SessionCheck();
		sessionCheck.fSessionCheck(request,response);
	%>
<html>
<TITLE>Reporting Tool</TITLE>
<head>
<link rel='stylesheet' href='styles/ReportFormat.css' type='text/css'>

<style TYPE="text/css" MEDIA="screen">
IFRAME { 
scrollbar-face-color: #818181; 
scrollbar-highlight-color: #FFFFFF; 
scrollbar-shadow-color: #FFFFFF; 
scrollbar-3dlight-color: #818181; 
scrollbar-arrow-color: #FFFFFF; 
scrollbar-track-color: #FFFFFF; 
scrollbar-darkshadow-color: #818181; 
} 
 </style>

 <SCRIPT LANGUAGE="JavaScript">
 <!--
		var finalVal="";
		var count=0;
		function addVal(chkVal,sCondition)
		{
			if(chkVal.checked == true)
			{
				if(document.f10.checkflag.value =="")
				{
					document.f10.sFinalVal.value=chkVal.value
					document.f10.checkflag.value="yes";
				}else
				{
					alert("Only one value is allowed !!");
					chkVal.checked = false
				}
			}else
			{
				document.f10.checkflag.value="";
				document.f10.sFinalVal.value="";

			}

			
		}
		function setColumn(cmbFunction,pos,Column)
		{
			if(cmbFunction != '0')
			{
				if(cmbFunction =='substring')
				{
					var startInd = prompt("Enter Starting Index ",""); 
					if (startInd == null || startInd==""){ // Cancel pressed 
						startInd=1;
					}
					var endInd = prompt("Enter Ending Index ",""); 
					if (endInd == null || endInd==""){ // Cancel pressed 
						endInd=2;
					}
					document.getElementById("ColName"+pos).value="substring("+Column+","+startInd+","+endInd+")";
				}else if(cmbFunction =='DatePart')
				{
					var startInd = prompt("Enter DatePart",""); 
					if (startInd == null || startInd==""){ // Cancel pressed 
						startInd="month";
					}
					document.getElementById("ColName"+pos).value="DatePart("+startInd+","+Column+")";
				}else if(cmbFunction =='DateName')
				{
					var startInd = prompt("Enter DatePart",""); 
					if (startInd == null || startInd==""){ // Cancel pressed 
						startInd="month";
					}
					document.getElementById("ColName"+pos).value="DateName("+startInd+","+Column+")";
				}else
				{
					document.getElementById("ColName"+pos).value=cmbFunction+"("+Column+")";
				}
			}else
			{
				document.getElementById("ColName"+pos).value=Column;
			}
		}

		function  launchDefValues(sDataBase,sTableName,sColumnName,stxtName,src,width,height)
		{
			branch=window.open(src+'?DataBase='+sDataBase+'&TableName='+sTableName+'&ColumnName='+sColumnName+'&txtName='+stxtName,'','width='+width+',height='+height);
			if (branch && !branch.closed) branch.focus(); 
		}	
 
 //-->
 </SCRIPT>

</head>
<body background='images/website_bg_stripes.gif'>
<%@ page language="java"  import="java.sql.*,java.util.*, com.ReportTool.*;" session="true"%>
<%!
			public String replaceVal(String s)
			{
				String strBuf	= "";
				if(s.trim().equals("<"))
				{
					strBuf="&lt;";
				}else if(s.trim().equals(">"))
				{
					strBuf="&gt;";
				}else if(s.trim().equals("<="))
				{
					strBuf="&lt;=";
				}else if(s.trim().equals(">="))
				{
					strBuf="&gt;=";
				}else if(s.trim().equals("<>"))
				{
					strBuf="&lt;&gt;";
				}else
				{
					strBuf=s;
				}
				return strBuf;
			}
		%>
<%
 ResourceBundle rBundle =  ResourceBundle.getBundle("Report_en_USS");
 
  //Common class initialization for access control
    int iCount=0;
	String sReportHeaderCol=rBundle.getString("sReportHeaderCol");
	String sRowColor=rBundle.getString("sRowColor");
	String sRowAltColor=rBundle.getString("sRowAltColor");
    String   sColor =sRowColor;

	String sReportContentCol="#FFFFFF";

	String sDataBase	=	request.getParameter("DataBase");
	String sTableName	=	request.getParameter("TableName");
	String sColumnName	=	request.getParameter("ColumnName");
	String stxtName		=	request.getParameter("txtName");

	String tableName=sTableName.substring(0,sTableName.indexOf(":"));
	String tableAlias=sTableName.substring(sTableName.indexOf(":")+1,sTableName.length());
	String sQuery="";

	ReportRegisterParameter objRP	= new ReportRegisterParameter();
	ArrayList arColumns=objRP.getColumnArrayFromTable(tableName,sDataBase);
	ArrayList arParameters = ArrayList(session.getAttribute("arParameters"));
	//08-Apr-05session.setAttribute("arParameters",arParameters);

	
%>
<form name="f10">
<input type="hidden" name="sFinalVal">
<input type="hidden" name="checkflag">
<table border="0" width="100%" height="5" cellpadding=0 cellspacing=0> 
<%
int iVal=0;
int iCtr=1;
for(int i=0,j=1;i<arColumns.size();i=i+2,j++)
{
      		String ColType  =	(String)arColumns.get(i+1);
			ArrayList arFunctions=new ArrayList();
			if(ColType.trim().equals("TEXT"))
			{
				arFunctions=arFunctionString;
				
			}else if(ColType.trim().equals("NUMERIC"))
			{
				arFunctions=arFunctionNumeric;
			}else if(ColType.trim().equals("DATE"))
			{
				arFunctions=arFunctionDate;
			}
%>
	<tr class='ReportContentFont' >
			<td bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<input type='checkbox' name='chk' value='<%=j%>'>
			</td>
			<td width="10%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center"><%=arColumns.get(i)%></td>
			<td width="15%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<select size="1" name="cmbFunction<%=j%>" class=FormFieldLabelFont  style="width:80px" onChange='setColumn(this.value,<%=j%>,"<%=tableAlias+"."+arColumns.get(i)%>")'>
				 <%     
					try
					{%>
						<option value="0" >Select..</option>
						<%for (int n=0;n<arFunctions.size();n=n+1)
						{%>
							<option value = <%= arFunctions.get(n) %> ><%=arFunctions.get(n) %> </option>
						<%
						 }//end of for
					}catch(Exception e){
						System.out.println("Error");
					}
					
				%>
			</td>
			<td width="15%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<input type='text' name='ColName<%=j%>' class=FormFieldLabelFont style="width:80px" value='<%=tableAlias+"."+arColumns.get(i)%>'>
			</td>
			
			<td width="10%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<input type='checkbox' name='range<%=j%>' value='1' onClick='if(this.checked==true){document.getElementById("SVal<%=j%>").style.display="block";document.getElementById("cmbSyntax<%=j%>").style.display="none";document.getElementById("cmbExSyntax<%=j%>").style.display="block";}else{document.getElementById("SVal<%=j%>").style.display="none";document.getElementById("cmbSyntax<%=j%>").style.display="block";document.getElementById("cmbExSyntax<%=j%>").style.display="none";}'>
			</td>

			<td width="10%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<select size="1" name="cmbSyntax<%=j%>" id="cmbSyntax" class=FormFieldLabelFont style="width:80px">
				<%
					for(int iCmb=0;iCmb<arSyntax.length;iCmb=iCmb+1)
					{
						if(iCmb==0)
						{
							out.println("<option value='"+arSyntax[iCmb]+"' selected >"+replaceVal((String)arSyntax[iCmb])+"</option>");

						}else
						{
							out.println("<option value='"+arSyntax[iCmb]+"'>"+replaceVal((String)arSyntax[iCmb])+"</option>");
						}
					}
				%>
				</select>
				<select size="1" name="cmbExSyntax<%=j%>"  style='display:none' class=FormFieldLabelFont style="width:80px">
				<%
					for(int iCmb=0;iCmb<arSyntaxEx.length;iCmb=iCmb+1)
					{
						if(iCmb==0)
						{
							out.println("<option value='"+arSyntaxEx[iCmb]+"' selected >"+arSyntaxEx[iCmb]+"</option>");

						}else
						{
							out.println("<option value='"+arSyntaxEx[iCmb]+"'>"+arSyntaxEx[iCmb]+"</option>");
						}
					}
				%>
				</select>
			</td> 

			<td width="15%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<input type='text'  name='FVal<%=j%>' class=FormFieldLabelFont style="width:80px" onDblClick='launchDefValues("<%=sDataBase%>","<%=sTableName%>",document.getElementById("ColName<%=j%>").value,"FVal<%=j%>","ReportParametersRightValueDisplay.jsp",600,300)'>
			</td>
			<td width="15%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<input type='text' name='SVal<%=j%>' style='display:none' class=FormFieldLabelFont style="width:80px" onDblClick='launchDefValues("<%=sDataBase%>","<%=sTableName%>",document.getElementById("ColName<%=j%>").value,"SVal<%=j%>","ReportParametersRightValueDisplay.jsp",600,300)'>
			</td>
			<td width="10%" bgcolor='<%=sReportContentCol%>' class='FormFieldFont' align="center">
				<select size="1" name="cmbOperator<%=j%>" id="cmbSyntax" class=FormFieldLabelFont style="width:80px">
				<%
					for(int iCmb=0;iCmb<arOperator.length;iCmb=iCmb+1)
					{
						if(iCmb==0)
						{
							out.println("<option value='"+arOperator[iCmb]+"' Selected >"+replaceVal((String)arOperator[iCmb])+"</option>");
						}else
						{
							out.println("<option value='"+arOperator[iCmb]+"'>"+replaceVal((String)arOperator[iCmb])+"</option>");
						}
					}
				%>
				</select>
			</td>

		</tr>
		<%	
	  if(sReportContentCol.trim().equals("#FFFFFF"))
			 sReportContentCol="#E6E6E6";
		else
			 sReportContentCol="#FFFFFF";
		if(iVal==200)
		{
			out.println("</table>");
			iVal=0;
			out.println("<table border='0' width='100%' height='5' cellpadding=0 cellspacing=0>");

		}
		iVal++;
		iCtr++;
		
		}%>

	</table></form>

</body>
</html>
<%}catch(Exception e){
  out.println(e);
}%>