﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.security.ireport.model.vo.*"%>
<%@ page import="com.security.ireport.engine.definition.*"%>
<%@ page import="com.security.ireport.engine.ReportConstants"%>
<%@ page import="com.security.ireport.util.EscapeUtil"%>
<%@ page import="com.security.ireport.util.IReportUtil"%>
<%@ page import="com.security.ireport.util.IReportConfCheckUtil"%>
<%@ page import="com.security.ireport.util.chart.LegendUtil"%>
<%@ page import="com.security.ireport.util.TableGroupShowUtil.ClassCount"%>
<%@ page import="com.security.ireport.util.TableGroupShowUtil"%>
<%@ page import="com.hs.atic.util.AticUtil"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page isELIgnored="false" %>

<link href="<s:url value='/iReport/styles/public.css' includeParams='none' />" type="text/css" rel="stylesheet"></link>
<%
	
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
	String sessionId = String.valueOf(request.getAttribute("sessionId"));
	String index = String.valueOf(request.getAttribute("index"));
	String tableId=String.valueOf(request.getParameter("tableId"));
	if("null".equals(tableId))
	{
	    tableId=String.valueOf(request.getAttribute("tableId"));
	}
	request.setAttribute("tableId",tableId);
	
	
%>
<s:i18n name="IReport">
	
		
		<input type="hidden" id="sessionId" name="sessionId"
			value="<%=sessionId%>" />
			
		<input type="hidden" id="index" name="index"
			value="<%=index%>" />

		   <%		
				TableObj tableObj = (TableObj) request.getAttribute("tableObj");	
				
				StringBuffer sbPaginator=new StringBuffer();
				sbPaginator.append("tableId="+tableId);
				sbPaginator.append("&tablePanel=tablePanel"+tableId);
				
				sbPaginator.append("&sessionId="+sessionId);
				sbPaginator.append("&index="+index);
				sbPaginator.append("&orderField="+tableObj.getOrderInfo().getOrderField());
				sbPaginator.append("&orderType="+tableObj.getOrderInfo().getOrderType());
				sbPaginator.append("&pageNum="+tableObj.getPageNum());
				sbPaginator.append("&pageSize="+tableObj.getPageSize());
				sbPaginator.append("&totalPageNum="+tableObj.getTotalPageNum());
				sbPaginator.append("&totalRecordNum="+tableObj.getTotalNum());
				String strPaginator = sbPaginator.toString();
			%>
		<table totalRecordNum="<%=tableObj.getTotalNum() %>" cellspacing="0" cellpadding="0" class="table_list"  align="center" id="tab_List<%=tableId%>">
<%
if(!IReportConfCheckUtil.isStringEmpty(tableObj.getTableHeader()))
{
%>
<tr>
<td colspan="<%=tableObj.getColumnList().size()+1%>">
<%
out.print(tableObj.getTableHeader());
%>
</td>
</tr>
<% 
}
%>

<tr><td colspan="<%=tableObj.getColumnList().size()+1%>">

<%
if (tableObj.isTopPageBarShow()) 
{ 
%>
    <jsp:include page="page.jsp" flush="true"></jsp:include>
<% 
}
%>
</td></tr>


<%
if(!tableObj.getHeaderRowList().isEmpty())
{
    HeaderRow row;
    HeaderColumn column;
    for(int i=0; i< tableObj.getHeaderRowList().size(); i++)
    {
        row = tableObj.getHeaderRowList().get(i);
        %>
        <tr>
        <%
        for(int j=0; j<row.getHeaderColumnList().size(); j++)
        {
            column = row.getHeaderColumnList().get(j);
            %>
            <td class="report_td_title_serialNumber" colspan=<%=column.getColspan()%>>
             <%
             out.print(IReportUtil.transHtml(column.getValue()));
             %>
            </td>
            <%
        }
        %>
        </tr>
        <%
    }
}
%>


			<tr>
			<% 
			if(!tableObj.isFlexTable() && tableObj.isSerialNumShow())
			{ 
			%>
				<td class="td_list_title_left">&nbsp;&nbsp;&nbsp;&nbsp;	</td>
			<%	
			}
					int tableWidth = 0;
					for (int i = 0; i < tableObj.getColumnList().size(); i++) {
						IRColumn columnObj = (IRColumn)tableObj.getColumnList().get(i);
						tableWidth = tableWidth + Integer.valueOf(columnObj.getWidth());
					}
					for (int i = 0; i < tableObj.getColumnList().size(); i++) {
						IRColumn columnObj = (IRColumn)tableObj.getColumnList().get(i);
	  			 %>
					<td class="report_td_title_serialNumber" width="<%=Integer.valueOf(columnObj.getWidth()) * 99 / tableWidth%>%">
					<% 
					   if(!tableObj.isFlexTable())
					   { 
					   		if (columnObj.getSortable().equals("true"))
		                    {
					%>
						         <a style="cursor:pointer;color:#464646;font-weight:bold;font-family:arial,'宋体';"  title="<s:text name='page.sort'/>" href="javascript:changeSort('<%=columnObj.getField() %>','<%=strPaginator%>')"><%out.print(columnObj.getHeader()); %></a>
						        <%if (columnObj.getField().equals(tableObj.getOrderInfo().getOrderField())) {
								if (tableObj.getOrderInfo().getOrderType().equals("ASC")) {
								%>
									<img src="<s:url value='/iReport/images/vsm_sort_asc.gif' includeParams='none' />" >
								<%
								}
								if (tableObj.getOrderInfo().getOrderType().equals("DESC")) {
								%>
									<img src="<s:url value='/iReport/images/vsm_sort_desc.gif' includeParams='none' />" >
							    <%	  
							  }
							  }
						}
						else
						{
						%>
						<font style="color:#464646;font-weight:bold;font-family:arial,'宋体';">
						<%
							
							out.print(columnObj.getHeader());
						%>
						</font>
						<%	
						}
						}
						else
						{
						
							if(IReportConfCheckUtil.isStringEmpty(columnObj.getDataDrillAction()))
						
							{
						    %>	
						    <font style="color:#464646;font-weight:bold;font-family:arial,'宋体';">
						    <% 	
								out.print(columnObj.getHeader());
						    %>
						    </font>
						    <%	
							}
							else
							{
								String outPrintValue = "<a style='cursor:pointer;color:#464646;font-weight:bold;font-family:arial,'宋体';' href=\"javascript:window.open('"+LegendUtil.changeToWOS(basePath+"/"+columnObj.getDataDrillAction())+"')\">"+columnObj.getHeader()+"</a>";
		    					out.print(outPrintValue);
							}
						}
							%>
					</td>
				<% 
					}							
				%>
			</tr>
			<% 
			if(null != tableObj.getGroupTableCellNodeList())
			{
				StringBuilder builder = new StringBuilder() ;
				ClassCount count = new ClassCount() ;
				TableGroupShowUtil.showTableCellNode(tableObj , tableObj.getGroupTableCellNodeList() , count , tableObj.getColumnList() , basePath , builder , 0) ;
				out.print(builder.toString()) ;
			}
			else 
			{
			if (tableObj.getCellOjbListMap() == null || tableObj.getCellOjbListMap().isEmpty())    
			{
			%>
			<tr>
				<td class="report_td_list_resultContent" colspan="<%=tableObj.getColumnList().size() + 1%>">
					<s:text name="page.nodata"/>
				</td>
			</tr>
			<% 
			}
			List<TableCellObj[]> dataSet = null;
			for(String groupValue : tableObj.getGroupKeyList())
			{
			    dataSet = tableObj.getCellOjbListMap().get(groupValue);
			
			    for (int i = 0; i < dataSet.size(); i++)
				{
					if (i%2 == 0)
					{
					%>
						<tr class="ireport_tr_line2">
					<%  
					}
					else
					{%>
						<tr class="ireport_tr_line1"><%
					} 
					if(!tableObj.isFlexTable() && tableObj.isSerialNumShow())
					{ %>
						<td class="td_sn">
						<%out.print(i + 1);%>&nbsp;
						</td>
				<%  } 
				    for (int j = 0; j < tableObj.getColumnList().size(); j++) 
				    {
							TableCellObj[] column = dataSet.get(i);
							String colTooltips = tableObj.getColumnList().get(j).getTooltips();
							IRColumn dcolumn = tableObj.getColumnList().get(j);
							if(tableObj.isFlexTable())
							{
								if(0 == j)
								{
					%>
					<td class="ireport_table_td" style="text-align:center">
					<%			}
								else
								{
								%>
								<td class="ireport_table_td" style="text-align:center">
								<% 
								} 		
							}
							else 
							{
							    if(0 == j && !groupValue.equals(ReportConstants.DEFAULT_GROUP_NAME))
								{
							        if(0 == i)
							        {
							            %>
										<td class="ireport_table_td" rowspan="<%=dataSet.size() %>" <%=tableObj.getColumnList().get(j).getTextAlignStyle()  %> >
										<%
							        }
							        else
							        {
							            continue;
							        }
								}
							    else
							    {
							        %>
							        <td class="ireport_table_td" <%=tableObj.getColumnList().get(j).getTextAlignStyle()  %> >
							        <%
							    }
							}
							
							try
							{
							    String outPrintValue = "";
							    if(false == IReportConfCheckUtil.isStringEmpty(column[j].getImgPath()))
							    {
							        outPrintValue ="<img border=\"0\" src=\"" + column[j].getImgPath() + "\" >";
							    }
							    else
							    {
							        outPrintValue = (column[j].getDataText());
							    }
								
								if(!IReportConfCheckUtil.isStringEmpty(column[j].getUrlText()))
								{
								    if(column[j].getDataTextList().isEmpty() || (false == IReportConfCheckUtil.isStringEmpty(column[j].getImgPath())))
									{
									    String urlText = column[j].getUrlText();
										if(!IReportConfCheckUtil.isStringEmpty(column[j].getDataDrillCond()))
										{
											if(urlText.indexOf("&") > 0)
	            							{
	                							urlText += "&";
	            							}	
	            							else
	            							{
	            								urlText += "?";
	            							}
	            							urlText += column[j].getDataDrillCond();
										}
										if(!IReportConfCheckUtil.isStringEmpty(dcolumn.getDataDrillTitle()))
										{
	            							urlText += "&dataDrillTitle="+dcolumn.getDataDrillTitle();
										}
									    if(dcolumn.isUserJavaScript())  
										{
								        	outPrintValue = "<a href=\"#\" onclick=\""+urlText+"\">"+outPrintValue+"</a>";
								     	}
								     	else
								     	{
											outPrintValue = "<a href=\"javascript:window.open(('"+LegendUtil.changeToWOS(basePath+"/"+urlText).replace("'", "\\'").replace("\"", "\\&quot;")+"'),'_blank');void(0);\">"+outPrintValue+"</a>";
										}
									}
								    else
								    {
								        outPrintValue = "";
								     	if(dcolumn.isUserJavaScript())
								        {
								        	outPrintValue += "<a href=\"#\" onclick=\""+column[j].getUrlTextList().get(0)+"\">"+(column[j].getDataTextList().get(0))+"</a>";
								     	}
								     	else
								     	{
								     		outPrintValue += "<a href=\"javascript:window.open(('"+LegendUtil.changeToWOS(basePath+"/"+column[j].getUrlTextList().get(0)+"&dataDrillTitle="+dcolumn.getDataDrillTitle()).replace("'", "\\'").replace("\"", "\\&quot;")+"'),'_blank');void(0);\">"+(column[j].getDataTextList().get(0))+"</a>";
								     	}
								     	for(int k=1;k<column[j].getDataTextList().size();k++)
								     	{
								     	   if(dcolumn.isUserJavaScript())
								     	  {
								           	outPrintValue += " | <a href=\"#\" onclick=\""+column[j].getUrlTextList().get(k)+"\">"+(column[j].getDataTextList().get(k))+"</a>";
								     	  }
								     	  else{
								     	   	outPrintValue += " | <a href=\"javascript:window.open(('"+LegendUtil.changeToWOS(basePath+"/"+column[j].getUrlTextList().get(k)+"&dataDrillTitle="+dcolumn.getDataDrillTitle()).replace("'", "\\'").replace("\"", "\\&quot;")+"'),'_blank');void(0);\">"+(column[j].getDataTextList().get(k))+"</a>";
								     	  }
								     	}
								    }
								    out.print(IReportUtil.transHtml(outPrintValue));
								}
								else if (colTooltips.length() != 0 && outPrintValue.length() > Integer.valueOf(colTooltips))
								{
									%>
									<%
										String title = AticUtil.htmlDecode(outPrintValue);
										String subDecodeStr = title.substring(0, Integer.valueOf(colTooltips));
										String subOutPrintValue = AticUtil.htmlEncodeCore(subDecodeStr);
									%>
									<a id="toolTip<%=i%>" style="color:#000000;"><%=subOutPrintValue%>...</a>
									<script type="text/javascript">
									var strToolTip ="toolTip<%=i%>";
									var buffer="<%=title%>";
									if (buffer.length > 0)
									{
									  var titleBuffer = '';
									  var str = ''; 
								      for(var n = 0; n < buffer.length;n++)
								      {
								        str = buffer.substring(n,n+1);
								        titleBuffer+= str;
								        if(n!=0 && n%75==0)
								         {
								          titleBuffer+=" ";
								         }
								      }
								      $("#"+ strToolTip).attr("title", titleBuffer);
								    }

									</script>		
									<% 
								}
								else
								{
									
									out.print(IReportUtil.transHtml(outPrintValue));
								}
							}
							catch(Exception e)
							{
							    out.print(IReportUtil.transHtml(column[j].toString()));
							}
							%>
						</td>
					<% 
						}
					%>
				</tr>
<% 
	}
	}
}
%>
<%
if (tableObj.isPageShow()) 
{ 
%>	
<tr><td colspan="<%=tableObj.getColumnList().size()+1%>">
	
<jsp:include page="page.jsp" flush="true"></jsp:include>
</td></tr>
<% 
}
%>
<%
if(!IReportConfCheckUtil.isStringEmpty(tableObj.getTableFooter()))
{
%>
<tr>
<td colspan="<%=tableObj.getColumnList().size()+1%>">
<%
out.print(tableObj.getTableFooter().length());
%>
</td>
</tr>
<% 
}
%>
		</table>
<script type="text/javascript">
function jsObject(url)
{
	var retVal = {};
	var params = url.split("&");
	for(var i=0;i<params.length;i++)
	{
		var kv=params[i].split("=");
		var key=kv[0];
		var value=kv[1];
		eval("retVal."+key+"='"+value+"'");	
	}
	return retVal;
}
	var JS_IREPORT_EXT="${IREPORT_EXT}";
	
	function IsNum(s)
	{
	    if(s!=null){
	        var r,re;
			
	        re = /\d*/i; 
	        r = s.match(re);
	        return (r==s)?true:false;
	    }
	    return false;
	}

    
	function goPageNum(obj,params)
	{
		var paginator = jsObject(params);
		
		var oChildren = jQuery(obj).parent().children();
		var pageNum =oChildren[4].value;
                	
	        var pageSize = paginator.pageSize;
		var totalPageNum = paginator.totalPageNum;
		var sessionId = paginator.sessionId;
		var index = paginator.index;
	    if("" == pageNum || null == pageNum)
	    {
	    	pageNum = 1;
	    }
	    if(pageNum < 1){
	        pageNum = 1;
	    }
		if(pageNum * 1 > totalPageNum)
		{
			pageNum = totalPageNum;
		}
		
		var orderField = paginator.orderField;
		var orderType = paginator.orderType;
		var queryTableUrl = "<s:url value='/atic/ireport/queryTable.do' includeParams='none' />";
		var url=queryTableUrl+"?tableId="+paginator.tableId+"&pageNum=" + pageNum 
								+ "&pageSize=" + pageSize
								+ "&sessionId=" + sessionId
								+ "&orderField=" + orderField
								+ "&orderType=" + orderType
								+ "&index=" + index;	
		
		$("#"+paginator.tablePanel).load(url);													
    }
    
    function switchPageSize(obj,params)
	{
		var paginator = jsObject(params);
		var orderField = paginator.orderField;
		var orderType = paginator.orderType;
		
		var pageSize = (obj.value=="" || !IsNum(obj.value))?<%=tableObj.getPageSize()%>:obj.value;
		if(IsNum(obj.value) && obj.value >100){
		pageSize=100;
		}
		
		var pageNum = 1;
		var sessionId = paginator.sessionId;
		var index = paginator.index;
		var queryTableUrl = "<s:url value='/atic/ireport/queryTable.do' includeParams='none' />";
		var url=queryTableUrl+"?tableId="+paginator.tableId+"&pageNum=" + pageNum 
								+ "&pageSize=" + pageSize
								+ "&sessionId=" + sessionId
								+ "&orderField=" + orderField
								+ "&orderType=" + orderType
								+ "&index=" + index;								
	$("#"+paginator.tablePanel).load(url);							
	}
	
    function noPermitInput(e){     
        var evt = window.event || e ; 
	    var k = evt.keyCode || evt.charCode;
	    var isSpecialKey = k == 9 || k == 13  || k == 40 || k == 27 ||
			(k == 16) || (k == 17) ||(k >= 18 && k <= 20) ||
			(k >= 33 && k <= 35) ||(k >= 36 && k <= 39) ||(k >= 44 && k <= 45);  
        if(isIE()){
            if(k < 48 && k!=13 && k!=8 || k > 57){  

            evt.returnValue=false; 
            } 
        }else{
            if(k < 48 && k!=13 && k!=8 || k > 57){   
			
            evt.preventDefault(); 
            }  
        }
	}   
	function isIE() {   
     if(window.navigator.userAgent.toLowerCase().indexOf("msie") >= 1)   
        return true;   
     else   
        return false;   
	}    
	
	function pageSubmit(pageNum,params)
	{
		var paginator = jsObject(params);
		var orderField = paginator.orderField;
		var orderType = paginator.orderType;
		var pageSize = paginator.pageSize;
		var sessionId = paginator.sessionId;
		var index = paginator.index;
		var queryTableUrl = "<s:url value='/atic/ireport/queryTable.do' includeParams='none' />";
		var url=queryTableUrl+"?tableId="+paginator.tableId+"&pageNum=" + pageNum 
								+ "&pageSize=" + pageSize
								+ "&sessionId=" + sessionId
								+ "&orderField=" + orderField
								+ "&orderType=" + orderType
								+ "&index=" + index;
		$("#"+paginator.tablePanel).load(url);								
	} 
	
	
	function changeSort(orderField,params)
	{
		var paginator = jsObject(params);
		var oldOrderField = paginator.orderField; 
		var orderType = paginator.orderType; 
		if (orderField == oldOrderField) {
		
			if (orderType == "DESC") {
				orderType = "ASC";
			} else {
				orderType = "DESC";
			}
		} else {
			orderType = "DESC";
		}	
		
		var pageSize = paginator.pageSize;
		var sessionId = paginator.sessionId;
		var index = paginator.index;
		var pageNum = 1;
		var queryTableUrl = "<s:url value='/atic/ireport/queryTable.do' includeParams='none' />";
		var url=queryTableUrl+"?tableId="+paginator.tableId+"&pageNum=" + pageNum 
								+ "&pageSize=" + pageSize
								+ "&sessionId=" + sessionId
								+ "&orderField=" + orderField
								+ "&orderType=" + orderType
								+ "&index=" + index;									
		$("#"+paginator.tablePanel).load(url);
	} 
</script>	
</s:i18n>
